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:57 UTC

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

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)