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=d1245ff956ddb381481446974ee6df1f21dee546;hb=3ee2fdf1cb2047b3c4eda153ce1e9ac2b24f6f9c;hp=bcb745e08acb95cc5cb6badf29209d970c4b7adf;hpb=de6db61267ed21ac93c95813b7cfc49fd85ad28a;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 bcb745e08..d1245ff95 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2012 Mathieu Baudier + * Copyright (C) 2007-2012 Argeo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.aether.AetherTemplate; +import org.argeo.slc.aether.ArtifactIdComparator; import org.argeo.slc.repo.ArtifactIndexer; import org.argeo.slc.repo.JarFileIndexer; import org.argeo.slc.repo.RepoConstants; @@ -53,22 +54,19 @@ 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 String parentPomCoordinates = "org.argeo:parent:1.2.0"; private Set excludedArtifacts = new HashSet(); private Repository repository; private String workspace; - private String artifactBasePath = RepoConstants.ARTIFACTS_BASE_PATH; + private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); private JarFileIndexer jarFileIndexer = new JarFileIndexer(); - private Comparator artifactComparator = new Comparator() { - public int compare(Artifact o1, Artifact o2) { - return o1.getArtifactId().compareTo(o2.getArtifactId()); - } - }; + private Comparator artifactComparator = new ArtifactIdComparator(); public void run() { // resolve @@ -86,10 +84,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); @@ -112,7 +113,8 @@ public class ImportMavenDependencies implements Runnable { registeredArtifacts, pomArtifact); Artifact sdkArtifact = new DefaultArtifact(distCoordinates); String sdkPom = MavenConventionsUtils.artifactsAsDependencyPom( - sdkArtifact, registeredArtifacts); + sdkArtifact, registeredArtifacts, new DefaultArtifact( + parentPomCoordinates)); if (log.isDebugEnabled()) log.debug("Gathered " + registeredArtifacts.size() + " artifacts:\n" + sdkPom); @@ -134,11 +136,12 @@ public class ImportMavenDependencies implements Runnable { if (log.isDebugEnabled()) { log.debug("Resolved " + artifacts.size() + " artifacts"); -// 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(); } /* @@ -178,13 +181,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 @@ -198,8 +210,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); @@ -216,7 +227,8 @@ public class ImportMavenDependencies implements Runnable { jarFileIndexer.index(fileNode); jcrSession.save(); - addPdeSource(jcrSession, artifact, jarFile, artifactsWithoutSources); + addPdeSource(jcrSession, artifact, jarFile, + artifactsWithoutSources); jcrSession.save(); if (log.isDebugEnabled()) @@ -250,7 +262,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()); @@ -259,22 +271,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); @@ -291,8 +303,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()) { @@ -351,4 +363,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; + } + }