X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2FImportMavenDependencies.java;h=0bda72b7e87e91d272eaa86e0cf7d5b99f767345;hb=418a82cb85b477af9f2b8d850ca14c8512546643;hp=e0a8d067b886237d4db2bfbaccb9b3fb6fec0c81;hpb=0daf700ed7880d6496c5cab6e5aafa71663894fb;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java index e0a8d067b..0bda72b7e 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/ImportMavenDependencies.java @@ -53,7 +53,8 @@ public class ImportMavenDependencies implements Runnable { .getLog(ImportMavenDependencies.class); private AetherTemplate aetherTemplate; - private String rootCoordinates; + private String rootCoordinates = "org.argeo.dep:versions-all:pom:1.2.0"; + private String distCoordinates = "org.argeo.tp:dist:pom:1.3.0"; private Set excludedArtifacts = new HashSet(); private Repository repository; @@ -74,6 +75,10 @@ public class ImportMavenDependencies implements Runnable { Set artifacts = resolveDistribution(); // sync + sync(artifacts); + } + + void sync(Set artifacts) { Session session = null; try { session = JcrUtils.loginOrCreateWorkspace(repository, workspace); @@ -81,10 +86,13 @@ public class ImportMavenDependencies implements Runnable { NodeIterator nit = session.getNode(artifactBasePath).getNodes(); while (nit.hasNext()) { Node node = nit.nextNode(); - if (node.isNodeType(NodeType.NT_FOLDER)) + if (node.isNodeType(NodeType.NT_FOLDER) + || node.isNodeType(NodeType.NT_UNSTRUCTURED)) node.remove(); } session.save(); + + // sync syncDistribution(session, artifacts); } catch (Exception e) { throw new SlcException("Cannot import distribution", e); @@ -93,7 +101,11 @@ public class ImportMavenDependencies implements Runnable { } } - private Set resolveDistribution() { + /** + * Generate a POM with all the artifacts declared in root coordinates as + * dependencies AND in dependency management. + */ + void createDistPom() { try { Artifact pomArtifact = new DefaultArtifact(rootCoordinates); @@ -101,38 +113,58 @@ public class ImportMavenDependencies implements Runnable { artifactComparator); MavenConventionsUtils.gatherPomDependencies(aetherTemplate, registeredArtifacts, pomArtifact); + Artifact sdkArtifact = new DefaultArtifact(distCoordinates); + String sdkPom = MavenConventionsUtils.artifactsAsDependencyPom( + sdkArtifact, registeredArtifacts); if (log.isDebugEnabled()) log.debug("Gathered " + registeredArtifacts.size() - + " artifacts"); + + " artifacts:\n" + sdkPom); + } catch (Exception e) { + throw new SlcException("Cannot resolve distribution", e); + } + } - // Resolve and add non-optional dependencies + /** Returns all transitive dependencies of dist POM */ + private Set resolveDistribution() { + try { + Artifact distArtifact = new DefaultArtifact(distCoordinates); Set artifacts = new TreeSet(artifactComparator); - for (Artifact artifact : registeredArtifacts) { - try { - Boolean wasAdded = addArtifact(artifacts, artifact); - if (wasAdded) { - DependencyNode node = aetherTemplate - .resolveDependencies(artifact); - addDependencies(artifacts, node, null); - } - } catch (Exception e) { - log.error("Could not resolve dependencies of " + artifact - + ": " + e.getCause().getMessage()); - } - } + DependencyNode node = aetherTemplate + .resolveDependencies(distArtifact); + addDependencies(artifacts, node, null); - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Resolved " + artifacts.size() + " artifacts"); - // distribution descriptor - // Properties distributionDescriptor = - // generateDistributionDescriptor(artifacts); - // ByteArrayOutputStream out = new ByteArrayOutputStream(); - // distributionDescriptor.store(out, ""); - // log.debug(new String(out.toByteArray())); - // out.close(); + // Properties distributionDescriptor = + // generateDistributionDescriptor(artifacts); + // ByteArrayOutputStream out = new ByteArrayOutputStream(); + // distributionDescriptor.store(out, ""); + // log.debug(new String(out.toByteArray())); + // out.close(); + } + /* + * for (Artifact artifact : registeredArtifacts) { try { Boolean + * wasAdded = addArtifact(artifacts, artifact); if (wasAdded) { + * DependencyNode node = aetherTemplate + * .resolveDependencies(artifact); addDependencies(artifacts, node, + * null); } } catch (Exception e) { + * log.error("Could not resolve dependencies of " + artifact + ": " + * + e.getCause().getMessage()); } + * + * } + * + * if (log.isDebugEnabled()) log.debug("Resolved " + + * artifacts.size() + " artifacts"); + * + * // distribution descriptor // Properties distributionDescriptor = + * // generateDistributionDescriptor(artifacts); // + * ByteArrayOutputStream out = new ByteArrayOutputStream(); // + * distributionDescriptor.store(out, ""); // log.debug(new + * String(out.toByteArray())); // out.close(); + */ return artifacts; } catch (Exception e) { throw new SlcException("Cannot resolve distribution", e); @@ -150,13 +182,22 @@ public class ImportMavenDependencies implements Runnable { return distributionDescriptor; } - private void syncDistribution(Session jcrSession, Set artifacts) { + /** Write artifacts to the target workspace, skipping excluded ones */ + protected void syncDistribution(Session jcrSession, Set artifacts) { Set artifactsWithoutSources = new TreeSet( artifactComparator); Long begin = System.currentTimeMillis(); try { - JcrUtils.mkdirs(jcrSession, artifactBasePath); + JcrUtils.mkfolders(jcrSession, artifactBasePath); artifacts: for (Artifact artifact : artifacts) { + // skip excluded + if (excludedArtifacts.contains(artifact.getGroupId() + ":" + + artifact.getArtifactId())) { + if (log.isDebugEnabled()) + log.debug("Exclude " + artifact); + continue artifacts; + } + File jarFile = MavenConventionsUtils.artifactToFile(artifact); if (!jarFile.exists()) { log.warn("Generated file " + jarFile + " for " + artifact @@ -170,8 +211,7 @@ public class ImportMavenDependencies implements Runnable { .artifactParentPath(artifactBasePath, artifact); Node parentNode; if (!jcrSession.itemExists(parentPath)) - parentNode = JcrUtils.mkdirs(jcrSession, parentPath, - NodeType.NT_FOLDER); + parentNode = JcrUtils.mkfolders(jcrSession, parentPath); else parentNode = jcrSession.getNode(parentPath); @@ -188,7 +228,8 @@ public class ImportMavenDependencies implements Runnable { jarFileIndexer.index(fileNode); jcrSession.save(); - addPdeSource(jcrSession, artifact, jarFile, artifacts); + addPdeSource(jcrSession, artifact, jarFile, + artifactsWithoutSources); jcrSession.save(); if (log.isDebugEnabled()) @@ -222,7 +263,7 @@ public class ImportMavenDependencies implements Runnable { Artifact origSourceArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "sources", artifact.getExtension(), artifact.getVersion()); - Artifact targetSourceArtifact = new DefaultArtifact( + Artifact newSourceArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId() + ".source", artifact.getExtension(), artifact.getVersion()); @@ -231,22 +272,22 @@ public class ImportMavenDependencies implements Runnable { .getResolvedFile(origSourceArtifact); } catch (Exception e) { // also try artifact following the conventions - origSourceArtifact = targetSourceArtifact; + origSourceArtifact = newSourceArtifact; origSourceFile = aetherTemplate .getResolvedFile(origSourceArtifact); } - String parentPath = MavenConventionsUtils.artifactParentPath( - artifactBasePath, artifact); - Node parentNode = JcrUtils.mkdirs(session, parentPath, - NodeType.NT_FOLDER); + String newSourceParentPath = MavenConventionsUtils + .artifactParentPath(artifactBasePath, newSourceArtifact); + Node newSourceParentNode = JcrUtils.mkfolders(session, + newSourceParentPath); NameVersion bundleNameVersion = RepoUtils .readNameVersion(artifactFile); RepoUtils.packagesAsPdeSource(origSourceFile, bundleNameVersion, out); - String targetSourceFileName = MavenConventionsUtils - .artifactFileName(targetSourceArtifact); - JcrUtils.copyBytesAsFile(parentNode, targetSourceFileName, + String newSourceFileName = MavenConventionsUtils + .artifactFileName(newSourceArtifact); + JcrUtils.copyBytesAsFile(newSourceParentNode, newSourceFileName, out.toByteArray()); } catch (Exception e) { log.error("Cannot add PDE source for " + artifact + ": " + e); @@ -263,8 +304,8 @@ public class ImportMavenDependencies implements Runnable { /** Recursively adds non optional dependencies */ private void addDependencies(Set artifacts, DependencyNode node, String ancestors) { - if (artifacts.contains(node.getDependency().getArtifact())) - return; + // if (artifacts.contains(node.getDependency().getArtifact())) + // return; String currentArtifactId = node.getDependency().getArtifact() .getArtifactId(); if (log.isDebugEnabled()) { @@ -323,4 +364,12 @@ public class ImportMavenDependencies implements Runnable { this.workspace = workspace; } + public void setDistCoordinates(String distCoordinates) { + this.distCoordinates = distCoordinates; + } + + public void setArtifactBasePath(String artifactBasePath) { + this.artifactBasePath = artifactBasePath; + } + }