You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/03/23 05:43:50 UTC

[tomee-patch-plugin] branch master updated (b8f8843 -> 13f5b18)

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

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


    from b8f8843  Add release plugin configuration from TomEE repo
     new b5913b1  [maven-release-plugin] prepare release tomee-patch-parent-0.3
     new 52a50cb  [maven-release-plugin] prepare for next development iteration
     new b54dcb0  Ability to create tar.gz files from the zip
     new 8729d52  Log error if no artifacts match select regex
     new 3097165  Allow replacements to be null
     new 43bbb4f  Allow multiple patch source directories
     new 5ba3914  Ability to exclude selected sources
     new 13f5b18  Remove unused method

The 8 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:
 pom.xml                                            |  2 +-
 tomee-patch-core/pom.xml                           |  7 +-
 .../apache/tomee/patch/core/Transformation.java    |  4 +-
 .../java/org/apache/tomee/patch/core/ZipToTar.java | 85 +++++++++++++++++++++
 .../org/apache/tomee/patch/core/ZipToTarTest.java  | 68 +++++++++++++++++
 tomee-patch-plugin/pom.xml                         |  2 +-
 .../org/apache/tomee/patch/plugin/PatchMojo.java   | 88 +++++++++++++++++++---
 7 files changed, 241 insertions(+), 15 deletions(-)
 create mode 100644 tomee-patch-core/src/main/java/org/apache/tomee/patch/core/ZipToTar.java
 create mode 100644 tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ZipToTarTest.java

[tomee-patch-plugin] 01/08: [maven-release-plugin] prepare release tomee-patch-parent-0.3

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

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

commit b5913b1d48d118c06f6bd4feaee1123e59afecd0
Author: David Blevins <da...@gmail.com>
AuthorDate: Thu Mar 18 20:29:59 2021 -0700

    [maven-release-plugin] prepare release tomee-patch-parent-0.3
---
 pom.xml                    | 4 ++--
 tomee-patch-core/pom.xml   | 2 +-
 tomee-patch-plugin/pom.xml | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 00aaa79..1e727cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@
   <groupId>org.apache.tomee.patch</groupId>
   <artifactId>tomee-patch-parent</artifactId>
   <packaging>pom</packaging>
-  <version>0.3-SNAPSHOT</version>
+  <version>0.3</version>
 
   <name>Apache TomEE Patch Plugin</name>
   <description>Tools and Maven Plugin to help complete the javax-to-jakarta bytecode transformation</description>
@@ -47,7 +47,7 @@
     <connection>scm:git:git@github.com:apache/tomee-patch-plugin.git</connection>
     <url>scm:git:git@github.com:apache/tomee-patch-plugin.git</url>
     <developerConnection>scm:git:git@github.com:apache/tomee-patch-plugin.git</developerConnection>
-    <tag>tomee-patch-parent-0.2</tag>
+    <tag>tomee-patch-parent-0.3</tag>
   </scm>
 
   <issueManagement>
diff --git a/tomee-patch-core/pom.xml b/tomee-patch-core/pom.xml
index 703ac5a..86406dc 100644
--- a/tomee-patch-core/pom.xml
+++ b/tomee-patch-core/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.apache.tomee.patch</groupId>
     <artifactId>tomee-patch-parent</artifactId>
-    <version>0.3-SNAPSHOT</version>
+    <version>0.3</version>
   </parent>
 
   <artifactId>tomee-patch-core</artifactId>
diff --git a/tomee-patch-plugin/pom.xml b/tomee-patch-plugin/pom.xml
index b5edd8c..f6d1c43 100644
--- a/tomee-patch-plugin/pom.xml
+++ b/tomee-patch-plugin/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.apache.tomee.patch</groupId>
     <artifactId>tomee-patch-parent</artifactId>
-    <version>0.3-SNAPSHOT</version>
+    <version>0.3</version>
   </parent>
 
   <artifactId>tomee-patch-plugin</artifactId>

[tomee-patch-plugin] 03/08: Ability to create tar.gz files from the zip

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

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

commit b54dcb0c6ec405560eca7a761ff60e4b1210b59a
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 17:59:45 2021 -0700

    Ability to create tar.gz files from the zip
---
 tomee-patch-core/pom.xml                           |  5 ++
 .../java/org/apache/tomee/patch/core/ZipToTar.java | 85 ++++++++++++++++++++++
 .../org/apache/tomee/patch/core/ZipToTarTest.java  | 68 +++++++++++++++++
 .../org/apache/tomee/patch/plugin/PatchMojo.java   | 21 ++++++
 4 files changed, 179 insertions(+)

