Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/it/gh-554/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions src/it/gh-554/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
24 changes: 24 additions & 0 deletions src/it/gh-554/src/main/webapp/web.xml
Original file line number Diff line number Diff line change
@@ -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>
23 changes: 23 additions & 0 deletions src/it/gh-554/verify.groovy
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;overlay&gt; element may contain:
* <ul>
Expand Down Expand Up @@ -826,6 +846,24 @@ public void deleteOutdatedResources() {
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());
}
}

/**
Expand Down Expand Up @@ -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;
}
}
57 changes: 0 additions & 57 deletions src/main/java/org/apache/maven/plugins/war/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}