[FELIX-2825] - The maven-ipojo-plugin does not replace component classes in WAR files
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1067986 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/doc/changelog.txt b/ipojo/manipulator/doc/changelog.txt
index d9972cd..6ad10c6 100644
--- a/ipojo/manipulator/doc/changelog.txt
+++ b/ipojo/manipulator/doc/changelog.txt
@@ -1,3 +1,9 @@
+Changes from the 1.8.0 to 1.8.2
+-------------------------------
+** Bug
+ * [FELIX-2825] - The maven-ipojo-plugin does not replace component classes in WAR files
+
+
Changes from the 1.6.4 to 1.8.0
-------------------------------
** Bug
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
index 8250617..e406c82 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
@@ -351,6 +351,21 @@
}
/**
+ * Gets the class name from the jar entry.
+ * This method handles the WAR case.
+ * @param entry the entry
+ * @return the class name
+ */
+ private String getClassNameForEntry(JarEntry entry) {
+ // If we're manipulating a war file remove the WEB-INF/classes prefix.
+ if (entry.getName().startsWith("WEB-INF/classes/")) {
+ return entry.getName().substring("WEB-INF/classes/".length());
+ } else {
+ return entry.getName();
+ }
+ }
+
+ /**
* Manipulate the input bundle.
* @param out final bundle
*/
@@ -381,9 +396,11 @@
// If the class was manipulated, write out the manipulated
// version of the bytecode
- if (m_classes.containsKey(curEntry.getName())) {
+
+ String classEntry = getClassNameForEntry(curEntry);
+ if (m_classes.containsKey(classEntry)) {
JarEntry je = new JarEntry(curEntry.getName());
- byte[] outClazz = (byte[]) m_classes.get(curEntry.getName());
+ byte[] outClazz = (byte[]) m_classes.get(classEntry);
if (outClazz != null && outClazz.length != 0) {
jos.putNextEntry(je); // copy the entry header to jos
jos.write(outClazz);
@@ -475,7 +492,6 @@
while (entries.hasMoreElements()) {
String curName = (String) entries.nextElement();
try {
-
// Need to load the bytecode for each .class entry
byte[] in = getBytecode(curName);
@@ -484,7 +500,7 @@
// We check the array size to avoid manipulating empty files
// produced by incremental compilers (like Eclipse Compiler)
- if(in != null || in.length > 0) {
+ if(in != null && in.length > 0) {
computeAnnotations(in);
} else {
error("Cannot compute annotations from " + curName + " : Empty file");
@@ -1088,7 +1104,7 @@
}
if (meta == null || meta.length == 0) {
- warn("Neither component types, nor instances in the metadata");
+ warn("Neither component types, nor instances in the XML metadata");
}
m_metadata.addAll(Arrays.asList(meta));
diff --git a/ipojo/plugin/doc/changelog.txt b/ipojo/plugin/doc/changelog.txt
index cd9fe58..c69878a 100644
--- a/ipojo/plugin/doc/changelog.txt
+++ b/ipojo/plugin/doc/changelog.txt
@@ -1,6 +1,7 @@
Changes from the 1.8.0 to 1.8.2
-------------------------------
** Bug
+ * [FELIX-2825] - The maven-ipojo-plugin does not replace component classes in WAR files
* [FELIX-2829] - The maven-ipojo-plugin archetype descriptor is not conform
Changes from the 1.6.0 to 1.8.0
diff --git a/ipojo/plugin/pom.xml b/ipojo/plugin/pom.xml
index 6f64771..408bfc9 100644
--- a/ipojo/plugin/pom.xml
+++ b/ipojo/plugin/pom.xml
@@ -72,7 +72,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.manipulator</artifactId>
- <version>1.8.0</version>
+ <version>1.9.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>