You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by dj...@apache.org on 2011/03/22 23:01:41 UTC
svn commit: r1084372 - in /karaf/trunk: ./ tooling/features-maven-plugin/
tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/
tooling/features-maven-plugin/src/main/resources/META-INF/plexus/
Author: djencks
Date: Tue Mar 22 22:01:41 2011
New Revision: 1084372
URL: http://svn.apache.org/viewvc?rev=1084372&view=rev
Log:
KARAF-424 use maven 3 dependency resolution using aether. Require maven 3
Modified:
karaf/trunk/pom.xml
karaf/trunk/tooling/features-maven-plugin/pom.xml
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesFileMojo.java
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
karaf/trunk/tooling/features-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Modified: karaf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Tue Mar 22 22:01:41 2011
@@ -97,7 +97,7 @@
</mailingLists>
<prerequisites>
- <maven>2.2.1</maven>
+ <maven>3.0.3</maven>
</prerequisites>
<properties>
Modified: karaf/trunk/tooling/features-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/pom.xml?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/pom.xml (original)
+++ karaf/trunk/tooling/features-maven-plugin/pom.xml Tue Mar 22 22:01:41 2011
@@ -40,18 +40,52 @@
</properties>
<dependencies>
+ <!-- Aether resolver support -->
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-jdk14</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>3.0.3</version>
+ <!--<scope>provided</scope>-->
</dependency>
<dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-util</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
+ <artifactId>maven-artifact</artifactId>
+ <version>3.0.3</version>
+ <!--<scope>provided</scope>-->
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0.3</version>
+ <!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.0.3</version>
+ <!--<scope>provided</scope>-->
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
</dependency>
+ <!--<dependency>-->
+ <!--<groupId>org.apache.maven</groupId>-->
+ <!--<artifactId>maven-project</artifactId>-->
+ <!--<version>3.0.3</version>-->
+ <!--</dependency>-->
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
@@ -113,6 +147,7 @@
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
+
</dependencies>
<build>
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesFileMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesFileMojo.java?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesFileMojo.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesFileMojo.java Tue Mar 22 22:01:41 2011
@@ -371,7 +371,7 @@ public class GenerateFeaturesFileMojo ex
protected String getBestVersionForArtifact(Artifact artifact, List<ArtifactVersion> versions) throws ArtifactMetadataRetrievalException {
if (versions.size() == 0) {
- throw new ArtifactMetadataRetrievalException("No wrapper bundle available for " + artifact);
+ throw new ArtifactMetadataRetrievalException("No wrapper bundle available for ", null, artifact);
}
Collections.sort(versions, Collections.reverseOrder());
//check for same version
@@ -387,7 +387,7 @@ public class GenerateFeaturesFileMojo ex
return version.toString();
}
}
- throw new ArtifactMetadataRetrievalException("No suitable version found for " + artifact + " wrapper bundle");
+ throw new ArtifactMetadataRetrievalException("No suitable version found for " + artifact + " wrapper bundle", null, artifact);
}
private boolean isProvided(Artifact bundle) {
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateFeaturesXmlMojo2.java Tue Mar 22 22:01:41 2011
@@ -40,21 +40,15 @@ import java.util.Set;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
-import org.apache.karaf.deployer.kar.KarArtifactInstaller;
import org.apache.karaf.features.internal.model.Dependency;
import org.apache.karaf.features.internal.model.Feature;
import org.apache.karaf.features.internal.model.Bundle;
import org.apache.karaf.features.internal.model.Features;
import org.apache.karaf.features.internal.model.JaxbUtil;
import org.apache.karaf.features.internal.model.ObjectFactory;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -63,20 +57,36 @@ import org.apache.maven.plugin.logging.L
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.shared.dependency.tree.DependencyNode;
-import org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.collection.CollectRequest;
+import org.sonatype.aether.collection.CollectResult;
+import org.sonatype.aether.collection.DependencyCollectionException;
+import org.sonatype.aether.collection.DependencyGraphTransformer;
+import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.resolution.ArtifactRequest;
+import org.sonatype.aether.resolution.ArtifactResult;
+import org.sonatype.aether.util.DefaultRepositorySystemSession;
+import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
+import org.sonatype.aether.util.graph.transformer.ConflictMarker;
+import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
+import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
import org.xml.sax.SAXException;
+import static org.apache.karaf.deployer.kar.KarArtifactInstaller.FEATURE_CLASSIFIER;
+
/**
* Generates the features XML file
+ * NB this requires a recent maven-install-plugin such as 2.3.1
*
* @version $Revision: 1.1 $
* @goal generate-features-xml2
@@ -91,7 +101,7 @@ public class GenerateFeaturesXmlMojo2 ex
/**
* The (optional) input feature.file to extend
*
- * @parameter default-value="${project.build.directory}/src/main/feature/feature.xml"
+ * @parameter default-value="${project.basedir}/src/main/feature/feature.xml"
*/
private File inputFile;
@@ -159,44 +169,39 @@ public class GenerateFeaturesXmlMojo2 ex
protected MavenProjectHelper projectHelper;
/**
- * The artifact factory to use.
+ * The entry point to Aether, i.e. the component doing all the work.
*
* @component
- * @required
- * @readonly
*/
- protected ArtifactFactory artifactFactory;
+ private RepositorySystem repoSystem;
+
/**
- * The artifact repository to use.
+ * The current repository/network configuration of Maven.
*
- * @parameter expression="${localRepository}"
- * @required
+ * @parameter default-value="${repositorySystemSession}"
* @readonly
*/
- private ArtifactRepository localRepository;
+ private RepositorySystemSession repoSession;
/**
- * The artifact metadata source to use.
+ * The project's remote repositories to use for the resolution of project dependencies.
*
- * @component
- * @required
+ * @parameter default-value="${project.remoteProjectRepositories}"
* @readonly
*/
- private ArtifactMetadataSource artifactMetadataSource;
+ private List<RemoteRepository> projectRepos;
/**
- * The artifact collector to use.
+ * The project's remote repositories to use for the resolution of plugins and their dependencies.
*
- * @component
- * @required
+ * @parameter default-value="${project.remotePluginRepositories}"
* @readonly
*/
- private ArtifactCollector artifactCollector;
+ private List<RemoteRepository> pluginRepos;
+
- //all dependencies
- protected Set<Artifact> dependencyArtifacts;
//dependencies we are interested in
- protected Set<Artifact> localDependencies;
+ protected Map<Artifact, String> localDependencies;
//log of what happened during search
protected String treeListing;
@@ -257,10 +262,11 @@ public class GenerateFeaturesXmlMojo2 ex
}
feature.setVersion(project.getArtifact().getBaseVersion());
feature.setResolver(resolver);
- for (Artifact artifact : localDependencies) {
+ for (Map.Entry<Artifact, String> entry : localDependencies.entrySet()) {
+ Artifact artifact = entry.getKey();
if (isFeature(artifact)) {
- if (aggregateFeatures && KarArtifactInstaller.FEATURE_CLASSIFIER.equals(artifact.getClassifier())) {
- File featuresFile = artifact.getFile();
+ if (aggregateFeatures && FEATURE_CLASSIFIER.equals(artifact.getClassifier())) {
+ File featuresFile = resolve(artifact);
if (featuresFile == null || !featuresFile.exists()) {
throw new MojoExecutionException("Cannot locate file for feature: " + artifact + " at " + featuresFile);
}
@@ -276,14 +282,14 @@ public class GenerateFeaturesXmlMojo2 ex
}
} else {
String bundleName;
- if (artifact.getType().equals("jar")) {
+ if (artifact.getExtension().equals("jar")) {
bundleName = String.format("mvn:%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
} else {
- bundleName = String.format("mvn:%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getType());
+ bundleName = String.format("mvn:%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getExtension());
}
Bundle bundle = objectFactory.createBundle();
bundle.setLocation(bundleName);
- if ("runtime".equals(artifact.getScope())) {
+ if ("runtime".equals(entry.getValue())) {
bundle.setDependency(true);
}
if (startLevel != null) {
@@ -307,6 +313,29 @@ public class GenerateFeaturesXmlMojo2 ex
getLogger().info("...done!");
}
+ private File resolve(Artifact artifact) {
+ ArtifactRequest request = new ArtifactRequest();
+ request.setArtifact(artifact);
+ request.setRepositories(projectRepos);
+
+ getLog().debug("Resolving artifact " + artifact +
+ " from " + projectRepos);
+
+ ArtifactResult result;
+ try {
+ result = repoSystem.resolveArtifact(repoSession, request);
+ } catch (org.sonatype.aether.resolution.ArtifactResolutionException e) {
+ getLog().warn("could not resolve " + artifact, e);
+ return null;
+ }
+
+ getLog().debug("Resolved artifact " + artifact + " to " +
+ result.getArtifact().getFile() + " from "
+ + result.getRepository());
+ return result.getArtifact().getFile();
+ }
+
+
private Features readFeaturesFile(File featuresFile) throws XMLStreamException, JAXBException, IOException {
Features features;
InputStream in = new FileInputStream(featuresFile);
@@ -323,36 +352,30 @@ public class GenerateFeaturesXmlMojo2 ex
protected void getDependencies(MavenProject project, boolean useTransitiveDependencies) throws MojoExecutionException {
- DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener(getLogger());
-
- DependencyNode rootNode;
- try {
- Map managedVersions = project.getManagedVersionMap();
-
- Set dependencyArtifacts = project.getDependencyArtifacts();
-
- if (dependencyArtifacts == null) {
- dependencyArtifacts = project.createArtifacts(artifactFactory, null, null);
- }
- ArtifactResolutionResult result = artifactCollector.collect(dependencyArtifacts, project.getArtifact(), managedVersions, localRepository,
- project.getRemoteArtifactRepositories(), artifactMetadataSource, null,
- Collections.singletonList(listener));
-
- this.dependencyArtifacts = result.getArtifacts();
- rootNode = listener.getRootNode();
- } catch (ArtifactResolutionException exception) {
- throw new MojoExecutionException("Cannot build project dependency tree", exception);
- } catch (InvalidDependencyVersionException e) {
- throw new MojoExecutionException("Invalid dependency version for artifact "
- + project.getArtifact());
- }
+ DependencyNode rootNode = getDependencyTree(RepositoryUtils.toArtifact(project.getArtifact()));
Scanner scanner = new Scanner();
scanner.scan(rootNode, useTransitiveDependencies);
- localDependencies = scanner.localDependencies.keySet();
+ localDependencies = scanner.localDependencies;
treeListing = scanner.getLog();
}
+ private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
+ try {
+ List<org.sonatype.aether.graph.Dependency> managedArtifacts = new ArrayList<org.sonatype.aether.graph.Dependency>();
+ CollectRequest collectRequest = new CollectRequest(new org.sonatype.aether.graph.Dependency(artifact, "compile"), null, projectRepos);
+ DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repoSession);
+ DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(),
+ new JavaEffectiveScopeCalculator(),
+ new JavaDependencyContextRefiner());
+ session.setDependencyGraphTransformer(transformer);
+ CollectResult result = repoSystem.collectDependencies(session, collectRequest);
+ return result.getRoot();
+ } catch (DependencyCollectionException e) {
+ throw new MojoExecutionException("Cannot build project dependency tree", e);
+ }
+ }
+
public void setLog(Log log) {
this.log = log;
}
@@ -364,7 +387,9 @@ public class GenerateFeaturesXmlMojo2 ex
return log;
}
+
private static class Scanner {
+
private static enum Accept {
ACCEPT(true, true),
PROVIDED(true, false),
@@ -387,75 +412,60 @@ public class GenerateFeaturesXmlMojo2 ex
}
}
- //all the dependencies needed for this car, with provided dependencies removed
- private final Map<Artifact, Set<Artifact>> localDependencies = new LinkedHashMap<Artifact, Set<Artifact>>();
+ //all the dependencies needed for this car, with provided dependencies removed. artifact to scope map
+ private final Map<Artifact, String> localDependencies = new LinkedHashMap<Artifact, String>();
//dependencies from ancestor cars, to be removed from localDependencies.
private final Set<Artifact> carDependencies = new LinkedHashSet<Artifact>();
private final StringBuilder log = new StringBuilder();
- public void scan(DependencyNode rootNode, boolean useTransitiveDependencies) {
- Set<Artifact> children = new LinkedHashSet<Artifact>();
- for (DependencyNode child : (List<DependencyNode>) rootNode.getChildren()) {
- scan(child, Accept.ACCEPT, useTransitiveDependencies, false, "", children);
+ public void scan(DependencyNode rootNode, boolean useTransitiveDependencies) throws MojoExecutionException {
+ for (DependencyNode child : rootNode.getChildren()) {
+ scan(child, Accept.ACCEPT, useTransitiveDependencies, false, "");
}
if (useTransitiveDependencies) {
localDependencies.keySet().removeAll(carDependencies);
}
}
- private void scan(DependencyNode rootNode, Accept parentAccept, boolean useTransitiveDependencies, boolean isFromCar, String indent, Set<Artifact> parentsChildren) {
- Artifact artifact = getArtifact(rootNode);
+ private void scan(DependencyNode dependencyNode, Accept parentAccept, boolean useTransitiveDependencies, boolean isFromFeature, String indent) throws MojoExecutionException {
+// Artifact artifact = getArtifact(rootNode);
- Accept accept = accept(artifact, parentAccept);
+ Accept accept = accept(dependencyNode, parentAccept);
if (accept.isContinue()) {
- Set<Artifact> children = localDependencies.get(artifact);
- if (isFromCar) {
- if (!isFeature(artifact)) {
- log.append(indent).append("from feature:").append(artifact).append("\n");
- carDependencies.add(artifact);
+ List<DependencyNode> children = dependencyNode.getChildren();
+ if (isFromFeature) {
+ if (!isFeature(dependencyNode)) {
+ log.append(indent).append("from feature:").append(dependencyNode).append("\n");
+ carDependencies.add(dependencyNode.getDependency().getArtifact());
} else {
- log.append(indent).append("is feature:").append(artifact).append("\n");
+ log.append(indent).append("is feature:").append(dependencyNode).append("\n");
}
} else {
- log.append(indent).append("local:").append(artifact).append("\n");
- if (carDependencies.contains(artifact)) {
- log.append(indent).append("already in feature, returning:").append(artifact).append("\n");
- parentsChildren.add(artifact);
+ log.append(indent).append("local:").append(dependencyNode).append("\n");
+ if (carDependencies.contains(dependencyNode.getDependency().getArtifact())) {
+ log.append(indent).append("already in feature, returning:").append(dependencyNode).append("\n");
return;
}
- parentsChildren.add(artifact);
- if (children == null) {
- children = new LinkedHashSet<Artifact>();
- localDependencies.put(artifact, children);
- }
- if (isFeature(artifact) || !useTransitiveDependencies) {
- isFromCar = true;
+ //TODO resolve scope conflicts
+ localDependencies.put(dependencyNode.getDependency().getArtifact(), dependencyNode.getDependency().getScope());
+ if (isFeature(dependencyNode) || !useTransitiveDependencies) {
+ isFromFeature = true;
}
}
- for (DependencyNode child : (List<DependencyNode>) rootNode.getChildren()) {
- scan(child, accept, useTransitiveDependencies, isFromCar, indent + " ", children);
+ for (DependencyNode child : children) {
+ scan(child, accept, useTransitiveDependencies, isFromFeature, indent + " ");
}
}
}
+
public String getLog() {
return log.toString();
}
- private Artifact getArtifact(DependencyNode rootNode) {
- Artifact artifact = rootNode.getArtifact();
- if (rootNode.getRelatedArtifact() != null) {
- artifact = rootNode.getRelatedArtifact();
- }
- return artifact;
- }
-
- private Accept accept(Artifact dependency, Accept previous) {
-// if (dependency.getGroupId().startsWith("org.apache.geronimo.genesis")) {
-// return Accept.STOP;
-// }
- String scope = dependency.getScope();
+ private Accept accept(DependencyNode dependency, Accept previous) {
+ String scope = dependency.getPremanagedScope();
if (scope == null || "runtime".equalsIgnoreCase(scope) || "compile".equalsIgnoreCase(scope)) {
return previous;
}
@@ -464,8 +474,12 @@ public class GenerateFeaturesXmlMojo2 ex
}
+ private static boolean isFeature(DependencyNode dependencyNode) {
+ return isFeature(dependencyNode.getDependency().getArtifact());
+ }
+
private static boolean isFeature(Artifact artifact) {
- return artifact.getType().equals("kar") || KarArtifactInstaller.FEATURE_CLASSIFIER.equals(artifact.getClassifier());
+ return artifact.getExtension().equals("kar") || FEATURE_CLASSIFIER.equals(artifact.getClassifier());
}
//------------------------------------------------------------------------//
@@ -638,6 +652,8 @@ public class GenerateFeaturesXmlMojo2 ex
if (overwriteChangedDependencies) {
writeDependencies(features, dependencyFile);
}
+ } else {
+ getLog().info(saveTreeListing());
}
} else {
@@ -657,9 +673,9 @@ public class GenerateFeaturesXmlMojo2 ex
Features removed = toFeatures(removedBundles, removedDependencys, objectFactory);
writeDependencies(removed, removedFile);
- File treeListing = saveTreeListing();
-
StringWriter out = new StringWriter();
+ out.write(saveTreeListing());
+
out.write("Dependencies have changed:\n");
if (!addedBundles.isEmpty() || ! addedDependencys.isEmpty()) {
out.write("\tAdded dependencies are saved here: " + addedFile.getAbsolutePath() + "\n");
@@ -673,7 +689,6 @@ public class GenerateFeaturesXmlMojo2 ex
JaxbUtil.marshal(Features.class, removed, out);
}
}
- out.write("\tTree listing is saved here: " + treeListing.getAbsolutePath() + "\n");
out.write("Delete " + dependencyFile.getAbsolutePath()
+ " if you are happy with the dependency changes.");
@@ -725,7 +740,7 @@ public class GenerateFeaturesXmlMojo2 ex
}
- protected File saveTreeListing() throws IOException {
+ protected String saveTreeListing() throws IOException {
File treeListFile = new File(filteredDependencyFile.getParentFile(), "treeListing.txt");
OutputStream os = new FileOutputStream(treeListFile);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
@@ -734,7 +749,7 @@ public class GenerateFeaturesXmlMojo2 ex
} finally {
writer.close();
}
- return treeListFile;
+ return "\tTree listing is saved here: " + treeListFile.getAbsolutePath() + "\n";
}
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GraphArtifactCollector.java Tue Mar 22 22:01:41 2011
@@ -33,6 +33,7 @@ import org.apache.maven.artifact.metadat
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.CyclicDependencyException;
import org.apache.maven.artifact.resolver.ResolutionListener;
@@ -41,6 +42,7 @@ import org.apache.maven.artifact.resolve
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver;
/**
* @version $Revision: 1.1 $
@@ -66,13 +68,17 @@ public class GraphArtifactCollector impl
List remoteRepositories,
ArtifactMetadataSource source,
ArtifactFilter filter,
- List listeners) throws ArtifactResolutionException {
+ List listeners) {
Map resolvedArtifacts = new HashMap();
ResolutionNode root = new ResolutionNode(originatingArtifact, remoteRepositories);
- root.addDependencies(artifacts, remoteRepositories, filter);
- recurse(root, resolvedArtifacts, managedVersions, localRepository,
- remoteRepositories, source, filter, listeners);
+ try {
+ root.addDependencies(artifacts, remoteRepositories, filter);
+ recurse(root, resolvedArtifacts, managedVersions, localRepository,
+ remoteRepositories, source, filter, listeners);
+ } catch (ArtifactResolutionException e) {
+ throw new RuntimeException(e);
+ }
Set set = new HashSet();
for (Iterator i = resolvedArtifacts.values().iterator(); i.hasNext();) {
@@ -80,13 +86,17 @@ public class GraphArtifactCollector impl
for (Iterator j = nodes.iterator(); j.hasNext();) {
ResolutionNode node = (ResolutionNode) j.next();
Artifact artifact = node.getArtifact();
- if (!node.equals(root) && node.isActive() && node.filterTrail(filter)
- // If it was optional and not a direct dependency,
- // we don't add it or its children, just allow the
- // update of the version and scope
- && (node.isChildOfRootNode() || !artifact.isOptional())) {
- artifact.setDependencyTrail(node.getDependencyTrail());
- set.add(node);
+ try {
+ if (!node.equals(root) && node.isActive() && node.filterTrail(filter)
+ // If it was optional and not a direct dependency,
+ // we don't add it or its children, just allow the
+ // update of the version and scope
+ && (node.isChildOfRootNode() || !artifact.isOptional())) {
+ artifact.setDependencyTrail(node.getDependencyTrail());
+ set.add(node);
+ }
+ } catch (OverConstrainedVersionException e) {
+ throw new RuntimeException(e);
}
}
}
@@ -432,4 +442,12 @@ public class GraphArtifactCollector impl
}
}
}
+
+ public ArtifactResolutionResult collect(Set<Artifact> artifacts, Artifact artifact, Map map, ArtifactResolutionRequest artifactResolutionRequest, ArtifactMetadataSource artifactMetadataSource, ArtifactFilter artifactFilter, List<ResolutionListener> resolutionListeners, List<ConflictResolver> conflictResolvers) {
+ return null;
+ }
+
+ public ArtifactResolutionResult collect(Set<Artifact> artifacts, Artifact artifact, Map map, ArtifactRepository artifactRepository, List<ArtifactRepository> artifactRepositories, ArtifactMetadataSource artifactMetadataSource, ArtifactFilter artifactFilter, List<ResolutionListener> resolutionListeners, List<ConflictResolver> conflictResolvers) {
+ return null;
+ }
}
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java Tue Mar 22 22:01:41 2011
@@ -20,9 +20,11 @@
package org.apache.karaf.tooling.features;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
@@ -48,6 +50,13 @@ import org.apache.maven.artifact.Artifac
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.resolution.ArtifactRequest;
+import org.sonatype.aether.resolution.ArtifactResolutionException;
+import org.sonatype.aether.resolution.ArtifactResult;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
/**
* Installs kar dependencies into a server-under-construction in target/assembly
@@ -108,9 +117,52 @@ public class InstallKarsMojo extends Moj
* @required
*/
protected String systemDirectory;
+
+ //Aether support
+ /**
+ * The entry point to Aether, i.e. the component doing all the work.
+ *
+ * @component
+ */
+ private RepositorySystem repoSystem;
+
+ /**
+ * The current repository/network configuration of Maven.
+ *
+ * @parameter default-value="${repositorySystemSession}"
+ * @readonly
+ */
+ private RepositorySystemSession repoSession;
+
+ /**
+ * The project's remote repositories to use for the resolution of plugins and their dependencies.
+ *
+ * @parameter default-value="${project.remoteProjectRepositories}"
+ * @readonly
+ */
+ private List<RemoteRepository> remoteRepos;
+
private String repoPath;
+ private CommentProperties startupProperties = new CommentProperties();
public void execute() throws MojoExecutionException, MojoFailureException {
+ if (startupPropertiesFile.exists()) {
+ try {
+ InputStream in = new FileInputStream(startupPropertiesFile);
+ try {
+ startupProperties.load(in);
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ throw new MojoFailureException("Could not open existing startup.properties file at " + startupPropertiesFile, e);
+ }
+ } else {
+ startupProperties.setHeader(Collections.singletonList("#Bundles to be started on startup, with startlevel"));
+ if (!startupPropertiesFile.getParentFile().exists()) {
+ startupPropertiesFile.getParentFile().mkdirs();
+ }
+ }
KarArtifactInstaller installer = new KarArtifactInstaller();
installer.setBasePath(workDirectory);
repoPath = unpackToLocalRepo ? localRepoDirectory : systemDirectory;
@@ -131,14 +183,121 @@ public class InstallKarsMojo extends Moj
}
}
if ("features".equals(artifact.getClassifier()) && "compile".equals(artifact.getScope())) {
- //TODO
+ File file = artifact.getFile();
+ try {
+ featuresService.addRepository(file.toURI());
+ } catch (Exception e) {
+ buf.append("Could not install feature: ").append(artifact.toString()).append("\n");
+ buf.append(e.getMessage()).append("\n\n");
+ }
}
}
+
+ byte[] buffer = new byte[4096];
+ for (String key: startupProperties.keySet()) {
+ String path = fromMaven(key);
+ File target = new File(repoPath + "/" + path);
+ if (!target.exists()) {
+ target.getParentFile().mkdirs();
+ File source = resolve(key);
+ try {
+ InputStream is = new FileInputStream(source);
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
+ int count = 0;
+ while ((count = is.read(buffer)) > 0)
+ {
+ bos.write(buffer, 0, count);
+ }
+ bos.close();
+ } catch (IOException e) {
+ getLog().error("Could not copy bundle " + key, e);
+ }
+
+ }
+ }
+
+ try {
+ OutputStream out = new FileOutputStream(startupPropertiesFile);
+ try {
+ startupProperties.save(out);
+ } finally {
+ out.close();
+ }
+ } catch (IOException e) {
+ throw new MojoFailureException("Could not write startup.properties file at " + startupPropertiesFile, e);
+ }
if (buf.length() > 0) {
throw new MojoExecutionException("Could not unpack all dependencies:\n" + buf.toString());
}
}
+ /**
+ * Copied from Main class
+ * Returns a path for an srtifact.
+ * Input: path (no ':') returns path
+ * Input: mvn:<groupId>/<artifactId>/<version>/<type>/<classifier> converts to default repo location path
+ * Input: <groupId>:<artifactId>:<version>:<type>:<classifier> converts to default repo location path
+ * type and classifier are optional.
+ *
+ *
+ * @param name input artifact info
+ * @return path as supplied or a default maven repo path
+ */
+ private static String fromMaven(String name) {
+ if (name.indexOf(':') == -1) {
+ return name;
+ }
+ int firstBit = 0;
+ if (name.startsWith("mvn:")) {
+ firstBit = 1;
+ }
+ String[] bits = name.split("[:/]");
+ StringBuilder b = new StringBuilder(bits[firstBit]);
+ for (int i = 0; i < b.length(); i++) {
+ if (b.charAt(i) == '.') {
+ b.setCharAt(i, '/');
+ }
+ }
+ b.append('/').append(bits[firstBit + 1]); //artifactId
+ b.append('/').append(bits[firstBit + 2]); //version
+ b.append('/').append(bits[firstBit + 1]).append('-').append(bits[firstBit + 2]);
+ if (bits.length == firstBit + 5 && !bits[firstBit + 4].isEmpty()) {
+ b.append('-').append(bits[firstBit + 4]); //classifier
+ }
+ if (bits.length >= firstBit + 4 && !bits[firstBit + 3].isEmpty()) {
+ b.append('.').append(bits[firstBit + 3]);
+ } else {
+ b.append(".jar");
+ }
+ return b.toString();
+ }
+
+ public File resolve(String id) {
+ if (id.startsWith("mvn:")) {
+ id = id.substring("mvn:".length()).replaceAll("/", ":");
+ }
+ ArtifactRequest request = new ArtifactRequest();
+ request.setArtifact(
+ new DefaultArtifact(id));
+ request.setRepositories(remoteRepos);
+
+ getLog().debug("Resolving artifact " + id +
+ " from " + remoteRepos);
+
+ ArtifactResult result;
+ try {
+ result = repoSystem.resolveArtifact(repoSession, request);
+ } catch (ArtifactResolutionException e) {
+ getLog().warn("could not resolve " + id, e);
+ return null;
+ }
+
+ getLog().debug("Resolved artifact " + id + " to " +
+ result.getArtifact().getFile() + " from "
+ + result.getRepository());
+ return result.getArtifact().getFile();
+ }
+
private class OfflineFeaturesService implements FeaturesService {
private static final String FEATURES_REPOSITORIES = "featuresRepositories";
@@ -168,25 +327,16 @@ public class InstallKarsMojo extends Moj
}
} else {
getLog().info("Installing feature to system and startup.properties");
- CommentProperties startupProperties = new CommentProperties();
- if (startupPropertiesFile.exists()) {
- InputStream in = new FileInputStream(startupPropertiesFile);
- try {
- startupProperties.load(in);
- } finally {
- in.close();
- }
+ File repoFile;
+ if (url.toString().startsWith("mvn:")) {
+ DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
+ String[] bits = url.toString().split("[:/]");
+ Artifact artifact = factory.createArtifactWithClassifier(bits[1], bits[2], bits[3], bits[4], bits[5]);
+ String featuresPath = repoPath + "/" + layout.pathOf(artifact);
+ repoFile = new File(featuresPath);
} else {
- startupProperties.setHeader(Collections.singletonList("#Bundles to be started on startup, with startlevel"));
- if (!startupPropertiesFile.getParentFile().exists()) {
- startupPropertiesFile.getParentFile().mkdirs();
- }
+ repoFile = new File(url);
}
- DefaultRepositoryLayout layout = new DefaultRepositoryLayout();
- String[] bits = url.toString().split("[:/]");
- Artifact artifact = factory.createArtifactWithClassifier(bits[1], bits[2], bits[3], bits[4], bits[5]);
- String featuresPath = repoPath + "/" + layout.pathOf(artifact);
- File repoFile = new File(featuresPath);
InputStream in = new FileInputStream(repoFile);
Features features;
try {
@@ -199,13 +349,6 @@ public class InstallKarsMojo extends Moj
for (Bundle bundle: feature.getBundle()) {
String location = bundle.getLocation();
String startLevel = Integer.toString(bundle.getStartLevel());
-// bits = location.toString().split("[:/]");
-// if (bits.length < 4) {
-// getLog().warn("bad bundle: " + location);
-// } else {
-// Artifact bundleArtifact = factory.createArtifact(bits[1], bits[2], bits[3], null, bits.length == 4? "jar": bits[4]);
-// String bundlePath = location.startsWith("mvn:")? location.substring("mvn:".length()).replaceAll("/", ":"): location;
- //layout.pathOf(bundleArtifact);
if (startupProperties.containsKey(location)) {
int oldStartLevel = Integer.decode(startupProperties.get(location));
if (oldStartLevel > bundle.getStartLevel()) {
@@ -222,12 +365,6 @@ public class InstallKarsMojo extends Moj
}
}
- OutputStream out = new FileOutputStream(startupPropertiesFile);
- try {
- startupProperties.save(out);
- } finally {
- out.close();
- }
}
}
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java Tue Mar 22 22:01:41 2011
@@ -104,8 +104,6 @@ public abstract class MojoSupport extend
*/
protected ArtifactResolver resolver;
- protected ArtifactCollector collector = new GraphArtifactCollector();
-
/**
* @component
*/
@@ -206,36 +204,6 @@ public abstract class MojoSupport extend
return finalIncludes;
}
- protected ResolutionListenerImpl resolveProject() {
- Map managedVersions = null;
- try {
- managedVersions = createManagedVersionMap(project.getId(), project
- .getDependencyManagement());
- } catch (ProjectBuildingException e) {
- getLog().error(
- "An error occurred while resolving project dependencies.",
- e);
- }
- ResolutionListenerImpl listener = new ResolutionListenerImpl();
- listener.setLog(getLog());
- try {
- collector.collect(project.getDependencyArtifacts(), project
- .getArtifact(), managedVersions, localRepo, remoteRepos,
- artifactMetadataSource, null, Collections
- .singletonList(listener));
- } catch (ArtifactResolutionException e) {
- getLog().error(
- "An error occurred while resolving project dependencies.",
- e);
- }
- if (getLog().isDebugEnabled()) {
- getLog().debug("Dependency graph");
- getLog().debug("================");
- print(listener.getRootNode());
- getLog().debug("================");
- }
- return listener;
- }
protected Map createManagedVersionMap(String projectId,
DependencyManagement dependencyManagement) throws ProjectBuildingException {
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=1084372&r1=1084371&r2=1084372&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/resources/META-INF/plexus/components.xml Tue Mar 22 22:01:41 2011
@@ -23,12 +23,6 @@
<component-set>
<components>
<component>
- <role>org.codehaus.plexus.archiver.UnArchiver</role>
- <role-hint>kar</role-hint>
- <implementation>org.codehaus.plexus.archiver.zip.ZipUnArchiver</implementation>
- <instantiation-strategy>per-lookup</instantiation-strategy>
- </component>
- <component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>feature</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
@@ -43,10 +37,6 @@
<compile>
org.apache.karaf.tooling:features-maven-plugin:generate-features-xml2
</compile>
- <!--<package>-->
- <!--org.apache.geronimo.buildsupport:car-maven-plugin:package,-->
- <!--org.apache.geronimo.buildsupport:car-maven-plugin:archive-car-->
- <!--</package>-->
<install>
org.apache.maven.plugins:maven-install-plugin:install
</install>
@@ -59,6 +49,19 @@
</configuration>
</component>
<component>
+ <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
+ <role-hint>feature</role-hint>
+ <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
+ <configuration>
+ <type>xml</type>
+ <extension>xml</extension>
+ <packaging>feature</packaging>
+ <addedToClasspath>false</addedToClasspath>
+ <language>java</language>
+ </configuration>
+ </component>
+
+ <component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>kar</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
@@ -100,6 +103,13 @@
</configuration>
</component>
<component>
+ <role>org.codehaus.plexus.archiver.UnArchiver</role>
+ <role-hint>kar</role-hint>
+ <implementation>org.codehaus.plexus.archiver.zip.ZipUnArchiver</implementation>
+ <instantiation-strategy>per-lookup</instantiation-strategy>
+ </component>
+
+ <component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>karaf-assembly</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
@@ -129,103 +139,6 @@
</configuration>
</component>
- <!--
- FIXME: For some crazy reason, when the following are enabled it causes other packagings
- picked up from tools-maven-plugin to now configure their artifact handlers?!?!!
- -->
-
- <!--
- Custom packaging for geronimo modules.
- -->
- <!--
- <component>
- <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
- <role-hint>geronimo-module</role-hint>
- <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
- <configuration>
- <lifecycles>
- <lifecycle>
- <id>default</id>
- <phases>
- <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
- <compile>org.apache.geronimo.buildsupport:car-maven-plugin:prepare-plan</compile>
- <package>org.apache.geronimo.buildsupport:car-maven-plugin:package</package>
- <install>org.apache.maven.plugins:maven-install-plugin:install</install>
- <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
- </phases>
- </lifecycle>
- </lifecycles>
- </configuration>
- </component>
- -->
-
- <!--
- Install geronimo-module artifact files as .car files
- -->
- <!--
- <component>
- <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
- <role-hint>geronimo-module</role-hint>
- <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
- <configuration>
- <type>geronimo-module</type>
- <extension>car</extension>
- <packaging>geronimo-module</packaging>
- <addedToClasspath>false</addedToClasspath>
- <language>java</language>
- </configuration>
- </component>
- -->
-
- <!--
- Custom packaging for server assembly modules.
- -->
- <!--<component>-->
- <!--<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>-->
- <!--<role-hint>server-assembly</role-hint>-->
- <!--<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>-->
- <!--<configuration>-->
- <!--<lifecycles>-->
- <!--<lifecycle>-->
- <!--<id>default</id>-->
- <!--<phases>-->
- <!--<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>-->
- <!--<compile>org.apache.geronimo.buildsupport:car-maven-plugin:install-modules</compile>-->
- <!--<package>org.apache.geronimo.buildsupport:car-maven-plugin:archive</package>-->
- <!--<install>org.apache.maven.plugins:maven-install-plugin:install</install>-->
- <!--<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>-->
- <!--</phases>-->
- <!--</lifecycle>-->
- <!--</lifecycles>-->
- <!--</configuration>-->
- <!--</component>-->
-
- <!--
- Install server-assembly artifact files as .pom xml files
- -->
- <!--<component>-->
- <!--<role>org.apache.maven.artifact.handler.ArtifactHandler</role>-->
- <!--<role-hint>application-assembly</role-hint>-->
- <!--<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>-->
- <!--<configuration>-->
- <!--<type>application-assembly</type>-->
- <!--<extension>pom</extension>-->
- <!--<packaging>application-assembly</packaging>-->
- <!--<addedToClasspath>false</addedToClasspath>-->
- <!--<language>xml</language>-->
- <!--</configuration>-->
- <!--</component>-->
-
- <!--<component>-->
- <!--<role>org.apache.maven.artifact.handler.ArtifactHandler</role>-->
- <!--<role-hint>plugin-metadata</role-hint>-->
- <!--<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>-->
- <!--<configuration>-->
- <!--<type>plugin-metadata</type>-->
- <!--<extension>plugin-metadata</extension>-->
- <!--<language>xml</language>-->
- <!--</configuration>-->
- <!--</component>-->
</components>
</component-set>