diff --git a/tomee-patch-core/pom.xml b/tomee-patch-core/pom.xml
index 7896d0b..60bae10 100644
--- a/tomee-patch-core/pom.xml
+++ b/tomee-patch-core/pom.xml
@@ -82,6 +82,11 @@
       <version>0.10</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-compress</artifactId>
+      <version>1.20</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.10</version>
diff --git a/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/ZipToTar.java b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/ZipToTar.java
new file mode 100644
index 0000000..cd9bd53
--- /dev/null
+++ b/tomee-patch-core/src/main/java/org/apache/tomee/patch/core/ZipToTar.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomee.patch.core;
+
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.tomitribe.util.IO;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class ZipToTar {
+
+    public static File toTarGz(final File zip) throws Exception {
+
+        final String tarGzName = zip.getName().replaceAll("\\.(zip|jar)$", ".tar.gz");
+        final File tarGz = new File(zip.getParentFile(), tarGzName);
+
+        try (final InputStream in = IO.read(zip); final TarArchiveOutputStream tarOut = tar(tarGz)) {
+
+            tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
+
+            final ZipInputStream zipIn = new ZipInputStream(in);
+
+            ZipEntry zipEntry;
+            while ((zipEntry = zipIn.getNextEntry()) != null) {
+                final String name = zipEntry.getName();
+
+                // The ZipEntry often shows -1 as the size and the
+                // TarArchiveOutputStream API requires us to know the
+                // exact size before we start writing.  So we have to
+                // buffer everything in memory first to learn the size
+                final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+                IO.copy(zipIn, buffer);
+                final byte[] bytes = buffer.toByteArray();
+
+                final TarArchiveEntry tarEntry = new TarArchiveEntry(name);
+
+                // Set the size and date
+                tarEntry.setSize(bytes.length);
+                tarEntry.setModTime(zipEntry.getLastModifiedTime().toMillis());
+
+                // Mark any shell scripts as executable
+                if (name.endsWith(".sh")) {
+                    tarEntry.setMode(493);
+                }
+
+                // Finally out the Entry into the archive
+                // Any attributes set on tarEntry after this
+                // point are ignored.
+                tarOut.putArchiveEntry(tarEntry);
+
+                IO.copy(bytes, tarOut);
+                tarOut.closeArchiveEntry();
+            }
+
+            tarOut.finish();
+        }
+
+        return tarGz;
+    }
+
+    private static TarArchiveOutputStream tar(final File tarGz) throws IOException {
+        return new TarArchiveOutputStream(new GZIPOutputStream(IO.write(tarGz)));
+    }
+}
diff --git a/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ZipToTarTest.java b/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ZipToTarTest.java
new file mode 100644
index 0000000..13bca8f
--- /dev/null
+++ b/tomee-patch-core/src/test/java/org/apache/tomee/patch/core/ZipToTarTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomee.patch.core;
+
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.junit.Test;
+import org.tomitribe.util.Archive;
+import org.tomitribe.util.IO;
+import org.tomitribe.util.PrintString;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+import static org.junit.Assert.assertEquals;
+
+public class ZipToTarTest {
+
+    @Test
+    public void createTarGz() throws Exception {
+        final File zip = Archive.archive()
+                .add("color/red/crimson.txt", "DC143C")
+                .add("color/red/ruby.txt", "9b111e")
+                .add("color/blue/navy.sh", "000080")
+                .add("color/green/forest.txt", "228b22")
+                .add("index.txt", "red,green,blue")
+                .toJar();
+
+
+        final File tarGz = ZipToTar.toTarGz(zip);
+
+        final PrintString out = new PrintString();
+        {
+
+            final InputStream in = IO.read(tarGz);
+            final GZIPInputStream gzipIn = new GZIPInputStream(in);
+            final TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn);
+
+            TarArchiveEntry tarEntry = null;
+            while ((tarEntry = (TarArchiveEntry) tarIn.getNextEntry()) != null) {
+                out.printf("%s %s %s%n", tarEntry.getSize(), tarEntry.getMode(), tarEntry.getName());
+            }
+        }
+
+        assertEquals("" +
+                "14 33188 index.txt\n" +
+                "6 33188 color/red/crimson.txt\n" +
+                "6 493 color/blue/navy.sh\n" +
+                "6 33188 color/red/ruby.txt\n" +
+                "6 33188 color/green/forest.txt\n", out.toString());
+    }
+
+}
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 c76ab47..00afa53 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
@@ -26,11 +26,13 @@ import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.AttachedArtifact;
 import org.apache.maven.toolchain.Toolchain;
 import org.apache.maven.toolchain.ToolchainManager;
 import org.apache.tomee.patch.core.Clazz;
 import org.apache.tomee.patch.core.Is;
 import org.apache.tomee.patch.core.Transformation;
