Make sure we don't rely on any side-effects of BND property processing

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@722890 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 e7a9fbf..ab63aea 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -288,7 +288,7 @@
 
             if ( errors.size() > 0 )
             {
-                String failok = properties.getProperty( "-failok" );
+                String failok = builder.getProperty( "-failok" );
                 if ( null == failok || "false".equalsIgnoreCase( failok ) )
                 {
                     jarFile.delete();
@@ -363,48 +363,49 @@
         builder.setClasspath( classpath );
 
         // update BND instructions to add included Maven resources
-        includeMavenResources( currentProject, properties, getLog() );
+        includeMavenResources( currentProject, builder, getLog() );
 
-        if ( !properties.containsKey( Analyzer.EXPORT_PACKAGE ) && !properties.containsKey( Analyzer.PRIVATE_PACKAGE ) )
+        if ( builder.getProperty( Analyzer.EXPORT_PACKAGE ) == null &&
+             builder.getProperty( Analyzer.PRIVATE_PACKAGE ) == null )
         {
-            if ( properties.containsKey( Analyzer.EXPORT_CONTENTS ) )
+            if ( builder.getProperty( Analyzer.EXPORT_CONTENTS ) != null )
             {
                 /*
                  * if we have exportcontents but no export packages or private packages then we're probably embedding or
                  * inlining one or more jars, so set private package to a non-null (but empty) value to keep Bnd happy.
                  */
-                properties.put( Analyzer.PRIVATE_PACKAGE, "!*" );
+                builder.setProperty( Analyzer.PRIVATE_PACKAGE, "!*" );
             }
             else
             {
-                String bsn = properties.getProperty( Analyzer.BUNDLE_SYMBOLICNAME );
+                String bsn = builder.getProperty( Analyzer.BUNDLE_SYMBOLICNAME );
                 String namespace = bsn.replaceAll( "\\W", "." );
 
-                properties.put( Analyzer.EXPORT_PACKAGE, namespace + ".*" );
+                builder.setProperty( Analyzer.EXPORT_PACKAGE, namespace + ".*" );
             }
         }
 
         // update BND instructions to embed selected Maven dependencies
-        Collection embeddableArtifacts = getEmbeddableArtifacts( currentProject, properties );
-        new DependencyEmbedder( embeddableArtifacts ).processHeaders( properties );
+        Collection embeddableArtifacts = getEmbeddableArtifacts( currentProject, builder );
+        new DependencyEmbedder( embeddableArtifacts ).processHeaders( builder );
 
         builder.build();
         Jar jar = builder.getJar();
         doMavenMetadata( currentProject, jar );
         builder.setJar( jar );
 
-        String[] removeHeaders = properties.getProperty( Analyzer.REMOVE_HEADERS, "" ).split( "," );
+        String[] removeHeaders = builder.getProperty( Analyzer.REMOVE_HEADERS, "" ).split( "," );
         mergeMavenManifest( currentProject, jar, removeHeaders, getLog() );
 
         return builder;
     }
 
 
-    protected static void includeMavenResources( MavenProject currentProject, Properties properties, Log log )
+    protected static void includeMavenResources( MavenProject currentProject, Analyzer analyzer, Log log )
     {
         // pass maven resource paths onto BND analyzer
         final String mavenResourcePaths = getMavenResourcePaths( currentProject );
-        final String includeResource = ( String ) properties.get( Analyzer.INCLUDE_RESOURCE );
+        final String includeResource = ( String ) analyzer.getProperty( Analyzer.INCLUDE_RESOURCE );
         if ( includeResource != null )
         {
             if ( includeResource.indexOf( MAVEN_RESOURCES ) >= 0 )
@@ -416,18 +417,18 @@
                     String cleanedResource = removeTagFromInstruction( includeResource, MAVEN_RESOURCES );
                     if ( cleanedResource.length() > 0 )
                     {
-                        properties.put( Analyzer.INCLUDE_RESOURCE, cleanedResource );
+                        analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, cleanedResource );
                     }
                     else
                     {
-                        properties.remove( Analyzer.INCLUDE_RESOURCE );
+                        analyzer.unsetProperty( Analyzer.INCLUDE_RESOURCE );
                     }
                 }
                 else
                 {
                     String combinedResource = StringUtils
                         .replace( includeResource, MAVEN_RESOURCES, mavenResourcePaths );
-                    properties.put( Analyzer.INCLUDE_RESOURCE, combinedResource );
+                    analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, combinedResource );
                 }
             }
             else if ( mavenResourcePaths.length() > 0 )
