You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2011/06/28 20:26:45 UTC

svn commit: r1140774 - in /felix/trunk/bundleplugin/src: main/java/org/apache/felix/bundleplugin/BundlePlugin.java main/java/org/apache/felix/bundleplugin/ManifestPlugin.java test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java

Author: mcculls
Date: Tue Jun 28 18:26:45 2011
New Revision: 1140774

URL: http://svn.apache.org/viewvc?rev=1140774&view=rev
Log:
Reduce code duplication

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
    felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1140774&r1=1140773&r2=1140774&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Tue Jun 28 18:26:45 2011
@@ -286,10 +286,10 @@ public class BundlePlugin extends Abstra
     }
 
 
-    protected boolean reportErrors( String prefix, Builder builder )
+    protected boolean reportErrors( String prefix, Analyzer analyzer )
     {
-        List errors = builder.getErrors();
-        List warnings = builder.getWarnings();
+        List errors = analyzer.getErrors();
+        List warnings = analyzer.getWarnings();
 
         for ( Iterator w = warnings.iterator(); w.hasNext(); )
         {
@@ -401,10 +401,7 @@ public class BundlePlugin extends Abstra
         properties.putAll( transformDirectives( originalInstructions ) );
 
         Builder builder = new Builder();
-        if ( currentProject.getBasedir() != null )
-        {
-            builder.setBase( currentProject.getBasedir() );
-        }
+        builder.setBase( getBase( currentProject ) );
         builder.setProperties( properties );
         if ( classpath != null )
         {
@@ -416,11 +413,14 @@ public class BundlePlugin extends Abstra
 
     protected void addMavenInstructions( MavenProject currentProject, Builder builder ) throws Exception
     {
-        // update BND instructions to add included Maven resources
-        includeMavenResources( currentProject, builder, getLog() );
+        if ( currentProject.getBasedir() != null )
+        {
+            // update BND instructions to add included Maven resources
+            includeMavenResources( currentProject, builder, getLog() );
 
-        // calculate default export/private settings based on sources
-        addLocalPackages( outputDirectory, builder );
+            // calculate default export/private settings based on sources
+            addLocalPackages( outputDirectory, builder );
+        }
 
         // update BND instructions to embed selected Maven dependencies
         Collection embeddableArtifacts = getEmbeddableArtifacts( currentProject, builder );
@@ -543,7 +543,7 @@ public class BundlePlugin extends Abstra
 
         dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
 
-        boolean addMavenDescriptor = true;
+        boolean addMavenDescriptor = currentProject.getBasedir() != null;
 
         try
         {
@@ -552,7 +552,7 @@ public class BundlePlugin extends Abstra
              */
             MavenArchiveConfiguration archiveConfig = JarPluginConfiguration.getArchiveConfiguration( currentProject );
             String mavenManifestText = new MavenArchiver().getManifest( currentProject, archiveConfig ).toString();
-            addMavenDescriptor = archiveConfig.isAddMavenDescriptor();
+            addMavenDescriptor = addMavenDescriptor && archiveConfig.isAddMavenDescriptor();
 
             Manifest mavenManifest = new Manifest();
 
@@ -959,7 +959,7 @@ public class BundlePlugin extends Abstra
         {
             extension = currentProject.getArtifact().getType();
         }
-        if ( StringUtils.isEmpty( extension ) || "bundle".equals( extension ) )
+        if ( StringUtils.isEmpty( extension ) || "bundle".equals( extension ) || "pom".equals( extension ) )
         {
             extension = "jar"; // just in case maven gets confused
         }
@@ -1044,7 +1044,7 @@ public class BundlePlugin extends Abstra
         properties.putAll( getProperties( currentProject.getModel(), "pom." ) );
         properties.putAll( getProperties( currentProject.getModel(), "project." ) );
 
-        properties.put( "project.baseDir", currentProject.getBasedir() );
+        properties.put( "project.baseDir", getBase( currentProject ) );
         properties.put( "project.build.directory", getBuildDirectory() );
         properties.put( "project.build.outputdirectory", getOutputDirectory() );
 
@@ -1059,6 +1059,12 @@ public class BundlePlugin extends Abstra
     }
 
 
+    protected static File getBase( MavenProject currentProject )
+    {
+        return currentProject.getBasedir() != null ? currentProject.getBasedir() : new File( "" );
+    }
+
+
     protected File getOutputDirectory()
     {
         return outputDirectory;
@@ -1155,15 +1161,15 @@ public class BundlePlugin extends Abstra
     }
 
 
-    private static List getMavenResources( MavenProject project )
+    private static List getMavenResources( MavenProject currentProject )
     {
-        List resources = new ArrayList(project.getResources());
+        List resources = new ArrayList(currentProject.getResources());
 
-        if ( project.getCompileSourceRoots() != null )
+        if ( currentProject.getCompileSourceRoots() != null )
         {
             // also scan for any "packageinfo" files lurking in the source folders
             List packageInfoIncludes = Collections.singletonList( "**/packageinfo" );
-            for ( Iterator i = project.getCompileSourceRoots().iterator(); i.hasNext(); )
+            for ( Iterator i = currentProject.getCompileSourceRoots().iterator(); i.hasNext(); )
             {
                 String sourceRoot = (String) i.next();
                 Resource packageInfoResource = new Resource();
@@ -1177,12 +1183,12 @@ public class BundlePlugin extends Abstra
     }
 
 
-    protected static String getMavenResourcePaths( MavenProject project )
+    protected static String getMavenResourcePaths( MavenProject currentProject )
     {
-        final String basePath = project.getBasedir().getAbsolutePath();
+        final String basePath = currentProject.getBasedir().getAbsolutePath();
 
         Set pathSet = new LinkedHashSet();
-        for ( Iterator i = getMavenResources( project ).iterator(); i.hasNext(); )
+        for ( Iterator i = getMavenResources( currentProject ).iterator(); i.hasNext(); )
         {
             Resource resource = ( Resource ) i.next();
 
@@ -1272,7 +1278,7 @@ public class BundlePlugin extends Abstra
     }
 
 
-    protected Collection getEmbeddableArtifacts( MavenProject project, Analyzer analyzer )
+    protected Collection getEmbeddableArtifacts( MavenProject currentProject, Analyzer analyzer )
         throws MojoExecutionException
     {
         final Collection artifacts;
@@ -1281,12 +1287,12 @@ public class BundlePlugin extends Abstra
         if ( Boolean.valueOf( embedTransitive ).booleanValue() )
         {
             // includes transitive dependencies
-            artifacts = project.getArtifacts();
+            artifacts = currentProject.getArtifacts();
         }
         else
         {
             // only includes direct dependencies
-            artifacts = project.getDependencyArtifacts();
+            artifacts = currentProject.getDependencyArtifacts();
         }
 
         return getSelectedDependencies( artifacts );

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java?rev=1140774&r1=1140773&r2=1140774&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java Tue Jun 28 18:26:45 2011
@@ -103,7 +103,7 @@ public class ManifestPlugin extends Bund
     public Manifest getManifest( MavenProject project, Jar[] classpath ) throws IOException, MojoFailureException,
         MojoExecutionException, Exception
     {
-        return getManifest( project, new Properties(), new Properties(), classpath );
+        return getManifest( project, new LinkedHashMap(), new Properties(), classpath );
     }
 
 
@@ -111,22 +111,8 @@ public class ManifestPlugin extends Bund
         throws IOException, MojoFailureException, MojoExecutionException, Exception
     {
         Analyzer analyzer = getAnalyzer( project, instructions, properties, classpath );
-
-        List errors = analyzer.getErrors();
-        List warnings = analyzer.getWarnings();
-
-        for ( Iterator w = warnings.iterator(); w.hasNext(); )
-        {
-            String msg = ( String ) w.next();
-            getLog().warn( "Warning in manifest for " + project.getArtifact() + " : " + msg );
-        }
-        for ( Iterator e = errors.iterator(); e.hasNext(); )
-        {
-            String msg = ( String ) e.next();
-            getLog().error( "Error in manifest for " + project.getArtifact() + " : " + msg );
-        }
-
-        if ( errors.size() > 0 )
+        boolean hasErrors = reportErrors( "Manifest " + project.getArtifact(), analyzer );
+        if ( hasErrors )
         {
             String failok = analyzer.getProperty( "-failok" );
             if ( null == failok || "false".equalsIgnoreCase( failok ) )
@@ -165,19 +151,7 @@ public class ManifestPlugin extends Bund
             throw new FileNotFoundException( file.getPath() );
         }
 
-        properties.putAll( getDefaultProperties( project ) );
-        properties.putAll( transformDirectives( instructions ) );
-
-//        PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer();
-        Builder analyzer = new Builder();
-
-        if ( project.getBasedir() != null )
-            analyzer.setBase( project.getBasedir() );
-
-        analyzer.setProperties( properties );
-
-        if ( classpath != null )
-            analyzer.setClasspath( classpath );
+        Builder analyzer = getOSGiBuilder( project, instructions, properties, classpath );
 
         analyzer.setJar( file );
 
@@ -189,17 +163,12 @@ public class ManifestPlugin extends Bund
             analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
         }
 
-        // Apply Embed-Dependency headers, even though the contents won't be changed
-        Collection embeddableArtifacts = getEmbeddableArtifacts( project, analyzer );
-        new DependencyEmbedder( getLog(), embeddableArtifacts ).processHeaders( analyzer );
-
-        dumpInstructions( "BND Instructions:", analyzer.getProperties(), getLog() );
-        dumpClasspath( "BND Classpath:", analyzer.getClasspath(), getLog() );
+        addMavenInstructions( project, analyzer );
 
         analyzer.mergeManifest( analyzer.getJar().getManifest() );
         analyzer.calcManifest();
 
-        dumpManifest( "BND Manifest:", analyzer.getJar().getManifest(), getLog() );
+        mergeMavenManifest( project, analyzer );
 
         return analyzer;
     }

Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java?rev=1140774&r1=1140773&r2=1140774&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundleAllPluginTest.java Tue Jun 28 18:26:45 2011
@@ -93,6 +93,8 @@ public class BundleAllPluginTest extends
         artifact.setVersion( "1.0.0.0" );
 
         MavenProject project = new MavenProjectStub();
+        project.setGroupId( artifact.getGroupId() );
+        project.setArtifactId( artifact.getArtifactId() );
         project.setVersion( artifact.getVersion() );
         project.setArtifact( artifact );
         project.setArtifacts( Collections.EMPTY_SET );