+import org.apache.tomee.patch.core.ZipToTar;
 import org.codehaus.plexus.compiler.Compiler;
 import org.codehaus.plexus.compiler.CompilerConfiguration;
 import org.codehaus.plexus.compiler.CompilerMessage;
@@ -89,6 +91,9 @@ public class PatchMojo extends AbstractMojo {
     @Parameter
     private Map<String, String> replacements;
 
+    @Parameter(defaultValue = "false")
+    private Boolean createTarGz;
+
     /**
      * Sets the executable of the compiler to use when fork is <code>true</code>.
      */
@@ -180,6 +185,22 @@ public class PatchMojo extends AbstractMojo {
                 getLog().debug("Patching " + file.getAbsolutePath());
                 final File patched = transformation.transformArchive(file);
                 IO.copy(patched, file);
+
+                if (createTarGz && file.getName().endsWith(".zip")) {
+                    final File tarGz;
+                    try {
+                        tarGz = ZipToTar.toTarGz(file);
+                    } catch (Exception e) {
+                        getLog().error("Failed to create tar.gz from " + file.getAbsolutePath(), e);
+                        continue;
+                    }
+
+                    final String classifier = artifact.getClassifier();
+                    final AttachedArtifact attachedArtifact = new AttachedArtifact(project.getArtifact(), "tar.gz", classifier, project.getArtifact().getArtifactHandler());
+                    attachedArtifact.setFile(tarGz);
+                    attachedArtifact.setResolved(true);
+                    project.addAttachedArtifact(attachedArtifact);
+                }
             }
 
             transformation.complete();

[tomee-patch-plugin] 05/08: Allow replacements to be null

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

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

commit 3097165eda9dbeaee6fda2b729819fd4043b7293
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 19:32:28 2021 -0700

    Allow replacements to be null
---
 .../src/main/java/org/apache/tomee/patch/core/Transformation.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 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 2625c5a..8312aca 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
@@ -55,7 +55,7 @@ public class Transformation {
     public Transformation(final List<Clazz> classes, final Map<String, String> replacements, final Log log) {
         this.classes.addAll(classes);
         this.log = log;
-        this.replacements = replacements;
+        this.replacements = replacements == null ? Collections.EMPTY_MAP : replacements;
     }
 
     public static File transform(final File jar) throws IOException {
@@ -224,7 +224,7 @@ public class Transformation {
                 inputStream = IO.read(new File(replacement));
             }
         }
-        
+
         IO.copy(inputStream, outputStream);
     }
 

[tomee-patch-plugin] 06/08: Allow multiple patch source directories

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

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

commit 43bbb4f71e02b53d25a6d426afc6d4d6372f00af
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 20:01:42 2021 -0700

    Allow multiple patch source directories
---
 .../java/org/apache/tomee/patch/plugin/PatchMojo.java    | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

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 d41ae88..812ac52 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
@@ -51,7 +51,6 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Predicate;
@@ -69,7 +68,7 @@ public class PatchMojo extends AbstractMojo {
     private MavenSession session;
 
     @Parameter(defaultValue = "${project.basedir}/src/patch/java", required = true)
-    private File patchSourceDirectory;
+    private List<File> patchSources;
 
     /**
      * Regex to identify which archives should be matched
@@ -176,7 +175,7 @@ public class PatchMojo extends AbstractMojo {
             // Extract any zips and return a list of jars
             final List<File> jars = prepareJars(artifacts);
 
-            compile(patchSourceDirectory, jars);
+            compile(jars);
 
             final List<Clazz> clazzes = classes();
 
@@ -278,7 +277,7 @@ public class PatchMojo extends AbstractMojo {
         return selected;
     }
 
-    private void compile(final File patchSourceDirectory, final List<File> jars) throws MojoExecutionException, CompilationFailureException {
+    private void compile(final List<File> jars) throws MojoExecutionException, CompilationFailureException {
 
         getLog().debug("Using compiler '" + compilerId + "'.");
 
@@ -405,12 +404,9 @@ public class PatchMojo extends AbstractMojo {
     }
 
     private List<String> getPatchSourceLocations() {
-        return Collections.singletonList(patchSourceDirectory.getAbsolutePath());
-    }
-
-    private void patch(final Artifact artifact) throws IOException {
-        final File file = artifact.getFile();
-
+        return patchSources.stream()
+                .map(File::getAbsolutePath)
+                .collect(Collectors.toList());
     }
 
     //TODO remove the part with ToolchainManager lookup once we depend on

[tomee-patch-plugin] 08/08: Remove unused method

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

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

commit 13f5b18a58880b720b4780162148853f1e2df0f1
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 22:43:36 2021 -0700

    Remove unused method
---
 .../src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java      | 6 ------
 1 file changed, 6 deletions(-)

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 84e4c02..663805b 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
@@ -441,12 +441,6 @@ public class PatchMojo extends AbstractMojo {
         }
     }
 
-    private List<String> getPatchSourceLocations() {
-        return patchSources.stream()
-                .map(File::getAbsolutePath)
-                .collect(Collectors.toList());
-    }
-
     //TODO remove the part with ToolchainManager lookup once we depend on
     //3.0.9 (have it as prerequisite). Define as regular component field then.
     protected final Toolchain getToolchain() {

[tomee-patch-plugin] 02/08: [maven-release-plugin] prepare for next development iteration

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

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

commit 52a50cb0a5d78903b444a011f20a519010e550e4
Author: David Blevins <da...@gmail.com>
AuthorDate: Thu Mar 18 20:30:10 2021 -0700

    [maven-release-plugin] prepare for next development iteration
---
 pom.xml                    | 4 ++--
 tomee-patch-core/pom.xml   | 2 +-
 tomee-patch-plugin/pom.xml | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 1e727cf..d847cda 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@
   <groupId>org.apache.tomee.patch</groupId>
   <artifactId>tomee-patch-parent</artifactId>
   <packaging>pom</packaging>
-  <version>0.3</version>
+  <version>0.4-SNAPSHOT</version>
 
   <name>Apache TomEE Patch Plugin</name>
   <description>Tools and Maven Plugin to help complete the javax-to-jakarta bytecode transformation</description>
@@ -47,7 +47,7 @@
     <connection>scm:git:git@github.com:apache/tomee-patch-plugin.git</connection>
     <url>scm:git:git@github.com:apache/tomee-patch-plugin.git</url>
     <developerConnection>scm:git:git@github.com:apache/tomee-patch-plugin.git</developerConnection>
-    <tag>tomee-patch-parent-0.3</tag>
+    <tag>tomee-patch-parent-0.2</tag>
   </scm>
 
   <issueManagement>
diff --git a/tomee-patch-core/pom.xml b/tomee-patch-core/pom.xml
index 86406dc..7896d0b 100644
--- a/tomee-patch-core/pom.xml
+++ b/tomee-patch-core/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.apache.tomee.patch</groupId>
     <artifactId>tomee-patch-parent</artifactId>
-    <version>0.3</version>
+    <version>0.4-SNAPSHOT</version>
   </parent>
 
   <artifactId>tomee-patch-core</artifactId>
diff --git a/tomee-patch-plugin/pom.xml b/tomee-patch-plugin/pom.xml
index f6d1c43..2113905 100644
--- a/tomee-patch-plugin/pom.xml
+++ b/tomee-patch-plugin/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.apache.tomee.patch</groupId>
     <artifactId>tomee-patch-parent</artifactId>
-    <version>0.3</version>
+    <version>0.4-SNAPSHOT</version>
   </parent>
 
   <artifactId>tomee-patch-plugin</artifactId>

[tomee-patch-plugin] 04/08: Log error if no artifacts match select regex

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

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

commit 8729d529d4e30f10d7305c8a6f830e2bee795161
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 18:33:39 2021 -0700

    Log error if no artifacts match select regex
---
 .../org/apache/tomee/patch/plugin/PatchMojo.java    | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

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 00afa53..d41ae88 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
@@ -50,6 +50,7 @@ import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -259,9 +260,22 @@ public class PatchMojo extends AbstractMojo {
 
     private List<Artifact> getPatchArtifacts() {
         final Predicate<String> match = Pattern.compile(select).asPredicate();
-        return Stream.of(getSourceArtifacts())
+        final Artifact[] available = getSourceArtifacts();
+
+        final List<Artifact> selected = Stream.of(available)
                 .filter(artifact -> match.test(artifact.getFile().getName()))
                 .collect(Collectors.toList());
+
+        if (selected.size() == 0) {
+            final String message = String.format("No artifacts matched expression '%s'.  %s available artifacts:", select, available.length);
+            getLog().error(message);
+            Arrays.stream(available)
+                    .map(artifact -> artifact.getFile().getName())
+                    .forEach(s -> getLog().error(" - " + s));
+
+            throw new NoMatchingArtifactsException(select);
+        }
+        return selected;
     }
 
     private void compile(final File patchSourceDirectory, final List<File> jars) throws MojoExecutionException, CompilationFailureException {
@@ -452,4 +466,9 @@ public class PatchMojo extends AbstractMojo {
         return artifactList.toArray(new Artifact[0]);
     }
 
+    private static class NoMatchingArtifactsException extends RuntimeException {
+        public NoMatchingArtifactsException(final String select) {
+            super(String.format("No artifacts matched expression '%s'", select));
+        }
+    }
 }

[tomee-patch-plugin] 07/08: Ability to exclude selected sources

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

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

commit 5ba3914921c59c20557eb291f7a8bdd49bf713fc
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 22:43:07 2021 -0700

    Ability to exclude selected sources
---
 .../org/apache/tomee/patch/plugin/PatchMojo.java   | 40 +++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

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 812ac52..84e4c02 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
@@ -47,10 +47,12 @@ import org.tomitribe.util.Zips;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Predicate;
@@ -70,6 +72,9 @@ public class PatchMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project.basedir}/src/patch/java", required = true)
     private List<File> patchSources;
 
+    @Parameter
+    private List<String> sourceExcludes = new ArrayList<>();
+
     /**
      * Regex to identify which archives should be matched
      */
@@ -125,6 +130,9 @@ public class PatchMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project.build.directory}/patch-classpath", required = true)
     private File patchClasspathDirectory;
 
+    @Parameter(defaultValue = "${project.build.directory}/patch-sources", required = true)
+    private File patchSourceDirectory;
+
     /**
      * The -encoding argument for the Java compiler.
      *
@@ -296,6 +304,9 @@ public class PatchMojo extends AbstractMojo {
             executable = tc.findTool(compilerId);
         }
 
+        Files.mkdir(patchSourceDirectory);
+        patchSources.forEach(file -> copy(file, file, patchSourceDirectory));
+
 
         final CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
         compilerConfiguration.setOutputLocation(buildDirectory.getAbsolutePath());
@@ -310,7 +321,7 @@ public class PatchMojo extends AbstractMojo {
         compilerConfiguration.setTargetVersion(target);
         compilerConfiguration.setReleaseVersion(null);
         compilerConfiguration.setProc(null);
-        compilerConfiguration.setSourceLocations(getPatchSourceLocations());
+        compilerConfiguration.setSourceLocations(Collections.singletonList(patchSourceDirectory.getAbsolutePath()));
         compilerConfiguration.setAnnotationProcessors(null);
         compilerConfiguration.setSourceEncoding(encoding);
         compilerConfiguration.setFork(true);
@@ -403,6 +414,33 @@ public class PatchMojo extends AbstractMojo {
         }
     }
 
+    private void copy(final File root, final File src, final File dest) {
+        copy:
+        for (final File file : src.listFiles()) {
+
+            final String path = file.getAbsolutePath().substring(root.getAbsolutePath().length() + 1);
+
+            for (final String exclude : sourceExcludes) {
+                if (path.matches(exclude)) {
+                    getLog().debug("Exclude source file: " + file.getAbsolutePath());
+                    continue copy;
+                }
+            }
+
+            if (file.isDirectory()) {
+                final File dir = new File(dest, file.getName());
+                Files.mkdir(dir);
+                copy(root, file, dir);
+            } else if (file.isFile()) {
+                try {
+                    IO.copy(file, new File(dest, file.getName()));
+                } catch (IOException e) {
+                    throw new UncheckedIOException("Cannot copy file " + file.getAbsolutePath(), e);
+                }
+            }
+        }
+    }
+
     private List<String> getPatchSourceLocations() {
         return patchSources.stream()
                 .map(File::getAbsolutePath)