Skip to content

Commit 3202ec3

Browse files
committed
enh: uses packagingExclude / include parameters for all goals, not just war:war goal
1 parent da70d3c commit 3202ec3

File tree

4 files changed

+114
-57
lines changed

4 files changed

+114
-57
lines changed

src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ public abstract class AbstractWarMojo extends AbstractMojo {
230230
@Parameter
231231
private String dependentWarExcludes = StringUtils.join(Overlay.DEFAULT_EXCLUDES, ",");
232232

233+
/**
234+
* The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement
235+
* the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude
236+
* specific pattern using the expression %regex[]. Hint: read the about (?!Pattern).
237+
*
238+
* @since 2.1-alpha-2
239+
*/
240+
@Parameter(property = "maven.war.packagingExcludes")
241+
private String packagingExcludes;
242+
243+
/**
244+
* The comma separated list of tokens to include in the WAR before packaging. By default everything is included.
245+
* This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions
246+
* engine to include and exclude specific pattern using the expression %regex[].
247+
*
248+
* @since 2.1-beta-1
249+
*/
250+
@Parameter
251+
private String packagingIncludes;
252+
233253
/**
234254
* The overlays to apply. Each <overlay> element may contain:
235255
* <ul>
@@ -826,6 +846,24 @@ public void deleteOutdatedResources() {
826846
public String getOutputTimestamp() {
827847
return outputTimestamp;
828848
}
849+
850+
/**
851+
* @return list of packaging excludes.
852+
* @since 3.4.1
853+
*/
854+
@Override
855+
public List<String> getPackagingExcludes() {
856+
return Arrays.asList(AbstractWarMojo.this.getPackagingExcludes());
857+
}
858+
859+
/**
860+
* @return list of packaging includes.
861+
* @since 3.4.1
862+
*/
863+
@Override
864+
public List<String> getPackagingIncludes() {
865+
return Arrays.asList(AbstractWarMojo.this.getPackagingIncludes());
866+
}
829867
}
830868

831869
/**
@@ -1044,4 +1082,40 @@ protected boolean isRecompressZippedFiles() {
10441082
protected boolean isIncludeEmptyDirectories() {
10451083
return includeEmptyDirectories;
10461084
}
1085+
1086+
/**
1087+
* @return The package excludes.
1088+
*/
1089+
public String[] getPackagingExcludes() {
1090+
if (packagingExcludes == null || packagingExcludes.isEmpty()) {
1091+
return new String[0];
1092+
} else {
1093+
return org.codehaus.plexus.util.StringUtils.split(packagingExcludes, ",");
1094+
}
1095+
}
1096+
1097+
/**
1098+
* @param packagingExcludes {@link #packagingExcludes}
1099+
*/
1100+
public void setPackagingExcludes(String packagingExcludes) {
1101+
this.packagingExcludes = packagingExcludes;
1102+
}
1103+
1104+
/**
1105+
* @return The packaging includes.
1106+
*/
1107+
public String[] getPackagingIncludes() {
1108+
if (packagingIncludes == null || packagingIncludes.isEmpty()) {
1109+
return new String[] {"**"};
1110+
} else {
1111+
return org.codehaus.plexus.util.StringUtils.split(packagingIncludes, ",");
1112+
}
1113+
}
1114+
1115+
/**
1116+
* @param packagingIncludes {@link #packagingIncludes}
1117+
*/
1118+
public void setPackagingIncludes(String packagingIncludes) {
1119+
this.packagingIncludes = packagingIncludes;
1120+
}
10471121
}

src/main/java/org/apache/maven/plugins/war/WarMojo.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.codehaus.plexus.archiver.manager.ArchiverManager;
5252
import org.codehaus.plexus.archiver.war.WarArchiver;
5353
import org.codehaus.plexus.util.FileUtils;
54-
import org.codehaus.plexus.util.StringUtils;
5554

