This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 95ab859 enh: uses packagingExclude / include for war:exploded (#555)
95ab859 is described below
commit 95ab8597cbf6389832f1e56e4405f26009d547d5
Author: Lenny Primak <[email protected]>
AuthorDate: Wed Oct 15 14:41:59 2025 -0500
enh: uses packagingExclude / include for war:exploded (#555)
* enh: uses packagingExclude / include parameters for all goals, not just
war:war goal
* Add simple IT
---------
Co-authored-by: Slawomir Jaranowski <[email protected]>
---
src/it/gh-554/invoker.properties | 18 ++++++
src/it/gh-554/pom.xml | 53 ++++++++++++++++
src/it/gh-554/src/main/webapp/web.xml | 24 +++++++
src/it/gh-554/verify.groovy | 23 +++++++
.../apache/maven/plugins/war/AbstractWarMojo.java | 74 ++++++++++++++++++++++
.../java/org/apache/maven/plugins/war/WarMojo.java | 57 -----------------
.../war/packaging/AbstractWarPackagingTask.java | 28 ++++++++
.../plugins/war/packaging/WarPackagingContext.java | 12 ++++
8 files changed, 232 insertions(+), 57 deletions(-)
diff --git a/src/it/gh-554/invoker.properties b/src/it/gh-554/invoker.properties
new file mode 100644
index 0000000..9e5e2ce
--- /dev/null
+++ b/src/it/gh-554/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=war:exploded
diff --git a/src/it/gh-554/pom.xml b/src/it/gh-554/pom.xml
new file mode 100644
index 0000000..e261325
--- /dev/null
+++ b/src/it/gh-554/pom.xml
@@ -0,0 +1,53 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+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.
+-->
+<project xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd'
xmlns='http://maven.apache.org/POM/4.0.0'>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>testwar</groupId>
+ <artifactId>gh-554</artifactId>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>gh-554 Maven Webapp</name>
+ <url>https://github.com/apache/maven-war-plugin/issues/554</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.19.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.20.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <packagingExcludes>WEB-INF/lib/*io*.jar</packagingExcludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/gh-554/src/main/webapp/web.xml
b/src/it/gh-554/src/main/webapp/web.xml
new file mode 100644
index 0000000..6a8fa70
--- /dev/null
+++ b/src/it/gh-554/src/main/webapp/web.xml
@@ -0,0 +1,24 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+<!--
+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.
+-->
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+</web-app>
diff --git a/src/it/gh-554/verify.groovy b/src/it/gh-554/verify.groovy
new file mode 100644
index 0000000..2a8f221
--- /dev/null
+++ b/src/it/gh-554/verify.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+def libDirectory = new File(basedir, 'target/gh-554-1.0-SNAPSHOT/WEB-INF/lib');
+
+// only one dependency should be copied
+assert libDirectory.list().length == 1
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
index 2a357b0..434ed37 100644
--- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
@@ -230,6 +230,26 @@ public abstract class AbstractWarMojo extends AbstractMojo
{
@Parameter
private String dependentWarExcludes =
StringUtils.join(Overlay.DEFAULT_EXCLUDES, ",");
+ /**
+ * The comma separated list of tokens to exclude from the WAR before
packaging. This option may be used to implement
+ * the skinny WAR use case. Note that you can use the Java Regular
Expressions engine to include and exclude
+ * specific pattern using the expression %regex[]. Hint: read the about
(?!Pattern).
+ *
+ * @since 2.1-alpha-2
+ */
+ @Parameter(property = "maven.war.packagingExcludes")
+ private String packagingExcludes;
+
+ /**
+ * The comma separated list of tokens to include in the WAR before
packaging. By default everything is included.
+ * This option may be used to implement the skinny WAR use case. Note that
you can use the Java Regular Expressions
+ * engine to include and exclude specific pattern using the expression
%regex[].
+ *
+ * @since 2.1-beta-1
+ */
+ @Parameter
+ private String packagingIncludes;
+
/**
* The overlays to apply. Each <overlay> element may contain:
* <ul>
@@ -826,6 +846,24 @@ public abstract class AbstractWarMojo extends AbstractMojo
{
public String getOutputTimestamp() {
return outputTimestamp;
}
+
+ /**
+ * @return list of packaging excludes.
+ * @since 3.4.1
+ */
+ @Override
+ public List<String> getPackagingExcludes() {
+ return Arrays.asList(AbstractWarMojo.this.getPackagingExcludes());
+ }
+
+ /**
+ * @return list of packaging includes.
+ * @since 3.4.1
+ */
+ @Override
+ public List<String> getPackagingIncludes() {
+ return Arrays.asList(AbstractWarMojo.this.getPackagingIncludes());
+ }
}
/**
@@ -1044,4 +1082,40 @@ public abstract class AbstractWarMojo extends
AbstractMojo {
protected boolean isIncludeEmptyDirectories() {
return includeEmptyDirectories;
}
+
+ /**
+ * @return The package excludes.
+ */
+ public String[] getPackagingExcludes() {
+ if (packagingExcludes == null || packagingExcludes.isEmpty()) {
+ return new String[0];
+ } else {
+ return
org.codehaus.plexus.util.StringUtils.split(packagingExcludes, ",");
+ }
+ }
+
+ /**
+ * @param packagingExcludes {@link #packagingExcludes}
+ */
+ public void setPackagingExcludes(String packagingExcludes) {
+ this.packagingExcludes = packagingExcludes;
+ }
+
+ /**
+ * @return The packaging includes.
+ */
+ public String[] getPackagingIncludes() {
+ if (packagingIncludes == null || packagingIncludes.isEmpty()) {
+ return new String[] {"**"};
+ } else {
+ return
org.codehaus.plexus.util.StringUtils.split(packagingIncludes, ",");
+ }
+ }
+
+ /**
+ * @param packagingIncludes {@link #packagingIncludes}
+ */
+ public void setPackagingIncludes(String packagingIncludes) {
+ this.packagingIncludes = packagingIncludes;
+ }
}
diff --git a/src/main/java/org/apache/maven/plugins/war/WarMojo.java
b/src/main/java/org/apache/maven/plugins/war/WarMojo.java
index a42cc59..7d121aa 100644
--- a/src/main/java/org/apache/maven/plugins/war/WarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/WarMojo.java
@@ -51,7 +51,6 @@ import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.war.WarArchiver;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
/**
* Build a WAR file.
@@ -83,26 +82,6 @@ public class WarMojo extends AbstractWarMojo {
@Parameter
private String classifier;
- /**
- * The comma separated list of tokens to exclude from the WAR before
packaging. This option may be used to implement
- * the skinny WAR use case. Note that you can use the Java Regular
Expressions engine to include and exclude
- * specific pattern using the expression %regex[]. Hint: read the about
(?!Pattern).
- *
- * @since 2.1-alpha-2
- */
- @Parameter(property = "maven.war.packagingExcludes")
- private String packagingExcludes;
-
- /**
- * The comma separated list of tokens to include in the WAR before
packaging. By default everything is included.
- * This option may be used to implement the skinny WAR use case. Note that
you can use the Java Regular Expressions
- * engine to include and exclude specific pattern using the expression
%regex[].
- *
- * @since 2.1-beta-1
- */
- @Parameter
- private String packagingIncludes;
-
/**
* The WAR archiver.
*/
@@ -385,42 +364,6 @@ public class WarMojo extends AbstractWarMojo {
this.classifier = classifier;
}
- /**
- * @return The package excludes.
- */
- public String[] getPackagingExcludes() {
- if (packagingExcludes == null || packagingExcludes.isEmpty()) {
- return new String[0];
- } else {
- return StringUtils.split(packagingExcludes, ",");
- }
- }
-
- /**
- * @param packagingExcludes {@link #packagingExcludes}
- */
- public void setPackagingExcludes(String packagingExcludes) {
- this.packagingExcludes = packagingExcludes;
- }
-
- /**
- * @return The packaging includes.
- */
- public String[] getPackagingIncludes() {
- if (packagingIncludes == null || packagingIncludes.isEmpty()) {
- return new String[] {"**"};
- } else {
- return StringUtils.split(packagingIncludes, ",");
- }
- }
-
- /**
- * @param packagingIncludes {@link #packagingIncludes}
- */
- public void setPackagingIncludes(String packagingIncludes) {
- this.packagingIncludes = packagingIncludes;
- }
-
/**
* @return {@link #outputDirectory}
*/
diff --git
a/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java
b/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java
index 7e4e5f6..cdce808 100644
---
a/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java
+++
b/src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
import org.apache.commons.io.input.XmlStreamReader;
import org.apache.maven.artifact.Artifact;
@@ -38,6 +39,7 @@ import
org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.SelectorUtils;
/**
* @author Stephane Nicoll
@@ -149,6 +151,10 @@ public abstract class AbstractWarPackagingTask implements
WarPackagingTask {
throws IOException
// CHECKSTYLE_ON: LineLength
{
+ if (isExcluded(targetFilename, context.getPackagingIncludes(),
context.getPackagingExcludes())) {
+ context.getLog().debug("Skipping excluded file: " +
targetFilename);
+ return;
+ }
final File targetFile = new File(context.getWebappDirectory(),
targetFilename);
if (file.isFile()) {
@@ -455,4 +461,26 @@ public abstract class AbstractWarPackagingTask implements
WarPackagingTask {
private boolean isXmlFile(File file) {
return isFileOfType(file, ".xml");
}
+
+ /**
+ * Check whether the specified file is excluded or not.
+ *
+ * @param targetFilename the target filename
+ * @param packagingIncludes the includes
+ * @param packagingExcludes the excludes
+ * @return true if the file is excluded
+ */
+ private boolean isExcluded(String targetFilename, List<String>
packagingIncludes, List<String> packagingExcludes) {
+ for (String exclude : packagingExcludes) {
+ if (SelectorUtils.matchPath(exclude.trim(), targetFilename)) {
+ return true;
+ }
+ }
+ for (String include : packagingIncludes) {
+ if (SelectorUtils.matchPath(include.trim(), targetFilename)) {
+ return false;
+ }
+ }
+ return true;
+ }
}
diff --git
a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
index 873409b..9863711 100644
---
a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
+++
b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java
@@ -256,4 +256,16 @@ public interface WarPackagingContext {
* @since 3.3.0
*/
String getOutputTimestamp();
+
+ /**
+ * @return list of packaging excludes.
+ * @since 3.4.1
+ */
+ List<String> getPackagingExcludes();
+
+ /**
+ * @return list of packaging includes.
+ * @since 3.4.1
+ */
+ List<String> getPackagingIncludes();
}