You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/07/02 12:19:58 UTC

svn commit: r1498867 - in /felix/trunk/ipojo/manipulator/manipulator/src: main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java

Author: guillaume
Date: Tue Jul  2 10:19:58 2013
New Revision: 1498867

URL: http://svn.apache.org/r1498867
Log:
FELIX-4021 maven-ipojo-plugin fails on WAR packaging

* Only map WEB-INF/classes/** resources
* Leave others unchanged

Modified:
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java?rev=1498867&r1=1498866&r2=1498867&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java Tue Jul  2 10:19:58 2013
@@ -19,28 +19,40 @@
 
 package org.apache.felix.ipojo.manipulator.store.mapper;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.felix.ipojo.manipulator.store.ResourceMapper;
 
 /**
  * A {@code WABResourceMapper} knows how to map resource names for a Web Application Bundle (WAB).
  *
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- *
- * TODO It is not actually used by default, that will probably lead to some Exception
  */
 public class WABResourceMapper implements ResourceMapper {
 
     public static final String WEB_INF_CLASSES = "WEB-INF/classes/";
 
+    /**
+     * Store externalized names so that internalize can rebuild the good resource name.
+     */
+    private List<String> mappedNames = new ArrayList<String>();
+
     public String internalize(String name) {
-        return WEB_INF_CLASSES + name;
+        if (mappedNames.contains(name)) {
+            return WEB_INF_CLASSES + name;
+        }
+        return name;
     }
 
     public String externalize(String name) {
         if (name.startsWith(WEB_INF_CLASSES)) {
-            return name.substring(WEB_INF_CLASSES.length());
-        } else {
-            throw new IllegalArgumentException("Path '" + name + "' do not start with '" + WEB_INF_CLASSES + "'");
+            String externalized = name.substring(WEB_INF_CLASSES.length());
+            mappedNames.add(externalized);
+            return externalized;
         }
+        // Leave the name unchanged
+        // (it's probably META-INF/** or WEB-INF/lib/**)
+        return name;
     }
 }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java?rev=1498867&r1=1498866&r2=1498867&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java Tue Jul  2 10:19:58 2013
@@ -24,27 +24,42 @@ import junit.framework.TestCase;
 import org.apache.felix.ipojo.manipulator.store.ResourceMapper;
 
 public class WABResourceMapperTestCase extends TestCase {
-    public void testSimpleInternalize() throws Exception {
+
+    public void testWebInfClassesResourceIsMapped() throws Exception {
         ResourceMapper mapper = new WABResourceMapper();
-        String path = "jndi.properties";
-        Assert.assertEquals("WEB-INF/classes/" + path, mapper.internalize(path));
+
+        String normalized = "jndi.properties";
+        String resource = "WEB-INF/classes/jndi.properties";
+
+        Assert.assertEquals(normalized, mapper.externalize(resource));
+        Assert.assertEquals(resource, mapper.internalize(normalized));
     }
 
-    public void testSimpleExternalize() throws Exception {
+    public void testWebInfLibResourceIsUnchanged() throws Exception {
         ResourceMapper mapper = new WABResourceMapper();
-        String path = "WEB-INF/classes/jndi.properties";
-        Assert.assertEquals("jndi.properties", mapper.externalize(path));
+
+        String normalized = "WEB-INF/lib/commons-logging.jar";
+        String resource = "WEB-INF/lib/commons-logging.jar";
+
+        Assert.assertEquals(normalized, mapper.externalize(resource));
+        Assert.assertEquals(resource, mapper.internalize(normalized));
     }
 
-    public void testExternalizeError() throws Exception {
+    public void testMetaInfManifestIsUnchanged() throws Exception {
         ResourceMapper mapper = new WABResourceMapper();
-        String path = "jndi.properties";
 
-        try {
-            mapper.externalize(path);
-            fail("Should have thrown an IllegalArgumentException");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
+        String normalized = "META-INF/MANIFEST.MF";
+        String resource = "META-INF/MANIFEST.MF";
+
+        Assert.assertEquals(normalized, mapper.externalize(resource));
+        Assert.assertEquals(resource, mapper.internalize(normalized));
+    }
+
+    public void testResourceNotMapped() throws Exception {
+        ResourceMapper mapper = new WABResourceMapper();
+
+        String resource = "images/logo.png";
+
+        Assert.assertEquals(resource, mapper.internalize(resource));
     }
 }