5655
/**
5756
* Build a WAR file.
@@ -83,26 +82,6 @@ public class WarMojo extends AbstractWarMojo {
8382
@Parameter
8483
private String classifier;
8584

86-
/**
87-
* The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement
88-
* the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude
89-
* specific pattern using the expression %regex[]. Hint: read the about (?!Pattern).
90-
*
91-
* @since 2.1-alpha-2
92-
*/
93-
@Parameter(property = "maven.war.packagingExcludes")
94-
private String packagingExcludes;
95-
96-
/**
97-
* The comma separated list of tokens to include in the WAR before packaging. By default everything is included.
98-
* This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions
99-
* engine to include and exclude specific pattern using the expression %regex[].
100-
*
101-
* @since 2.1-beta-1
102-
*/
103-
@Parameter
104-
private String packagingIncludes;
105-
10685
/**
10786
* The WAR archiver.
10887
*/
@@ -385,42 +364,6 @@ public void setClassifier(String classifier) {
385364
this.classifier = classifier;
386365
}
387366

388-
/**
389-
* @return The package excludes.
390-
*/
391-
public String[] getPackagingExcludes() {
392-
if (packagingExcludes == null || packagingExcludes.isEmpty()) {
393-
return new String[0];
394-
} else {
395-
return StringUtils.split(packagingExcludes, ",");
396-
}
397-
}
398-
399-
/**
400-
* @param packagingExcludes {@link #packagingExcludes}
401-
*/
402-
public void setPackagingExcludes(String packagingExcludes) {
403-
this.packagingExcludes = packagingExcludes;
404-
}
405-
406-
/**
407-
* @return The packaging includes.
408-
*/
409-
public String[] getPackagingIncludes() {
410-
if (packagingIncludes == null || packagingIncludes.isEmpty()) {
411-
return new String[] {"**"};
412-
} else {
413-
return StringUtils.split(packagingIncludes, ",");
414-
}
415-
}
416-
417-
/**
418-
* @param packagingIncludes {@link #packagingIncludes}
419-
*/
420-
public void setPackagingIncludes(String packagingIncludes) {
421-
this.packagingIncludes = packagingIncludes;
422-
}
423-
424367
/**
425368
* @return {@link #outputDirectory}
426369
*/

src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.nio.file.Files;
2424
import java.nio.file.attribute.BasicFileAttributes;
25+
import java.util.List;
2526

2627
import org.apache.commons.io.input.XmlStreamReader;
2728
import org.apache.maven.artifact.Artifact;
@@ -38,6 +39,7 @@
3839
import org.codehaus.plexus.interpolation.InterpolationException;
3940
import org.codehaus.plexus.util.DirectoryScanner;
4041
import org.codehaus.plexus.util.FileUtils;
42+
import org.codehaus.plexus.util.SelectorUtils;
4143

4244
/**
4345
* @author Stephane Nicoll
@@ -149,6 +151,10 @@ protected void copyFile(String sourceId, final WarPackagingContext context, fina
149151
throws IOException
150152
// CHECKSTYLE_ON: LineLength
151153
{
154+
if (isExcluded(targetFilename, context.getPackagingIncludes(), context.getPackagingExcludes())) {
155+
context.getLog().debug("Skipping excluded file: " + targetFilename);
156+
return;
157+
}
152158
final File targetFile = new File(context.getWebappDirectory(), targetFilename);
153159

154160
if (file.isFile()) {
@@ -455,4 +461,26 @@ private boolean isPropertiesFile(File file) {
455461
private boolean isXmlFile(File file) {
456462
return isFileOfType(file, ".xml");
457463
}
464+
465+
/**
466+
* Check whether the specified file is excluded or not.
467+
*
468+
* @param targetFilename the target filename
469+
* @param packagingIncludes the includes
470+
* @param packagingExcludes the excludes
471+
* @return true if the file is excluded
472+
*/
473+
private boolean isExcluded(String targetFilename, List<String> packagingIncludes, List<String> packagingExcludes) {
474+
for (String exclude : packagingExcludes) {
475+
if (SelectorUtils.matchPath(exclude.trim(), targetFilename)) {
476+
return true;
477+
}
478+
}
479+
for (String include : packagingIncludes) {
480+
if (SelectorUtils.matchPath(include.trim(), targetFilename)) {
481+
return false;
482+
}
483+
}
484+
return true;
485+
}
458486
}

src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,16 @@ public interface WarPackagingContext {
256256
* @since 3.3.0
257257
*/
258258
String getOutputTimestamp();
259+
260+
/**
261+
* @return list of packaging excludes.
262+
* @since 3.4.1
263+
*/
264+
List<String> getPackagingExcludes();
265+
266+
/**
267+
* @return list of packaging includes.
268+
* @since 3.4.1
269+
*/
270+
List<String> getPackagingIncludes();
259271
}

0 commit comments

Comments
 (0)