You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2021/03/26 16:55:00 UTC

[tomee-patch-plugin] branch master updated (28b3fca -> 8428a1b)

This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-patch-plugin.git.


    from 28b3fca  Ability to replace both resources and jars (fixed) Initial use case is actually to restore mojarra and eclipselink with completely unmodified versions
     new 08e5744  Add a flag so we can skip the javax -> jakarta namespace transformation
     new 8428a1b  Make sure to be as fine as possible in checking the class names so we don't mess up in case classes share the same prefix

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/tomee/patch/core/Transformation.java    | 59 ++++++++++++++--------
 .../org/apache/tomee/patch/plugin/PatchMojo.java   |  5 +-
 2 files changed, 42 insertions(+), 22 deletions(-)

[tomee-patch-plugin] 02/02: Make sure to be as fine as possible in checking the class names so we don't mess up in case classes share the same prefix

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-patch-plugin.git

commit 8428a1b5301c47694f20668c5ec2b1f479ea92ef
Author: Jean-Louis Monteiro <jl...@tomitribe.com>
AuthorDate: Fri Mar 26 17:51:49 2021 +0100

    Make sure to be as fine as possible in checking the class names so we don't mess up in case classes share the same prefix
---
 .../src/main/java/org/apache/tomee/patch/core/Transformation.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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 fc59495..a49c061 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
@@ -383,7 +383,9 @@ public class Transformation {
 
     private boolean isPatched(final String path, final Jar jar) {
         for (final Clazz clazz : classes) {
-            if (path.startsWith(clazz.getPrefix())) {
+            if (path.equals(clazz.getName()) ||
+                    path.startsWith(clazz.getPrefix() + "$")) {
+
                 jar.patch(clazz, classes);
                 return true;
             }

[tomee-patch-plugin] 01/02: Add a flag so we can skip the javax -> jakarta namespace transformation

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-patch-plugin.git

commit 08e5744164339de2276513123e63d57e2aaabdc0
Author: Jean-Louis Monteiro <jl...@tomitribe.com>
AuthorDate: Fri Mar 26 17:50:50 2021 +0100

    Add a flag so we can skip the javax -> jakarta namespace transformation
---
 .../apache/tomee/patch/core/Transformation.java    | 55 ++++++++++++++--------
 .../org/apache/tomee/patch/plugin/PatchMojo.java   |  5 +-
 2 files changed, 39 insertions(+), 21 deletions(-)

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 9cb12d2..fc59495 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
@@ -44,17 +44,20 @@ public class Transformation {
     private final List<Clazz> classes = new ArrayList<Clazz>();
     private final Log log;
     private final Replacements replacements;
+    private final Boolean skipTransform;
 
     public Transformation() {
         this.log = new NullLog();
         this.replacements = new Replacements();
+        this.skipTransform = false;
     }
 
 
-    public Transformation(final List<Clazz> classes, final Replacements replacements, final Log log) {
+    public Transformation(final List<Clazz> classes, final Replacements replacements, final Log log, final Boolean skipTransform) {
         this.classes.addAll(classes);
         this.log = log;
         this.replacements = replacements == null ? new Replacements() : replacements;
+        this.skipTransform = skipTransform;
     }
 
     public static File transform(final File jar) throws IOException {
@@ -85,11 +88,7 @@ public class Transformation {
                 log.info(String.format("Replaced %s", name));
                 IO.copy(file, outputStream);
 
-                IO.copy(inputStream, new OutputStream() {
-                    @Override
-                    public void write(final int b) throws IOException {
-                    }
-                });
+                IO.copy(inputStream, skipped);
 
                 return;
             }
@@ -194,6 +193,28 @@ public class Transformation {
     }
 
     private void scanResource(final String path, InputStream inputStream, final OutputStream outputStream) throws IOException {
+
+        {
+            final String name = new File(path).getName();
+            final String replacement = replacements.getResources().get(name);
+            if (replacement != null) {
+                log.info(String.format("Replaced %s", path));
+                final File file = new File(replacement);
+                if (!file.exists()) {
+                    throw new ReplacementNotFoundException("resource", path, file.getAbsolutePath());
+                }
+                inputStream = IO.read(file);
+                IO.copy(inputStream, outputStream);
+                return;
+            }
+        }
+
+        // in case we don't want to apply any transformation. Only replacement will happen
+        if (skipTransform) {
+            return;
+        }
+
+
         if (path.endsWith("openwebbeans.properties")) {
             inputStream = StreamBuilder.create(inputStream)
                     .replace("org.apache.webbeans.proxy.mapping.javax.enterprise", "org.apache.webbeans.proxy.mapping.jakarta.enterprise")
@@ -236,19 +257,6 @@ public class Transformation {
                 .replace("javax\\.faces", "jakarta\\.faces") // in some javascript files
                 .get();
 
-        {
-            final String name = new File(path).getName();
-            final String replacement = replacements.getResources().get(name);
-            if (replacement != null) {
-                log.info(String.format("Replaced %s", path));
-                final File file = new File(replacement);
-                if (!file.exists()) {
-                    throw new ReplacementNotFoundException("resource", path, file.getAbsolutePath());
-                }
-                inputStream = IO.read(file);
-            }
-        }
-
         IO.copy(inputStream, outputStream);
     }
 
@@ -267,7 +275,14 @@ public class Transformation {
         return Is.Zip.accept(path);
     }
 
-    private static void scanClass(final InputStream in, final OutputStream outputStream) throws IOException {
+    private void scanClass(final InputStream in, final OutputStream outputStream) throws IOException {
+
+        // in case we don't want to apply any transformation. Only replacement will happen
+        if (skipTransform) {
+            IO.copy(in, outputStream);
+            return;
+        }
+
         final ClassWriter classWriter = new ClassWriter(Opcodes.ASM8);
         final ClassTransformer classTransformer = new ClassTransformer(classWriter);
         final ClassReader classReader = new ClassReader(in);
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 f6c41b4..954c2e9 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
@@ -100,6 +100,9 @@ public class PatchMojo extends AbstractMojo {
     @Parameter(defaultValue = "false")
     private Boolean createTarGz;
 
+    @Parameter(defaultValue = "false")
+    private Boolean skipTransform;
+
     /**
      * Sets the executable of the compiler to use when fork is <code>true</code>.
      */
@@ -188,7 +191,7 @@ public class PatchMojo extends AbstractMojo {
 
             final List<Clazz> clazzes = classes();
 
-            final Transformation transformation = new Transformation(clazzes, replace, new MavenLog(getLog()));
+            final Transformation transformation = new Transformation(clazzes, replace, new MavenLog(getLog()), skipTransform);
             for (final Artifact artifact : artifacts) {
                 final File file = artifact.getFile();
                 getLog().debug("Patching " + file.getAbsolutePath());