FELIX-4021 maven-ipojo-plugin fails on WAR packaging
* Only map WEB-INF/classes/** resources
* Leave others unchanged
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1498867 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java
index 4999a3c..c73b235 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapper.java
@@ -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;
}
}
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java
index 2421cc9..bb6f75c 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/store/mapper/WABResourceMapperTestCase.java
@@ -24,27 +24,42 @@
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));
}
}