FELIX-806: pickup <archive> settings in bundleplugin configuration (otherwise fall back to the jarplugin settings) and enable support of the addMavenDescriptor setting

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@739224 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
index 8b37754..21e09d2 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -174,6 +174,13 @@
      */
     private Maven2OsgiConverter m_maven2OsgiConverter;
 
+    /**
+     * The archive configuration to use.
+     *
+     * @parameter
+     */
+    private MavenArchiveConfiguration archive; // accessed indirectly in JarPluginConfiguration
+
     private static final String MAVEN_RESOURCES = "{maven-resources}";
 
     private static final String[] EMPTY_STRING_ARRAY =
@@ -400,7 +407,6 @@
 
         String[] removeHeaders = builder.getProperty( Analyzer.REMOVE_HEADERS, "" ).split( "," );
 
-        doMavenMetadata( currentProject, jar );
         mergeMavenManifest( currentProject, jar, removeHeaders, getLog() );
         builder.setJar( jar );
 
@@ -418,7 +424,7 @@
             log.debug( "------------------------------------------------------------------------" );
             for ( Enumeration e = properties.propertyNames(); e.hasMoreElements(); )
             {
-                String key = (String) e.nextElement();
+                String key = ( String ) e.nextElement();
                 log.debug( key + ": " + properties.getProperty( key ) );
             }
             log.debug( "------------------------------------------------------------------------" );
@@ -434,7 +440,7 @@
             log.debug( "------------------------------------------------------------------------" );
             for ( Iterator i = classpath.iterator(); i.hasNext(); )
             {
-                File path = ((Jar)i.next()).getSource();
+                File path = ( ( Jar ) i.next() ).getSource();
                 log.debug( null == path ? "null" : path.toString() );
             }
             log.debug( "------------------------------------------------------------------------" );
@@ -450,7 +456,7 @@
             log.debug( "------------------------------------------------------------------------" );
             for ( Iterator i = manifest.getMainAttributes().entrySet().iterator(); i.hasNext(); )
             {
-                Map.Entry entry = (Map.Entry) i.next();
+                Map.Entry entry = ( Map.Entry ) i.next();
                 log.debug( entry.getKey() + ": " + entry.getValue() );
             }
             log.debug( "------------------------------------------------------------------------" );
@@ -501,8 +507,11 @@
     }
 
 
-    protected static void mergeMavenManifest( MavenProject currentProject, Jar jar, String[] removeHeaders, Log log )
+    protected void mergeMavenManifest( MavenProject currentProject, Jar jar, String[] removeHeaders, Log log )
+        throws IOException
     {
+        boolean addMavenDescriptor = true;
+
         try
         {
             /*
@@ -510,6 +519,8 @@
              */
             MavenArchiveConfiguration archiveConfig = JarPluginConfiguration.getArchiveConfiguration( currentProject );
             String mavenManifestText = new MavenArchiver().getManifest( currentProject, archiveConfig ).toString();
+            addMavenDescriptor = archiveConfig.isAddMavenDescriptor();
+
             Manifest mavenManifest = new Manifest();
 
             // First grab the external manifest file (if specified)
@@ -576,6 +587,11 @@
         {
             log.warn( "Unable to merge Maven manifest: " + e.getLocalizedMessage() );
         }
+
+        if ( addMavenDescriptor )
+        {
+            doMavenMetadata( currentProject, jar );
+        }
     }
 
 
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/JarPluginConfiguration.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/JarPluginConfiguration.java
index 696d5ca..6726fb4 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/JarPluginConfiguration.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/JarPluginConfiguration.java
@@ -49,10 +49,26 @@
             ExpressionEvaluator evaluator = new DefaultExpressionEvaluator();
             ConverterLookup converters = new DefaultConverterLookup();
 
-            PlexusConfiguration pluginSettings = getCorePluginConfiguration( project, "jar" );
-            PlexusConfiguration archiveSettings = pluginSettings.getChild( "archive" );
+            PlexusConfiguration settings = null;
 
-            converter.processConfiguration( converters, archiveConfig, loader, archiveSettings, evaluator, null );
+            try
+            {
+                // first look for bundle specific archive settings
+                settings = getPluginConfiguration( project, "org.apache.felix", "maven-bundle-plugin" );
+                settings = settings.getChild( "archive" );
+            }
+            catch ( Exception e )
+            {
+            }
+
+            // if it's empty fall back to the jar archive settings
+            if ( null == settings || settings.getChildCount() == 0 )
+            {
+                settings = getCorePluginConfiguration( project, "jar" );
+                settings = settings.getChild( "archive" );
+            }
+
+            converter.processConfiguration( converters, archiveConfig, loader, settings, evaluator, null );
         }
         catch ( Exception e )
         {