Applying patch (FELIX-290) to fix a concurrent modification exception
with included unit test.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@539482 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java b/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
index 7a8fb0f..c0f69cd 100644
--- a/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
+++ b/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
@@ -117,21 +117,23 @@
/* transform directives from their XML form to the expected BND syntax (eg. _include becomes -include) */
protected Map transformDirectives(Map instructions) {
- Set removedKeys = new HashSet();
+ Map transformedInstructions = new HashMap();
for (Iterator i = instructions.entrySet().iterator(); i.hasNext();) {
- final Map.Entry e = (Map.Entry)i.next();
- final String key = (String)e.getKey();
- if (e.getValue() == null) {
- e.setValue("");
- }
+ Map.Entry e = (Map.Entry)i.next();
+
+ String key = (String)e.getKey();
if (key.startsWith("_")) {
- final String transformedKey = "-"+key.substring(1);
- instructions.put(transformedKey, e.getValue());
- removedKeys.add(key);
+ key = "-"+key.substring(1);
}
+
+ String value = (String)e.getValue();
+ if (null == value) {
+ value = "";
+ }
+
+ transformedInstructions.put(key, value);
}
- instructions.keySet().removeAll(removedKeys);
- return instructions;
+ return transformedInstructions;
}
protected void execute(MavenProject project, Map instructions, Properties properties, Jar[] classpath) throws MojoExecutionException {
diff --git a/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java b/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java
index e024b62..f157e3e 100644
--- a/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java
+++ b/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java
@@ -22,6 +22,8 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.project.MavenProject;
@@ -148,4 +150,42 @@
archiver.setDestFile( jarFile );
archiver.createArchive();
}
+
+ public void testTransformDirectives()
+ throws Exception
+ {
+ Map instructions = new TreeMap();
+
+ instructions.put("a", "1");
+ instructions.put("-a", "2");
+ instructions.put("_a", "3");
+ instructions.put("A", "3");
+ instructions.put("_A", "1");
+ instructions.put("_b", "4");
+ instructions.put("b", "6");
+ instructions.put("_B", "6");
+ instructions.put("-B", "5");
+ instructions.put("B", "4");
+
+ instructions.put("z", null);
+ instructions.put("_z", null);
+
+ Map transformedInstructions = plugin.transformDirectives( instructions );
+
+ assertEquals( "1", transformedInstructions.get("a") );
+ assertEquals( "3", transformedInstructions.get("-a") );
+ assertEquals( null, transformedInstructions.get("_a") );
+ assertEquals( "3", transformedInstructions.get("A") );
+ assertEquals( "1", transformedInstructions.get("-A") );
+ assertEquals( null, transformedInstructions.get("_A") );
+ assertEquals( null, transformedInstructions.get("_b") );
+ assertEquals( "4", transformedInstructions.get("-b") );
+ assertEquals( "6", transformedInstructions.get("b") );
+ assertEquals( null, transformedInstructions.get("_B") );
+ assertEquals( "6", transformedInstructions.get("-B") );
+ assertEquals( "4", transformedInstructions.get("B") );
+
+ assertEquals( "", transformedInstructions.get("z") );
+ assertEquals( "", transformedInstructions.get("-z") );
+ }
}