You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/05/18 16:33:56 UTC

svn commit: r539482 - in /felix/trunk/tools/maven2/maven-bundle-plugin/src: main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java

Author: rickhall
Date: Fri May 18 07:33:55 2007
New Revision: 539482

URL: http://svn.apache.org/viewvc?view=rev&rev=539482
Log:
Applying patch (FELIX-290) to fix a concurrent modification exception
with included unit test.

Modified:
    felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
    felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java?view=diff&rev=539482&r1=539481&r2=539482
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java Fri May 18 07:33:55 2007
@@ -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 {

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java?view=diff&rev=539482&r1=539481&r2=539482
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java Fri May 18 07:33:55 2007
@@ -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;
@@ -147,5 +149,43 @@
         archiver.addFile( getTestFile( "pom.xml" ), "org/apache/maven/test/resources/someresource" );
         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") );
     }
 }