You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/03 19:38:13 UTC

(maven-acr-plugin) branch master updated: Leave the configured excludes unchanged

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

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-acr-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new d26768c  Leave the configured excludes unchanged
d26768c is described below

commit d26768cbcac13488ca89445daa92f8f01c7c0a56
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Wed Sep 30 23:32:55 2026 +0200

    Leave the configured excludes unchanged
---
 pom.xml                                            | 11 +++
 .../java/org/apache/maven/plugins/acr/AcrMojo.java |  6 +-
 .../org/apache/maven/plugins/acr/AcrMojoTest.java  | 90 ++++++++++++++++++++++
 3 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4ccd4dd..6e80719 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,6 +84,12 @@ under the License.
       <version>${mavenVersion}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
@@ -116,6 +122,11 @@ under the License.
       <artifactId>commons-io</artifactId>
       <version>2.22.0</version>
     </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/src/main/java/org/apache/maven/plugins/acr/AcrMojo.java b/src/main/java/org/apache/maven/plugins/acr/AcrMojo.java
index 8c479a2..5418a00 100644
--- a/src/main/java/org/apache/maven/plugins/acr/AcrMojo.java
+++ b/src/main/java/org/apache/maven/plugins/acr/AcrMojo.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.input.XmlStreamReader;
@@ -198,8 +199,9 @@ public class AcrMojo extends AbstractMojo {
             String[] mainJarExcludes = DEFAULT_EXCLUDES;
 
             if (excludes != null && !excludes.isEmpty()) {
-                excludes.add(APP_CLIENT_XML);
-                mainJarExcludes = excludes.toArray(new String[0]);
+                List<String> allExcludes = new ArrayList<>(excludes);
+                allExcludes.add(APP_CLIENT_XML);
+                mainJarExcludes = allExcludes.toArray(new String[0]);
             }
 
             if (outputDirectory.exists()) {
diff --git a/src/test/java/org/apache/maven/plugins/acr/AcrMojoTest.java b/src/test/java/org/apache/maven/plugins/acr/AcrMojoTest.java
new file mode 100644
index 0000000..291ac18
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/acr/AcrMojoTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.maven.plugins.acr;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.FileSet;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class AcrMojoTest {
+
+    @TempDir
+    Path tmp;
+
+    @Test
+    void executeDoesNotModifyConfiguredExcludes() throws Exception {
+        Path classes = Files.createDirectories(tmp.resolve("classes"));
+        Files.write(classes.resolve("A.class"), new byte[] {1});
+
+        List<String> excludes = new ArrayList<>(Arrays.asList("**/*DevOnly.class"));
+        List<String[]> seen = new ArrayList<>();
+        JarArchiver archiver = new JarArchiver() {
+            @Override
+            public void addFileSet(FileSet fileSet) throws ArchiverException {
+                seen.add(fileSet.getExcludes());
+            }
+
+            @Override
+            public void addFile(File inputFile, String destFileName) {
+                // not needed: only the file set is under test
+            }
+        };
+
+        AcrMojo mojo = new AcrMojo(archiver, null);
+        set(mojo, "basedir", tmp.resolve("target").toFile());
+        set(mojo, "outputDirectory", classes.toFile());
+        set(mojo, "jarName", "test");
+        set(mojo, "excludes", excludes);
+        MavenProject project = new MavenProject();
+        project.setArtifact(new DefaultArtifact("g", "a", "1", null, "jar", null, new DefaultArtifactHandler("jar")));
+        project.getBuild().setDirectory(tmp.resolve("target").toString());
+        set(mojo, "project", project);
+        Files.createDirectories(tmp.resolve("target"));
+
+        mojo.execute();
+        mojo.execute();
+
+        assertEquals(Arrays.asList("**/*DevOnly.class"), excludes);
+        assertEquals(2, seen.size());
+        List<String> expected = Arrays.asList("**/*DevOnly.class", "META-INF/application-client.xml");
+        assertEquals(expected, Arrays.asList(seen.get(0)));
+        assertEquals(expected, Arrays.asList(seen.get(1)));
+    }
+
+    private static void set(Object o, String name, Object value) throws Exception {
+        Field f = AcrMojo.class.getDeclaredField(name);
+        f.setAccessible(true);
+        f.set(o, value);
+    }
+}