@@ -438,7 +439,7 @@
         }
         else if ( mavenResourcePaths.length() > 0 )
         {
-            properties.put( Analyzer.INCLUDE_RESOURCE, mavenResourcePaths );
+            analyzer.setProperty( Analyzer.INCLUDE_RESOURCE, mavenResourcePaths );
         }
     }
 
@@ -947,9 +948,9 @@
     }
 
 
-    protected static Collection getEmbeddableArtifacts( MavenProject project, Properties properties )
+    protected static Collection getEmbeddableArtifacts( MavenProject project, Analyzer analyzer )
     {
-        String embedTransitive = properties.getProperty( DependencyEmbedder.EMBED_TRANSITIVE );
+        String embedTransitive = analyzer.getProperty( DependencyEmbedder.EMBED_TRANSITIVE );
         if ( Boolean.valueOf( embedTransitive ).booleanValue() )
         {
             // includes transitive dependencies
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
index 6e9cf18..e6307dc 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
@@ -24,7 +24,6 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -79,7 +78,7 @@
     }
 
 
-    public void processHeaders( Properties properties ) throws MojoExecutionException
+    public void processHeaders( Analyzer analyzer ) throws MojoExecutionException
     {
         StringBuffer includeResource = new StringBuffer();
         StringBuffer bundleClassPath = new StringBuffer();
@@ -87,12 +86,12 @@
         m_inlinedPaths.clear();
         m_embeddedArtifacts.clear();
 
-        String embedDependencyHeader = properties.getProperty( EMBED_DEPENDENCY );
+        String embedDependencyHeader = analyzer.getProperty( EMBED_DEPENDENCY );
         if ( null != embedDependencyHeader && embedDependencyHeader.length() > 0 )
         {
-            m_embedDirectory = properties.getProperty( EMBED_DIRECTORY );
-            m_embedStripGroup = properties.getProperty( EMBED_STRIP_GROUP, "true" );
-            m_embedStripVersion = properties.getProperty( EMBED_STRIP_VERSION );
+            m_embedDirectory = analyzer.getProperty( EMBED_DIRECTORY );
+            m_embedStripGroup = analyzer.getProperty( EMBED_STRIP_GROUP, "true" );
+            m_embedStripVersion = analyzer.getProperty( EMBED_STRIP_VERSION );
 
             Map embedInstructions = OSGiHeader.parseHeader( embedDependencyHeader );
             processEmbedInstructions( embedInstructions );
@@ -110,14 +109,14 @@
         if ( bundleClassPath.length() > 0 )
         {
             // set explicit default before merging dependency classpath
-            if ( !properties.containsKey( Analyzer.BUNDLE_CLASSPATH ) )
+            if ( analyzer.getProperty( Analyzer.BUNDLE_CLASSPATH ) == null )
             {
-                properties.setProperty( Analyzer.BUNDLE_CLASSPATH, "." );
+                analyzer.setProperty( Analyzer.BUNDLE_CLASSPATH, "." );
             }
         }
 
-        appendDependencies( properties, Analyzer.INCLUDE_RESOURCE, includeResource.toString() );
-        appendDependencies( properties, Analyzer.BUNDLE_CLASSPATH, bundleClassPath.toString() );
+        appendDependencies( analyzer, Analyzer.INCLUDE_RESOURCE, includeResource.toString() );
+        appendDependencies( analyzer, Analyzer.BUNDLE_CLASSPATH, bundleClassPath.toString() );
     }
 
     protected static abstract class DependencyFilter
@@ -417,12 +416,12 @@
     }
 
 
-    private static void appendDependencies( Properties properties, String directiveName, String mavenDependencies )
+    private static void appendDependencies( Analyzer analyzer, String directiveName, String mavenDependencies )
     {
         /*
          * similar algorithm to {maven-resources} but default behaviour here is to append rather than override
          */
-        final String instruction = properties.getProperty( directiveName );
+        final String instruction = analyzer.getProperty( directiveName );
         if ( instruction != null && instruction.length() > 0 )
         {
             if ( instruction.indexOf( MAVEN_DEPENDENCIES ) >= 0 )
@@ -432,12 +431,12 @@
                 if ( mavenDependencies.length() == 0 )
                 {
                     String cleanInstruction = BundlePlugin.removeTagFromInstruction( instruction, MAVEN_DEPENDENCIES );
-                    properties.setProperty( directiveName, cleanInstruction );
+                    analyzer.setProperty( directiveName, cleanInstruction );
                 }
                 else
                 {
                     String mergedInstruction = StringUtils.replace( instruction, MAVEN_DEPENDENCIES, mavenDependencies );
-                    properties.setProperty( directiveName, mergedInstruction );
+                    analyzer.setProperty( directiveName, mergedInstruction );
                 }
             }
             else if ( mavenDependencies.length() > 0 )
@@ -445,20 +444,20 @@
                 if ( Analyzer.INCLUDE_RESOURCE.equalsIgnoreCase( directiveName ) )
                 {
                     // dependencies should be prepended so they can be overwritten by local resources
-                    properties.setProperty( directiveName, mavenDependencies + ',' + instruction );
+                    analyzer.setProperty( directiveName, mavenDependencies + ',' + instruction );
                 }
                 else
                 // Analyzer.BUNDLE_CLASSPATH
                 {
                     // for the classpath we want dependencies to be appended after local entries
-                    properties.setProperty( directiveName, instruction + ',' + mavenDependencies );
+                    analyzer.setProperty( directiveName, instruction + ',' + mavenDependencies );
                 }
             }
             // otherwise leave instruction unchanged
         }
         else if ( mavenDependencies.length() > 0 )
         {
-            properties.setProperty( directiveName, mavenDependencies );
+            analyzer.setProperty( directiveName, mavenDependencies );
         }
         // otherwise leave instruction unchanged
     }
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
index 0f62d6a..ca3cecc 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
@@ -127,7 +127,7 @@
 
         if ( errors.size() > 0 )
         {
-            String failok = properties.getProperty( "-failok" );
+            String failok = analyzer.getProperty( "-failok" );
             if ( null == failok || "false".equalsIgnoreCase( failok ) )
             {
                 throw new MojoFailureException( "Error(s) found in manifest configuration" );
@@ -178,16 +178,17 @@
 
         analyzer.setJar( file );
 
-        if ( !properties.containsKey( Analyzer.EXPORT_PACKAGE ) && !properties.containsKey( Analyzer.EXPORT_CONTENTS )
-            && !properties.containsKey( Analyzer.PRIVATE_PACKAGE ) )
+        if ( analyzer.getProperty( Analyzer.EXPORT_PACKAGE ) == null &&
+             analyzer.getProperty( Analyzer.EXPORT_CONTENTS ) == null &&
+             analyzer.getProperty( Analyzer.PRIVATE_PACKAGE ) == null )
         {
             String export = analyzer.calculateExportsFromContents( analyzer.getJar() );
             analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
         }
 
         // Apply Embed-Dependency headers, even though the contents won't be changed
-        Collection embeddableArtifacts = getEmbeddableArtifacts( project, properties );
-        new DependencyEmbedder( embeddableArtifacts ).processHeaders( properties );
+        Collection embeddableArtifacts = getEmbeddableArtifacts( project, analyzer );
+        new DependencyEmbedder( embeddableArtifacts ).processHeaders( analyzer );
 
         analyzer.mergeManifest( analyzer.getJar().getManifest() );
         analyzer.calcManifest();