diff --git a/src/it/gh-554/invoker.properties b/src/it/gh-554/invoker.properties
new file mode 100644
index 00000000..9e5e2cea
--- /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 00000000..e2613252
--- /dev/null
+++ b/src/it/gh-554/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+ 4.0.0
+ testwar
+ gh-554
+ war
+ 1.0-SNAPSHOT
+ gh-554 Maven Webapp
+ https://github.com/apache/maven-war-plugin/issues/554
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.19.0
+
+
+ commons-io
+ commons-io
+ 2.20.0
+
+
+
+
+
+
+ maven-war-plugin
+ @project.version@
+
+ WEB-INF/lib/*io*.jar
+
+
+
+
+
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 00000000..6a8fa709
--- /dev/null
+++ b/src/it/gh-554/src/main/webapp/web.xml
@@ -0,0 +1,24 @@
+
+
+
+ Archetype Created Web Application
+
diff --git a/src/it/gh-554/verify.groovy b/src/it/gh-554/verify.groovy
new file mode 100644
index 00000000..2a8f2215
--- /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 2a357b05..434ed379 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:
*
@@ -826,6 +846,24 @@ public void deleteOutdatedResources() {
public String getOutputTimestamp() {
return outputTimestamp;
}
+
+ /**
+ * @return list of packaging excludes.
+ * @since 3.4.1
+ */
+ @Override
+ public List getPackagingExcludes() {
+ return Arrays.asList(AbstractWarMojo.this.getPackagingExcludes());
+ }
+
+ /**
+ * @return list of packaging includes.
+ * @since 3.4.1
+ */
+ @Override
+ public List getPackagingIncludes() {
+ return Arrays.asList(AbstractWarMojo.this.getPackagingIncludes());
+ }
}
/**
@@ -1044,4 +1082,40 @@ protected boolean isRecompressZippedFiles() {
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 a42cc595..7d121aa3 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.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 void setClassifier(String classifier) {
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 7e4e5f6d..cdce8081 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.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.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 @@ protected void copyFile(String sourceId, final WarPackagingContext context, fina
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 @@ private boolean isPropertiesFile(File file) {
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 packagingIncludes, List 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 873409b3..98637115 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 getPackagingExcludes();
+
+ /**
+ * @return list of packaging includes.
+ * @since 3.4.1
+ */
+ List getPackagingIncludes();
}