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:01 UTC
[tomee-patch-plugin] 01/02: Add a flag so we can skip the javax ->
jakarta namespace transformation
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());