Enabled plugig configuration for the list of jars to skip
diff --git a/README.adoc b/README.adoc index 679c8c0..e7154af 100644 --- a/README.adoc +++ b/README.adoc
@@ -98,7 +98,7 @@ Note that transitive dependecies are not supported, so each jar directly needed to compile must be specified individually. -## Repacing Jar files in the Archive +## Replacing Jar files in the Archive The `<replace><jars>` list allows us to tell the plugin, "when you see a `jakarta.faces-3.0.0.jar` in the war file, replace it with the `org.glassfish:jakarta.faces:jar:3.0.0` artifact from our local maven repo." @@ -122,3 +122,16 @@ The `<replace><jars>` list allows us to tell the plugin, "when you see an `openejb-version.properties` file anywhere in the war file or its libraries, replace it with the specially modified version from `target/classes/`." In the module we're generating a new `openejb-version.properties` so we can change the version TomEE reports from "8.0.7-SNAPSHOT" to "9.0.0-M7-SNAPSHOT" +## Skipping Jar files from the Archives +This is useful when you have jars found in the archive need to preserve jar signature metadata. +The `<skips><jars>` list allows you to tell the plugin which Jars should be skipped during archive transformation. +Example configuration: + + <configuration> + <skips> + <jars> + <eclipselink-3.0.0.jar>org.eclipse.persistence:eclipselink:jar:3.0.0</eclipselink-3.0.0.jar> + <bcprov-jdk15on-1.69.jar>org.bouncycastle:bcprov-jdk15on:jar:1.69</bcprov-jdk15on-1.69.jar> + </jars> + </skips> + </configuration> \ No newline at end of file
diff --git a/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Skips.java b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Skips.java new file mode 100644 index 0000000..a548047 --- /dev/null +++ b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Skips.java
@@ -0,0 +1,11 @@ +package org.apache.tomee.patch.core; + +import java.util.HashMap; +import java.util.Map; + +public class Skips { + private Map<String, String> jars = new HashMap<>(); + public Map<String, String> getJars() { + return jars; + } +}
diff --git a/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Transformation.java b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Transformation.java index a83f237..3cc2a39 100644 --- a/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Transformation.java +++ b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/Transformation.java
@@ -28,11 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.zip.ZipEntry; @@ -46,6 +42,7 @@ private final List<Clazz> classes = new ArrayList<Clazz>(); private final Log log; private final Replacements replacements; + private final Skips skips; private final Additions additions; private final Boolean skipTransform; private final File patchResources; @@ -53,16 +50,18 @@ public Transformation() { this.log = new NullLog(); this.replacements = new Replacements(); + this.skips = new Skips(); this.additions = new Additions(); this.skipTransform = false; this.patchResources = new File("does not exist"); } - public Transformation(final List<Clazz> classes, final File patchResources, final Replacements replacements, final Additions additions, final Log log, final Boolean skipTransform) { + public Transformation(final List<Clazz> classes, final File patchResources, final Replacements replacements, final Skips skips, final Additions additions, final Log log, final Boolean skipTransform) { this.classes.addAll(classes); this.log = log; this.replacements = replacements == null ? new Replacements() : replacements; + this.skips = skips == null ? new Skips() : skips; this.additions = additions == null ? new Additions() : additions; this.patchResources = patchResources; this.skipTransform = skipTransform; @@ -268,7 +267,16 @@ } private boolean isExcludedJar(final String path) { - if (path.matches(".*bcprov-jdk15on-.*.jar")) return true; + if (skips != null) { + Map<String, String> skipsJars = skips.getJars(); + if (!skipsJars.isEmpty()) { + for (Map.Entry<String, String> set : skipsJars.entrySet()) { + if (path.contains(set.getKey())) { + return true; + } + } + } + } return false; }
diff --git a/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ExcludeJarsTest.java b/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ExcludeJarsTest.java index d5d918c..719ba97 100644 --- a/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ExcludeJarsTest.java +++ b/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ExcludeJarsTest.java
@@ -1,5 +1,6 @@ package org.apache.tomee.patch.core; +import org.junit.Before; import org.junit.Test; import org.tomitribe.util.Archive; @@ -7,9 +8,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.zip.ZipEntry; @@ -20,6 +19,13 @@ public class ExcludeJarsTest { public static final int DEFAULT_BUFFER_SIZE = 8192; + public Skips customSkips = new Skips(); + + @Before + public void prepareLists(){ + customSkips.getJars().put("eclipselink-3.0.0.jar","org.eclipse.persistence:eclipselink:jar:3.0.0"); + customSkips.getJars().put("bcprov-jdk15on-1.69.jar","org.bouncycastle:bcprov-jdk15on:jar:1.69"); + } @Test public void transformWithJarExclusions() throws Exception { @@ -34,7 +40,8 @@ .add("README.txt", "hi") .add(jarName, testJar).toJar(); - File transformedJar = Transformation.transform(zipFile); + Transformation transformation = new Transformation(new ArrayList<Clazz>(), new File("does not exist"),null, customSkips, null, new NullLog(), false); + File transformedJar = transformation.transformArchive(zipFile); assertTrue(obtainJarContent(transformedJar).contains(jarSignatureFileName)); } @@ -52,7 +59,8 @@ .add("README.txt", "hi") .add(jarName, testJar).toJar(); - File transformedJar = Transformation.transform(zipFile); + Transformation transformation = new Transformation(new ArrayList<Clazz>(), new File("does not exist"),null, customSkips, null, new NullLog(), false); + File transformedJar = transformation.transformArchive(zipFile); assertFalse(obtainJarContent(transformedJar).contains(jarSignatureFileName)); }
diff --git a/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java b/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java index 4975a39..192e54a 100644 --- a/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java +++ b/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java
@@ -48,12 +48,7 @@ import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException; import org.apache.maven.toolchain.Toolchain; import org.apache.maven.toolchain.ToolchainManager; -import org.apache.tomee.patch.core.Additions; -import org.apache.tomee.patch.core.Clazz; -import org.apache.tomee.patch.core.Is; -import org.apache.tomee.patch.core.Replacements; -import org.apache.tomee.patch.core.Transformation; -import org.apache.tomee.patch.core.ZipToTar; +import org.apache.tomee.patch.core.*; import org.codehaus.plexus.compiler.Compiler; import org.codehaus.plexus.compiler.CompilerConfiguration; import org.codehaus.plexus.compiler.CompilerMessage; @@ -180,6 +175,9 @@ private Replacements replace; @Parameter + private Skips skips; + + @Parameter private Additions add; @Parameter(defaultValue = "false") @@ -285,7 +283,7 @@ final List<Clazz> clazzes = classes(); - final Transformation transformation = new Transformation(clazzes, patchResourceDirectory, replace, add, new MavenLog(getLog()), skipTransform); + final Transformation transformation = new Transformation(clazzes, patchResourceDirectory, replace, skips, add, new MavenLog(getLog()), skipTransform); for (final Artifact artifact : artifacts) { final File file = artifact.getFile(); getLog().debug("Patching " + file.getAbsolutePath());