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/06 23:43:22 UTC
svn commit: r504347 - in /maven/sandbox/plugins/maven-bundle-plugin: pom.xml
src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java
Author: carlos
Date: Tue Feb 6 14:43:21 2007
New Revision: 504347
URL: http://svn.apache.org/viewvc?view=rev&rev=504347
Log:
Add versions to import and export package
Modified:
maven/sandbox/plugins/maven-bundle-plugin/pom.xml
maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/RecursiveBundlePlugin.java
Modified: maven/sandbox/plugins/maven-bundle-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/pom.xml?view=diff&rev=504347&r1=504346&r2=504347
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/pom.xml (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/pom.xml Tue Feb 6 14:43:21 2007
@@ -74,12 +74,12 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
- <version>1.0-alpha-2</version>
+ <version>1.0-alpha-3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
- <version>1.0-beta-1</version>
+ <version>1.0-beta-2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java?view=diff&rev=504347&r1=504346&r2=504347
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java Tue Feb 6 14:43:21 2007
@@ -95,6 +95,10 @@
header(properties, Analyzer.INCLUDE_RESOURCE, "src/main/resources/");
}
+ execute(project, instructions, properties);
+ }
+
+ protected void execute(MavenProject project, Map instructions, Properties properties) throws MojoExecutionException {
try {
execute(project, instructions, properties, getClasspath(project));
}
@@ -105,7 +109,7 @@
protected void execute(MavenProject project, Map instructions, Properties properties, Jar[] classpath) throws MojoExecutionException {
try {
- File jarFile = new File(buildDirectory, getBundleName(project));
+ File jarFile = new File(getBuildDirectory(), getBundleName(project));
// Setup defaults
String bsn = project.getGroupId() + "." + project.getArtifactId();
@@ -139,7 +143,7 @@
properties.putAll( getProperies(project.getModel(), "pom.", project.getModel()));
properties.putAll( getProperies(project.getModel(), "project.", project));
properties.put("project.baseDir", baseDir );
- properties.put("project.build.directory", buildDirectory );
+ properties.put("project.build.directory", getBuildDirectory() );
properties.put("project.build.outputdirectory", outputDirectory );
properties.putAll(instructions);
@@ -247,7 +251,7 @@
* @throws ZipException
* @throws IOException
*/
- private Jar[] getClasspath(MavenProject project) throws ZipException, IOException {
+ protected Jar[] getClasspath(MavenProject project) throws ZipException, IOException {
List list = new ArrayList();
if (outputDirectory != null && outputDirectory.exists()) {
@@ -260,7 +264,7 @@
if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
|| Artifact.SCOPE_SYSTEM.equals(artifact.getScope())
|| Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
- Jar jar = new Jar(artifact.getArtifactId(), artifact.getFile());
+ Jar jar = new Jar(artifact.getArtifactId(), getFile(artifact));
list.add(jar);
}
}
@@ -269,6 +273,15 @@
return cp;
}
+ /**
+ * Get the file for an Artifact
+ *
+ * @param artifact
+ */
+ protected File getFile(Artifact artifact) {
+ return artifact.getFile();
+ }
+
private void header(Properties properties, String key, Object value) {
if (value == null)
return;
@@ -375,5 +388,27 @@
protected String getBundleName(MavenProject project) {
return project.getBuild().getFinalName() + ".jar";
+ }
+
+ public String getBuildDirectory() {
+ return buildDirectory;
+ }
+
+ /**
+ * Get a list of packages inside a Jar
+ *
+ * @param jar
+ * @return list of package names
+ */
+ public List getPackages(Jar jar) {
+ List packages = new ArrayList();
+ for (Iterator p = jar.getDirectories().entrySet().iterator(); p.hasNext();) {
+ Map.Entry directory = (Map.Entry) p.next();
+ String path = (String) directory.getKey();
+
+ String pack = path.replace('/', '.');
+ packages.add(pack);
+ }
+ return packages;
}
}
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=504347&r1=504346&r2=504347
==============================================================================
--- 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 Tue Feb 6 14:43:21 2007
@@ -41,8 +41,6 @@
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
-import sun.tools.jar.resources.jar;
-
import aQute.lib.osgi.Analyzer;
import aQute.lib.osgi.Jar;
@@ -107,11 +105,6 @@
/**
* @component
*/
- private ArtifactMetadataSource metadataSource;
-
- /**
- * @component
- */
private MavenProjectBuilder mavenProjectBuilder;
private Map mapOfArtifacts;
@@ -131,78 +124,39 @@
throw new MojoExecutionException( "Unable to build dependency tree", e );
}
- DependencyNode rootNode = dependencyTree.getRootNode();
+ System.out.println( dependencyTree );
mapOfArtifacts = createMapOfArtifacts( project );
- bundle( rootNode );
+ for ( Iterator it = dependencyTree.inverseIterator(); it.hasNext(); )
+ {
+ DependencyNode node = (DependencyNode) it.next();
+ Artifact artifact = node.getArtifact();
+ if ( ( artifact.getScope() == Artifact.SCOPE_COMPILE ) || ( artifact.getScope() == Artifact.SCOPE_RUNTIME ) )
+ {
+ bundle( node.getArtifact() );
+ }
+ }
}
- private void bundle( DependencyNode node )
+ private void bundle( Artifact artifact )
throws MojoExecutionException
{
- List children = node.getChildren();
- if ( ( children == null ) || children.isEmpty() )
+ MavenProject project;
+ try
{
- return;
+ project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository, true );
}
-
- Iterator it = children.iterator();
- while ( it.hasNext() )
+ catch ( ProjectBuildingException e )
{
- DependencyNode child = (DependencyNode) it.next();
- Artifact artifact = child.getArtifact();
-
- /* skip non compile or runtime artifacts */
- if ( !( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) || Artifact.SCOPE_RUNTIME.equals( artifact
- .getScope() ) ) )
- {
- continue;
- }
-
- // ResolutionGroup resolutionGroup;
- // try
- // {
- // resolutionGroup = metadataSource.retrieve( artifact, localRepository, remoteRepositories );
- // }
- // catch ( ArtifactMetadataRetrievalException e )
- // {
- // throw new MojoExecutionException( "Unable to retrieve metadata for: " + artifact, e );
- // }
-
- MavenProject project;
- try
- {
- project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository, true );
- }
- catch ( ProjectBuildingException e )
- {
- throw new MojoExecutionException( "Unable to build project object for artifact " + artifact, e );
- }
-
- // for ( Iterator it2 = resolutionGroup.getArtifacts().iterator(); it2.hasNext(); )
- // {
- // Artifact a = (Artifact) it2.next();
- // System.out.println( a.getArtifactId() + " " + a.getFile());
- //
- // }
-
- /* process the node */
- Map instructions = new HashMap();
- instructions.put( Analyzer.EXPORT_PACKAGE, "*" );
- execute( project, instructions, artifact );
-
- bundle( child );
+ throw new MojoExecutionException( "Unable to build project object for artifact " + artifact, e );
}
- }
- private void execute( MavenProject project, Map instructions, Artifact artifact )
- throws MojoExecutionException
- {
- Properties properties = new Properties();
try
{
- execute( project, instructions, properties, new Jar[] { getJar( artifact ) } );
+ Map instructions = new HashMap();
+ instructions.put( Analyzer.EXPORT_PACKAGE, packagesAsString( getJar( artifact ) ) );
+ execute( project, instructions, artifact );
}
catch ( IOException e )
{
@@ -210,6 +164,13 @@
}
}
+ private void execute( MavenProject project, Map instructions, Artifact artifact )
+ throws MojoExecutionException, IOException
+ {
+ Properties properties = new Properties();
+ execute( project, instructions, properties, getClasspath( this.project ) );
+ }
+
private Map createMapOfArtifacts( MavenProject project )
{
Set artifacts = project.getArtifacts();
@@ -226,19 +187,22 @@
throws IOException
{
Artifact a = (Artifact) mapOfArtifacts.get( getArtifactKey( artifact ) );
- if ((a == null ) )
+
+ if ( ( a == null ) )
{
- throw new RuntimeException( "The artifact " + artifact + " from the dependency tree is not in the dependency set" );
+ throw new RuntimeException( "The artifact " + artifact
+ + " from the dependency tree is not in the dependency set" );
}
+
String name = a.getArtifactId();
- File jarFile = a.getFile();
- if ((name == null ) || (jarFile == null ))
+ File jarFile = getFile( a );
+ if ( ( name == null ) || ( jarFile == null ) )
{
throw new RuntimeException( "The artifact " + artifact + " has no name or file couldn't be determined" );
}
return new Jar( name, jarFile );
}
-
+
private String getArtifactKey( Artifact artifact )
{
return artifact.getGroupId() + ":" + artifact.getArtifactId();
@@ -246,6 +210,43 @@
protected String getBundleName( MavenProject project )
{
- return project.getGroupId() + "." + project.getArtifactId() + "_" + convertVersionToOsgi(project.getVersion()) + ".jar";
+ return getBundleName( project.getArtifact() );
+ }
+
+ private String getBundleName( Artifact artifact )
+ {
+ return artifact.getGroupId() + "." + artifact.getArtifactId() + "_"
+ + convertVersionToOsgi( artifact.getVersion() ) + ".jar";
+ }
+
+ /**
+ * Use previously built bundles when available.
+ *
+ * @param artifact
+ */
+ protected File getFile( Artifact artifact )
+ {
+ /* if bundle was already built use it instead of jar from repo */
+ File bundle = new File( getBuildDirectory(), getBundleName( artifact ) );
+ if ( bundle.exists() )
+ {
+ return bundle;
+ }
+ return super.getFile( artifact );
+ }
+
+ private String packagesAsString( Jar jar )
+ {
+ StringBuffer sb = new StringBuffer();
+ for ( Iterator it = getPackages( jar ).iterator(); it.hasNext(); )
+ {
+ String packageName = (String) it.next();
+ sb.append( packageName );
+ if ( it.hasNext() )
+ {
+ sb.append( "," );
+ }
+ }
+ return sb.toString();
}
}