You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2007/02/13 07:33:24 UTC
svn commit: r506884 -
/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java
Author: carlos
Date: Mon Feb 12 22:33:24 2007
New Revision: 506884
URL: http://svn.apache.org/viewvc?view=rev&rev=506884
Log:
Refactor to use artifact resolver
Modified:
maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java
Modified: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java?view=diff&rev=506884&r1=506883&r2=506884
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java Mon Feb 12 22:33:24 2007
@@ -31,6 +31,9 @@
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.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@@ -97,6 +100,13 @@
private ArtifactCollector collector;
/**
+ * Artifact resolver, needed to download jars.
+ *
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
* @component
*/
private DependencyTreeBuilder dependencyTreeBuilder;
@@ -106,11 +116,21 @@
*/
private MavenProjectBuilder mavenProjectBuilder;
- private Map mapOfArtifacts;
-
public void execute()
throws MojoExecutionException
{
+ bundle( project );
+ }
+
+ /**
+ * Bundle a project and all its dependencies
+ *
+ * @param project
+ * @throws MojoExecutionException
+ */
+ private void bundle( MavenProject project )
+ throws MojoExecutionException
+ {
DependencyTree dependencyTree;
try
@@ -123,22 +143,35 @@
throw new MojoExecutionException( "Unable to build dependency tree", e );
}
- mapOfArtifacts = createMapOfArtifacts( project );
+ getLog().info( "Will bundle the following dependency tree\n" + dependencyTree );
for ( Iterator it = dependencyTree.inverseIterator(); it.hasNext(); )
{
DependencyNode node = (DependencyNode) it.next();
- Artifact artifact = node.getArtifact();
+ if (!it.hasNext())
+ {
+ /* this is the root, current project */
+ break;
+ }
+ Artifact artifact = resolveArtifact( node.getArtifact() );
if ( ( artifact.getScope() == Artifact.SCOPE_COMPILE ) || ( artifact.getScope() == Artifact.SCOPE_RUNTIME ) )
{
- bundle( node.getArtifact() );
+ bundle( artifact );
}
}
}
+ /**
+ * Bundle one artifact only
+ *
+ * @param artifact
+ * @throws MojoExecutionException
+ */
private void bundle( Artifact artifact )
throws MojoExecutionException
{
+ getLog().info( "Bundling " + artifact );
+
MavenProject project;
try
{
@@ -170,18 +203,6 @@
}
}
- private Map createMapOfArtifacts( MavenProject project )
- {
- Set artifacts = project.getArtifacts();
- Map map = new HashMap();
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
- {
- Artifact artifact = (Artifact) it.next();
- map.put( getArtifactKey( artifact ), artifact );
- }
- return map;
- }
-
private String getArtifactKey( Artifact artifact )
{
return artifact.getGroupId() + ":" + artifact.getArtifactId();
@@ -211,17 +232,33 @@
{
return bundle;
}
- File file = super.getFile( artifact );
- if ( file == null )
- {
- Artifact a = (Artifact) mapOfArtifacts.get( getArtifactKey( artifact ) );
- file = a.getFile();
- }
- return file;
+ return super.getFile( artifact );
}
protected File getOutputFile( Artifact artifact )
{
return new File( getBuildDirectory(), getBundleName( artifact ) );
+ }
+
+ private Artifact resolveArtifact( Artifact artifact )
+ throws MojoExecutionException
+ {
+ Artifact resolvedArtifact = factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact
+ .getVersion(), artifact.getScope(), artifact.getType() );
+
+ try
+ {
+ artifactResolver.resolve( resolvedArtifact, remoteRepositories, localRepository );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( "Artifact was not found in the repo" + resolvedArtifact, e );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new MojoExecutionException( "Error resolving artifact " + resolvedArtifact, e );
+ }
+
+ return resolvedArtifact;
}
}