You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/05/21 11:06:37 UTC
[maven-war-plugin] 02/02: [MWAR-463] Upgrade Parent to 39 - code reformat
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MWAR-463
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git
commit 2a76403475968393bbd71f731e11b4851021886c
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun May 21 13:06:17 2023 +0200
[MWAR-463] Upgrade Parent to 39 - code reformat
---
pom.xml | 44 +-
.../apache/maven/plugins/war/AbstractWarMojo.java | 547 ++++++-------
.../java/org/apache/maven/plugins/war/Overlay.java | 172 ++---
.../apache/maven/plugins/war/WarExplodedMojo.java | 23 +-
.../apache/maven/plugins/war/WarInPlaceMojo.java | 19 +-
.../java/org/apache/maven/plugins/war/WarMojo.java | 312 +++-----
.../maven/plugins/war/overlay/DefaultOverlay.java | 29 +-
.../InvalidOverlayConfigurationException.java | 19 +-
.../maven/plugins/war/overlay/OverlayManager.java | 145 ++--
.../war/packaging/AbstractWarPackagingTask.java | 415 +++++-----
.../war/packaging/ArtifactsPackagingTask.java | 149 ++--
.../war/packaging/ClassesPackagingTask.java | 113 ++-
.../war/packaging/CopyUserManifestTask.java | 40 +-
.../war/packaging/OverlayPackagingTask.java | 109 +--
.../plugins/war/packaging/WarPackagingContext.java | 18 +-
.../plugins/war/packaging/WarPackagingTask.java | 12 +-
.../war/packaging/WarProjectPackagingTask.java | 317 ++++----
.../maven/plugins/war/util/ClassesPackager.java | 52 +-
.../maven/plugins/war/util/DependencyInfo.java | 36 +-
.../org/apache/maven/plugins/war/util/PathSet.java | 129 ++--
.../apache/maven/plugins/war/util/WarUtils.java | 56 +-
.../maven/plugins/war/util/WebappStructure.java | 214 ++----
.../plugins/war/AbstractWarExplodedMojoTest.java | 202 ++---
.../maven/plugins/war/AbstractWarMojoTest.java | 231 +++---
.../plugins/war/WarExplodedMojoFilteringTest.java | 252 +++---
.../maven/plugins/war/WarExplodedMojoTest.java | 843 ++++++++++-----------
.../maven/plugins/war/WarInPlaceMojoTest.java | 79 +-
.../org/apache/maven/plugins/war/WarMojoTest.java | 663 ++++++++--------
.../apache/maven/plugins/war/WarOverlaysTest.java | 544 +++++++------
.../org/apache/maven/plugins/war/WarZipTest.java | 183 ++---
.../plugins/war/overlay/OverlayManagerTest.java | 226 +++---
.../maven/plugins/war/stub/AarArtifactStub.java | 44 +-
.../plugins/war/stub/AbstractArtifactStub.java | 115 +--
.../maven/plugins/war/stub/EJBArtifactStub.java | 51 +-
.../war/stub/EJBArtifactStubWithClassifier.java | 57 +-
.../plugins/war/stub/EJBClientArtifactStub.java | 54 +-
.../war/stub/IncludeExcludeWarArtifactStub.java | 24 +-
.../maven/plugins/war/stub/JarArtifactStub.java | 93 +--
.../maven/plugins/war/stub/MarArtifactStub.java | 43 +-
.../war/stub/MavenProject4CopyConstructor.java | 46 +-
.../war/stub/MavenProjectArtifactsStub.java | 60 +-
.../plugins/war/stub/MavenProjectBasicStub.java | 71 +-
.../maven/plugins/war/stub/MavenZipProject.java | 27 +-
.../apache/maven/plugins/war/stub/ModelStub.java | 44 +-
.../maven/plugins/war/stub/PARArtifactStub.java | 25 +-
.../maven/plugins/war/stub/ProjectHelperStub.java | 47 +-
.../maven/plugins/war/stub/ResourceStub.java | 24 +-
.../maven/plugins/war/stub/TLDArtifactStub.java | 25 +-
.../maven/plugins/war/stub/WarArtifact4CCStub.java | 28 +-
.../maven/plugins/war/stub/WarArtifactStub.java | 68 +-
.../maven/plugins/war/stub/WarOverlayStub.java | 44 +-
.../maven/plugins/war/stub/XarArtifactStub.java | 44 +-
.../maven/plugins/war/stub/ZipArtifactStub.java | 46 +-
.../apache/maven/plugins/war/util/PathSetTest.java | 186 +++--
.../plugins/war/util/WebappStructureTest.java | 110 ++-
55 files changed, 3244 insertions(+), 4325 deletions(-)
diff --git a/pom.xml b/pom.xml
index 859ab96..0c26479 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?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
@@ -18,13 +17,12 @@
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <artifactId>maven-plugins</artifactId>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugins</artifactId>
<version>39</version>
<relativePath />
</parent>
@@ -36,6 +34,21 @@
<name>Apache Maven WAR Plugin</name>
<description>Builds a Web Application Archive (WAR) file from the project output and its dependencies.</description>
+ <contributors>
+ <contributor>
+ <name>Auke Schrijnen</name>
+ </contributor>
+ <contributor>
+ <name>Ludwig Magnusson</name>
+ </contributor>
+ <contributor>
+ <name>Hayarobi Park</name>
+ </contributor>
+ <contributor>
+ <name>Enrico Olivelli</name>
+ </contributor>
+ </contributors>
+
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -43,8 +56,8 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git</developerConnection>
- <url>https://github.com/apache/maven-war-plugin/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-war-plugin/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>JIRA</system>
@@ -69,21 +82,6 @@
<project.build.outputTimestamp>2021-09-05T09:31:59Z</project.build.outputTimestamp>
</properties>
- <contributors>
- <contributor>
- <name>Auke Schrijnen</name>
- </contributor>
- <contributor>
- <name>Ludwig Magnusson</name>
- </contributor>
- <contributor>
- <name>Hayarobi Park</name>
- </contributor>
- <contributor>
- <name>Enrico Olivelli</name>
- </contributor>
- </contributors>
-
<dependencyManagement>
<dependencies>
<dependency>
@@ -136,7 +134,7 @@
<artifactId>maven-shared-utils</artifactId>
<version>3.3.4</version>
</dependency>
-
+
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
@@ -172,7 +170,7 @@
<artifactId>org.eclipse.sisu.plexus</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<!-- looks up RepositorySystem -->
<groupId>org.apache.maven</groupId>
@@ -197,8 +195,8 @@
<build>
<resources>
<resource>
- <directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
+ <directory>src/main/resources-filtered</directory>
</resource>
</resources>
<pluginManagement>
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 3812a92..fbee014 100644
--- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.IOException;
@@ -64,9 +63,7 @@ import org.codehaus.plexus.archiver.manager.ArchiverManager;
/**
* Contains common jobs for WAR mojos.
*/
-public abstract class AbstractWarMojo
- extends AbstractMojo
-{
+public abstract class AbstractWarMojo extends AbstractMojo {
private static final String META_INF = "META-INF";
private static final String WEB_INF = "WEB-INF";
@@ -86,13 +83,13 @@ public abstract class AbstractWarMojo
/**
* The Maven project.
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
* The directory containing compiled classes.
*/
- @Parameter( defaultValue = "${project.build.outputDirectory}", required = true, readonly = true )
+ @Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
private File classesDirectory;
/**
@@ -102,7 +99,7 @@ public abstract class AbstractWarMojo
*
* @since 2.0.1
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean archiveClasses;
/**
@@ -110,7 +107,7 @@ public abstract class AbstractWarMojo
*
* @since 2.3
*/
- @Parameter( defaultValue = "${project.build.sourceEncoding}" )
+ @Parameter(defaultValue = "${project.build.sourceEncoding}")
private String resourceEncoding;
/**
@@ -125,19 +122,19 @@ public abstract class AbstractWarMojo
/**
* The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib.
*/
- @Component( role = Archiver.class, hint = "jar" )
+ @Component(role = Archiver.class, hint = "jar")
private JarArchiver jarArchiver;
/**
* The directory where the webapp is built.
*/
- @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}", required = true )
+ @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}", required = true)
private File webappDirectory;
/**
* Single directory for extra files to include in the WAR. This is where you place your JSP files.
*/
- @Parameter( defaultValue = "${basedir}/src/main/webapp", required = true )
+ @Parameter(defaultValue = "${basedir}/src/main/webapp", required = true)
private File warSourceDirectory;
/**
@@ -160,7 +157,7 @@ public abstract class AbstractWarMojo
* <p>
* So, the default filtering delimiters might be specified as:
* </p>
- *
+ *
* <pre>
* <delimiters>
* <delimiter>${*}</delimiter>
@@ -181,7 +178,7 @@ public abstract class AbstractWarMojo
*
* @since 3.0.0
*/
- @Parameter( defaultValue = "true" )
+ @Parameter(defaultValue = "true")
private boolean useDefaultDelimiters;
/**
@@ -201,7 +198,7 @@ public abstract class AbstractWarMojo
/**
* Directory to unpack dependent WARs into if needed.
*/
- @Parameter( defaultValue = "${project.build.directory}/war/work", required = true )
+ @Parameter(defaultValue = "${project.build.directory}/war/work", required = true)
private File workDirectory;
/**
@@ -215,29 +212,29 @@ public abstract class AbstractWarMojo
/**
*/
- @Component( role = ArtifactFactory.class )
+ @Component(role = ArtifactFactory.class)
private ArtifactFactory artifactFactory;
/**
* To look up Archiver/UnArchiver implementations.
*/
- @Component( role = ArchiverManager.class )
+ @Component(role = ArchiverManager.class)
private ArchiverManager archiverManager;
/**
*/
- @Component( role = MavenFileFilter.class, hint = "default" )
+ @Component(role = MavenFileFilter.class, hint = "default")
private MavenFileFilter mavenFileFilter;
/**
*/
- @Component( role = MavenResourcesFiltering.class, hint = "default" )
+ @Component(role = MavenResourcesFiltering.class, hint = "default")
private MavenResourcesFiltering mavenResourcesFiltering;
/**
* The comma separated list of tokens to include when copying the content of the warSourceDirectory.
*/
- @Parameter( defaultValue = "**" )
+ @Parameter(defaultValue = "**")
private String warSourceIncludes;
/**
@@ -247,20 +244,20 @@ public abstract class AbstractWarMojo
private String warSourceExcludes;
/**
- * The comma separated list of tokens to include when doing a WAR overlay. Default is
+ * The comma separated list of tokens to include when doing a WAR overlay. Default is
* {@link org.apache.maven.plugins.war.Overlay#DEFAULT_INCLUDES}
*
*/
@Parameter
- private String dependentWarIncludes = StringUtils.join( Overlay.DEFAULT_INCLUDES, "," );
+ private String dependentWarIncludes = StringUtils.join(Overlay.DEFAULT_INCLUDES, ",");
/**
- * The comma separated list of tokens to exclude when doing a WAR overlay. Default is
+ * The comma separated list of tokens to exclude when doing a WAR overlay. Default is
* {@link org.apache.maven.plugins.war.Overlay#DEFAULT_EXCLUDES}
*
*/
@Parameter
- private String dependentWarExcludes = StringUtils.join( Overlay.DEFAULT_EXCLUDES, "," );
+ private String dependentWarExcludes = StringUtils.join(Overlay.DEFAULT_EXCLUDES, ",");
/**
* The overlays to apply. Each <overlay> element may contain:
@@ -294,7 +291,7 @@ public abstract class AbstractWarMojo
/**
* @since 2.1-alpha-2
*/
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
/**
@@ -302,7 +299,7 @@ public abstract class AbstractWarMojo
*
* @since 2.1-alpha-2
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean filteringDeploymentDescriptors;
/**
@@ -311,7 +308,7 @@ public abstract class AbstractWarMojo
*
* @since 2.1-alpha-2
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean escapedBackslashesInFilePath;
/**
@@ -329,29 +326,29 @@ public abstract class AbstractWarMojo
*
* @since 2.3
*/
- @Parameter( defaultValue = "true" )
+ @Parameter(defaultValue = "true")
private boolean recompressZippedFiles;
/**
* @since 2.4
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean includeEmptyDirectories;
/**
* Stop searching endToken at the end of line
- *
+ *
* @since 2.4
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean supportMultiLineFiltering;
/**
* use jvmChmod rather that cli chmod and forking process
- *
+ *
* @since 2.4
*/
- @Parameter( defaultValue = "true" )
+ @Parameter(defaultValue = "true")
private boolean useJvmChmod;
/**
@@ -368,7 +365,7 @@ public abstract class AbstractWarMojo
*
* @since 3.3.0
*/
- @Parameter( defaultValue = "${project.build.outputTimestamp}" )
+ @Parameter(defaultValue = "${project.build.outputTimestamp}")
protected String outputTimestamp;
/**
@@ -379,7 +376,7 @@ public abstract class AbstractWarMojo
*
* @since 3.3.1
*/
- @Parameter( defaultValue = "WEB-INF/lib/" )
+ @Parameter(defaultValue = "WEB-INF/lib/")
private String outdatedCheckPath;
private final Overlay currentProjectOverlay = Overlay.createInstance();
@@ -387,8 +384,7 @@ public abstract class AbstractWarMojo
/**
* @return The current overlay.
*/
- public Overlay getCurrentProjectOverlay()
- {
+ public Overlay getCurrentProjectOverlay() {
return currentProjectOverlay;
}
@@ -397,27 +393,23 @@ public abstract class AbstractWarMojo
*
* @return an array of tokens to exclude
*/
- protected String[] getExcludes()
- {
+ protected String[] getExcludes() {
List<String> excludeList = new ArrayList<>();
- if ( warSourceExcludes != null && !warSourceExcludes.isEmpty() )
- {
- excludeList.addAll( Arrays.asList( StringUtils.split( warSourceExcludes, "," ) ) );
+ if (warSourceExcludes != null && !warSourceExcludes.isEmpty()) {
+ excludeList.addAll(Arrays.asList(StringUtils.split(warSourceExcludes, ",")));
}
// if webXML is specified, omit the one in the source directory
- if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) )
- {
- excludeList.add( "**/" + WEB_INF + "/web.xml" );
+ if (webXml != null && StringUtils.isNotEmpty(webXml.getName())) {
+ excludeList.add("**/" + WEB_INF + "/web.xml");
}
// if contextXML is specified, omit the one in the source directory
- if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) )
- {
- excludeList.add( "**/" + META_INF + "/" + containerConfigXML.getName() );
+ if (containerConfigXML != null && StringUtils.isNotEmpty(containerConfigXML.getName())) {
+ excludeList.add("**/" + META_INF + "/" + containerConfigXML.getName());
}
- return excludeList.toArray( new String[excludeList.size()] );
+ return excludeList.toArray(new String[excludeList.size()]);
}
/**
@@ -425,9 +417,8 @@ public abstract class AbstractWarMojo
*
* @return an array of tokens to include
*/
- protected String[] getIncludes()
- {
- return StringUtils.split( StringUtils.defaultString( warSourceIncludes ), "," );
+ protected String[] getIncludes() {
+ return StringUtils.split(StringUtils.defaultString(warSourceIncludes), ",");
}
/**
@@ -435,9 +426,8 @@ public abstract class AbstractWarMojo
*
* @return an array of tokens to exclude
*/
- protected String[] getDependentWarExcludes()
- {
- return StringUtils.split( StringUtils.defaultString( dependentWarExcludes ), "," );
+ protected String[] getDependentWarExcludes() {
+ return StringUtils.split(StringUtils.defaultString(dependentWarExcludes), ",");
}
/**
@@ -445,9 +435,8 @@ public abstract class AbstractWarMojo
*
* @return an array of tokens to include
*/
- protected String[] getDependentWarIncludes()
- {
- return StringUtils.split( StringUtils.defaultString( dependentWarIncludes ), "," );
+ protected String[] getDependentWarIncludes() {
+ return StringUtils.split(StringUtils.defaultString(dependentWarIncludes), ",");
}
/**
@@ -455,18 +444,13 @@ public abstract class AbstractWarMojo
* @throws MojoExecutionException In case of failure.
* @throws MojoFailureException In case of failure.
*/
- public void buildExplodedWebapp( File webapplicationDirectory )
- throws MojoExecutionException, MojoFailureException
- {
+ public void buildExplodedWebapp(File webapplicationDirectory) throws MojoExecutionException, MojoFailureException {
webapplicationDirectory.mkdirs();
- try
- {
- buildWebapp( project, webapplicationDirectory );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Could not build webapp", e );
+ try {
+ buildWebapp(project, webapplicationDirectory);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not build webapp", e);
}
}
@@ -480,70 +464,69 @@ public abstract class AbstractWarMojo
* @throws MojoFailureException if an unexpected error occurred while packaging the webapp
* @throws IOException if an error occurred while copying the files
*/
- public void buildWebapp( MavenProject mavenProject, File webapplicationDirectory )
- throws MojoExecutionException, MojoFailureException, IOException
- {
+ public void buildWebapp(MavenProject mavenProject, File webapplicationDirectory)
+ throws MojoExecutionException, MojoFailureException, IOException {
- WebappStructure structure = new WebappStructure( mavenProject.getDependencies() );
+ WebappStructure structure = new WebappStructure(mavenProject.getDependencies());
// CHECKSTYLE_OFF: LineLength
final long startTime = System.currentTimeMillis();
- getLog().info( "Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]" );
+ getLog().info("Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]");
- final OverlayManager overlayManager =
- new OverlayManager( overlays, mavenProject, getDependentWarIncludes(), getDependentWarExcludes(),
- currentProjectOverlay );
+ final OverlayManager overlayManager = new OverlayManager(
+ overlays, mavenProject, getDependentWarIncludes(), getDependentWarExcludes(), currentProjectOverlay);
// CHECKSTYLE_ON: LineLength
List<FilterWrapper> defaultFilterWrappers;
- try
- {
+ try {
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
- mavenResourcesExecution.setEscapeString( escapeString );
- mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering );
- mavenResourcesExecution.setMavenProject( mavenProject );
+ mavenResourcesExecution.setEscapeString(escapeString);
+ mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
+ mavenResourcesExecution.setMavenProject(mavenProject);
// if these are NOT set, just use the defaults, which are '${*}' and '@'.
- mavenResourcesExecution.setDelimiters( delimiters, useDefaultDelimiters );
+ mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters);
- if ( nonFilteredFileExtensions != null )
- {
- mavenResourcesExecution.setNonFilteredFileExtensions( nonFilteredFileExtensions );
+ if (nonFilteredFileExtensions != null) {
+ mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
}
-
- if ( filters == null )
- {
+
+ if (filters == null) {
filters = getProject().getBuild().getFilters();
}
- mavenResourcesExecution.setFilters( filters );
- mavenResourcesExecution.setEscapedBackslashesInFilePath( escapedBackslashesInFilePath );
- mavenResourcesExecution.setMavenSession( this.session );
- mavenResourcesExecution.setEscapeString( this.escapeString );
- mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering );
+ mavenResourcesExecution.setFilters(filters);
+ mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
+ mavenResourcesExecution.setMavenSession(this.session);
+ mavenResourcesExecution.setEscapeString(this.escapeString);
+ mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
- defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenResourcesExecution );
+ defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);
- }
- catch ( MavenFilteringException e )
- {
- getLog().error( "fail to build filtering wrappers " + e.getMessage() );
- throw new MojoExecutionException( e.getMessage(), e );
+ } catch (MavenFilteringException e) {
+ getLog().error("fail to build filtering wrappers " + e.getMessage());
+ throw new MojoExecutionException(e.getMessage(), e);
}
- final WarPackagingContext context =
- new DefaultWarPackagingContext( webapplicationDirectory, structure, overlayManager, defaultFilterWrappers,
- getNonFilteredFileExtensions(), filteringDeploymentDescriptors,
- this.artifactFactory, resourceEncoding, propertiesEncoding, useJvmChmod,
- failOnMissingWebXml, outputTimestamp );
-
- final List<WarPackagingTask> packagingTasks = getPackagingTasks( overlayManager );
-
- for ( WarPackagingTask warPackagingTask : packagingTasks )
- {
- warPackagingTask.performPackaging( context );
+ final WarPackagingContext context = new DefaultWarPackagingContext(
+ webapplicationDirectory,
+ structure,
+ overlayManager,
+ defaultFilterWrappers,
+ getNonFilteredFileExtensions(),
+ filteringDeploymentDescriptors,
+ this.artifactFactory,
+ resourceEncoding,
+ propertiesEncoding,
+ useJvmChmod,
+ failOnMissingWebXml,
+ outputTimestamp);
+
+ final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager);
+
+ for (WarPackagingTask warPackagingTask : packagingTasks) {
+ warPackagingTask.performPackaging(context);
}
- getLog().debug( "Webapp assembled in [" + ( System.currentTimeMillis() - startTime ) + " msecs]" );
-
+ getLog().debug("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]");
}
/**
@@ -554,24 +537,18 @@ public abstract class AbstractWarMojo
* @return the list of packaging tasks
* @throws MojoExecutionException if the packaging tasks could not be built
*/
- private List<WarPackagingTask> getPackagingTasks( OverlayManager overlayManager )
- throws MojoExecutionException
- {
+ private List<WarPackagingTask> getPackagingTasks(OverlayManager overlayManager) throws MojoExecutionException {
final List<WarPackagingTask> packagingTasks = new ArrayList<>();
- packagingTasks.add( new CopyUserManifestTask() );
+ packagingTasks.add(new CopyUserManifestTask());
final List<Overlay> resolvedOverlays = overlayManager.getOverlays();
- for ( Overlay overlay : resolvedOverlays )
- {
- if ( overlay.isCurrentProject() )
- {
- packagingTasks.add( new WarProjectPackagingTask( webResources, webXml, containerConfigXML,
- currentProjectOverlay ) );
- }
- else
- {
- packagingTasks.add( new OverlayPackagingTask( overlay, currentProjectOverlay ) );
+ for (Overlay overlay : resolvedOverlays) {
+ if (overlay.isCurrentProject()) {
+ packagingTasks.add(
+ new WarProjectPackagingTask(webResources, webXml, containerConfigXML, currentProjectOverlay));
+ } else {
+ packagingTasks.add(new OverlayPackagingTask(overlay, currentProjectOverlay));
}
}
return packagingTasks;
@@ -580,9 +557,7 @@ public abstract class AbstractWarMojo
/**
* WarPackagingContext default implementation
*/
- private class DefaultWarPackagingContext
- implements WarPackagingContext
- {
+ private class DefaultWarPackagingContext implements WarPackagingContext {
private final ArtifactFactory artifactFactory;
private final String resourceEncoding;
@@ -623,14 +598,19 @@ public abstract class AbstractWarMojo
* @param failOnMissingWebXml Flag to check whether we should ignore missing web.xml or not
* @param outputTimestamp the output timestamp for reproducible archive creation
*/
- DefaultWarPackagingContext( final File webappDirectory, final WebappStructure webappStructure,
- final OverlayManager overlayManager,
- List<FilterWrapper> filterWrappers,
- List<String> nonFilteredFileExtensions,
- boolean filteringDeploymentDescriptors, ArtifactFactory artifactFactory,
- String resourceEncoding, String propertiesEncoding, boolean useJvmChmod,
- final Boolean failOnMissingWebXml, String outputTimestamp )
- {
+ DefaultWarPackagingContext(
+ final File webappDirectory,
+ final WebappStructure webappStructure,
+ final OverlayManager overlayManager,
+ List<FilterWrapper> filterWrappers,
+ List<String> nonFilteredFileExtensions,
+ boolean filteringDeploymentDescriptors,
+ ArtifactFactory artifactFactory,
+ String resourceEncoding,
+ String propertiesEncoding,
+ boolean useJvmChmod,
+ final Boolean failOnMissingWebXml,
+ String outputTimestamp) {
this.webappDirectory = webappDirectory;
this.webappStructure = webappStructure;
this.overlayManager = overlayManager;
@@ -638,257 +618,211 @@ public abstract class AbstractWarMojo
this.artifactFactory = artifactFactory;
this.filteringDeploymentDescriptors = filteringDeploymentDescriptors;
this.nonFilteredFileExtensions =
- nonFilteredFileExtensions == null ? Collections.emptyList() : nonFilteredFileExtensions;
+ nonFilteredFileExtensions == null ? Collections.emptyList() : nonFilteredFileExtensions;
this.resourceEncoding = resourceEncoding;
this.propertiesEncoding = propertiesEncoding;
// This is kinda stupid but if we loop over the current overlays and we request the path structure
// it will register it. This will avoid wrong warning messages in a later phase
- for ( String overlayId : overlayManager.getOverlayIds() )
- {
- webappStructure.getStructure( overlayId );
+ for (String overlayId : overlayManager.getOverlayIds()) {
+ webappStructure.getStructure(overlayId);
}
this.useJvmChmod = useJvmChmod;
this.failOnMissingWebXml = failOnMissingWebXml;
- if ( !webappDirectory.exists() )
- {
+ if (!webappDirectory.exists()) {
outdatedResources = Collections.emptyList();
- }
- else if ( getWarSourceDirectory().toPath().equals( webappDirectory.toPath() ) )
- {
- getLog().info( "Can't detect outdated resources when running inplace goal" );
+ } else if (getWarSourceDirectory().toPath().equals(webappDirectory.toPath())) {
+ getLog().info("Can't detect outdated resources when running inplace goal");
outdatedResources = Collections.emptyList();
- }
- else if ( session.getStartTime() == null )
- {
+ } else if (session.getStartTime() == null) {
// MWAR-439: this should never happen, but has happened in some integration context...
- getLog().warn( "Can't detect outdated resources because unexpected session.getStartTime() == null" );
+ getLog().warn("Can't detect outdated resources because unexpected session.getStartTime() == null");
outdatedResources = Collections.emptyList();
- }
- else
- {
+ } else {
outdatedResources = new ArrayList<>();
- try
- {
- if ( '\\' == File.separatorChar )
- {
- if ( ! checkAllPathsForOutdated() )
- {
- outdatedCheckPath = outdatedCheckPath.replace( '/', '\\' );
+ try {
+ if ('\\' == File.separatorChar) {
+ if (!checkAllPathsForOutdated()) {
+ outdatedCheckPath = outdatedCheckPath.replace('/', '\\');
}
}
- Files.walkFileTree( webappDirectory.toPath(), new SimpleFileVisitor<Path>()
- {
+ Files.walkFileTree(webappDirectory.toPath(), new SimpleFileVisitor<Path>() {
@Override
- public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
- throws IOException
- {
- if ( file.toFile().lastModified() < session.getStartTime().getTime() )
- {
- String path = webappDirectory.toPath().relativize( file ).toString();
- if ( checkAllPathsForOutdated() || path.startsWith( outdatedCheckPath ) )
- {
- outdatedResources.add( path );
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ if (file.toFile().lastModified()
+ < session.getStartTime().getTime()) {
+ String path = webappDirectory
+ .toPath()
+ .relativize(file)
+ .toString();
+ if (checkAllPathsForOutdated() || path.startsWith(outdatedCheckPath)) {
+ outdatedResources.add(path);
}
}
- return super.visitFile( file, attrs );
+ return super.visitFile(file, attrs);
}
- } );
- }
- catch ( IOException e )
- {
- getLog().warn( "Can't detect outdated resources", e );
+ });
+ } catch (IOException e) {
+ getLog().warn("Can't detect outdated resources", e);
}
}
this.outputTimestamp = outputTimestamp;
}
- protected boolean checkAllPathsForOutdated()
- {
- return outdatedCheckPath.equals( "/" );
+ protected boolean checkAllPathsForOutdated() {
+ return outdatedCheckPath.equals("/");
}
@Override
- public MavenProject getProject()
- {
+ public MavenProject getProject() {
return project;
}
@Override
- public File getWebappDirectory()
- {
+ public File getWebappDirectory() {
return webappDirectory;
}
@Override
- public File getClassesDirectory()
- {
+ public File getClassesDirectory() {
return classesDirectory;
}
@Override
- public Log getLog()
- {
+ public Log getLog() {
return AbstractWarMojo.this.getLog();
}
@Override
- public String getOutputFileNameMapping()
- {
+ public String getOutputFileNameMapping() {
return outputFileNameMapping;
}
@Override
- public File getWebappSourceDirectory()
- {
+ public File getWebappSourceDirectory() {
return warSourceDirectory;
}
@Override
- public String[] getWebappSourceIncludes()
- {
+ public String[] getWebappSourceIncludes() {
return getIncludes();
}
@Override
- public String[] getWebappSourceExcludes()
- {
+ public String[] getWebappSourceExcludes() {
return getExcludes();
}
@Override
- public boolean isWebappSourceIncludeEmptyDirectories()
- {
+ public boolean isWebappSourceIncludeEmptyDirectories() {
return includeEmptyDirectories;
}
@Override
- public boolean archiveClasses()
- {
+ public boolean archiveClasses() {
return archiveClasses;
}
@Override
- public File getOverlaysWorkDirectory()
- {
+ public File getOverlaysWorkDirectory() {
return workDirectory;
}
@Override
- public ArchiverManager getArchiverManager()
- {
+ public ArchiverManager getArchiverManager() {
return archiverManager;
}
@Override
- public MavenArchiveConfiguration getArchive()
- {
+ public MavenArchiveConfiguration getArchive() {
return archive;
}
@Override
- public JarArchiver getJarArchiver()
- {
+ public JarArchiver getJarArchiver() {
return jarArchiver;
}
@Override
- public List<String> getFilters()
- {
+ public List<String> getFilters() {
return filters;
}
@Override
- public WebappStructure getWebappStructure()
- {
+ public WebappStructure getWebappStructure() {
return webappStructure;
}
@Override
- public List<String> getOwnerIds()
- {
+ public List<String> getOwnerIds() {
return overlayManager.getOverlayIds();
}
@Override
- public MavenFileFilter getMavenFileFilter()
- {
+ public MavenFileFilter getMavenFileFilter() {
return mavenFileFilter;
}
@Override
- public List<FilterWrapper> getFilterWrappers()
- {
+ public List<FilterWrapper> getFilterWrappers() {
return filterWrappers;
}
@Override
- public boolean isNonFilteredExtension( String fileName )
- {
- return !mavenResourcesFiltering.filteredFileExtension( fileName, nonFilteredFileExtensions );
+ public boolean isNonFilteredExtension(String fileName) {
+ return !mavenResourcesFiltering.filteredFileExtension(fileName, nonFilteredFileExtensions);
}
@Override
- public boolean isFilteringDeploymentDescriptors()
- {
+ public boolean isFilteringDeploymentDescriptors() {
return filteringDeploymentDescriptors;
}
@Override
- public ArtifactFactory getArtifactFactory()
- {
+ public ArtifactFactory getArtifactFactory() {
return this.artifactFactory;
}
@Override
- public MavenSession getSession()
- {
+ public MavenSession getSession() {
return session;
}
@Override
- public String getResourceEncoding()
- {
+ public String getResourceEncoding() {
return resourceEncoding;
}
@Override
- public String getPropertiesEncoding()
- {
+ public String getPropertiesEncoding() {
return propertiesEncoding;
}
@Override
- public boolean isUseJvmChmod()
- {
+ public boolean isUseJvmChmod() {
return useJvmChmod;
}
@Override
- public Boolean isFailOnMissingWebXml()
- {
+ public Boolean isFailOnMissingWebXml() {
return failOnMissingWebXml;
}
@Override
- public void addResource( String resource )
- {
- outdatedResources.remove( resource.replace( '/', File.separatorChar ) );
+ public void addResource(String resource) {
+ outdatedResources.remove(resource.replace('/', File.separatorChar));
}
@Override
- public void deleteOutdatedResources()
- {
- for ( String resource : outdatedResources )
- {
- getLog().info( "deleting outdated resource " + resource );
- new File( getWebappDirectory(), resource ).delete();
+ public void deleteOutdatedResources() {
+ for (String resource : outdatedResources) {
+ getLog().info("deleting outdated resource " + resource);
+ new File(getWebappDirectory(), resource).delete();
}
}
@Override
- public String getOutputTimestamp()
- {
+ public String getOutputTimestamp() {
return outputTimestamp;
}
}
@@ -896,312 +830,273 @@ public abstract class AbstractWarMojo
/**
* @return The Maven Project.
*/
- public MavenProject getProject()
- {
+ public MavenProject getProject() {
return project;
}
/**
* @param project The project to be set.
*/
- public void setProject( MavenProject project )
- {
+ public void setProject(MavenProject project) {
this.project = project;
}
/**
* @return the classes directory.
*/
- public File getClassesDirectory()
- {
+ public File getClassesDirectory() {
return classesDirectory;
}
/**
* @param classesDirectory The classes directory to be set.
*/
- public void setClassesDirectory( File classesDirectory )
- {
+ public void setClassesDirectory(File classesDirectory) {
this.classesDirectory = classesDirectory;
}
/**
* @return {@link #webappDirectory}
*/
- public File getWebappDirectory()
- {
+ public File getWebappDirectory() {
return webappDirectory;
}
/**
* @param webappDirectory The web application directory.
*/
- public void setWebappDirectory( File webappDirectory )
- {
+ public void setWebappDirectory(File webappDirectory) {
this.webappDirectory = webappDirectory;
}
/**
* @return {@link #warSourceDirectory}
*/
- public File getWarSourceDirectory()
- {
+ public File getWarSourceDirectory() {
return warSourceDirectory;
}
/**
* @param warSourceDirectory {@link #warSourceDirectory}
*/
- public void setWarSourceDirectory( File warSourceDirectory )
- {
+ public void setWarSourceDirectory(File warSourceDirectory) {
this.warSourceDirectory = warSourceDirectory;
}
/**
* @return The {@link #webXml}
*/
- public File getWebXml()
- {
+ public File getWebXml() {
return webXml;
}
/**
* @param webXml The {@link #webXml}
*/
- public void setWebXml( File webXml )
- {
+ public void setWebXml(File webXml) {
this.webXml = webXml;
}
/**
* @return {@link #containerConfigXML}
*/
- public File getContainerConfigXML()
- {
+ public File getContainerConfigXML() {
return containerConfigXML;
}
/**
* @param containerConfigXML {@link #containerConfigXML}
*/
- public void setContainerConfigXML( File containerConfigXML )
- {
+ public void setContainerConfigXML(File containerConfigXML) {
this.containerConfigXML = containerConfigXML;
}
/**
* @return {@link #outputFileNameMapping}
*/
- public String getOutputFileNameMapping()
- {
+ public String getOutputFileNameMapping() {
return outputFileNameMapping;
}
/**
* @param outputFileNameMapping {@link #outputFileNameMapping}
*/
- public void setOutputFileNameMapping( String outputFileNameMapping )
- {
+ public void setOutputFileNameMapping(String outputFileNameMapping) {
this.outputFileNameMapping = outputFileNameMapping;
}
/**
* @return {@link #overlays}
*/
- public List<Overlay> getOverlays()
- {
+ public List<Overlay> getOverlays() {
return overlays;
}
/**
* @param overlays {@link #overlays}
*/
- public void setOverlays( List<Overlay> overlays )
- {
+ public void setOverlays(List<Overlay> overlays) {
this.overlays = overlays;
}
/**
* @param overlay add {@link #overlays}.
*/
- public void addOverlay( Overlay overlay )
- {
- overlays.add( overlay );
+ public void addOverlay(Overlay overlay) {
+ overlays.add(overlay);
}
/**
* @return {@link #archiveClasses}
*/
- public boolean isArchiveClasses()
- {
+ public boolean isArchiveClasses() {
return archiveClasses;
}
/**
* @param archiveClasses {@link #archiveClasses}
*/
- public void setArchiveClasses( boolean archiveClasses )
- {
+ public void setArchiveClasses(boolean archiveClasses) {
this.archiveClasses = archiveClasses;
}
/**
* @return {@link JarArchiver}
*/
- public JarArchiver getJarArchiver()
- {
+ public JarArchiver getJarArchiver() {
return jarArchiver;
}
/**
* @param jarArchiver {@link JarArchiver}
*/
- public void setJarArchiver( JarArchiver jarArchiver )
- {
+ public void setJarArchiver(JarArchiver jarArchiver) {
this.jarArchiver = jarArchiver;
}
/**
* @return {@link #webResources}.
*/
- public Resource[] getWebResources()
- {
+ public Resource[] getWebResources() {
return webResources;
}
/**
* @param webResources {@link #webResources}.
*/
- public void setWebResources( Resource[] webResources )
- {
+ public void setWebResources(Resource[] webResources) {
this.webResources = webResources;
}
/**
* @return {@link #filters}
*/
- public List<String> getFilters()
- {
+ public List<String> getFilters() {
return filters;
}
/**
* @param filters {@link #filters}
*/
- public void setFilters( List<String> filters )
- {
+ public void setFilters(List<String> filters) {
this.filters = filters;
}
/**
* @return {@link #workDirectory}
*/
- public File getWorkDirectory()
- {
+ public File getWorkDirectory() {
return workDirectory;
}
/**
* @param workDirectory {@link #workDirectory}
*/
- public void setWorkDirectory( File workDirectory )
- {
+ public void setWorkDirectory(File workDirectory) {
this.workDirectory = workDirectory;
}
/**
* @return {@link #warSourceIncludes}
*/
- public String getWarSourceIncludes()
- {
+ public String getWarSourceIncludes() {
return warSourceIncludes;
}
/**
* @param warSourceIncludes {@link #warSourceIncludes}
*/
- public void setWarSourceIncludes( String warSourceIncludes )
- {
+ public void setWarSourceIncludes(String warSourceIncludes) {
this.warSourceIncludes = warSourceIncludes;
}
/**
* @return {@link #warSourceExcludes}
*/
- public String getWarSourceExcludes()
- {
+ public String getWarSourceExcludes() {
return warSourceExcludes;
}
/**
* @param warSourceExcludes {@link #warSourceExcludes}
*/
- public void setWarSourceExcludes( String warSourceExcludes )
- {
+ public void setWarSourceExcludes(String warSourceExcludes) {
this.warSourceExcludes = warSourceExcludes;
}
/**
* @return {@link #archive}
*/
- public MavenArchiveConfiguration getArchive()
- {
+ public MavenArchiveConfiguration getArchive() {
return archive;
}
/**
* @return {@link #nonFilteredFileExtensions}
*/
- public List<String> getNonFilteredFileExtensions()
- {
+ public List<String> getNonFilteredFileExtensions() {
return nonFilteredFileExtensions;
}
/**
* @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions}
*/
- public void setNonFilteredFileExtensions( List<String> nonFilteredFileExtensions )
- {
+ public void setNonFilteredFileExtensions(List<String> nonFilteredFileExtensions) {
this.nonFilteredFileExtensions = nonFilteredFileExtensions;
}
/**
* @return {@link #artifactFactory}
*/
- public ArtifactFactory getArtifactFactory()
- {
+ public ArtifactFactory getArtifactFactory() {
return this.artifactFactory;
}
/**
* @param artifactFactory {@link #artifactFactory}
*/
- public void setArtifactFactory( ArtifactFactory artifactFactory )
- {
+ public void setArtifactFactory(ArtifactFactory artifactFactory) {
this.artifactFactory = artifactFactory;
}
/**
* @return {@link #session}
*/
- protected MavenSession getSession()
- {
+ protected MavenSession getSession() {
return this.session;
}
/**
* @return {@link #recompressZippedFiles}
*/
- protected boolean isRecompressZippedFiles()
- {
+ protected boolean isRecompressZippedFiles() {
return recompressZippedFiles;
}
/**
* @return {@link #includeEmptyDirectories}
*/
- protected boolean isIncludeEmptyDirectories()
- {
+ protected boolean isIncludeEmptyDirectories() {
return includeEmptyDirectories;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/Overlay.java b/src/main/java/org/apache/maven/plugins/war/Overlay.java
index c42f1c7..9ad4b01 100644
--- a/src/main/java/org/apache/maven/plugins/war/Overlay.java
+++ b/src/main/java/org/apache/maven/plugins/war/Overlay.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,38 +16,38 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.artifact.Artifact;
+package org.apache.maven.plugins.war;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.maven.artifact.Artifact;
+
/**
* <p>
* An overlay is a skeleton WAR added to another WAR project in order to inject a functionality, resources or any other
* shared component.</p>
- *
+ *
* <p>Note that a particular WAR dependency can be added multiple times as an overlay with different includes/excludes
* filter; this allows building a fine grained overwriting policy.</p>
- *
+ *
* <p>The current project can also be described as an overlay and can not be specified twice. An overlay with no groupId
* and no artifactId represents the current project.</p>
*
* @author Stephane Nicoll
*/
-public class Overlay
-{
+public class Overlay {
/**
* The list of default includes.
*/
- public static final String[] DEFAULT_INCLUDES = new String[] { "**/**" };
+ public static final String[] DEFAULT_INCLUDES = new String[] {"**/**"};
/**
* The list of default excludes.
*/
- public static final String[] DEFAULT_EXCLUDES = new String[] { "META-INF/MANIFEST.MF" };
+ public static final String[] DEFAULT_EXCLUDES = new String[] {"META-INF/MANIFEST.MF"};
private String id;
@@ -77,8 +75,7 @@ public class Overlay
/**
* Create instance.
*/
- public Overlay()
- {
+ public Overlay() {
super();
}
@@ -86,8 +83,7 @@ public class Overlay
* @param groupId {@link #groupId}
* @param artifactId {@link #artifactId}
*/
- public Overlay( String groupId, String artifactId )
- {
+ public Overlay(String groupId, String artifactId) {
this();
this.groupId = groupId;
this.artifactId = artifactId;
@@ -98,18 +94,16 @@ public class Overlay
*
* @return true if the overlay represents the current project, false otherwise
*/
- public boolean isCurrentProject()
- {
- return ( groupId == null && artifactId == null );
+ public boolean isCurrentProject() {
+ return (groupId == null && artifactId == null);
}
/**
* @return {@link Overlay} instance.
*/
- public static Overlay createInstance()
- {
+ public static Overlay createInstance() {
Overlay overlay = new Overlay();
- overlay.setId( "currentBuild" );
+ overlay.setId("currentBuild");
return overlay;
}
@@ -118,15 +112,12 @@ public class Overlay
/**
* @return The id.
*/
- public String getId()
- {
- if ( id == null )
- {
+ public String getId() {
+ if (id == null) {
final StringBuilder sb = new StringBuilder();
- sb.append( getGroupId() ).append( ":" ).append( getArtifactId() );
- if ( getClassifier() != null )
- {
- sb.append( ":" ).append( getClassifier() );
+ sb.append(getGroupId()).append(":").append(getArtifactId());
+ if (getClassifier() != null) {
+ sb.append(":").append(getClassifier());
}
id = sb.toString();
}
@@ -136,217 +127,187 @@ public class Overlay
/**
* @param id The id.
*/
- public void setId( String id )
- {
+ public void setId(String id) {
this.id = id;
}
/**
* @return {@link #groupId}
*/
- public String getGroupId()
- {
+ public String getGroupId() {
return groupId;
}
/**
* @param groupId {@link #groupId}
*/
- public void setGroupId( String groupId )
- {
+ public void setGroupId(String groupId) {
this.groupId = groupId;
}
/**
* @return {@link #artifactId}
*/
- public String getArtifactId()
- {
+ public String getArtifactId() {
return artifactId;
}
/**
* @param artifactId {@link #artifactId}
*/
- public void setArtifactId( String artifactId )
- {
+ public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
/**
* @return {@link #classifier}
*/
- public String getClassifier()
- {
+ public String getClassifier() {
return classifier;
}
/**
* @param classifier {@link #classifier}
*/
- public void setClassifier( String classifier )
- {
+ public void setClassifier(String classifier) {
this.classifier = classifier;
}
/**
* @return {@link #includes}
*/
- public String[] getIncludes()
- {
+ public String[] getIncludes() {
return includes;
}
/**
* @param includes {@link #includes}
*/
- public void setIncludes( String includes )
- {
- this.includes = parse( includes );
+ public void setIncludes(String includes) {
+ this.includes = parse(includes);
}
/**
* @param includes {@link #includes}
*/
- public void setIncludes( String[] includes )
- {
+ public void setIncludes(String[] includes) {
this.includes = includes;
}
/**
* @return {@link #excludes}
*/
- public String[] getExcludes()
- {
+ public String[] getExcludes() {
return excludes;
}
/**
* @param excludes {@link #excludes}
*/
- public void setExcludes( String excludes )
- {
- this.excludes = parse( excludes );
+ public void setExcludes(String excludes) {
+ this.excludes = parse(excludes);
}
/**
* @param excludes {@link #excludes}
*/
- public void setExcludes( String[] excludes )
- {
+ public void setExcludes(String[] excludes) {
this.excludes = excludes;
}
/**
* @return {@link #filtered}
*/
- public boolean isFiltered()
- {
+ public boolean isFiltered() {
return filtered;
}
/**
* @param filtered {@link #filtered}
*/
- public void setFiltered( boolean filtered )
- {
+ public void setFiltered(boolean filtered) {
this.filtered = filtered;
}
/**
* @return {@link #skip}
*/
- public boolean shouldSkip()
- {
+ public boolean shouldSkip() {
return skip;
}
/**
* @param skip {@link #skip}
*/
- public void setSkip( boolean skip )
- {
+ public void setSkip(boolean skip) {
this.skip = skip;
}
/**
* @return {@link #artifact}
*/
- public Artifact getArtifact()
- {
+ public Artifact getArtifact() {
return artifact;
}
/**
* @param artifact {@link #artifact}
*/
- public void setArtifact( Artifact artifact )
- {
+ public void setArtifact(Artifact artifact) {
this.artifact = artifact;
}
/**
* @return {@link #targetPath}
*/
- public String getTargetPath()
- {
+ public String getTargetPath() {
return targetPath;
}
/**
* @param targetPath {@link #targetPath}
*/
- public void setTargetPath( String targetPath )
- {
+ public void setTargetPath(String targetPath) {
this.targetPath = targetPath;
}
/**
* @return {@link #type}
*/
- public String getType()
- {
+ public String getType() {
return type;
}
/**
* @param type {@link #type}
*/
- public void setType( String type )
- {
+ public void setType(String type) {
this.type = type;
}
@Override
- public String toString()
- {
+ public String toString() {
return " id " + getId();
}
@Override
- public boolean equals( Object o )
- {
- if ( this == o )
- {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if ( o == null || getClass() != o.getClass() )
- {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
Overlay overlay = (Overlay) o;
- if ( excludes != null ? !Arrays.equals( excludes, overlay.excludes ) : overlay.excludes != null )
- {
+ if (excludes != null ? !Arrays.equals(excludes, overlay.excludes) : overlay.excludes != null) {
return false;
}
- if ( getId() != null ? !getId().equals( overlay.getId() ) : overlay.getId() != null )
- {
+ if (getId() != null ? !getId().equals(overlay.getId()) : overlay.getId() != null) {
return false;
}
- if ( includes != null ? !Arrays.equals( includes, overlay.includes ) : overlay.includes != null )
- {
+ if (includes != null ? !Arrays.equals(includes, overlay.includes) : overlay.includes != null) {
return false;
}
@@ -354,31 +315,24 @@ public class Overlay
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
int result;
- result = ( getId() != null ? getId().hashCode() : 0 );
- result = 31 * result + ( includes != null ? includes.hashCode() : 0 );
- result = 31 * result + ( excludes != null ? excludes.hashCode() : 0 );
+ result = (getId() != null ? getId().hashCode() : 0);
+ result = 31 * result + (includes != null ? includes.hashCode() : 0);
+ result = 31 * result + (excludes != null ? excludes.hashCode() : 0);
return result;
}
- private String[] parse( String s )
- {
+ private String[] parse(String s) {
final List<String> result = new ArrayList<>();
- if ( s == null )
- {
- return result.toArray( new String[result.size()] );
- }
- else
- {
- String[] tokens = s.split( "," );
- for ( String token : tokens )
- {
- result.add( token.trim() );
+ if (s == null) {
+ return result.toArray(new String[result.size()]);
+ } else {
+ String[] tokens = s.split(",");
+ for (String token : tokens) {
+ result.add(token.trim());
}
- return result.toArray( new String[result.size()] );
+ return result.toArray(new String[result.size()]);
}
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java b/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java
index 1327068..7e543ff 100644
--- a/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/WarExplodedMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -29,18 +28,16 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
* Create an exploded webapp in a specified directory.
*
*/
-@Mojo( name = "exploded", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true,
- requiresDependencyResolution = ResolutionScope.RUNTIME )
-public class WarExplodedMojo
- extends AbstractWarMojo
-{
+@Mojo(
+ name = "exploded",
+ defaultPhase = LifecyclePhase.PACKAGE,
+ threadSafe = true,
+ requiresDependencyResolution = ResolutionScope.RUNTIME)
+public class WarExplodedMojo extends AbstractWarMojo {
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- getLog().info( "Exploding webapp" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info("Exploding webapp");
- buildExplodedWebapp( getWebappDirectory() );
+ buildExplodedWebapp(getWebappDirectory());
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java b/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java
index 9cfe02c..0190601 100644
--- a/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/WarInPlaceMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -28,16 +27,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
* Generate the webapp in the WAR source directory.
*
*/
-@Mojo( name = "inplace", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
-public class WarInPlaceMojo
- extends AbstractWarMojo
-{
+@Mojo(name = "inplace", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
+public class WarInPlaceMojo extends AbstractWarMojo {
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- getLog().info( "Generating webapp in source directory [" + getWarSourceDirectory() + "]" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info("Generating webapp in source directory [" + getWarSourceDirectory() + "]");
- buildExplodedWebapp( getWarSourceDirectory() );
+ buildExplodedWebapp(getWarSourceDirectory());
}
-}
\ No newline at end of file
+}
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 3241c75..861a10b 100644
--- a/src/main/java/org/apache/maven/plugins/war/WarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/WarMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.IOException;
@@ -51,21 +50,22 @@ import org.codehaus.plexus.util.StringUtils;
*
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
*/
-@Mojo( name = "war", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true,
- requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME )
-public class WarMojo
- extends AbstractWarMojo
-{
+@Mojo(
+ name = "war",
+ defaultPhase = LifecyclePhase.PACKAGE,
+ threadSafe = true,
+ requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
+public class WarMojo extends AbstractWarMojo {
/**
* The directory for the generated WAR.
*/
- @Parameter( defaultValue = "${project.build.directory}", required = true )
+ @Parameter(defaultValue = "${project.build.directory}", required = true)
private String outputDirectory;
/**
* The name of the generated WAR.
*/
- @Parameter( defaultValue = "${project.build.finalName}", required = true, readonly = true )
+ @Parameter(defaultValue = "${project.build.finalName}", required = true, readonly = true)
private String warName;
/**
@@ -98,7 +98,7 @@ public class WarMojo
/**
* The WAR archiver.
*/
- @Component( role = Archiver.class, hint = "war" )
+ @Component(role = Archiver.class, hint = "war")
private WarArchiver warArchiver;
/**
@@ -110,7 +110,7 @@ public class WarMojo
* Whether this is the main artifact being built. Set to <code>false</code> if you don't want to install or deploy
* it to the local repository instead of the default one in an execution.
*/
- @Parameter( defaultValue = "true" )
+ @Parameter(defaultValue = "true")
private boolean primaryArtifact;
/**
@@ -135,7 +135,7 @@ public class WarMojo
*
* @since 2.1-alpha-2
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean attachClasses;
/**
@@ -143,7 +143,7 @@ public class WarMojo
*
* @since 2.1-alpha-2
*/
- @Parameter( defaultValue = "classes" )
+ @Parameter(defaultValue = "classes")
private String classesClassifier;
/**
@@ -152,7 +152,7 @@ public class WarMojo
*
* @since 3.0.0
*/
- @Parameter( property = "maven.war.skip", defaultValue = "false" )
+ @Parameter(property = "maven.war.skip", defaultValue = "false")
private boolean skip;
// ----------------------------------------------------------------------
@@ -166,29 +166,21 @@ public class WarMojo
* @throws MojoFailureException if an error.
*/
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
+ public void execute() throws MojoExecutionException, MojoFailureException {
- if ( isSkip() )
- {
- getLog().info( "Skipping the execution." );
+ if (isSkip()) {
+ getLog().info("Skipping the execution.");
return;
}
File warFile = getTargetWarFile();
- try
- {
- performPackaging( warFile );
- }
- catch ( DependencyResolutionRequiredException | ArchiverException e )
- {
- throw new MojoExecutionException( "Error assembling WAR: " + e.getMessage(), e );
- }
- catch ( ManifestException | IOException e )
- {
- throw new MojoExecutionException( "Error assembling WAR", e );
+ try {
+ performPackaging(warFile);
+ } catch (DependencyResolutionRequiredException | ArchiverException e) {
+ throw new MojoExecutionException("Error assembling WAR: " + e.getMessage(), e);
+ } catch (ManifestException | IOException e) {
+ throw new MojoExecutionException("Error assembling WAR", e);
}
}
@@ -203,89 +195,80 @@ public class WarMojo
* @throws MojoExecutionException if the execution failed
* @throws MojoFailureException if a fatal exception occurred
*/
- private void performPackaging( File warFile )
- throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException,
- MojoFailureException
- {
- getLog().info( "Packaging webapp" );
+ private void performPackaging(File warFile)
+ throws IOException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException,
+ MojoFailureException {
+ getLog().info("Packaging webapp");
- buildExplodedWebapp( getWebappDirectory() );
+ buildExplodedWebapp(getWebappDirectory());
MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver( warArchiver );
+ archiver.setArchiver(warArchiver);
- archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" );
+ archiver.setCreatedBy("Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin");
- archiver.setOutputFile( warFile );
+ archiver.setOutputFile(warFile);
// configure for Reproducible Builds based on outputTimestamp value
- archiver.configureReproducible( outputTimestamp );
+ archiver.configureReproducible(outputTimestamp);
- getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() )
- + " from the generated webapp archive." );
- getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated webapp archive." );
+ getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated webapp archive.");
+ getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated webapp archive.");
- warArchiver.addDirectory( getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes() );
+ warArchiver.addDirectory(getWebappDirectory(), getPackagingIncludes(), getPackagingExcludes());
- final File webXmlFile = new File( getWebappDirectory(), "WEB-INF/web.xml" );
- if ( webXmlFile.exists() )
- {
- warArchiver.setWebxml( webXmlFile );
+ final File webXmlFile = new File(getWebappDirectory(), "WEB-INF/web.xml");
+ if (webXmlFile.exists()) {
+ warArchiver.setWebxml(webXmlFile);
}
- warArchiver.setRecompressAddedZips( isRecompressZippedFiles() );
+ warArchiver.setRecompressAddedZips(isRecompressZippedFiles());
- warArchiver.setIncludeEmptyDirs( isIncludeEmptyDirectories() );
+ warArchiver.setIncludeEmptyDirs(isIncludeEmptyDirectories());
- if ( Boolean.FALSE.equals( failOnMissingWebXml )
- || ( failOnMissingWebXml == null && isProjectUsingAtLeastServlet30() ) )
- {
- getLog().debug( "Build won't fail if web.xml file is missing." );
- warArchiver.setExpectWebXml( false );
+ if (Boolean.FALSE.equals(failOnMissingWebXml)
+ || (failOnMissingWebXml == null && isProjectUsingAtLeastServlet30())) {
+ getLog().debug("Build won't fail if web.xml file is missing.");
+ warArchiver.setExpectWebXml(false);
}
// create archive
- archiver.createArchive( getSession(), getProject(), getArchive() );
+ archiver.createArchive(getSession(), getProject(), getArchive());
// create the classes to be attached if necessary
- if ( isAttachClasses() )
- {
- if ( isArchiveClasses() && getJarArchiver().getDestFile() != null )
- {
+ if (isAttachClasses()) {
+ if (isArchiveClasses() && getJarArchiver().getDestFile() != null) {
// special handling in case of archived classes: MWAR-240
File targetClassesFile = getTargetClassesFile();
- FileUtils.copyFile( getJarArchiver().getDestFile(), targetClassesFile );
- projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), targetClassesFile );
- }
- else
- {
+ FileUtils.copyFile(getJarArchiver().getDestFile(), targetClassesFile);
+ projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), targetClassesFile);
+ } else {
ClassesPackager packager = new ClassesPackager();
- final File classesDirectory = packager.getClassesDirectory( getWebappDirectory() );
- if ( classesDirectory.exists() )
- {
- getLog().info( "Packaging classes" );
- packager.packageClasses( classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(),
- getProject(), getArchive(), outputTimestamp );
- projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), getTargetClassesFile() );
+ final File classesDirectory = packager.getClassesDirectory(getWebappDirectory());
+ if (classesDirectory.exists()) {
+ getLog().info("Packaging classes");
+ packager.packageClasses(
+ classesDirectory,
+ getTargetClassesFile(),
+ getJarArchiver(),
+ getSession(),
+ getProject(),
+ getArchive(),
+ outputTimestamp);
+ projectHelper.attachArtifact(getProject(), "jar", getClassesClassifier(), getTargetClassesFile());
}
}
}
- if ( this.classifier != null )
- {
- projectHelper.attachArtifact( getProject(), "war", this.classifier, warFile );
- }
- else
- {
+ if (this.classifier != null) {
+ projectHelper.attachArtifact(getProject(), "war", this.classifier, warFile);
+ } else {
Artifact artifact = getProject().getArtifact();
- if ( primaryArtifact )
- {
- artifact.setFile( warFile );
- }
- else if ( artifact.getFile() == null || artifact.getFile().isDirectory() )
- {
- artifact.setFile( warFile );
+ if (primaryArtifact) {
+ artifact.setFile(warFile);
+ } else if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
+ artifact.setFile(warFile);
}
}
}
@@ -305,47 +288,34 @@ public class WarMojo
* @throws MalformedURLException if the path to a dependency file can't be transformed to a URL.
*/
private boolean isProjectUsingAtLeastServlet30()
- throws DependencyResolutionRequiredException, MalformedURLException
- {
+ throws DependencyResolutionRequiredException, MalformedURLException {
List<String> classpathElements = getProject().getCompileClasspathElements();
URL[] urls = new URL[classpathElements.size()];
- for ( int i = 0; i < urls.length; i++ )
- {
- urls[i] = new File( classpathElements.get( i ) ).toURI().toURL();
+ for (int i = 0; i < urls.length; i++) {
+ urls[i] = new File(classpathElements.get(i)).toURI().toURL();
}
- URLClassLoader loader = new URLClassLoader( urls, Thread.currentThread().getContextClassLoader() );
- try
- {
- return hasWebServletAnnotationClassInClasspath( loader );
- }
- finally
- {
- try
- {
+ URLClassLoader loader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
+ try {
+ return hasWebServletAnnotationClassInClasspath(loader);
+ } finally {
+ try {
loader.close();
- }
- catch ( IOException ex )
- {
+ } catch (IOException ex) {
// ignore
}
}
}
- private static boolean hasWebServletAnnotationClassInClasspath( ClassLoader loader )
- {
- return hasClassInClasspath( loader, "javax.servlet.annotation.WebServlet" )
- || hasClassInClasspath( loader, "jakarta.servlet.annotation.WebServlet" );
+ private static boolean hasWebServletAnnotationClassInClasspath(ClassLoader loader) {
+ return hasClassInClasspath(loader, "javax.servlet.annotation.WebServlet")
+ || hasClassInClasspath(loader, "jakarta.servlet.annotation.WebServlet");
}
- private static boolean hasClassInClasspath( ClassLoader loader, String clazz )
- {
- try
- {
- Class.forName( clazz, false, loader );
+ private static boolean hasClassInClasspath(ClassLoader loader, String clazz) {
+ try {
+ Class.forName(clazz, false, loader);
return true;
- }
- catch ( ClassNotFoundException e )
- {
+ } catch (ClassNotFoundException e) {
return false;
}
}
@@ -357,35 +327,28 @@ public class WarMojo
* @param type The type.
* @return {@link File}
*/
- protected static File getTargetFile( File basedir, String finalName, String classifier, String type )
- {
- if ( classifier == null )
- {
+ protected static File getTargetFile(File basedir, String finalName, String classifier, String type) {
+ if (classifier == null) {
classifier = "";
- }
- else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
- {
+ } else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) {
classifier = "-" + classifier;
}
- return new File( basedir, finalName + classifier + "." + type );
+ return new File(basedir, finalName + classifier + "." + type);
}
/**
* @return The war {@link File}
*/
- protected File getTargetWarFile()
- {
- return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassifier(), "war" );
-
+ protected File getTargetWarFile() {
+ return getTargetFile(new File(getOutputDirectory()), getWarName(), getClassifier(), "war");
}
/**
* @return The target class {@link File}
*/
- protected File getTargetClassesFile()
- {
- return getTargetFile( new File( getOutputDirectory() ), getWarName(), getClassesClassifier(), "jar" );
+ protected File getTargetClassesFile() {
+ return getTargetFile(new File(getOutputDirectory()), getWarName(), getClassesClassifier(), "jar");
}
// Getters and Setters
@@ -393,190 +356,162 @@ public class WarMojo
/**
* @return {@link #classifier}
*/
- public String getClassifier()
- {
+ public String getClassifier() {
return classifier;
}
/**
* @param classifier {@link #classifier}
*/
- public void setClassifier( String classifier )
- {
+ public void setClassifier(String classifier) {
this.classifier = classifier;
}
/**
* @return The package excludes.
*/
- public String[] getPackagingExcludes()
- {
- if ( packagingExcludes == null || packagingExcludes.isEmpty() )
- {
+ public String[] getPackagingExcludes() {
+ if (packagingExcludes == null || packagingExcludes.isEmpty()) {
return new String[0];
- }
- else
- {
- return StringUtils.split( packagingExcludes, "," );
+ } else {
+ return StringUtils.split(packagingExcludes, ",");
}
}
/**
* @param packagingExcludes {@link #packagingExcludes}
*/
- public void setPackagingExcludes( String 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, "," );
+ 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 )
- {
+ public void setPackagingIncludes(String packagingIncludes) {
this.packagingIncludes = packagingIncludes;
}
/**
* @return {@link #outputDirectory}
*/
- public String getOutputDirectory()
- {
+ public String getOutputDirectory() {
return outputDirectory;
}
/**
* @param outputDirectory {@link #outputDirectory}
*/
- public void setOutputDirectory( String outputDirectory )
- {
+ public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;
}
/**
* @return {@link #warName}
*/
- public String getWarName()
- {
+ public String getWarName() {
return warName;
}
/**
* @param warName {@link #warName}
*/
- public void setWarName( String warName )
- {
+ public void setWarName(String warName) {
this.warName = warName;
}
/**
* @return {@link #warArchiver}
*/
- public WarArchiver getWarArchiver()
- {
+ public WarArchiver getWarArchiver() {
return warArchiver;
}
/**
* @param warArchiver {@link #warArchiver}
*/
- public void setWarArchiver( WarArchiver warArchiver )
- {
+ public void setWarArchiver(WarArchiver warArchiver) {
this.warArchiver = warArchiver;
}
/**
* @return {@link #projectHelper}
*/
- public MavenProjectHelper getProjectHelper()
- {
+ public MavenProjectHelper getProjectHelper() {
return projectHelper;
}
/**
* @param projectHelper {@link #projectHelper}
*/
- public void setProjectHelper( MavenProjectHelper projectHelper )
- {
+ public void setProjectHelper(MavenProjectHelper projectHelper) {
this.projectHelper = projectHelper;
}
/**
* @return {@link #primaryArtifact}
*/
- public boolean isPrimaryArtifact()
- {
+ public boolean isPrimaryArtifact() {
return primaryArtifact;
}
/**
* @param primaryArtifact {@link #primaryArtifact}
*/
- public void setPrimaryArtifact( boolean primaryArtifact )
- {
+ public void setPrimaryArtifact(boolean primaryArtifact) {
this.primaryArtifact = primaryArtifact;
}
/**
* @return {@link #attachClasses}
*/
- public boolean isAttachClasses()
- {
+ public boolean isAttachClasses() {
return attachClasses;
}
/**
* @param attachClasses {@link #attachClasses}
*/
- public void setAttachClasses( boolean attachClasses )
- {
+ public void setAttachClasses(boolean attachClasses) {
this.attachClasses = attachClasses;
}
/**
* @return {@link #classesClassifier}
*/
- public String getClassesClassifier()
- {
+ public String getClassesClassifier() {
return classesClassifier;
}
/**
* @param classesClassifier {@link #classesClassifier}
*/
- public void setClassesClassifier( String classesClassifier )
- {
+ public void setClassesClassifier(String classesClassifier) {
this.classesClassifier = classesClassifier;
}
/**
* @return {@link #failOnMissingWebXml}
*/
- public boolean isFailOnMissingWebXml()
- {
+ public boolean isFailOnMissingWebXml() {
return failOnMissingWebXml;
}
/**
* @param failOnMissingWebXml {@link #failOnMissingWebXml}
*/
- public void setFailOnMissingWebXml( boolean failOnMissingWebXml )
- {
+ public void setFailOnMissingWebXml(boolean failOnMissingWebXml) {
this.failOnMissingWebXml = failOnMissingWebXml;
}
@@ -584,8 +519,7 @@ public class WarMojo
* Skip the mojo run
* @return {@link #skip}
*/
- public boolean isSkip()
- {
+ public boolean isSkip() {
return skip;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java b/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java
index 831a53a..ec9be9f 100644
--- a/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java
+++ b/src/main/java/org/apache/maven/plugins/war/overlay/DefaultOverlay.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.overlay;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.overlay;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.overlay;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.war.Overlay;
@@ -27,23 +26,20 @@ import org.apache.maven.plugins.war.Overlay;
*
* @author Stephane Nicoll
*/
-public class DefaultOverlay
- extends Overlay
-{
+public class DefaultOverlay extends Overlay {
/**
* Creates an overlay for the specified artifact.
*
* @param a the artifact
*/
- public DefaultOverlay( Artifact a )
- {
+ public DefaultOverlay(Artifact a) {
super();
- setGroupId( a.getGroupId() );
- setArtifactId( a.getArtifactId() );
- setClassifier( a.getClassifier() );
- setArtifact( a );
- setType( a.getType() );
+ setGroupId(a.getGroupId());
+ setArtifactId(a.getArtifactId());
+ setClassifier(a.getClassifier());
+ setArtifact(a);
+ setType(a.getType());
}
/**
@@ -53,10 +49,9 @@ public class DefaultOverlay
* @param includes the includes to use
* @param excludes the excludes to use
*/
- public DefaultOverlay( Artifact a, String[] includes, String[] excludes )
- {
- this( a );
- setIncludes( includes );
- setExcludes( excludes );
+ public DefaultOverlay(Artifact a, String[] includes, String[] excludes) {
+ this(a);
+ setIncludes(includes);
+ setExcludes(excludes);
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java b/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java
index 3470ef5..e4b0ec5 100644
--- a/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java
+++ b/src/main/java/org/apache/maven/plugins/war/overlay/InvalidOverlayConfigurationException.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.overlay;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.overlay;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.overlay;
import org.apache.maven.plugin.MojoExecutionException;
@@ -26,29 +25,25 @@ import org.apache.maven.plugin.MojoExecutionException;
*
* @author Stephane Nicoll
*/
-public class InvalidOverlayConfigurationException
- extends MojoExecutionException
-{
+public class InvalidOverlayConfigurationException extends MojoExecutionException {
/**
- *
+ *
*/
private static final long serialVersionUID = -9048144470408031414L;
/**
* @param string Set the message of the exception.
*/
- public InvalidOverlayConfigurationException( String string )
- {
- super( string );
+ public InvalidOverlayConfigurationException(String string) {
+ super(string);
}
/**
* @param string Set the message of the exception.
* @param throwable {@link Throwable}
*/
- public InvalidOverlayConfigurationException( String string, Throwable throwable )
- {
- super( string, throwable );
+ public InvalidOverlayConfigurationException(String string, Throwable throwable) {
+ super(string, throwable);
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java b/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
index ae0ee8e..bf4193b 100644
--- a/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
+++ b/src/main/java/org/apache/maven/plugins/war/overlay/OverlayManager.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.overlay;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.overlay;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.overlay;
import java.util.ArrayList;
import java.util.Arrays;
@@ -36,8 +35,7 @@ import org.apache.maven.project.MavenProject;
*
* @author Stephane Nicoll
*/
-public class OverlayManager
-{
+public class OverlayManager {
private final List<Overlay> overlays;
private final MavenProject project;
@@ -46,7 +44,7 @@ public class OverlayManager
/**
* Creates a manager with the specified overlays.
- *
+ *
* Note that the list is potentially updated by the manager so a new list is created based on the overlays.
*
* @param overlays the overlays
@@ -56,22 +54,23 @@ public class OverlayManager
* @param currentProjectOverlay the overlay for the current project
* @throws InvalidOverlayConfigurationException if the config is invalid
*/
- public OverlayManager( List<Overlay> overlays, MavenProject project, String[] defaultIncludes,
- String[] defaultExcludes, Overlay currentProjectOverlay )
- throws InvalidOverlayConfigurationException
- {
+ public OverlayManager(
+ List<Overlay> overlays,
+ MavenProject project,
+ String[] defaultIncludes,
+ String[] defaultExcludes,
+ Overlay currentProjectOverlay)
+ throws InvalidOverlayConfigurationException {
this.overlays = new ArrayList<>();
- if ( overlays != null )
- {
- this.overlays.addAll( overlays );
+ if (overlays != null) {
+ this.overlays.addAll(overlays);
}
this.project = project;
this.artifactsOverlays = getOverlaysAsArtifacts();
// Initialize
- initialize( defaultIncludes, defaultExcludes, currentProjectOverlay );
-
+ initialize(defaultIncludes, defaultExcludes, currentProjectOverlay);
}
/**
@@ -79,8 +78,7 @@ public class OverlayManager
*
* @return the overlays
*/
- public List<Overlay> getOverlays()
- {
+ public List<Overlay> getOverlays() {
return overlays;
}
@@ -89,15 +87,12 @@ public class OverlayManager
*
* @return the overlay ids
*/
- public List<String> getOverlayIds()
- {
+ public List<String> getOverlayIds() {
final List<String> result = new ArrayList<>();
- for ( Overlay overlay : overlays )
- {
- result.add( overlay.getId() );
+ for (Overlay overlay : overlays) {
+ result.add(overlay.getId());
}
return result;
-
}
/**
@@ -108,68 +103,58 @@ public class OverlayManager
* @param currentProjectOverlay the overlay for the current project
* @throws InvalidOverlayConfigurationException if the configuration is invalid
*/
- void initialize( String[] defaultIncludes, String[] defaultExcludes, Overlay currentProjectOverlay )
- throws InvalidOverlayConfigurationException
- {
+ void initialize(String[] defaultIncludes, String[] defaultExcludes, Overlay currentProjectOverlay)
+ throws InvalidOverlayConfigurationException {
// Build the list of configured artifacts and makes sure that each overlay
// refer to a valid artifact
final List<Artifact> configuredWarArtifacts = new ArrayList<>();
final ListIterator<Overlay> it = overlays.listIterator();
- while ( it.hasNext() )
- {
+ while (it.hasNext()) {
Overlay overlay = it.next();
- if ( overlay == null )
- {
- throw new InvalidOverlayConfigurationException( "overlay could not be null." );
+ if (overlay == null) {
+ throw new InvalidOverlayConfigurationException("overlay could not be null.");
}
// If it's the current project, return the project instance
- if ( overlay.isCurrentProject() )
- {
+ if (overlay.isCurrentProject()) {
overlay = currentProjectOverlay;
- it.set( overlay );
+ it.set(overlay);
}
// default includes/excludes - only if the overlay uses the default settings
- if ( Arrays.equals( Overlay.DEFAULT_INCLUDES, overlay.getIncludes() )
- && Arrays.equals( Overlay.DEFAULT_EXCLUDES, overlay.getExcludes() ) )
- {
- overlay.setIncludes( defaultIncludes );
- overlay.setExcludes( defaultExcludes );
+ if (Arrays.equals(Overlay.DEFAULT_INCLUDES, overlay.getIncludes())
+ && Arrays.equals(Overlay.DEFAULT_EXCLUDES, overlay.getExcludes())) {
+ overlay.setIncludes(defaultIncludes);
+ overlay.setExcludes(defaultExcludes);
}
- final Artifact artifact = getAssociatedArtifact( overlay );
- if ( artifact != null )
- {
- configuredWarArtifacts.add( artifact );
- overlay.setArtifact( artifact );
+ final Artifact artifact = getAssociatedArtifact(overlay);
+ if (artifact != null) {
+ configuredWarArtifacts.add(artifact);
+ overlay.setArtifact(artifact);
}
}
// Build the list of missing overlays
- for ( Artifact artifact : artifactsOverlays )
- {
- if ( !configuredWarArtifacts.contains( artifact ) )
- {
+ for (Artifact artifact : artifactsOverlays) {
+ if (!configuredWarArtifacts.contains(artifact)) {
// Add a default overlay for the given artifact which will be applied after
// the ones that have been configured
- overlays.add( new DefaultOverlay( artifact, defaultIncludes, defaultExcludes ) );
+ overlays.add(new DefaultOverlay(artifact, defaultIncludes, defaultExcludes));
}
}
// Final validation, make sure that the current project is in there. Otherwise add it first
- for ( Overlay overlay : overlays )
- {
- if ( overlay.equals( currentProjectOverlay ) )
- {
+ for (Overlay overlay : overlays) {
+ if (overlay.equals(currentProjectOverlay)) {
return;
}
}
- overlays.add( 0, currentProjectOverlay );
+ overlays.add(0, currentProjectOverlay);
}
/**
* Returns the Artifact associated to the specified overlay.
- *
+ *
* If the overlay defines the current project, {@code null} is returned. If no artifact could not be found for the
* overlay a InvalidOverlayConfigurationException is thrown.
*
@@ -178,37 +163,29 @@ public class OverlayManager
* @throws org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException if the overlay does not have an
* associated artifact
*/
- Artifact getAssociatedArtifact( final Overlay overlay )
- throws InvalidOverlayConfigurationException
- {
- if ( overlay.isCurrentProject() )
- {
+ Artifact getAssociatedArtifact(final Overlay overlay) throws InvalidOverlayConfigurationException {
+ if (overlay.isCurrentProject()) {
return null;
}
- for ( Artifact artifact : artifactsOverlays )
- {
+ for (Artifact artifact : artifactsOverlays) {
// Handle classifier dependencies properly (clash management)
- if ( compareOverlayWithArtifact( overlay, artifact ) )
- {
+ if (compareOverlayWithArtifact(overlay, artifact)) {
return artifact;
}
}
// maybe its a project dependencies zip or an other type
Set<Artifact> projectArtifacts = this.project.getDependencyArtifacts();
- if ( projectArtifacts != null )
- {
- for ( Artifact artifact : projectArtifacts )
- {
- if ( compareOverlayWithArtifact( overlay, artifact ) )
- {
+ if (projectArtifacts != null) {
+ for (Artifact artifact : projectArtifacts) {
+ if (compareOverlayWithArtifact(overlay, artifact)) {
return artifact;
}
}
}
// CHECKSTYLE_OFF: LineLength
- throw new InvalidOverlayConfigurationException( "overlay [" + overlay + "] is not a dependency of the project." );
+ throw new InvalidOverlayConfigurationException("overlay [" + overlay + "] is not a dependency of the project.");
// CHECKSTYLE_ON: LineLength
}
@@ -220,14 +197,13 @@ public class OverlayManager
* @param artifact the artifact
* @return boolean true if equals
*/
- private boolean compareOverlayWithArtifact( Overlay overlay, Artifact artifact )
- {
- return ( Objects.equals( overlay.getGroupId(), artifact.getGroupId() )
- && Objects.equals( overlay.getArtifactId(), artifact.getArtifactId() )
- && Objects.equals( overlay.getType(), artifact.getType() )
- // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier
- && Objects.equals( Objects.toString( overlay.getClassifier() ),
- Objects.toString( artifact.getClassifier() ) ) );
+ private boolean compareOverlayWithArtifact(Overlay overlay, Artifact artifact) {
+ return (Objects.equals(overlay.getGroupId(), artifact.getGroupId())
+ && Objects.equals(overlay.getArtifactId(), artifact.getArtifactId())
+ && Objects.equals(overlay.getType(), artifact.getType())
+ // MWAR-241 Make sure to treat null and "" as equal when comparing the classifier
+ && Objects.equals(
+ Objects.toString(overlay.getClassifier()), Objects.toString(artifact.getClassifier())));
}
/**
@@ -235,17 +211,14 @@ public class OverlayManager
*
* @return the overlays as artifacts objects
*/
- private List<Artifact> getOverlaysAsArtifacts()
- {
- ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+ private List<Artifact> getOverlaysAsArtifacts() {
+ ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
final Set<Artifact> artifacts = project.getArtifacts();
final List<Artifact> result = new ArrayList<>();
- for ( Artifact artifact : artifacts )
- {
- if ( !artifact.isOptional() && filter.include( artifact ) && ( "war".equals( artifact.getType() ) ) )
- {
- result.add( artifact );
+ for (Artifact artifact : artifacts) {
+ if (!artifact.isOptional() && filter.include(artifact) && ("war".equals(artifact.getType()))) {
+ result.add(artifact);
}
}
return result;
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 171275f..7e4e5f6 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
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import java.io.File;
import java.io.IOException;
@@ -43,13 +42,11 @@ import org.codehaus.plexus.util.FileUtils;
/**
* @author Stephane Nicoll
*/
-public abstract class AbstractWarPackagingTask
- implements WarPackagingTask
-{
+public abstract class AbstractWarPackagingTask implements WarPackagingTask {
/**
* The default list of includes.
*/
- public static final String[] DEFAULT_INCLUDES = { "**/**" };
+ public static final String[] DEFAULT_INCLUDES = {"**/**"};
/**
* The {@code WEB-INF} path.
@@ -73,10 +70,10 @@ public abstract class AbstractWarPackagingTask
/**
* Copies the files if possible with an optional target prefix.
- *
+ *
* Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method
* makes sure to update the list of protected files which gives the list of files that have already been copied.
- *
+ *
* If the structure of the source directory is not the same as the root of the webapp, use the {@code targetPrefix}
* parameter to specify in which particular directory the files should be copied. Use {@code null} to copy the
* files with the same structure
@@ -90,38 +87,35 @@ public abstract class AbstractWarPackagingTask
* @throws IOException if an error occurred while copying the files
* @throws MojoExecutionException if an error occurs.
*/
- protected void copyFiles( String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet,
- String targetPrefix, boolean filtered )
- throws IOException, MojoExecutionException
- {
- for ( String fileToCopyName : sourceFilesSet.paths() )
- {
- final File sourceFile = new File( sourceBaseDir, fileToCopyName );
+ protected void copyFiles(
+ String sourceId,
+ WarPackagingContext context,
+ File sourceBaseDir,
+ PathSet sourceFilesSet,
+ String targetPrefix,
+ boolean filtered)
+ throws IOException, MojoExecutionException {
+ for (String fileToCopyName : sourceFilesSet.paths()) {
+ final File sourceFile = new File(sourceBaseDir, fileToCopyName);
String destinationFileName;
- if ( targetPrefix == null )
- {
+ if (targetPrefix == null) {
destinationFileName = fileToCopyName;
- }
- else
- {
+ } else {
destinationFileName = targetPrefix + fileToCopyName;
}
- if ( filtered && !context.isNonFilteredExtension( sourceFile.getName() ) )
- {
- copyFilteredFile( sourceId, context, sourceFile, destinationFileName );
- }
- else
- {
- copyFile( sourceId, context, sourceFile, destinationFileName );
+ if (filtered && !context.isNonFilteredExtension(sourceFile.getName())) {
+ copyFilteredFile(sourceId, context, sourceFile, destinationFileName);
+ } else {
+ copyFile(sourceId, context, sourceFile, destinationFileName);
}
}
}
/**
* Copies the files if possible as is.
- *
+ *
* Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method
* makes sure to update the list of protected files which gives the list of files that have already been copied.
*
@@ -133,16 +127,15 @@ public abstract class AbstractWarPackagingTask
* @throws IOException if an error occurred while copying the files
* @throws MojoExecutionException break the build.
*/
- protected void copyFiles( String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet,
- boolean filtered )
- throws IOException, MojoExecutionException
- {
- copyFiles( sourceId, context, sourceBaseDir, sourceFilesSet, null, filtered );
+ protected void copyFiles(
+ String sourceId, WarPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet, boolean filtered)
+ throws IOException, MojoExecutionException {
+ copyFiles(sourceId, context, sourceBaseDir, sourceFilesSet, null, filtered);
}
/**
* Copy the specified file if the target location has not yet already been used.
- *
+ *
* The {@code targetFileName} is the relative path according to the root of the generated web application.
*
* @param sourceId the source id
@@ -152,85 +145,67 @@ public abstract class AbstractWarPackagingTask
* @throws IOException if an error occurred while copying
*/
// CHECKSTYLE_OFF: LineLength
- protected void copyFile( String sourceId, final WarPackagingContext context, final File file, String targetFilename )
- throws IOException
- // CHECKSTYLE_ON: LineLength
- {
- final File targetFile = new File( context.getWebappDirectory(), targetFilename );
-
- if ( file.isFile() )
- {
- context.getWebappStructure().registerFile( sourceId, targetFilename,
- new WebappStructure.RegistrationCallback()
- {
- public void registered( String ownerId, String targetFilename )
- throws IOException
- {
- copyFile( context, file, targetFile, targetFilename,
- false );
- }
-
- public void alreadyRegistered( String ownerId,
- String targetFilename )
- throws IOException
- {
- copyFile( context, file, targetFile, targetFilename,
- true );
- }
-
- public void refused( String ownerId, String targetFilename,
- String actualOwnerId )
- throws IOException
- {
- context.getLog().debug( " - "
- + targetFilename
- + " wasn't copied because it has "
- + "already been packaged for overlay ["
- + actualOwnerId + "]." );
- }
-
- public void superseded( String ownerId,
- String targetFilename,
- String deprecatedOwnerId )
- throws IOException
- {
- context.getLog().info( "File ["
- + targetFilename
- + "] belonged to overlay ["
- + deprecatedOwnerId
- + "] so it will be overwritten." );
- copyFile( context, file, targetFile, targetFilename,
- false );
- }
-
- public void supersededUnknownOwner( String ownerId,
- String targetFilename,
- String unknownOwnerId )
- throws IOException
- {
- // CHECKSTYLE_OFF: LineLength
- context.getLog().warn( "File ["
- + targetFilename
- + "] belonged to overlay ["
- + unknownOwnerId
- + "] which does not exist anymore in the current project. It is recommended to invoke "
- + "clean if the dependencies of the project changed." );
- // CHECKSTYLE_ON: LineLength
- copyFile( context, file, targetFile, targetFilename,
- false );
- }
- } );
- }
- else if ( !targetFile.exists() && !targetFile.mkdirs() )
- {
- context.getLog().info( "Failed to create directory " + targetFile.getAbsolutePath() );
+ protected void copyFile(String sourceId, final WarPackagingContext context, final File file, String targetFilename)
+ throws IOException
+ // CHECKSTYLE_ON: LineLength
+ {
+ final File targetFile = new File(context.getWebappDirectory(), targetFilename);
+
+ if (file.isFile()) {
+ context.getWebappStructure()
+ .registerFile(sourceId, targetFilename, new WebappStructure.RegistrationCallback() {
+ public void registered(String ownerId, String targetFilename) throws IOException {
+ copyFile(context, file, targetFile, targetFilename, false);
+ }
+
+ public void alreadyRegistered(String ownerId, String targetFilename) throws IOException {
+ copyFile(context, file, targetFile, targetFilename, true);
+ }
+
+ public void refused(String ownerId, String targetFilename, String actualOwnerId)
+ throws IOException {
+ context.getLog()
+ .debug(" - "
+ + targetFilename
+ + " wasn't copied because it has "
+ + "already been packaged for overlay ["
+ + actualOwnerId + "].");
+ }
+
+ public void superseded(String ownerId, String targetFilename, String deprecatedOwnerId)
+ throws IOException {
+ context.getLog()
+ .info("File ["
+ + targetFilename
+ + "] belonged to overlay ["
+ + deprecatedOwnerId
+ + "] so it will be overwritten.");
+ copyFile(context, file, targetFile, targetFilename, false);
+ }
+
+ public void supersededUnknownOwner(String ownerId, String targetFilename, String unknownOwnerId)
+ throws IOException {
+ // CHECKSTYLE_OFF: LineLength
+ context.getLog()
+ .warn("File ["
+ + targetFilename
+ + "] belonged to overlay ["
+ + unknownOwnerId
+ + "] which does not exist anymore in the current project. It is recommended to invoke "
+ + "clean if the dependencies of the project changed.");
+ // CHECKSTYLE_ON: LineLength
+ copyFile(context, file, targetFile, targetFilename, false);
+ }
+ });
+ } else if (!targetFile.exists() && !targetFile.mkdirs()) {
+ context.getLog().info("Failed to create directory " + targetFile.getAbsolutePath());
}
}
/**
* Copy the specified file if the target location has not yet already been used and filter its content with the
* configured filter properties.
- *
+ *
* The {@code targetFileName} is the relative path according to the root of the generated web application.
*
* @param sourceId the source id
@@ -241,51 +216,39 @@ public abstract class AbstractWarPackagingTask
* @throws IOException if an error occurred while copying
* @throws MojoExecutionException if an error occurred while retrieving the filter properties
*/
- protected boolean copyFilteredFile( String sourceId, final WarPackagingContext context, File file,
- String targetFilename )
- throws IOException, MojoExecutionException
- {
- context.addResource( targetFilename );
-
- if ( context.getWebappStructure().registerFile( sourceId, targetFilename ) )
- {
- final File targetFile = new File( context.getWebappDirectory(), targetFilename );
+ protected boolean copyFilteredFile(
+ String sourceId, final WarPackagingContext context, File file, String targetFilename)
+ throws IOException, MojoExecutionException {
+ context.addResource(targetFilename);
+
+ if (context.getWebappStructure().registerFile(sourceId, targetFilename)) {
+ final File targetFile = new File(context.getWebappDirectory(), targetFilename);
final String encoding;
- try
- {
- if ( isXmlFile( file ) )
- {
+ try {
+ if (isXmlFile(file)) {
// For xml-files we extract the encoding from the files
- encoding = getEncoding( file );
- }
- else if ( isPropertiesFile( file ) && StringUtils.isNotEmpty( context.getPropertiesEncoding() ) )
- {
+ encoding = getEncoding(file);
+ } else if (isPropertiesFile(file) && StringUtils.isNotEmpty(context.getPropertiesEncoding())) {
encoding = context.getPropertiesEncoding();
- }
- else
- {
+ } else {
// For all others we use the configured encoding
encoding = context.getResourceEncoding();
}
// fix for MWAR-36, ensures that the parent dir are created first
targetFile.getParentFile().mkdirs();
- context.getMavenFileFilter().copyFile( file, targetFile, true, context.getFilterWrappers(), encoding );
- }
- catch ( MavenFilteringException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ context.getMavenFileFilter().copyFile(file, targetFile, true, context.getFilterWrappers(), encoding);
+ } catch (MavenFilteringException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
// CHECKSTYLE_OFF: LineLength
// Add the file to the protected list
- context.getLog().debug( " + " + targetFilename + " has been copied (filtered encoding='" + encoding + "')." );
+ context.getLog().debug(" + " + targetFilename + " has been copied (filtered encoding='" + encoding + "').");
// CHECKSTYLE_ON: LineLength
return true;
- }
- else
- {
- context.getLog().debug( " - " + targetFilename
- + " wasn't copied because it has already been packaged (filtered)." );
+ } else {
+ context.getLog()
+ .debug(" - " + targetFilename + " wasn't copied because it has already been packaged (filtered).");
return false;
}
}
@@ -298,28 +261,25 @@ public abstract class AbstractWarPackagingTask
* @param unpackDirectory the directory to use for th unpacked file
* @throws MojoExecutionException if an error occurred while unpacking the file
*/
- protected void doUnpack( WarPackagingContext context, File file, File unpackDirectory )
- throws MojoExecutionException
- {
- String archiveExt = FileUtils.getExtension( file.getAbsolutePath() ).toLowerCase();
-
- try
- {
- UnArchiver unArchiver = context.getArchiverManager().getUnArchiver( archiveExt );
- unArchiver.setSourceFile( file );
- unArchiver.setDestDirectory( unpackDirectory );
- unArchiver.setOverwrite( true );
+ protected void doUnpack(WarPackagingContext context, File file, File unpackDirectory)
+ throws MojoExecutionException {
+ String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();
+
+ try {
+ UnArchiver unArchiver = context.getArchiverManager().getUnArchiver(archiveExt);
+ unArchiver.setSourceFile(file);
+ unArchiver.setDestDirectory(unpackDirectory);
+ unArchiver.setOverwrite(true);
unArchiver.extract();
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error unpacking file [" + file.getAbsolutePath() + "]" + " to ["
- + unpackDirectory.getAbsolutePath() + "]", e );
- }
- catch ( NoSuchArchiverException e )
- {
- context.getLog().warn( "Skip unpacking dependency file [" + file.getAbsolutePath()
- + " with unknown extension [" + archiveExt + "]" );
+ } catch (ArchiverException e) {
+ throw new MojoExecutionException(
+ "Error unpacking file [" + file.getAbsolutePath() + "]" + " to ["
+ + unpackDirectory.getAbsolutePath() + "]",
+ e);
+ } catch (NoSuchArchiverException e) {
+ context.getLog()
+ .warn("Skip unpacking dependency file [" + file.getAbsolutePath() + " with unknown extension ["
+ + archiveExt + "]");
}
}
@@ -338,44 +298,36 @@ public abstract class AbstractWarPackagingTask
* @throws IOException if <code>source</code> does not exist, <code>destination</code> cannot be written to, or an
* IO error occurs during copying
*/
- protected boolean copyFile( WarPackagingContext context, File source, File destination, String targetFilename,
- boolean onlyIfModified )
- throws IOException
- {
- context.addResource( targetFilename );
-
- BasicFileAttributes readAttributes = Files.readAttributes( source.toPath(), BasicFileAttributes.class );
- if ( onlyIfModified && destination.lastModified() >= readAttributes.lastModifiedTime().toMillis() )
- {
- context.getLog().debug( " * " + targetFilename + " is up to date." );
+ protected boolean copyFile(
+ WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified)
+ throws IOException {
+ context.addResource(targetFilename);
+
+ BasicFileAttributes readAttributes = Files.readAttributes(source.toPath(), BasicFileAttributes.class);
+ if (onlyIfModified
+ && destination.lastModified()
+ >= readAttributes.lastModifiedTime().toMillis()) {
+ context.getLog().debug(" * " + targetFilename + " is up to date.");
return false;
- }
- else
- {
- if ( readAttributes.isDirectory() )
- {
- context.getLog().warn( " + " + targetFilename + " is packaged from the source folder" );
+ } else {
+ if (readAttributes.isDirectory()) {
+ context.getLog().warn(" + " + targetFilename + " is packaged from the source folder");
- try
- {
+ try {
JarArchiver archiver = context.getJarArchiver();
- archiver.addDirectory( source );
- archiver.setDestFile( destination );
+ archiver.addDirectory(source);
+ archiver.setDestFile(destination);
archiver.createArchive();
- }
- catch ( ArchiverException e )
- {
+ } catch (ArchiverException e) {
String msg = "Failed to create " + targetFilename;
- context.getLog().error( msg, e );
- throw new IOException( msg, e );
+ context.getLog().error(msg, e);
+ throw new IOException(msg, e);
}
- }
- else
- {
- FileUtils.copyFile( source.getCanonicalFile(), destination );
+ } else {
+ FileUtils.copyFile(source.getCanonicalFile(), destination);
// preserve timestamp
- destination.setLastModified( readAttributes.lastModifiedTime().toMillis() );
- context.getLog().debug( " + " + targetFilename + " has been copied." );
+ destination.setLastModified(readAttributes.lastModifiedTime().toMillis());
+ context.getLog().debug(" + " + targetFilename + " has been copied.");
}
return true;
}
@@ -388,11 +340,8 @@ public abstract class AbstractWarPackagingTask
* @return The encoding of the XML-file, or UTF-8 if it's not specified in the file
* @throws java.io.IOException if an error occurred while reading the file
*/
- protected String getEncoding( File webXml )
- throws IOException
- {
- try ( XmlStreamReader xmlReader = new XmlStreamReader( webXml ) )
- {
+ protected String getEncoding(File webXml) throws IOException {
+ try (XmlStreamReader xmlReader = new XmlStreamReader(webXml)) {
return xmlReader.getEncoding();
}
}
@@ -405,9 +354,8 @@ public abstract class AbstractWarPackagingTask
* @param excludes the excludes
* @return the files to copy
*/
- protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes )
- {
- return getFilesToIncludes( baseDir, includes, excludes, false );
+ protected PathSet getFilesToIncludes(File baseDir, String[] includes, String[] excludes) {
+ return getFilesToIncludes(baseDir, includes, excludes, false);
}
/**
@@ -420,34 +368,30 @@ public abstract class AbstractWarPackagingTask
* @return the files to copy
*/
// CHECKSTYLE_OFF: LineLength
- protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] excludes, boolean includeDirectories )
- // CHECKSTYLE_ON: LineLength
- {
+ protected PathSet getFilesToIncludes(
+ File baseDir, String[] includes, String[] excludes, boolean includeDirectories)
+ // CHECKSTYLE_ON: LineLength
+ {
final DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( baseDir );
+ scanner.setBasedir(baseDir);
- if ( excludes != null )
- {
- scanner.setExcludes( excludes );
+ if (excludes != null) {
+ scanner.setExcludes(excludes);
}
scanner.addDefaultExcludes();
- if ( includes != null && includes.length > 0 )
- {
- scanner.setIncludes( includes );
- }
- else
- {
- scanner.setIncludes( DEFAULT_INCLUDES );
+ if (includes != null && includes.length > 0) {
+ scanner.setIncludes(includes);
+ } else {
+ scanner.setIncludes(DEFAULT_INCLUDES);
}
scanner.scan();
- PathSet pathSet = new PathSet( scanner.getIncludedFiles() );
+ PathSet pathSet = new PathSet(scanner.getIncludedFiles());
- if ( includeDirectories )
- {
- pathSet.addAll( scanner.getIncludedDirectories() );
+ if (includeDirectories) {
+ pathSet.addAll(scanner.getIncludedDirectories());
}
return pathSet;
@@ -455,7 +399,7 @@ public abstract class AbstractWarPackagingTask
/**
* Returns the final name of the specified artifact.
- *
+ *
* If the {@code outputFileNameMapping} is set, it is used, otherwise the standard naming scheme is used.
*
* @param context the packaging context
@@ -463,24 +407,18 @@ public abstract class AbstractWarPackagingTask
* @return the converted filename of the artifact
* @throws InterpolationException in case of interpolation problem.
*/
- protected String getArtifactFinalName( WarPackagingContext context, Artifact artifact )
- throws InterpolationException
- {
- if ( context.getOutputFileNameMapping() != null )
- {
- return MappingUtils.evaluateFileNameMapping( context.getOutputFileNameMapping(), artifact );
+ protected String getArtifactFinalName(WarPackagingContext context, Artifact artifact)
+ throws InterpolationException {
+ if (context.getOutputFileNameMapping() != null) {
+ return MappingUtils.evaluateFileNameMapping(context.getOutputFileNameMapping(), artifact);
}
String classifier = artifact.getClassifier();
- if ( ( classifier != null ) && !( "".equals( classifier.trim() ) ) )
- {
- return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, artifact );
+ if ((classifier != null) && !("".equals(classifier.trim()))) {
+ return MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, artifact);
+ } else {
+ return MappingUtils.evaluateFileNameMapping(MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact);
}
- else
- {
- return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact );
- }
-
}
/**
@@ -491,9 +429,8 @@ public abstract class AbstractWarPackagingTask
* @return <code>true</code> if the file is a file of the specified type, otherwise <code>false</code>
* @since 3.4.0
*/
- private boolean isFileOfType( File file, String extension )
- {
- return file != null && file.isFile() && file.getName().endsWith( extension );
+ private boolean isFileOfType(File file, String extension) {
+ return file != null && file.isFile() && file.getName().endsWith(extension);
}
/**
@@ -503,9 +440,8 @@ public abstract class AbstractWarPackagingTask
* @return <code>true</code> if the file is a properties file, otherwise <code>false</code>
* @since 3.4.0
*/
- private boolean isPropertiesFile( File file )
- {
- return isFileOfType( file, ".properties" );
+ private boolean isPropertiesFile(File file) {
+ return isFileOfType(file, ".properties");
}
/**
@@ -516,8 +452,7 @@ public abstract class AbstractWarPackagingTask
* @return <code>true</code> if the file is an xml-file, otherwise <code>false</code>
* @since 2.3
*/
- private boolean isXmlFile( File file )
- {
- return isFileOfType( file, ".xml" );
+ private boolean isXmlFile(File file) {
+ return isFileOfType(file, ".xml");
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java
index 2fa484d..6b6755a 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/ArtifactsPackagingTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import java.io.IOException;
import java.util.ArrayList;
@@ -35,9 +34,7 @@ import org.codehaus.plexus.interpolation.InterpolationException;
*
* @author Stephane Nicoll
*/
-public class ArtifactsPackagingTask
- extends AbstractWarPackagingTask
-{
+public class ArtifactsPackagingTask extends AbstractWarPackagingTask {
/**
* The {@code tld} path.
@@ -67,94 +64,69 @@ public class ArtifactsPackagingTask
* @param artifacts {@link #artifacts}
* @param currentProjectOverlay {@link #id}
*/
- public ArtifactsPackagingTask( Set<Artifact> artifacts, Overlay currentProjectOverlay )
- {
+ public ArtifactsPackagingTask(Set<Artifact> artifacts, Overlay currentProjectOverlay) {
this.artifacts = artifacts;
this.id = currentProjectOverlay.getId();
}
@Override
- public void performPackaging( WarPackagingContext context )
- throws MojoExecutionException
- {
- try
- {
- final ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
- final List<String> duplicates = findDuplicates( context, artifacts );
-
- for ( Artifact artifact : artifacts )
- {
- String targetFileName = getArtifactFinalName( context, artifact );
-
- context.getLog().debug( "Processing: " + targetFileName );
-
- if ( duplicates.contains( targetFileName ) )
- {
- context.getLog().debug( "Duplicate found: " + targetFileName );
+ public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
+ try {
+ final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+ final List<String> duplicates = findDuplicates(context, artifacts);
+
+ for (Artifact artifact : artifacts) {
+ String targetFileName = getArtifactFinalName(context, artifact);
+
+ context.getLog().debug("Processing: " + targetFileName);
+
+ if (duplicates.contains(targetFileName)) {
+ context.getLog().debug("Duplicate found: " + targetFileName);
targetFileName = artifact.getGroupId() + "-" + targetFileName;
- context.getLog().debug( "Renamed to: " + targetFileName );
+ context.getLog().debug("Renamed to: " + targetFileName);
}
- context.getWebappStructure().registerTargetFileName( artifact, targetFileName );
+ context.getWebappStructure().registerTargetFileName(artifact, targetFileName);
- if ( !artifact.isOptional() && filter.include( artifact ) )
- {
- try
- {
+ if (!artifact.isOptional() && filter.include(artifact)) {
+ try {
String type = artifact.getType();
- if ( "tld".equals( type ) )
- {
- copyFile( id, context, artifact.getFile(), TLD_PATH + targetFileName );
- }
- else if ( "aar".equals( type ) )
- {
- copyFile( id, context, artifact.getFile(), SERVICES_PATH + targetFileName );
- }
- else if ( "mar".equals( type ) )
- {
- copyFile( id, context, artifact.getFile(), MODULES_PATH + targetFileName );
- }
- else if ( "xar".equals( type ) )
- {
- copyFile( id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName );
- }
- else if ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type )
- || "test-jar".equals( type ) || "bundle".equals( type ) )
- {
- copyFile( id, context, artifact.getFile(), LIB_PATH + targetFileName );
- }
- else if ( "par".equals( type ) )
- {
- targetFileName = targetFileName.substring( 0, targetFileName.lastIndexOf( '.' ) ) + ".jar";
- copyFile( id, context, artifact.getFile(), LIB_PATH + targetFileName );
- }
- else if ( "war".equals( type ) )
- {
+ if ("tld".equals(type)) {
+ copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName);
+ } else if ("aar".equals(type)) {
+ copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName);
+ } else if ("mar".equals(type)) {
+ copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName);
+ } else if ("xar".equals(type)) {
+ copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName);
+ } else if ("jar".equals(type)
+ || "ejb".equals(type)
+ || "ejb-client".equals(type)
+ || "test-jar".equals(type)
+ || "bundle".equals(type)) {
+ copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
+ } else if ("par".equals(type)) {
+ targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";
+ copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
+ } else if ("war".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
- context.getLog().debug( "war artifacts are handled as overlays, ignoring [" + artifact
- + "]" );
- }
- else if ( "zip".equals( type ) )
- {
+ context.getLog()
+ .debug("war artifacts are handled as overlays, ignoring [" + artifact + "]");
+ } else if ("zip".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
- context.getLog().debug( "zip artifacts are handled as overlays, ignoring [" + artifact
- + "]" );
+ context.getLog()
+ .debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]");
+ } else {
+ context.getLog()
+ .debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact
+ + "]");
}
- else
- {
- context.getLog().debug( "Artifact of type [" + type + "] is not supported, ignoring ["
- + artifact + "]" );
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to copy file for artifact [" + artifact + "]", e );
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e);
}
}
}
- }
- catch ( InterpolationException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
+ } catch (InterpolationException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
}
}
@@ -165,21 +137,16 @@ public class ArtifactsPackagingTask
* @param artifacts set of artifacts
* @return List of duplicated artifacts as bundling file names
*/
- private List<String> findDuplicates( WarPackagingContext context, Set<Artifact> artifacts )
- throws InterpolationException
- {
+ private List<String> findDuplicates(WarPackagingContext context, Set<Artifact> artifacts)
+ throws InterpolationException {
List<String> duplicates = new ArrayList<>();
List<String> identifiers = new ArrayList<>();
- for ( Artifact artifact : artifacts )
- {
- String candidate = getArtifactFinalName( context, artifact );
- if ( identifiers.contains( candidate ) )
- {
- duplicates.add( candidate );
- }
- else
- {
- identifiers.add( candidate );
+ for (Artifact artifact : artifacts) {
+ String candidate = getArtifactFinalName(context, artifact);
+ if (identifiers.contains(candidate)) {
+ duplicates.add(candidate);
+ } else {
+ identifiers.add(candidate);
}
}
return duplicates;
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java
index 654469e..6f71048 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,10 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -28,58 +30,50 @@ import org.apache.maven.plugins.war.util.PathSet;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.interpolation.InterpolationException;
-import java.io.File;
-import java.io.IOException;
-
/**
* Handles the classes directory that needs to be packaged in the web application.
- *
+ *
* Based on the {@link WarPackagingContext#archiveClasses()} flag, the resources are either copied into to
* {@code WEB-INF/classes} directory or archived in a jar within the {@code WEB-INF/lib} directory.
*
* @author Stephane Nicoll
*/
-public class ClassesPackagingTask
- extends AbstractWarPackagingTask
-{
+public class ClassesPackagingTask extends AbstractWarPackagingTask {
private final Overlay currentProjectOverlay;
/**
* @param currentProjectOverlay {@link #currentProjectOverlay}
*/
- public ClassesPackagingTask( Overlay currentProjectOverlay )
- {
+ public ClassesPackagingTask(Overlay currentProjectOverlay) {
this.currentProjectOverlay = currentProjectOverlay;
}
@Override
- public void performPackaging( WarPackagingContext context )
- throws MojoExecutionException
- {
- final File webappClassesDirectory = new File( context.getWebappDirectory(), CLASSES_PATH );
- if ( !webappClassesDirectory.exists() )
- {
+ public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
+ final File webappClassesDirectory = new File(context.getWebappDirectory(), CLASSES_PATH);
+ if (!webappClassesDirectory.exists()) {
webappClassesDirectory.mkdirs();
}
- if ( context.getClassesDirectory().exists() && !context.getClassesDirectory().equals( webappClassesDirectory ) )
- {
- if ( context.archiveClasses() )
- {
- generateJarArchive( context );
- }
- else
- {
- final PathSet sources = getFilesToIncludes( context.getClassesDirectory(), null, null );
- try
- {
- copyFiles( currentProjectOverlay.getId(), context, context.getClassesDirectory(), sources,
- CLASSES_PATH, false );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Could not copy webapp classes ["
- + context.getClassesDirectory().getAbsolutePath() + "]", e );
+ if (context.getClassesDirectory().exists()
+ && !context.getClassesDirectory().equals(webappClassesDirectory)) {
+ if (context.archiveClasses()) {
+ generateJarArchive(context);
+ } else {
+ final PathSet sources = getFilesToIncludes(context.getClassesDirectory(), null, null);
+ try {
+ copyFiles(
+ currentProjectOverlay.getId(),
+ context,
+ context.getClassesDirectory(),
+ sources,
+ CLASSES_PATH,
+ false);
+ } catch (IOException e) {
+ throw new MojoExecutionException(
+ "Could not copy webapp classes ["
+ + context.getClassesDirectory().getAbsolutePath() + "]",
+ e);
}
}
}
@@ -89,40 +83,39 @@ public class ClassesPackagingTask
* @param context The warPackingContext.
* @throws MojoExecutionException In case of an error.
*/
- protected void generateJarArchive( WarPackagingContext context )
- throws MojoExecutionException
- {
+ protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException {
MavenProject project = context.getProject();
ArtifactFactory factory = context.getArtifactFactory();
Artifact artifact =
- factory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar" );
+ factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar");
String archiveName;
- try
- {
- archiveName = getArtifactFinalName( context, artifact );
- }
- catch ( InterpolationException e )
- {
- throw new MojoExecutionException( "Could not get the final name of the artifact [" + artifact.getGroupId()
- + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e );
+ try {
+ archiveName = getArtifactFinalName(context, artifact);
+ } catch (InterpolationException e) {
+ throw new MojoExecutionException(
+ "Could not get the final name of the artifact [" + artifact.getGroupId() + ":"
+ + artifact.getArtifactId() + ":" + artifact.getVersion() + "]",
+ e);
}
final String targetFilename = LIB_PATH + archiveName;
- if ( context.getWebappStructure().registerFile( currentProjectOverlay.getId(), targetFilename ) )
- {
- context.addResource( targetFilename );
+ if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) {
+ context.addResource(targetFilename);
- final File libDirectory = new File( context.getWebappDirectory(), LIB_PATH );
- final File jarFile = new File( libDirectory, archiveName );
+ final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH);
+ final File jarFile = new File(libDirectory, archiveName);
final ClassesPackager packager = new ClassesPackager();
- packager.packageClasses( context.getClassesDirectory(), jarFile, context.getJarArchiver(),
- context.getSession(), project, context.getArchive(),
- context.getOutputTimestamp() );
- }
- else
- {
- context.getLog().warn( "Could not generate archive classes file [" + targetFilename
- + "] has already been copied." );
+ packager.packageClasses(
+ context.getClassesDirectory(),
+ jarFile,
+ context.getJarArchiver(),
+ context.getSession(),
+ project,
+ context.getArchive(),
+ context.getOutputTimestamp());
+ } else {
+ context.getLog()
+ .warn("Could not generate archive classes file [" + targetFilename + "] has already been copied.");
}
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java
index f98a7c5..9b1be7a 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/CopyUserManifestTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import java.io.File;
import java.io.IOException;
@@ -31,9 +30,7 @@ import org.apache.maven.plugin.logging.SystemStreamLog;
* @author Haikal Saadh
*
*/
-public class CopyUserManifestTask
- extends AbstractWarPackagingTask
-{
+public class CopyUserManifestTask extends AbstractWarPackagingTask {
/** Instance logger */
private Log log;
@@ -43,10 +40,8 @@ public class CopyUserManifestTask
*
* @return logger
*/
- public Log getLog()
- {
- if ( log == null )
- {
+ public Log getLog() {
+ if (log == null) {
log = new SystemStreamLog();
}
return log;
@@ -57,31 +52,22 @@ public class CopyUserManifestTask
*
* @param log the logger to set
*/
- public void setLog( Log log )
- {
+ public void setLog(Log log) {
this.log = log;
}
- public void performPackaging( WarPackagingContext context )
- throws MojoExecutionException, MojoFailureException
- {
+ public void performPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException {
File userManifest = context.getArchive().getManifestFile();
- if ( userManifest != null )
- {
+ if (userManifest != null) {
- try
- {
- getLog().info( "Copying manifest..." );
- File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH );
- copyFile( context, userManifest, new File( metainfDir, "MANIFEST.MF" ), "META-INF/MANIFEST.MF", true );
+ try {
+ getLog().info("Copying manifest...");
+ File metainfDir = new File(context.getWebappDirectory(), META_INF_PATH);
+ copyFile(context, userManifest, new File(metainfDir, "MANIFEST.MF"), "META-INF/MANIFEST.MF", true);
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error copying user manifest", e );
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error copying user manifest", e);
}
}
-
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java
index df7f2b4..c46d9bb 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/OverlayPackagingTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,91 +16,75 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.war.Overlay;
import org.apache.maven.plugins.war.util.PathSet;
import org.codehaus.plexus.util.FileUtils;
-import java.io.File;
-import java.io.IOException;
-
/**
* Handles an overlay.
*
* @author Stephane Nicoll
*/
-public class OverlayPackagingTask
- extends AbstractWarPackagingTask
-{
+public class OverlayPackagingTask extends AbstractWarPackagingTask {
private final Overlay overlay;
/**
* @param overlay {@link #overlay}
* @param currentProjectOverlay current overlay.
*/
- public OverlayPackagingTask( Overlay overlay, Overlay currentProjectOverlay )
- {
- if ( overlay == null )
- {
- throw new NullPointerException( "overlay could not be null." );
+ public OverlayPackagingTask(Overlay overlay, Overlay currentProjectOverlay) {
+ if (overlay == null) {
+ throw new NullPointerException("overlay could not be null.");
}
- if ( overlay.equals( currentProjectOverlay ) )
- {
- throw new IllegalStateException( "Could not handle the current project with this task." );
+ if (overlay.equals(currentProjectOverlay)) {
+ throw new IllegalStateException("Could not handle the current project with this task.");
}
this.overlay = overlay;
}
@Override
- public void performPackaging( WarPackagingContext context )
- throws MojoExecutionException
- {
- context.getLog().debug( "OverlayPackagingTask performPackaging overlay.getTargetPath() "
- + overlay.getTargetPath() );
- if ( overlay.shouldSkip() )
- {
- context.getLog().info( "Skipping overlay [" + overlay + "]" );
- }
- else
- {
- try
- {
- context.getLog().info( "Processing overlay [" + overlay + "]" );
+ public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
+ context.getLog()
+ .debug("OverlayPackagingTask performPackaging overlay.getTargetPath() " + overlay.getTargetPath());
+ if (overlay.shouldSkip()) {
+ context.getLog().info("Skipping overlay [" + overlay + "]");
+ } else {
+ try {
+ context.getLog().info("Processing overlay [" + overlay + "]");
// Step1: Extract if necessary
- final File tmpDir = unpackOverlay( context, overlay );
+ final File tmpDir = unpackOverlay(context, overlay);
// Step2: setup
- final PathSet includes = getFilesToIncludes( tmpDir, overlay.getIncludes(), overlay.getExcludes() );
+ final PathSet includes = getFilesToIncludes(tmpDir, overlay.getIncludes(), overlay.getExcludes());
// Copy
- if ( null == overlay.getTargetPath() )
- {
- copyFiles( overlay.getId(), context, tmpDir, includes, overlay.isFiltered() );
- }
- else
- {
+ if (null == overlay.getTargetPath()) {
+ copyFiles(overlay.getId(), context, tmpDir, includes, overlay.isFiltered());
+ } else {
// overlay.getTargetPath() must ended with /
// if not we add it
String targetPath = overlay.getTargetPath();
- if ( !targetPath.endsWith( "/" ) )
- {
+ if (!targetPath.endsWith("/")) {
targetPath = targetPath + "/";
}
- copyFiles( overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered() );
+ copyFiles(overlay.getId(), context, tmpDir, includes, targetPath, overlay.isFiltered());
}
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to copy file for overlay [" + overlay + "]", e );
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to copy file for overlay [" + overlay + "]", e);
}
}
}
/**
* Unpacks the specified overlay.
- *
+ *
* Makes sure to skip the unpack process if the overlay has already been unpacked.
*
* @param context the packaging context
@@ -110,20 +92,15 @@ public class OverlayPackagingTask
* @return the directory containing the unpacked overlay
* @throws MojoExecutionException if an error occurred while unpacking the overlay
*/
- protected File unpackOverlay( WarPackagingContext context, Overlay overlay )
- throws MojoExecutionException
- {
- final File tmpDir = getOverlayTempDirectory( context, overlay );
+ protected File unpackOverlay(WarPackagingContext context, Overlay overlay) throws MojoExecutionException {
+ final File tmpDir = getOverlayTempDirectory(context, overlay);
// TODO: not sure it's good, we should reuse the markers of the dependency plugin
- if ( FileUtils.sizeOfDirectory( tmpDir ) == 0
- || overlay.getArtifact().getFile().lastModified() > tmpDir.lastModified() )
- {
- doUnpack( context, overlay.getArtifact().getFile(), tmpDir );
- }
- else
- {
- context.getLog().debug( "Overlay [" + overlay + "] was already unpacked" );
+ if (FileUtils.sizeOfDirectory(tmpDir) == 0
+ || overlay.getArtifact().getFile().lastModified() > tmpDir.lastModified()) {
+ doUnpack(context, overlay.getArtifact().getFile(), tmpDir);
+ } else {
+ context.getLog().debug("Overlay [" + overlay + "] was already unpacked");
}
return tmpDir;
}
@@ -135,21 +112,17 @@ public class OverlayPackagingTask
* @param overlay the overlay
* @return the temp directory for the overlay
*/
- protected File getOverlayTempDirectory( WarPackagingContext context, Overlay overlay )
- {
- final File groupIdDir = new File( context.getOverlaysWorkDirectory(), overlay.getGroupId() );
- if ( !groupIdDir.exists() )
- {
+ protected File getOverlayTempDirectory(WarPackagingContext context, Overlay overlay) {
+ final File groupIdDir = new File(context.getOverlaysWorkDirectory(), overlay.getGroupId());
+ if (!groupIdDir.exists()) {
groupIdDir.mkdir();
}
String directoryName = overlay.getArtifactId();
- if ( overlay.getClassifier() != null )
- {
+ if (overlay.getClassifier() != null) {
directoryName = directoryName + "-" + overlay.getClassifier();
}
- final File result = new File( groupIdDir, directoryName );
- if ( !result.exists() )
- {
+ final File result = new File(groupIdDir, directoryName);
+ if (!result.exists()) {
result.mkdirs();
}
return result;
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 6480114..873409b 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
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import java.io.File;
import java.util.List;
@@ -38,8 +37,7 @@ import org.codehaus.plexus.archiver.manager.ArchiverManager;
*
* @author Stephane Nicoll
*/
-public interface WarPackagingContext
-{
+public interface WarPackagingContext {
/**
* Returns the maven project.
*
@@ -180,7 +178,7 @@ public interface WarPackagingContext
* @return {@code true} if it should not be filtered, {@code false} otherwise
* @since 2.1-alpha-2
*/
- boolean isNonFilteredExtension( String fileName );
+ boolean isNonFilteredExtension(String fileName);
/**
* @return filtering deployment descriptor.
@@ -233,19 +231,19 @@ public interface WarPackagingContext
* Add a live resource to the war.
* Used to keep track of existing resources and all copied files.
* All others are outdated and will be removed.
- * This prevent calling <code>mvn clean</code> when resources are removed.
- *
+ * This prevent calling <code>mvn clean</code> when resources are removed.
+ *
* @param resource the resource that is to me marked as not outdated
* @since 3.3.0
* @see #deleteOutdatedResources()
*/
- void addResource( String resource );
+ void addResource(String resource);
/**
* Delete outdated resources, ie resources that are found in the war but that were not added by the current
* packaging process, then are supposed to be content from a previous run.
* This prevent calling <code>mvn clean</code> when resources are removed.
- *
+ *
* @since 3.3.0
* @see #addResource
*/
@@ -253,7 +251,7 @@ public interface WarPackagingContext
/**
* Output timestamp for reproducible archive creation.
- *
+ *
* @return the output timestamp (may be null)
* @since 3.3.0
*/
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java
index 4260e1d..2539b86 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -27,19 +26,16 @@ import org.apache.maven.plugin.MojoFailureException;
*
* @author Stephane Nicoll
*/
-public interface WarPackagingTask
-{
+public interface WarPackagingTask {
/**
* Performs the packaging for the specified task.
- *
+ *
* The task is responsible to update the packaging context, namely with the files that have been copied.
*
* @param context the packaging context
* @throws MojoExecutionException if an error occurred
* @throws MojoFailureException if the project configuration is invalid
*/
- void performPackaging( WarPackagingContext context )
- throws MojoExecutionException, MojoFailureException;
-
+ void performPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException;
}
diff --git a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
index 5993706..f6a960d 100644
--- a/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
+++ b/src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.packaging;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.packaging;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.packaging;
import java.io.File;
import java.io.IOException;
@@ -33,7 +32,7 @@ import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.StringUtils;
/**
- * Handles the project own resources, that is:
+ * Handles the project own resources, that is:
* <ul>
* <li>The list of web resources, if any</li>
* <li>The content of the webapp directory if it exists</li>
@@ -44,9 +43,7 @@ import org.codehaus.plexus.util.StringUtils;
*
* @author Stephane Nicoll
*/
-public class WarProjectPackagingTask
- extends AbstractWarPackagingTask
-{
+public class WarProjectPackagingTask extends AbstractWarPackagingTask {
private final Resource[] webResources;
private final File webXml;
@@ -63,15 +60,11 @@ public class WarProjectPackagingTask
* @param containerConfigXml {@link #containerConfigXML}
* @param currentProjectOverlay {@link #currentProjectOverlay}
*/
- public WarProjectPackagingTask( Resource[] webResources, File webXml, File containerConfigXml,
- Overlay currentProjectOverlay )
- {
- if ( webResources != null )
- {
+ public WarProjectPackagingTask(
+ Resource[] webResources, File webXml, File containerConfigXml, Overlay currentProjectOverlay) {
+ if (webResources != null) {
this.webResources = webResources;
- }
- else
- {
+ } else {
this.webResources = new Resource[0];
}
this.webXml = webXml;
@@ -81,38 +74,34 @@ public class WarProjectPackagingTask
}
@Override
- public void performPackaging( WarPackagingContext context )
- throws MojoExecutionException, MojoFailureException
- {
- context.getLog().info( "Processing war project" );
+ public void performPackaging(WarPackagingContext context) throws MojoExecutionException, MojoFailureException {
+ context.getLog().info("Processing war project");
// Prepare the INF directories
- File webinfDir = new File( context.getWebappDirectory(), WEB_INF_PATH );
+ File webinfDir = new File(context.getWebappDirectory(), WEB_INF_PATH);
webinfDir.mkdirs();
- File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH );
+ File metainfDir = new File(context.getWebappDirectory(), META_INF_PATH);
metainfDir.mkdirs();
- handleWebResources( context );
+ handleWebResources(context);
- handleWebAppSourceDirectory( context );
+ handleWebAppSourceDirectory(context);
// Debug mode: dump the path set for the current build
- PathSet pathSet = context.getWebappStructure().getStructure( "currentBuild" );
- context.getLog().debug( "Dump of the current build pathSet content -->" );
- for ( String path : pathSet )
- {
- context.getLog().debug( path );
+ PathSet pathSet = context.getWebappStructure().getStructure("currentBuild");
+ context.getLog().debug("Dump of the current build pathSet content -->");
+ for (String path : pathSet) {
+ context.getLog().debug(path);
}
- context.getLog().debug( "-- end of dump --" );
+ context.getLog().debug("-- end of dump --");
- handleDeploymentDescriptors( context, webinfDir, metainfDir, context.isFailOnMissingWebXml() );
+ handleDeploymentDescriptors(context, webinfDir, metainfDir, context.isFailOnMissingWebXml());
- handleClassesDirectory( context );
+ handleClassesDirectory(context);
- handleArtifacts( context );
+ handleArtifacts(context);
- if ( !context.getWebappDirectory().mkdirs() )
- {
+ if (!context.getWebappDirectory().mkdirs()) {
context.deleteOutdatedResources();
}
}
@@ -123,34 +112,25 @@ public class WarProjectPackagingTask
* @param context the packaging context
* @throws MojoExecutionException if a resource could not be copied
*/
- protected void handleWebResources( WarPackagingContext context )
- throws MojoExecutionException
- {
- for ( Resource resource : webResources )
- {
+ protected void handleWebResources(WarPackagingContext context) throws MojoExecutionException {
+ for (Resource resource : webResources) {
// MWAR-246
- if ( resource.getDirectory() == null )
- {
- throw new MojoExecutionException( "The <directory> tag is missing from the <resource> tag." );
+ if (resource.getDirectory() == null) {
+ throw new MojoExecutionException("The <directory> tag is missing from the <resource> tag.");
}
- if ( !( new File( resource.getDirectory() ) ).isAbsolute() )
- {
- resource.setDirectory( context.getProject().getBasedir() + File.separator + resource.getDirectory() );
+ if (!(new File(resource.getDirectory())).isAbsolute()) {
+ resource.setDirectory(context.getProject().getBasedir() + File.separator + resource.getDirectory());
}
// Make sure that the resource directory is not the same as the webappDirectory
- if ( !resource.getDirectory().equals( context.getWebappDirectory().getPath() ) )
- {
+ if (!resource.getDirectory().equals(context.getWebappDirectory().getPath())) {
- try
- {
- copyResources( context, resource );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Could not copy resource [" + resource.getDirectory() + "]", e );
+ try {
+ copyResources(context, resource);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not copy resource [" + resource.getDirectory() + "]", e);
}
}
}
@@ -162,29 +142,25 @@ public class WarProjectPackagingTask
* @param context the packaging context
* @throws MojoExecutionException if the sources could not be copied
*/
- protected void handleWebAppSourceDirectory( WarPackagingContext context )
- throws MojoExecutionException
- {
+ protected void handleWebAppSourceDirectory(WarPackagingContext context) throws MojoExecutionException {
// CHECKSTYLE_OFF: LineLength
- if ( !context.getWebappSourceDirectory().exists() )
- {
- context.getLog().debug( "webapp sources directory does not exist - skipping." );
- }
- else if ( !context.getWebappSourceDirectory().getAbsolutePath().equals( context.getWebappDirectory().getPath() ) )
- {
- context.getLog().info( "Copying webapp resources [" + context.getWebappSourceDirectory() + "]" );
- final PathSet sources =
- getFilesToIncludes( context.getWebappSourceDirectory(), context.getWebappSourceIncludes(),
- context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories() );
-
- try
- {
- copyFiles( id, context, context.getWebappSourceDirectory(), sources, false );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Could not copy webapp sources ["
- + context.getWebappDirectory().getAbsolutePath() + "]", e );
+ if (!context.getWebappSourceDirectory().exists()) {
+ context.getLog().debug("webapp sources directory does not exist - skipping.");
+ } else if (!context.getWebappSourceDirectory()
+ .getAbsolutePath()
+ .equals(context.getWebappDirectory().getPath())) {
+ context.getLog().info("Copying webapp resources [" + context.getWebappSourceDirectory() + "]");
+ final PathSet sources = getFilesToIncludes(
+ context.getWebappSourceDirectory(), context.getWebappSourceIncludes(),
+ context.getWebappSourceExcludes(), context.isWebappSourceIncludeEmptyDirectories());
+
+ try {
+ copyFiles(id, context, context.getWebappSourceDirectory(), sources, false);
+ } catch (IOException e) {
+ throw new MojoExecutionException(
+ "Could not copy webapp sources ["
+ + context.getWebappDirectory().getAbsolutePath() + "]",
+ e);
}
}
// CHECKSTYLE_ON: LineLength
@@ -196,12 +172,10 @@ public class WarProjectPackagingTask
* @param context the packaging context
* @throws MojoExecutionException if the artifacts could not be packaged
*/
- protected void handleArtifacts( WarPackagingContext context )
- throws MojoExecutionException
- {
+ protected void handleArtifacts(WarPackagingContext context) throws MojoExecutionException {
ArtifactsPackagingTask task =
- new ArtifactsPackagingTask( context.getProject().getArtifacts(), currentProjectOverlay );
- task.performPackaging( context );
+ new ArtifactsPackagingTask(context.getProject().getArtifacts(), currentProjectOverlay);
+ task.performPackaging(context);
}
/**
@@ -210,11 +184,9 @@ public class WarProjectPackagingTask
* @param context the packaging context
* @throws MojoExecutionException if the classes could not be packaged
*/
- protected void handleClassesDirectory( WarPackagingContext context )
- throws MojoExecutionException
- {
- ClassesPackagingTask task = new ClassesPackagingTask( currentProjectOverlay );
- task.performPackaging( context );
+ protected void handleClassesDirectory(WarPackagingContext context) throws MojoExecutionException {
+ ClassesPackagingTask task = new ClassesPackagingTask(currentProjectOverlay);
+ task.performPackaging(context);
}
/**
@@ -228,75 +200,73 @@ public class WarProjectPackagingTask
* @throws MojoFailureException if the web.xml is specified but does not exist and failOnMissingWebXml is true
* @throws MojoExecutionException if an error occurred while copying the descriptors
*/
- protected void handleDeploymentDescriptors( WarPackagingContext context, File webinfDir, File metainfDir,
- Boolean failOnMissingWebXml )
- throws MojoFailureException, MojoExecutionException
- {
- try
- {
- if ( webXml != null && StringUtils.isNotEmpty( webXml.getName() ) )
- {
- if ( !webXml.exists()
- && ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) ) )
- {
- throw new MojoFailureException( "The specified web.xml file '" + webXml + "' does not exist" );
+ protected void handleDeploymentDescriptors(
+ WarPackagingContext context, File webinfDir, File metainfDir, Boolean failOnMissingWebXml)
+ throws MojoFailureException, MojoExecutionException {
+ try {
+ if (webXml != null && StringUtils.isNotEmpty(webXml.getName())) {
+ if (!webXml.exists() && (failOnMissingWebXml == null || Boolean.TRUE.equals(failOnMissingWebXml))) {
+ throw new MojoFailureException("The specified web.xml file '" + webXml + "' does not exist");
}
// Making sure that it won't get overlayed
- context.getWebappStructure().registerFileForced( id, WEB_INF_PATH + "/web.xml" );
-
- if ( context.isFilteringDeploymentDescriptors() )
- {
- context.getMavenFileFilter().copyFile( webXml, new File( webinfDir, "web.xml" ), true,
- context.getFilterWrappers(), getEncoding( webXml ) );
+ context.getWebappStructure().registerFileForced(id, WEB_INF_PATH + "/web.xml");
+
+ if (context.isFilteringDeploymentDescriptors()) {
+ context.getMavenFileFilter()
+ .copyFile(
+ webXml,
+ new File(webinfDir, "web.xml"),
+ true,
+ context.getFilterWrappers(),
+ getEncoding(webXml));
+ } else {
+ copyFile(context, webXml, new File(webinfDir, "web.xml"), "WEB-INF/web.xml", true);
}
- else
- {
- copyFile( context, webXml, new File( webinfDir, "web.xml" ), "WEB-INF/web.xml", true );
- }
- }
- else
- {
+ } else {
// the webXml can be the default one
- File defaultWebXml = new File( context.getWebappSourceDirectory(), WEB_INF_PATH + "/web.xml" );
+ File defaultWebXml = new File(context.getWebappSourceDirectory(), WEB_INF_PATH + "/web.xml");
// if exists we can filter it
- if ( defaultWebXml.exists() && context.isFilteringDeploymentDescriptors() )
- {
- context.getWebappStructure().registerFile( id, WEB_INF_PATH + "/web.xml" );
- context.getMavenFileFilter().copyFile( defaultWebXml, new File( webinfDir, "web.xml" ), true,
- context.getFilterWrappers(), getEncoding( defaultWebXml ) );
+ if (defaultWebXml.exists() && context.isFilteringDeploymentDescriptors()) {
+ context.getWebappStructure().registerFile(id, WEB_INF_PATH + "/web.xml");
+ context.getMavenFileFilter()
+ .copyFile(
+ defaultWebXml,
+ new File(webinfDir, "web.xml"),
+ true,
+ context.getFilterWrappers(),
+ getEncoding(defaultWebXml));
}
}
- if ( containerConfigXML != null && StringUtils.isNotEmpty( containerConfigXML.getName() ) )
- {
+ if (containerConfigXML != null && StringUtils.isNotEmpty(containerConfigXML.getName())) {
String xmlFileName = containerConfigXML.getName();
- context.getWebappStructure().registerFileForced( id, META_INF_PATH + "/" + xmlFileName );
-
- if ( context.isFilteringDeploymentDescriptors() )
- {
- context.getMavenFileFilter().copyFile( containerConfigXML, new File( metainfDir, xmlFileName ),
- true, context.getFilterWrappers(),
- getEncoding( containerConfigXML ) );
- }
- else
- {
- copyFile( context, containerConfigXML, new File( metainfDir, xmlFileName ), "META-INF/"
- + xmlFileName, true );
+ context.getWebappStructure().registerFileForced(id, META_INF_PATH + "/" + xmlFileName);
+
+ if (context.isFilteringDeploymentDescriptors()) {
+ context.getMavenFileFilter()
+ .copyFile(
+ containerConfigXML,
+ new File(metainfDir, xmlFileName),
+ true,
+ context.getFilterWrappers(),
+ getEncoding(containerConfigXML));
+ } else {
+ copyFile(
+ context,
+ containerConfigXML,
+ new File(metainfDir, xmlFileName),
+ "META-INF/" + xmlFileName,
+ true);
}
}
- }
- catch ( IOException e )
- {
- if ( failOnMissingWebXml == null || Boolean.TRUE.equals( failOnMissingWebXml ) )
- {
- throw new MojoExecutionException( "Failed to copy deployment descriptor", e );
+ } catch (IOException e) {
+ if (failOnMissingWebXml == null || Boolean.TRUE.equals(failOnMissingWebXml)) {
+ throw new MojoExecutionException("Failed to copy deployment descriptor", e);
}
- }
- catch ( MavenFilteringException e )
- {
- throw new MojoExecutionException( "Failed to copy deployment descriptor", e );
+ } catch (MavenFilteringException e) {
+ throw new MojoExecutionException("Failed to copy deployment descriptor", e);
}
}
@@ -308,41 +278,35 @@ public class WarProjectPackagingTask
* @throws IOException if an error occurred while copying the resources
* @throws MojoExecutionException if an error occurred while retrieving the filter properties
*/
- public void copyResources( WarPackagingContext context, Resource resource )
- throws IOException, MojoExecutionException
- {
- if ( !context.getWebappDirectory().exists() )
- {
- context.getLog().warn( "Not copying webapp webResources [" + resource.getDirectory()
- + "]: webapp directory [" + context.getWebappDirectory().getAbsolutePath()
- + "] does not exist!" );
+ public void copyResources(WarPackagingContext context, Resource resource)
+ throws IOException, MojoExecutionException {
+ if (!context.getWebappDirectory().exists()) {
+ context.getLog()
+ .warn("Not copying webapp webResources [" + resource.getDirectory()
+ + "]: webapp directory ["
+ + context.getWebappDirectory().getAbsolutePath()
+ + "] does not exist!");
}
- context.getLog().info( "Copying webapp webResources [" + resource.getDirectory() + "] to ["
- + context.getWebappDirectory().getAbsolutePath() + "]" );
- String[] fileNames = getFilesToCopy( resource );
- for ( String fileName : fileNames )
- {
+ context.getLog()
+ .info("Copying webapp webResources [" + resource.getDirectory() + "] to ["
+ + context.getWebappDirectory().getAbsolutePath() + "]");
+ String[] fileNames = getFilesToCopy(resource);
+ for (String fileName : fileNames) {
String targetFileName = fileName;
- if ( resource.getTargetPath() != null )
- {
+ if (resource.getTargetPath() != null) {
// TODO make sure this thing is 100% safe
// MWAR-129 if targetPath is only a dot <targetPath>.</targetPath> or ./
// and the Resource is in a part of the warSourceDirectory the file from sources will override this
// that's we don't have to add the targetPath yep not nice but works
- if ( !Objects.equals( ".", resource.getTargetPath() )
- && !Objects.equals( "./", resource.getTargetPath() ) )
- {
+ if (!Objects.equals(".", resource.getTargetPath()) && !Objects.equals("./", resource.getTargetPath())) {
targetFileName = resource.getTargetPath() + File.separator + targetFileName;
}
}
- if ( resource.isFiltering() && !context.isNonFilteredExtension( fileName ) )
- {
- copyFilteredFile( id, context, new File( resource.getDirectory(), fileName ), targetFileName );
- }
- else
- {
- copyFile( id, context, new File( resource.getDirectory(), fileName ), targetFileName );
+ if (resource.isFiltering() && !context.isNonFilteredExtension(fileName)) {
+ copyFilteredFile(id, context, new File(resource.getDirectory(), fileName), targetFileName);
+ } else {
+ copyFile(id, context, new File(resource.getDirectory(), fileName), targetFileName);
}
}
}
@@ -353,22 +317,19 @@ public class WarProjectPackagingTask
* @param resource the resource to be scanned
* @return the array of filenames, relative to the sourceDir
*/
- private String[] getFilesToCopy( Resource resource )
- {
+ private String[] getFilesToCopy(Resource resource) {
// CHECKSTYLE_OFF: LineLength
DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( resource.getDirectory() );
- if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() )
- {
- scanner.setIncludes( resource.getIncludes().toArray( new String[resource.getIncludes().size()] ) );
- }
- else
- {
- scanner.setIncludes( DEFAULT_INCLUDES );
+ scanner.setBasedir(resource.getDirectory());
+ if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
+ scanner.setIncludes(resource.getIncludes()
+ .toArray(new String[resource.getIncludes().size()]));
+ } else {
+ scanner.setIncludes(DEFAULT_INCLUDES);
}
- if ( resource.getExcludes() != null && !resource.getExcludes().isEmpty() )
- {
- scanner.setExcludes( resource.getExcludes().toArray( new String[resource.getExcludes().size()] ) );
+ if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
+ scanner.setExcludes(resource.getExcludes()
+ .toArray(new String[resource.getExcludes().size()]));
}
scanner.addDefaultExcludes();
diff --git a/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java b/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java
index cdcdd96..19c2c9b 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,10 @@ package org.apache.maven.plugins.war.util;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.util;
+
+import java.io.File;
+import java.io.IOException;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
@@ -30,16 +32,12 @@ import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.ManifestException;
-import java.io.File;
-import java.io.IOException;
-
/**
* Packages the content of the classes directory.
*
* @author Stephane Nicoll
*/
-public class ClassesPackager
-{
+public class ClassesPackager {
/**
* Package the classes
@@ -53,25 +51,26 @@ public class ClassesPackager
* @param outputTimestamp the output timestamp for reproducibility
* @throws MojoExecutionException if an error occurred while creating the archive
*/
- public void packageClasses( File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session,
- MavenProject project, MavenArchiveConfiguration archiveConfiguration,
- String outputTimestamp )
- throws MojoExecutionException
- {
+ public void packageClasses(
+ File classesDirectory,
+ File targetFile,
+ JarArchiver jarArchiver,
+ MavenSession session,
+ MavenProject project,
+ MavenArchiveConfiguration archiveConfiguration,
+ String outputTimestamp)
+ throws MojoExecutionException {
- try
- {
+ try {
final MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver( jarArchiver );
- archiver.setOutputFile( targetFile );
- archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" );
- archiver.configureReproducibleBuild( outputTimestamp );
- archiver.getArchiver().addDirectory( classesDirectory );
- archiver.createArchive( session, project, archiveConfiguration );
- }
- catch ( ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( "Could not create classes archive", e );
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(targetFile);
+ archiver.setCreatedBy("Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin");
+ archiver.configureReproducibleBuild(outputTimestamp);
+ archiver.getArchiver().addDirectory(classesDirectory);
+ archiver.createArchive(session, project, archiveConfiguration);
+ } catch (ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e) {
+ throw new MojoExecutionException("Could not create classes archive", e);
}
}
@@ -81,8 +80,7 @@ public class ClassesPackager
* @param webappDirectory the webapp directory
* @return the classes directory of the specified webapp directory
*/
- public File getClassesDirectory( File webappDirectory )
- {
- return new File( webappDirectory, AbstractWarPackagingTask.CLASSES_PATH );
+ public File getClassesDirectory(File webappDirectory) {
+ return new File(webappDirectory, AbstractWarPackagingTask.CLASSES_PATH);
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java b/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java
index ece99dd..78906eb 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.util;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.util;
import java.util.Objects;
@@ -28,8 +27,7 @@ import org.apache.maven.model.Dependency;
*
* @author Stephane Nicoll
*/
-public class DependencyInfo
-{
+public class DependencyInfo {
private final Dependency dependency;
@@ -40,8 +38,7 @@ public class DependencyInfo
*
* @param dependency the dependency
*/
- public DependencyInfo( Dependency dependency )
- {
+ public DependencyInfo(Dependency dependency) {
this.dependency = dependency;
}
@@ -50,8 +47,7 @@ public class DependencyInfo
*
* @return the dependency
*/
- public Dependency getDependency()
- {
+ public Dependency getDependency() {
return dependency;
}
@@ -60,8 +56,7 @@ public class DependencyInfo
*
* @return the target file name or {@code null}
*/
- public String getTargetFileName()
- {
+ public String getTargetFileName() {
return targetFileName;
}
@@ -70,34 +65,29 @@ public class DependencyInfo
*
* @param targetFileName the target file name
*/
- public void setTargetFileName( String targetFileName )
- {
+ public void setTargetFileName(String targetFileName) {
this.targetFileName = targetFileName;
}
@Override
- public boolean equals( Object o )
- {
- if ( this == o )
- {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if ( o == null || getClass() != o.getClass() )
- {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
DependencyInfo that = (DependencyInfo) o;
- return Objects.equals( dependency, that.dependency );
+ return Objects.equals(dependency, that.dependency);
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
int result;
- result = ( dependency != null ? dependency.hashCode() : 0 );
- result = 31 * result + ( targetFileName != null ? targetFileName.hashCode() : 0 );
+ result = (dependency != null ? dependency.hashCode() : 0);
+ result = 31 * result + (targetFileName != null ? targetFileName.hashCode() : 0);
return result;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/war/util/PathSet.java b/src/main/java/org/apache/maven/plugins/war/util/PathSet.java
index 23da7b3..4d41418 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/PathSet.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/PathSet.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,8 +16,7 @@ package org.apache.maven.plugins.war.util;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.codehaus.plexus.util.DirectoryScanner;
+package org.apache.maven.plugins.war.util;
import java.io.File;
import java.util.Collection;
@@ -28,41 +25,35 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
+import org.codehaus.plexus.util.DirectoryScanner;
+
/**
* Set of file's paths.
- *
+ *
* The class extends functionality of a "normal" set of strings by a process of the paths normalization. All paths are
* converted to unix form (slashes) and they don't start with starting /.
*
* @author Piotr Tabor
*/
-
-public class PathSet
- implements Iterable<String>
-{
+public class PathSet implements Iterable<String> {
private static final String SEPARATOR = "/";
- private static final char SEPARATOR_CHAR = SEPARATOR.charAt( 0 );
+ private static final char SEPARATOR_CHAR = SEPARATOR.charAt(0);
/**
* Set of normalized paths
*/
private Set<String> pathsSet = new LinkedHashSet<>();
- static String normalizeSubPath( String path )
- {
- if ( path.isEmpty() )
- {
+ static String normalizeSubPath(String path) {
+ if (path.isEmpty()) {
return path;
}
- String cleanPath = path.replaceAll( "[\\\\]+", SEPARATOR )
- .replaceAll( "[/]+" , SEPARATOR );
- cleanPath = cleanPath.charAt( 0 ) == SEPARATOR_CHAR ? cleanPath.substring( 1 ) : cleanPath;
- if ( cleanPath.isEmpty() )
- {
+ String cleanPath = path.replaceAll("[\\\\]+", SEPARATOR).replaceAll("[/]+", SEPARATOR);
+ cleanPath = cleanPath.charAt(0) == SEPARATOR_CHAR ? cleanPath.substring(1) : cleanPath;
+ if (cleanPath.isEmpty()) {
return cleanPath;
}
- if ( cleanPath.charAt( cleanPath.length() - 1 ) == SEPARATOR_CHAR )
- {
- return cleanPath.substring( 0, cleanPath.length() - 1 );
+ if (cleanPath.charAt(cleanPath.length() - 1) == SEPARATOR_CHAR) {
+ return cleanPath.substring(0, cleanPath.length() - 1);
}
return cleanPath;
}
@@ -72,8 +63,7 @@ public class PathSet
/**
* Creates an empty paths set
*/
- public PathSet()
- {
+ public PathSet() {
/* Empty default constructor */
}
@@ -82,9 +72,8 @@ public class PathSet
*
* @param paths to be added
*/
- public PathSet( Collection<String> paths )
- {
- addAll( paths );
+ public PathSet(Collection<String> paths) {
+ addAll(paths);
}
/**
@@ -92,9 +81,8 @@ public class PathSet
*
* @param paths to be added
*/
- public PathSet( String[] paths )
- {
- addAll( paths );
+ public PathSet(String[] paths) {
+ addAll(paths);
}
/**
@@ -102,9 +90,8 @@ public class PathSet
*
* @param path to be added
*/
- public void add( String path )
- {
- pathsSet.add( normalizeSubPath( path ) );
+ public void add(String path) {
+ pathsSet.add(normalizeSubPath(path));
}
/**
@@ -113,11 +100,9 @@ public class PathSet
* @param paths - collection of strings to be added
* @param prefix added to all given paths
*/
- public void addAll( Collection<String> paths, String prefix )
- {
- for ( String val : paths )
- {
- add( prefix + SEPARATOR + val );
+ public void addAll(Collection<String> paths, String prefix) {
+ for (String val : paths) {
+ add(prefix + SEPARATOR + val);
}
}
@@ -127,11 +112,9 @@ public class PathSet
* @param paths to be added
* @param prefix added to all given paths
*/
- public void addAll( String[] paths, String prefix )
- {
- for ( String val : paths )
- {
- add( prefix + SEPARATOR + val );
+ public void addAll(String[] paths, String prefix) {
+ for (String val : paths) {
+ add(prefix + SEPARATOR + val);
}
}
@@ -141,11 +124,9 @@ public class PathSet
* @param paths to be added
* @param prefix added to all given paths
*/
- public void addAll( PathSet paths, String prefix )
- {
- for ( String path : paths )
- {
- add( prefix + SEPARATOR + path );
+ public void addAll(PathSet paths, String prefix) {
+ for (String path : paths) {
+ add(prefix + SEPARATOR + path);
}
}
@@ -154,9 +135,8 @@ public class PathSet
*
* @param paths - collection of strings to be added
*/
- public void addAll( Collection<String> paths )
- {
- addAll( paths, "" );
+ public void addAll(Collection<String> paths) {
+ addAll(paths, "");
}
/**
@@ -164,9 +144,8 @@ public class PathSet
*
* @param paths to be added
*/
- public void addAll( String[] paths )
- {
- addAll( paths, "" );
+ public void addAll(String[] paths) {
+ addAll(paths, "");
}
/**
@@ -174,9 +153,8 @@ public class PathSet
*
* @param paths to be added
*/
- public void addAll( PathSet paths )
- {
- addAll( paths, "" );
+ public void addAll(PathSet paths) {
+ addAll(paths, "");
}
/**
@@ -185,9 +163,8 @@ public class PathSet
* @param path we are looking for in the set.
* @return information if the set constains the path.
*/
- public boolean contains( String path )
- {
- return pathsSet.contains( normalizeSubPath( path ) );
+ public boolean contains(String path) {
+ return pathsSet.contains(normalizeSubPath(path));
}
/**
@@ -196,9 +173,8 @@ public class PathSet
* @param path the path to remove
* @return true if the path was removed, false if it did not existed
*/
- boolean remove( String path )
- {
- return pathsSet.remove( normalizeSubPath( path ) );
+ boolean remove(String path) {
+ return pathsSet.remove(normalizeSubPath(path));
}
/**
@@ -207,32 +183,28 @@ public class PathSet
* @return iterator of normalized paths (strings)
*/
@Override
- public Iterator<String> iterator()
- {
+ public Iterator<String> iterator() {
return pathsSet.iterator();
}
/**
* @return {@link #pathsSet}
*/
- public Collection<String> paths()
- {
+ public Collection<String> paths() {
return pathsSet;
}
/**
* Adds given prefix to all paths in the set.
- *
+ *
* The prefix should be ended by '/'. The generated paths are normalized.
*
* @param prefix to be added to all items
*/
- public void addPrefix( String prefix )
- {
+ public void addPrefix(String prefix) {
final Set<String> newSet = new HashSet<>();
- for ( String path : pathsSet )
- {
- newSet.add( normalizeSubPath( prefix + path ) );
+ for (String path : pathsSet) {
+ newSet.add(normalizeSubPath(prefix + path));
}
pathsSet = newSet;
}
@@ -242,8 +214,7 @@ public class PathSet
*
* @return count of the paths in the set
*/
- public int size()
- {
+ public int size() {
return pathsSet.size();
}
@@ -253,12 +224,10 @@ public class PathSet
* @param directory that will be searched for file's paths to add
* @param prefix to be added to all found files
*/
- public void addAllFilesInDirectory( File directory, String prefix )
- {
+ public void addAllFilesInDirectory(File directory, String prefix) {
DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( directory );
+ scanner.setBasedir(directory);
scanner.scan();
- addAll( scanner.getIncludedFiles(), prefix );
+ addAll(scanner.getIncludedFiles(), prefix);
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java b/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
index 19dbb79..a8313bd 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/WarUtils.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war.util;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war.util;
import java.util.Objects;
@@ -28,29 +27,22 @@ import org.apache.maven.project.MavenProject;
/**
* @author Stephane Nicoll
*/
-public class WarUtils
-{
+public class WarUtils {
/**
* @param project {@link MavenProject}
* @param dependency {@link Dependency}
* @return {@link Artifact}
*/
- public static Artifact getArtifact( MavenProject project, Dependency dependency )
- {
- for ( Artifact artifact : project.getArtifacts() )
- {
- if ( artifact.getGroupId().equals( dependency.getGroupId() )
- && artifact.getArtifactId().equals( dependency.getArtifactId() )
- && artifact.getType().equals( dependency.getType() ) )
- {
- if ( artifact.getClassifier() == null && dependency.getClassifier() == null )
- {
+ public static Artifact getArtifact(MavenProject project, Dependency dependency) {
+ for (Artifact artifact : project.getArtifacts()) {
+ if (artifact.getGroupId().equals(dependency.getGroupId())
+ && artifact.getArtifactId().equals(dependency.getArtifactId())
+ && artifact.getType().equals(dependency.getType())) {
+ if (artifact.getClassifier() == null && dependency.getClassifier() == null) {
return artifact;
- }
- else if ( dependency.getClassifier() != null
- && dependency.getClassifier().equals( artifact.getClassifier() ) )
- {
+ } else if (dependency.getClassifier() != null
+ && dependency.getClassifier().equals(artifact.getClassifier())) {
return artifact;
}
}
@@ -63,43 +55,33 @@ public class WarUtils
* @param dependency {@link Dependency}
* @return is related or not.
*/
- public static boolean isRelated( Artifact artifact, Dependency dependency )
- {
- if ( artifact == null || dependency == null )
- {
+ public static boolean isRelated(Artifact artifact, Dependency dependency) {
+ if (artifact == null || dependency == null) {
return false;
}
- if ( !Objects.equals( artifact.getGroupId(), dependency.getGroupId() ) )
- {
+ if (!Objects.equals(artifact.getGroupId(), dependency.getGroupId())) {
return false;
}
- if ( !Objects.equals( artifact.getArtifactId(), dependency.getArtifactId() ) )
- {
+ if (!Objects.equals(artifact.getArtifactId(), dependency.getArtifactId())) {
return false;
}
- if ( Objects.equals( artifact.getVersion(), dependency.getVersion() ) )
- {
+ if (Objects.equals(artifact.getVersion(), dependency.getVersion())) {
return false;
}
- if ( Objects.equals( artifact.getType(), dependency.getType() ) )
- {
+ if (Objects.equals(artifact.getType(), dependency.getType())) {
return false;
}
- if ( Objects.equals( artifact.getClassifier(), dependency.getClassifier() ) )
- {
+ if (Objects.equals(artifact.getClassifier(), dependency.getClassifier())) {
return false;
}
- if ( Objects.equals( artifact.getScope(), dependency.getScope() ) )
- {
+ if (Objects.equals(artifact.getScope(), dependency.getScope())) {
return false;
}
- if ( artifact.isOptional() != dependency.isOptional() )
- {
+ if (artifact.isOptional() != dependency.isOptional()) {
return false;
}
return true;
}
-
}
diff --git a/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java b/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java
index b48e1e6..e2cb735 100644
--- a/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java
+++ b/src/main/java/org/apache/maven/plugins/war/util/WebappStructure.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,9 +16,7 @@ package org.apache.maven.plugins.war.util;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Dependency;
+package org.apache.maven.plugins.war.util;
import java.io.IOException;
import java.util.ArrayList;
@@ -30,16 +26,18 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
+
/**
* Represents the structure of a web application composed of multiple overlays. Each overlay is registered within this
* structure with the set of files it holds.
- *
+ *
* Note that this structure is persisted to disk at each invocation to store which owner holds which path (file).
*
* @author Stephane Nicoll
*/
-public class WebappStructure
-{
+public class WebappStructure {
private Map<String, PathSet> registeredFiles;
@@ -52,9 +50,8 @@ public class WebappStructure
*
* @param dependencies the dependencies of the project
*/
- public WebappStructure( List<Dependency> dependencies )
- {
- this.dependenciesInfo = createDependenciesInfoList( dependencies );
+ public WebappStructure(List<Dependency> dependencies) {
+ this.dependenciesInfo = createDependenciesInfoList(dependencies);
this.registeredFiles = new HashMap<>();
}
@@ -63,8 +60,7 @@ public class WebappStructure
*
* @return the dependencies information of the project
*/
- public List<DependencyInfo> getDependenciesInfo()
- {
+ public List<DependencyInfo> getDependenciesInfo() {
return dependenciesInfo;
}
@@ -73,16 +69,13 @@ public class WebappStructure
*
* @return the dependencies of the project
*/
- public List<Dependency> getDependencies()
- {
+ public List<Dependency> getDependencies() {
final List<Dependency> result = new ArrayList<>();
- if ( dependenciesInfo == null )
- {
+ if (dependenciesInfo == null) {
return result;
}
- for ( DependencyInfo dependencyInfo : dependenciesInfo )
- {
- result.add( dependencyInfo.getDependency() );
+ for (DependencyInfo dependencyInfo : dependenciesInfo) {
+ result.add(dependencyInfo.getDependency());
}
return result;
}
@@ -93,10 +86,8 @@ public class WebappStructure
* @param path the relative path from the webapp root directory
* @return true if the path is registered, false otherwise
*/
- public boolean isRegistered( String path )
- {
- return getFullStructure().contains( path );
-
+ public boolean isRegistered(String path) {
+ return getFullStructure().contains(path);
}
/**
@@ -107,15 +98,11 @@ public class WebappStructure
* @param path the relative path from the webapp root directory
* @return true if the file was registered successfully
*/
- public boolean registerFile( String id, String path )
- {
- if ( !isRegistered( path ) )
- {
- doRegister( id, path );
+ public boolean registerFile(String id, String path) {
+ if (!isRegistered(path)) {
+ doRegister(id, path);
return true;
- }
- else
- {
+ } else {
return false;
}
}
@@ -132,21 +119,16 @@ public class WebappStructure
* @param path the relative path from the webapp root directory
* @return false if the file did not exist, true if the owner was replaced
*/
- public boolean registerFileForced( String id, String path )
- {
- if ( !isRegistered( path ) )
- {
- doRegister( id, path );
+ public boolean registerFileForced(String id, String path) {
+ if (!isRegistered(path)) {
+ doRegister(id, path);
return false;
- }
- else
- {
+ } else {
// Force the switch to the new owner
- getStructure( getOwner( path ) ).remove( path );
- getStructure( id ).add( path );
+ getStructure(getOwner(path)).remove(path);
+ getStructure(id).add(path);
return true;
}
-
}
/**
@@ -158,35 +140,26 @@ public class WebappStructure
* @param callback the callback to invoke with the result of the registration
* @throws IOException if the callback invocation throws an IOException
*/
- public void registerFile( String id, String path, RegistrationCallback callback )
- throws IOException
- {
+ public void registerFile(String id, String path, RegistrationCallback callback) throws IOException {
// If the file is already in the current structure, rejects it with the current owner
- if ( isRegistered( path ) )
- {
- callback.refused( id, path, getOwner( path ) );
- }
- else
- {
- doRegister( id, path );
+ if (isRegistered(path)) {
+ callback.refused(id, path, getOwner(path));
+ } else {
+ doRegister(id, path);
// This is a new file
- if ( getOwner( path ) == null )
- {
- callback.registered( id, path );
+ if (getOwner(path) == null) {
+ callback.registered(id, path);
} // The file already belonged to this owner
- else if ( getOwner( path ).equals( id ) )
- {
- callback.alreadyRegistered( id, path );
+ else if (getOwner(path).equals(id)) {
+ callback.alreadyRegistered(id, path);
} // The file belongs to another owner and it's known currently
- else if ( getOwners().contains( getOwner( path ) ) )
- {
- callback.superseded( id, path, getOwner( path ) );
+ else if (getOwners().contains(getOwner(path))) {
+ callback.superseded(id, path, getOwner(path));
} // The file belongs to another owner and it's unknown
- else
- {
- callback.supersededUnknownOwner( id, path, getOwner( path ) );
+ else {
+ callback.supersededUnknownOwner(id, path, getOwner(path));
}
}
}
@@ -197,27 +170,19 @@ public class WebappStructure
* @param path the relative path from the webapp root directory
* @return the owner or {@code null}.
*/
- public String getOwner( String path )
- {
- if ( !isRegistered( path ) )
- {
+ public String getOwner(String path) {
+ if (!isRegistered(path)) {
return null;
- }
- else
- {
- for ( final String owner : registeredFiles.keySet() )
- {
- final PathSet structure = getStructure( owner );
- if ( structure.contains( path ) )
- {
+ } else {
+ for (final String owner : registeredFiles.keySet()) {
+ final PathSet structure = getStructure(owner);
+ if (structure.contains(path)) {
return owner;
}
-
}
- throw new IllegalStateException( "Should not happen, path [" + path
- + "] is flagged as being registered but was not found." );
+ throw new IllegalStateException(
+ "Should not happen, path [" + path + "] is flagged as being registered but was not found.");
}
-
}
/**
@@ -225,8 +190,7 @@ public class WebappStructure
*
* @return the list of owners
*/
- public Set<String> getOwners()
- {
+ public Set<String> getOwners() {
return registeredFiles.keySet();
}
@@ -235,8 +199,7 @@ public class WebappStructure
*
* @return all registered path
*/
- public PathSet getFullStructure()
- {
+ public PathSet getFullStructure() {
return allFiles;
}
@@ -246,34 +209,26 @@ public class WebappStructure
* @param id the owner
* @return the list of files registered for that owner
*/
- public PathSet getStructure( String id )
- {
- PathSet pathSet = registeredFiles.get( id );
- if ( pathSet == null )
- {
+ public PathSet getStructure(String id) {
+ PathSet pathSet = registeredFiles.get(id);
+ if (pathSet == null) {
pathSet = new PathSet();
- registeredFiles.put( id, pathSet );
+ registeredFiles.put(id, pathSet);
}
return pathSet;
}
-
-
/**
* Registers the target file name for the specified artifact.
*
* @param artifact the artifact
* @param targetFileName the target file name
*/
- public void registerTargetFileName( Artifact artifact, String targetFileName )
- {
- if ( dependenciesInfo != null )
- {
- for ( DependencyInfo dependencyInfo : dependenciesInfo )
- {
- if ( WarUtils.isRelated( artifact, dependencyInfo.getDependency() ) )
- {
- dependencyInfo.setTargetFileName( targetFileName );
+ public void registerTargetFileName(Artifact artifact, String targetFileName) {
+ if (dependenciesInfo != null) {
+ for (DependencyInfo dependencyInfo : dependenciesInfo) {
+ if (WarUtils.isRelated(artifact, dependencyInfo.getDependency())) {
+ dependencyInfo.setTargetFileName(targetFileName);
}
}
}
@@ -281,33 +236,27 @@ public class WebappStructure
// Private helpers
- private void doRegister( String id, String path )
- {
- getFullStructure().add( path );
- getStructure( id ).add( path );
+ private void doRegister(String id, String path) {
+ getFullStructure().add(path);
+ getStructure(id).add(path);
}
- private List<DependencyInfo> createDependenciesInfoList( List<Dependency> dependencies )
- {
- if ( dependencies == null )
- {
+ private List<DependencyInfo> createDependenciesInfoList(List<Dependency> dependencies) {
+ if (dependencies == null) {
return Collections.emptyList();
}
final List<DependencyInfo> result = new ArrayList<>();
- for ( Dependency dependency : dependencies )
- {
- result.add( new DependencyInfo( dependency ) );
+ for (Dependency dependency : dependencies) {
+ result.add(new DependencyInfo(dependency));
}
return result;
}
- private Object readResolve()
- {
+ private Object readResolve() {
// the full structure should be resolved so let's rebuild it
this.allFiles = new PathSet();
- for ( PathSet pathSet : registeredFiles.values() )
- {
- this.allFiles.addAll( pathSet );
+ for (PathSet pathSet : registeredFiles.values()) {
+ this.allFiles.addAll(pathSet);
}
return this;
}
@@ -315,38 +264,35 @@ public class WebappStructure
/**
* Callback interface to handle events related to filepath registration in the webapp.
*/
- public interface RegistrationCallback
- {
+ public interface RegistrationCallback {
/**
* Called if the {@code targetFilename} for the specified {@code ownerId} has been registered successfully.
- *
+ *
* This means that the {@code targetFilename} was unknown and has been registered successfully.
*
* @param ownerId the ownerId
* @param targetFilename the relative path according to the root of the webapp
* @throws IOException if an error occurred while handling this event
*/
- void registered( String ownerId, String targetFilename )
- throws IOException;
+ void registered(String ownerId, String targetFilename) throws IOException;
/**
* Called if the {@code targetFilename} for the specified {@code ownerId} has already been registered.
- *
+ *
* This means that the {@code targetFilename} was known and belongs to the specified owner.
*
* @param ownerId the ownerId
* @param targetFilename the relative path according to the root of the webapp
* @throws IOException if an error occurred while handling this event
*/
- void alreadyRegistered( String ownerId, String targetFilename )
- throws IOException;
+ void alreadyRegistered(String ownerId, String targetFilename) throws IOException;
/**
* <p>
* Called if the registration of the {@code targetFilename} for the specified {@code ownerId} has been refused
* since the path already belongs to the {@code actualOwnerId}.
- * </p>
+ * </p>
* This means that the {@code targetFilename} was known and does not belong to the specified owner.
*
* @param ownerId the ownerId
@@ -354,13 +300,12 @@ public class WebappStructure
* @param actualOwnerId the actual owner
* @throws IOException if an error occurred while handling this event
*/
- void refused( String ownerId, String targetFilename, String actualOwnerId )
- throws IOException;
+ void refused(String ownerId, String targetFilename, String actualOwnerId) throws IOException;
/**
* Called if the {@code targetFilename} for the specified {@code ownerId} has been registered successfully by
* superseding a {@code deprecatedOwnerId}, that is the previous owner of the file.
- *
+ *
* This means that the {@code targetFilename} was known but for another owner. This usually happens after a
* project's configuration change. As a result, the file has been registered successfully to the new owner.
*
@@ -369,13 +314,12 @@ public class WebappStructure
* @param deprecatedOwnerId the previous owner that does not exist anymore
* @throws IOException if an error occurred while handling this event
*/
- void superseded( String ownerId, String targetFilename, String deprecatedOwnerId )
- throws IOException;
+ void superseded(String ownerId, String targetFilename, String deprecatedOwnerId) throws IOException;
/**
* Called if the {@code targetFilename} for the specified {@code ownerId} has been registered successfully by
* superseding a {@code unknownOwnerId}, that is an owner that does not exist anymore in the current project.
- *
+ *
* This means that the {@code targetFilename} was known but for an owner that does not exist anymore. Hence the
* file has been registered successfully to the new owner.
*
@@ -384,8 +328,6 @@ public class WebappStructure
* @param unknownOwnerId the previous owner that does not exist anymore
* @throws IOException if an error occurred while handling this event
*/
- void supersededUnknownOwner( String ownerId, String targetFilename, String unknownOwnerId )
- throws IOException;
+ void supersededUnknownOwner(String ownerId, String targetFilename, String unknownOwnerId) throws IOException;
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java
index f140940..1c872f8 100644
--- a/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,10 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub;
-import org.codehaus.plexus.util.FileUtils;
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.FileFilter;
@@ -32,20 +27,20 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub;
+import org.codehaus.plexus.util.FileUtils;
+
/**
* @author Stephane Nicoll
*/
-public abstract class AbstractWarExplodedMojoTest
- extends AbstractWarMojoTest
-{
+public abstract class AbstractWarExplodedMojoTest extends AbstractWarMojoTest {
protected WarExplodedMojo mojo;
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- mojo = (WarExplodedMojo) lookupMojo( "exploded", getPomFile() );
+ mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile());
}
/**
@@ -64,7 +59,7 @@ public abstract class AbstractWarExplodedMojoTest
/**
* Configures the exploded mojo for the specified test.
- *
+ *
* If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default.
*
* @param testId the id of the test
@@ -73,44 +68,34 @@ public abstract class AbstractWarExplodedMojoTest
* @return the webapp directory
* @throws Exception if an error occurs while configuring the mojo
*/
- protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles )
- throws Exception
- {
+ protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception {
final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- final File webAppDirectory = new File( getTestDirectory(), testId );
+ final File webAppDirectory = new File(getTestDirectory(), testId);
// Create the webapp sources
File webAppSource;
- if ( sourceFiles == null )
- {
- webAppSource = createWebAppSource( testId );
- }
- else
- {
- webAppSource = createWebAppSource( testId, false );
- for ( String sourceFile : sourceFiles )
- {
- File sample = new File( webAppSource, sourceFile );
- createFile( sample );
-
+ if (sourceFiles == null) {
+ webAppSource = createWebAppSource(testId);
+ } else {
+ webAppSource = createWebAppSource(testId, false);
+ for (String sourceFile : sourceFiles) {
+ File sample = new File(webAppSource, sourceFile);
+ createFile(sample);
}
-
}
- final File classesDir = createClassesDir( testId, true );
- final File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
- createDir( workDirectory );
+ final File classesDir = createClassesDir(testId, true);
+ final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
+ createDir(workDirectory);
- if ( artifactStubs != null )
- {
- for ( ArtifactStub artifactStub : artifactStubs )
- {
- project.addArtifact( artifactStub );
+ if (artifactStubs != null) {
+ for (ArtifactStub artifactStub : artifactStubs) {
+ project.addArtifact(artifactStub);
}
}
- configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "workDirectory", workDirectory);
return webAppDirectory;
}
@@ -123,10 +108,8 @@ public abstract class AbstractWarExplodedMojoTest
* @return the webapp directory
* @throws Exception if an error occurs while configuring the mojo
*/
- protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs )
- throws Exception
- {
- return setUpMojo( testId, artifactStubs, null );
+ protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception {
+ return setUpMojo(testId, artifactStubs, null);
}
/**
@@ -135,12 +118,9 @@ public abstract class AbstractWarExplodedMojoTest
* @param directory the directory to remove
* @throws IOException if an error occurred while removing the directory
*/
- protected void cleanDirectory( File directory )
- throws IOException
- {
- if ( directory != null && directory.isDirectory() && directory.exists() )
- {
- FileUtils.deleteDirectory( directory );
+ protected void cleanDirectory(File directory) throws IOException {
+ if (directory != null && directory.isDirectory() && directory.exists()) {
+ FileUtils.deleteDirectory(directory);
}
}
@@ -150,18 +130,17 @@ public abstract class AbstractWarExplodedMojoTest
* @param webAppDirectory the webapp directory
* @return a list of File objects that have been asserted
*/
- protected List<File> assertDefaultContent( File webAppDirectory )
- {
+ protected List<File> assertDefaultContent(File webAppDirectory) {
// Validate content of the webapp
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
- assertTrue( "source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
+ assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
final List<File> content = new ArrayList<>();
- content.add( expectedWebSourceFile );
- content.add( expectedWebSource2File );
+ content.add(expectedWebSourceFile);
+ content.add(expectedWebSource2File);
return content;
}
@@ -172,13 +151,12 @@ public abstract class AbstractWarExplodedMojoTest
* @param webAppDirectory the webapp directory
* @return a list with the web.xml File object
*/
- protected List<File> assertWebXml( File webAppDirectory )
- {
- File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
- assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
+ protected List<File> assertWebXml(File webAppDirectory) {
+ File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
+ assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
final List<File> content = new ArrayList<>();
- content.add( expectedWEBXMLFile );
+ content.add(expectedWEBXMLFile);
return content;
}
@@ -191,21 +169,16 @@ public abstract class AbstractWarExplodedMojoTest
* @param customMessage a custom message if an assertion fails
* @return a list of File objects that have been inspected
*/
- protected List<File> assertCustomContent( File webAppDirectory, String[] filePaths, String customMessage )
- {
+ protected List<File> assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) {
final List<File> content = new ArrayList<>();
- for ( String filePath : filePaths )
- {
- final File expectedFile = new File( webAppDirectory, filePath );
- if ( customMessage != null )
- {
- assertTrue( customMessage + " - " + expectedFile.toString(), expectedFile.exists() );
- }
- else
- {
- assertTrue( "source file not found: " + expectedFile.toString(), expectedFile.exists() );
+ for (String filePath : filePaths) {
+ final File expectedFile = new File(webAppDirectory, filePath);
+ if (customMessage != null) {
+ assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists());
+ } else {
+ assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists());
}
- content.add( expectedFile );
+ content.add(expectedFile);
}
return content;
}
@@ -217,28 +190,27 @@ public abstract class AbstractWarExplodedMojoTest
* @param expectedFiles the expected files
* @param filter an optional filter to ignore some resources
*/
- protected void assertWebAppContent( File webAppDirectory, List<File> expectedFiles, FileFilter filter )
- {
+ protected void assertWebAppContent(File webAppDirectory, List<File> expectedFiles, FileFilter filter) {
final List<File> webAppContent = new ArrayList<>();
- if ( filter != null )
- {
- buildFilesList( webAppDirectory, filter, webAppContent );
- }
- else
- {
- buildFilesList( webAppDirectory, new FileFilterImpl( webAppDirectory, null ), webAppContent );
+ if (filter != null) {
+ buildFilesList(webAppDirectory, filter, webAppContent);
+ } else {
+ buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent);
}
// Now we have the files, sort them.
- Collections.sort( expectedFiles );
- Collections.sort( webAppContent );
- assertEquals( "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles
- + " but got " + webAppContent.size() + " file(s) " + webAppContent, expectedFiles, webAppContent );
+ Collections.sort(expectedFiles);
+ Collections.sort(webAppContent);
+ assertEquals(
+ "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got "
+ + webAppContent.size() + " file(s) " + webAppContent,
+ expectedFiles,
+ webAppContent);
}
/**
* Builds the list of files and directories from the specified dir.
- *
+ *
* Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added
* but yet the subdirectories are added if any.
*
@@ -246,58 +218,44 @@ public abstract class AbstractWarExplodedMojoTest
* @param filter the filter
* @param content the current content, updated recursively
*/
- private void buildFilesList( final File dir, FileFilter filter, final List<File> content )
- {
+ private void buildFilesList(final File dir, FileFilter filter, final List<File> content) {
final File[] files = dir.listFiles();
- for ( File file : files )
- {
+ for (File file : files) {
// Add the file if the filter is ok with it
- if ( filter.accept( file ) )
- {
- content.add( file );
+ if (filter.accept(file)) {
+ content.add(file);
}
// Even if the file is not accepted and is a directory, add it
- if ( file.isDirectory() )
- {
- buildFilesList( file, filter, content );
+ if (file.isDirectory()) {
+ buildFilesList(file, filter, content);
}
-
}
}
- class FileFilterImpl
- implements FileFilter
- {
+ class FileFilterImpl implements FileFilter {
private final List<String> rejectedFilePaths;
private final int webAppDirIndex;
- public FileFilterImpl( File webAppDirectory, String[] rejectedFilePaths )
- {
- if ( rejectedFilePaths != null )
- {
- this.rejectedFilePaths = Arrays.asList( rejectedFilePaths );
- }
- else
- {
+ public FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) {
+ if (rejectedFilePaths != null) {
+ this.rejectedFilePaths = Arrays.asList(rejectedFilePaths);
+ } else {
this.rejectedFilePaths = new ArrayList<>();
}
this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1;
}
- public boolean accept( File file )
- {
- String effectiveRelativePath = buildRelativePath( file );
- return !( rejectedFilePaths.contains( effectiveRelativePath ) || file.isDirectory() );
+ public boolean accept(File file) {
+ String effectiveRelativePath = buildRelativePath(file);
+ return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory());
}
- private String buildRelativePath( File f )
- {
- return f.getAbsolutePath().substring( webAppDirIndex );
+ private String buildRelativePath(File f) {
+ return f.getAbsolutePath().substring(webAppDirIndex);
}
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
index 3de518f..23053c7 100644
--- a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.IOException;
@@ -38,18 +37,15 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.RepositorySystemSession;
-public abstract class AbstractWarMojoTest
- extends AbstractMojoTestCase
-{
+public abstract class AbstractWarMojoTest extends AbstractMojoTestCase {
- protected static final File OVERLAYS_TEMP_DIR = new File( getBasedir(), "target/test-overlays/" );
+ protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/");
- protected static final File OVERLAYS_ROOT_DIR = new File( getBasedir(), "target/test-classes/overlays/" );
+ protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/");
protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF";
- protected abstract File getTestDirectory()
- throws Exception;
+ protected abstract File getTestDirectory() throws Exception;
/**
* initialize required parameters
@@ -62,25 +58,30 @@ public abstract class AbstractWarMojoTest
* @param project The Maven project.
* @throws Exception in case of errors
*/
- protected void configureMojo( AbstractWarMojo mojo, List<String> filters, File classesDir, File webAppSource,
- File webAppDir, MavenProjectBasicStub project )
- throws Exception
- {
- setVariableValueToObject( mojo, "filters", filters );
- setVariableValueToObject( mojo, "mavenFileFilter", lookup( MavenFileFilter.class.getName() ) );
- setVariableValueToObject( mojo, "useJvmChmod", Boolean.TRUE );
-
- MavenExecutionRequest request =
- new DefaultMavenExecutionRequest().setSystemProperties( System.getProperties() ).setStartTime( new Date() );
+ protected void configureMojo(
+ AbstractWarMojo mojo,
+ List<String> filters,
+ File classesDir,
+ File webAppSource,
+ File webAppDir,
+ MavenProjectBasicStub project)
+ throws Exception {
+ setVariableValueToObject(mojo, "filters", filters);
+ setVariableValueToObject(mojo, "mavenFileFilter", lookup(MavenFileFilter.class.getName()));
+ setVariableValueToObject(mojo, "useJvmChmod", Boolean.TRUE);
+
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest()
+ .setSystemProperties(System.getProperties())
+ .setStartTime(new Date());
MavenSession mavenSession =
- new MavenSession( (PlexusContainer) null, (RepositorySystemSession) null, request, null );
- setVariableValueToObject( mojo, "session", mavenSession );
- setVariableValueToObject( mojo, "outdatedCheckPath", "WEB-INF/lib/" );
- mojo.setClassesDirectory( classesDir );
- mojo.setWarSourceDirectory( webAppSource );
- mojo.setWebappDirectory( webAppDir );
- mojo.setProject( project );
+ new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null);
+ setVariableValueToObject(mojo, "session", mavenSession);
+ setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/");
+ mojo.setClassesDirectory(classesDir);
+ mojo.setWarSourceDirectory(webAppSource);
+ mojo.setWebappDirectory(webAppDir);
+ mojo.setProject(project);
}
/**
@@ -91,20 +92,16 @@ public abstract class AbstractWarMojoTest
* @return The created file.
* @throws Exception in case of errors.
*/
- protected File createXMLConfigDir( String id, String[] xmlFiles )
- throws Exception
- {
- File xmlConfigDir = new File( getTestDirectory(), "/" + id + "-test-data/xml-config" );
+ protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception {
+ File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config");
File XMLFile;
- createDir( xmlConfigDir );
+ createDir(xmlConfigDir);
- if ( xmlFiles != null )
- {
- for ( String o : xmlFiles )
- {
- XMLFile = new File( xmlConfigDir, o );
- createFile( XMLFile );
+ if (xmlFiles != null) {
+ for (String o : xmlFiles) {
+ XMLFile = new File(xmlConfigDir, o);
+ createFile(XMLFile);
}
}
@@ -118,10 +115,8 @@ public abstract class AbstractWarMojoTest
* @return the source directory for that test
* @throws Exception if an exception occurs
*/
- protected File getWebAppSource( String id )
- throws Exception
- {
- return new File( getTestDirectory(), "/" + id + "-test-data/source" );
+ protected File getWebAppSource(String id) throws Exception {
+ return new File(getTestDirectory(), "/" + id + "-test-data/source");
}
/**
@@ -132,25 +127,20 @@ public abstract class AbstractWarMojoTest
* @return The created file.
* @throws Exception in case of errors.
*/
- protected File createWebAppSource( String id, boolean createSamples )
- throws Exception
- {
- File webAppSource = getWebAppSource( id );
- if ( createSamples )
- {
- File simpleJSP = new File( webAppSource, "pansit.jsp" );
- File jspFile = new File( webAppSource, "org/web/app/last-exile.jsp" );
-
- createFile( simpleJSP );
- createFile( jspFile );
+ protected File createWebAppSource(String id, boolean createSamples) throws Exception {
+ File webAppSource = getWebAppSource(id);
+ if (createSamples) {
+ File simpleJSP = new File(webAppSource, "pansit.jsp");
+ File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp");
+
+ createFile(simpleJSP);
+ createFile(jspFile);
}
return webAppSource;
}
- protected File createWebAppSource( String id )
- throws Exception
- {
- return createWebAppSource( id, true );
+ protected File createWebAppSource(String id) throws Exception {
+ return createWebAppSource(id, true);
}
/**
@@ -161,42 +151,33 @@ public abstract class AbstractWarMojoTest
* @return The created class file.
* @throws Exception in case of errors.
*/
- protected File createClassesDir( String id, boolean empty )
- throws Exception
- {
- File classesDir = new File( getTestDirectory() + "/" + id + "-test-data/classes/" );
+ protected File createClassesDir(String id, boolean empty) throws Exception {
+ File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/");
- createDir( classesDir );
+ createDir(classesDir);
- if ( !empty )
- {
- createFile( new File( classesDir + "/sample-servlet.class" ) );
+ if (!empty) {
+ createFile(new File(classesDir + "/sample-servlet.class"));
}
return classesDir;
}
- protected void createDir( File dir )
- {
- if ( !dir.exists() )
- {
- assertTrue( "can not create test dir: " + dir.toString(), dir.mkdirs() );
+ protected void createDir(File dir) {
+ if (!dir.exists()) {
+ assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs());
}
}
- protected void createFile( File testFile, String body )
- throws Exception
- {
- createDir( testFile.getParentFile() );
- FileUtils.fileWrite( testFile.toString(), body );
+ protected void createFile(File testFile, String body) throws Exception {
+ createDir(testFile.getParentFile());
+ FileUtils.fileWrite(testFile.toString(), body);
- assertTrue( "could not create file: " + testFile, testFile.exists() );
+ assertTrue("could not create file: " + testFile, testFile.exists());
}
- protected void createFile( File testFile )
- throws Exception
- {
- createFile( testFile, testFile.toString() );
+ protected void createFile(File testFile) throws Exception {
+ createFile(testFile, testFile.toString());
}
/**
@@ -243,28 +224,36 @@ public abstract class AbstractWarMojoTest
* @return the war file
* @throws Exception if an error occurs
*/
- protected File generateFullOverlayWar( String id )
- throws Exception
- {
- final File destFile = new File( OVERLAYS_TEMP_DIR, id + ".war" );
- if ( destFile.exists() )
- {
+ protected File generateFullOverlayWar(String id) throws Exception {
+ final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war");
+ if (destFile.exists()) {
return destFile;
}
// Archive was not yet created for that id so let's create it
- final File rootDir = new File( OVERLAYS_ROOT_DIR, id );
+ final File rootDir = new File(OVERLAYS_ROOT_DIR, id);
rootDir.mkdirs();
- String[] filePaths = new String[] { "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "jsp/a.jsp", "jsp/b.jsp",
- "jsp/c.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class",
- "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar", "WEB-INF/web.xml" };
-
- for ( String filePath : filePaths )
- {
- createFile( new File( rootDir, filePath ), id + "-" + filePath );
+ String[] filePaths = new String[] {
+ "jsp/d/a.jsp",
+ "jsp/d/b.jsp",
+ "jsp/d/c.jsp",
+ "jsp/a.jsp",
+ "jsp/b.jsp",
+ "jsp/c.jsp",
+ "WEB-INF/classes/a.class",
+ "WEB-INF/classes/b.class",
+ "WEB-INF/classes/c.class",
+ "WEB-INF/lib/a.jar",
+ "WEB-INF/lib/b.jar",
+ "WEB-INF/lib/c.jar",
+ "WEB-INF/web.xml"
+ };
+
+ for (String filePath : filePaths) {
+ createFile(new File(rootDir, filePath), id + "-" + filePath);
}
- createArchive( rootDir, destFile );
+ createArchive(rootDir, destFile);
return destFile;
}
@@ -276,52 +265,42 @@ public abstract class AbstractWarMojoTest
* @param id the id of the overlay (see test/resources/overlays)
* @return a test war artifact with the content of the given test overlay
*/
- protected ArtifactStub buildWarOverlayStub( String id )
- {
+ protected ArtifactStub buildWarOverlayStub(String id) {
// Create war file
- final File destFile = new File( OVERLAYS_TEMP_DIR, id + ".war" );
- if ( !destFile.exists() )
- {
- createArchive( new File( OVERLAYS_ROOT_DIR, id ), destFile );
+ final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war");
+ if (!destFile.exists()) {
+ createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile);
}
- return new WarOverlayStub( getBasedir(), id, destFile );
+ return new WarOverlayStub(getBasedir(), id, destFile);
}
- protected File getOverlayFile( String id, String filePath )
- {
- final File overlayDir = new File( OVERLAYS_ROOT_DIR, id );
- final File file = new File( overlayDir, filePath );
+ protected File getOverlayFile(String id, String filePath) {
+ final File overlayDir = new File(OVERLAYS_ROOT_DIR, id);
+ final File file = new File(overlayDir, filePath);
// Make sure the file exists
- assertTrue( "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(),
- file.exists() );
+ assertTrue(
+ "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(),
+ file.exists());
return file;
-
}
- protected void createArchive( final File directory, final File destinationFile )
- {
- try
- {
+ protected void createArchive(final File directory, final File destinationFile) {
+ try {
JarArchiver archiver = new JarArchiver();
- archiver.setDestFile( destinationFile );
- archiver.addDirectory( directory );
-
+ archiver.setDestFile(destinationFile);
+ archiver.addDirectory(directory);
+
archiver.createArchive();
- }
- catch ( ArchiverException e )
- {
+ } catch (ArchiverException e) {
e.printStackTrace();
- fail( "Failed to create overlay archive " + e.getMessage() );
- }
- catch ( IOException e )
- {
+ fail("Failed to create overlay archive " + e.getMessage());
+ } catch (IOException e) {
e.printStackTrace();
- fail( "Unexpected exception " + e.getMessage() );
+ fail("Unexpected exception " + e.getMessage());
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java
index 9997f4d..1837a5e 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.war;
/*
@@ -33,42 +51,36 @@ import org.codehaus.plexus.util.FileUtils;
* @author Olivier Lamy
* @since 21 juil. 2008
*/
-public class WarExplodedMojoFilteringTest
- extends AbstractWarExplodedMojoTest
-{
+public class WarExplodedMojoFilteringTest extends AbstractWarExplodedMojoTest {
- protected File getPomFile()
- {
- return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" );
+ protected File getPomFile() {
+ return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml");
}
- protected File getTestDirectory()
- {
- return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" );
+ protected File getTestDirectory() {
+ return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir");
}
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithResourceFiltering()
- throws Exception
- {
+ public void testExplodedWar_WithResourceFiltering() throws Exception {
// setup test data
String testId = "ExplodedWar_WithResourceFiltering";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File webAppResource = new File( getTestDirectory(), testId + "-test-data/resources" );
- File sampleResource = new File( webAppResource, "custom-setting.cfg" );
- File sampleResourceWDir = new File( webAppResource, "custom-config/custom-setting.cfg" );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File webAppResource = new File(getTestDirectory(), testId + "-test-data/resources");
+ File sampleResource = new File(webAppResource, "custom-setting.cfg");
+ File sampleResourceWDir = new File(webAppResource, "custom-config/custom-setting.cfg");
List<String> filterList = new LinkedList<>();
- ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
+ ResourceStub[] resources = new ResourceStub[] {new ResourceStub()};
- createFile( sampleResource );
- createFile( sampleResourceWDir );
+ createFile(sampleResource);
+ createFile(sampleResourceWDir);
- String ls = System.getProperty( "line.separator" );
+ String ls = System.getProperty("line.separator");
final String comment = "# this is comment created by author@somewhere@";
// prepare web resources
String content = comment + ls;
@@ -80,124 +92,145 @@ public class WarExplodedMojoFilteringTest
content += "project_name_2=@project.name@" + ls;
content += "system_property_1=${system.property}" + ls;
content += "system_property_2=@system.property@" + ls;
- FileUtils.fileWrite( sampleResourceWDir.getAbsolutePath(), content );
- FileUtils.fileWrite( sampleResource.getAbsolutePath(), content );
+ FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content);
+ FileUtils.fileWrite(sampleResource.getAbsolutePath(), content);
- System.setProperty( "system.property", "system-property-value" );
+ System.setProperty("system.property", "system-property-value");
// configure mojo
- project.addProperty( "is_this_simple", "i_think_so" );
- resources[0].setDirectory( webAppResource.getAbsolutePath() );
- resources[0].setFiltering( true );
- this.configureMojo( mojo, filterList, classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "webResources", resources );
+ project.addProperty("is_this_simple", "i_think_so");
+ resources[0].setDirectory(webAppResource.getAbsolutePath());
+ resources[0].setFiltering(true);
+ this.configureMojo(mojo, filterList, classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "webResources", resources);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedResourceFile = new File( webAppDirectory, "custom-setting.cfg" );
- File expectedResourceWDirFile = new File( webAppDirectory, "custom-config/custom-setting.cfg" );
-
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "resource file not found:" + expectedResourceFile.toString(), expectedResourceFile.exists() );
- assertTrue( "resource file with dir not found:" + expectedResourceWDirFile.toString(),
- expectedResourceWDirFile.exists() );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedResourceFile = new File(webAppDirectory, "custom-setting.cfg");
+ File expectedResourceWDirFile = new File(webAppDirectory, "custom-config/custom-setting.cfg");
+
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("resource file not found:" + expectedResourceFile.toString(), expectedResourceFile.exists());
+ assertTrue(
+ "resource file with dir not found:" + expectedResourceWDirFile.toString(),
+ expectedResourceWDirFile.exists());
// validate filtered file
- content = FileUtils.fileRead( expectedResourceWDirFile );
- BufferedReader reader = new BufferedReader( new StringReader( content ) );
+ content = FileUtils.fileRead(expectedResourceWDirFile);
+ BufferedReader reader = new BufferedReader(new StringReader(content));
- assertEquals( "error in filtering using System Properties", comment, reader.readLine() );
+ assertEquals("error in filtering using System Properties", comment, reader.readLine());
String line = reader.readLine();
- System.out.println( " line " + line );
- System.out.println( " need " + System.getProperty( "user.dir" ) );
- assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ),
- line );
+ System.out.println(" line " + line);
+ System.out.println(" need " + System.getProperty("user.dir"));
+ assertEquals(
+ "error in filtering using System properties", "system_key_1=" + System.getProperty("user.dir"), line);
line = reader.readLine();
- System.out.println( " line " + line );
- assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ),
- line );
+ System.out.println(" line " + line);
+ assertEquals(
+ "error in filtering using System properties", "system_key_2=" + System.getProperty("user.dir"), line);
- assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() );
+ assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine());
- assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() );
+ assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine());
- assertEquals( "error in filtering using System properties", "system_property_1=system-property-value",
- reader.readLine() );
- assertEquals( "error in filtering using System properties", "system_property_2=system-property-value",
- reader.readLine() );
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_1=system-property-value",
+ reader.readLine());
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_2=system-property-value",
+ reader.readLine());
// update property, and generate again
- System.setProperty( "system.property", "new-system-property-value" );
- this.configureMojo( mojo, filterList, classesDir, webAppSource, webAppDirectory, project );
+ System.setProperty("system.property", "new-system-property-value");
+ this.configureMojo(mojo, filterList, classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate filtered file
- content = FileUtils.fileRead( expectedResourceWDirFile );
- reader = new BufferedReader( new StringReader( content ) );
-
- assertEquals( "error in filtering using System Properties", comment, reader.readLine() );
-
- assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ),
- reader.readLine() );
- assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ),
- reader.readLine() );
-
- assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() );
-
- assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() );
-
- assertEquals( "error in filtering using System properties", "system_property_1=new-system-property-value",
- reader.readLine() );
- assertEquals( "error in filtering using System properties", "system_property_2=new-system-property-value",
- reader.readLine() );
+ content = FileUtils.fileRead(expectedResourceWDirFile);
+ reader = new BufferedReader(new StringReader(content));
+
+ assertEquals("error in filtering using System Properties", comment, reader.readLine());
+
+ assertEquals(
+ "error in filtering using System properties",
+ "system_key_1=" + System.getProperty("user.dir"),
+ reader.readLine());
+ assertEquals(
+ "error in filtering using System properties",
+ "system_key_2=" + System.getProperty("user.dir"),
+ reader.readLine());
+
+ assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine());
+
+ assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine());
+
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_1=new-system-property-value",
+ reader.readLine());
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_2=new-system-property-value",
+ reader.readLine());
// update property, and generate again
- File filterFile = new File( getTestDirectory(), testId + "-test-data/filters/filter.properties" );
- createFile( filterFile );
- filterList.add( filterFile.getAbsolutePath() );
+ File filterFile = new File(getTestDirectory(), testId + "-test-data/filters/filter.properties");
+ createFile(filterFile);
+ filterList.add(filterFile.getAbsolutePath());
content += "resource_key_1=${resource_value_1}\n";
content += "resource_key_2=@resource_value_2@\n" + content;
- FileUtils.fileWrite( sampleResourceWDir.getAbsolutePath(), content );
- FileUtils.fileWrite( sampleResource.getAbsolutePath(), content );
+ FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content);
+ FileUtils.fileWrite(sampleResource.getAbsolutePath(), content);
String filterContent = "resource_value_1=this_is_filtered\n";
filterContent += "resource_value_2=this_is_filtered";
- FileUtils.fileWrite( filterFile.getAbsolutePath(), filterContent );
+ FileUtils.fileWrite(filterFile.getAbsolutePath(), filterContent);
mojo.execute();
// validate filtered file
- content = FileUtils.fileRead( expectedResourceWDirFile );
- reader = new BufferedReader( new StringReader( content ) );
-
- assertEquals( "error in filtering using System Properties", comment, reader.readLine() );
-
- assertEquals( "error in filtering using System properties", "system_key_1=" + System.getProperty( "user.dir" ),
- reader.readLine() );
- assertEquals( "error in filtering using System properties", "system_key_2=" + System.getProperty( "user.dir" ),
- reader.readLine() );
-
- assertEquals( "error in filtering using project properties", "project_key_1=i_think_so", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_key_2=i_think_so", reader.readLine() );
-
- assertEquals( "error in filtering using project properties", "project_name_1=Test Project ", reader.readLine() );
- assertEquals( "error in filtering using project properties", "project_name_2=Test Project ", reader.readLine() );
-
- assertEquals( "error in filtering using System properties", "system_property_1=new-system-property-value",
- reader.readLine() );
- assertEquals( "error in filtering using System properties", "system_property_2=new-system-property-value",
- reader.readLine() );
-
- assertEquals( "error in filtering using filter files", "resource_key_1=this_is_filtered", reader.readLine() );
- assertEquals( "error in filtering using filter files", "resource_key_2=this_is_filtered", reader.readLine() );
+ content = FileUtils.fileRead(expectedResourceWDirFile);
+ reader = new BufferedReader(new StringReader(content));
+
+ assertEquals("error in filtering using System Properties", comment, reader.readLine());
+
+ assertEquals(
+ "error in filtering using System properties",
+ "system_key_1=" + System.getProperty("user.dir"),
+ reader.readLine());
+ assertEquals(
+ "error in filtering using System properties",
+ "system_key_2=" + System.getProperty("user.dir"),
+ reader.readLine());
+
+ assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine());
+
+ assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine());
+ assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine());
+
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_1=new-system-property-value",
+ reader.readLine());
+ assertEquals(
+ "error in filtering using System properties",
+ "system_property_2=new-system-property-value",
+ reader.readLine());
+
+ assertEquals("error in filtering using filter files", "resource_key_1=this_is_filtered", reader.readLine());
+ assertEquals("error in filtering using filter files", "resource_key_2=this_is_filtered", reader.readLine());
// house keeping
expectedWebSourceFile.delete();
@@ -205,5 +238,4 @@ public class WarExplodedMojoFilteringTest
expectedResourceFile.delete();
expectedResourceWDirFile.delete();
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java
index 45faf0f..0435269 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,8 +16,12 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
-import static org.junit.Assert.assertNotEquals;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.LinkedList;
+import java.util.Locale;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
@@ -39,63 +41,54 @@ import org.apache.maven.plugins.war.stub.WarArtifactStub;
import org.apache.maven.plugins.war.stub.XarArtifactStub;
import org.codehaus.plexus.util.FileUtils;
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.LinkedList;
-import java.util.Locale;
+import static org.junit.Assert.assertNotEquals;
-public class WarExplodedMojoTest
- extends AbstractWarExplodedMojoTest
-{
+public class WarExplodedMojoTest extends AbstractWarExplodedMojoTest {
- protected File getPomFile()
- {
- return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" );
+ protected File getPomFile() {
+ return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml");
}
- protected File getTestDirectory()
- {
- return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" );
+ protected File getTestDirectory() {
+ return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir");
}
/**
* @throws Exception in case of an error.
*/
- public void testSimpleExplodedWar()
- throws Exception
- {
+ public void testSimpleExplodedWar() throws Exception {
// setup test data
String testId = "SimpleExplodedWar";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File webAppResource = new File( getTestDirectory(), testId + "-resources" );
- File webAppDirectory = new File( getTestDirectory(), testId );
- File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
- ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File webAppResource = new File(getTestDirectory(), testId + "-resources");
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File sampleResource = new File(webAppResource, "pix/panis_na.jpg");
+ ResourceStub[] resources = new ResourceStub[] {new ResourceStub()};
- createFile( sampleResource );
+ createFile(sampleResource);
- assertTrue( "sampeResource not found", sampleResource.exists() );
+ assertTrue("sampeResource not found", sampleResource.exists());
// configure mojo
- resources[0].setDirectory( webAppResource.getAbsolutePath() );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "webResources", resources );
+ resources[0].setDirectory(webAppResource.getAbsolutePath());
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "webResources", resources);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedWebResourceFile = new File( webAppDirectory, "pix/panis_na.jpg" );
- File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
- File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
-
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
- assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedWebResourceFile = new File(webAppDirectory, "pix/panis_na.jpg");
+ File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF");
+ File expectedMETAINFDir = new File(webAppDirectory, "META-INF");
+
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists());
+ assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -106,40 +99,38 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testSimpleExplodedWarWTargetPath()
- throws Exception
- {
+ public void testSimpleExplodedWarWTargetPath() throws Exception {
// setup test data
String testId = "SimpleExplodedWar";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File webAppResource = new File( getTestDirectory(), "resources" );
- File webAppDirectory = new File( getTestDirectory(), testId );
- File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
- ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File webAppResource = new File(getTestDirectory(), "resources");
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File sampleResource = new File(webAppResource, "pix/panis_na.jpg");
+ ResourceStub[] resources = new ResourceStub[] {new ResourceStub()};
- createFile( sampleResource );
+ createFile(sampleResource);
// configure mojo
- resources[0].setDirectory( webAppResource.getAbsolutePath() );
- resources[0].setTargetPath( "targetPath" );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "webResources", resources );
+ resources[0].setDirectory(webAppResource.getAbsolutePath());
+ resources[0].setTargetPath("targetPath");
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "webResources", resources);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedWebResourceFile = new File( webAppDirectory, "targetPath/pix/panis_na.jpg" );
- File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
- File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
-
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
- assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedWebResourceFile = new File(webAppDirectory, "targetPath/pix/panis_na.jpg");
+ File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF");
+ File expectedMETAINFDir = new File(webAppDirectory, "META-INF");
+
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists());
+ assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -150,33 +141,31 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithCustomWebXML()
- throws Exception
- {
+ public void testExplodedWar_WithCustomWebXML() throws Exception {
// setup test data
String testId = "ExplodedWar_WithCustomWebXML";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
- File webAppDirectory = new File( getTestDirectory(), testId );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+ File webAppDirectory = new File(getTestDirectory(), testId);
// configure mojo
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
- File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
+ File expectedMETAINFDir = new File(webAppDirectory, "META-INF");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
- assertEquals( "WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead( expectedWEBXMLFile ) );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
+ assertEquals("WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead(expectedWEBXMLFile));
// house keeping
expectedWebSourceFile.delete();
@@ -188,33 +177,32 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithContainerConfigXML()
- throws Exception
- {
+ public void testExplodedWar_WithContainerConfigXML() throws Exception {
// setup test data
String testId = "ExplodedWar_WithContainerConfigXML";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File classesDir = createClassesDir( testId, true );
- File webAppSource = createWebAppSource( testId );
- File xmlSource = createXMLConfigDir( testId, new String[] { "config.xml" } );
- File webAppDirectory = new File( getTestDirectory(), testId );
+ File classesDir = createClassesDir(testId, true);
+ File webAppSource = createWebAppSource(testId);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"config.xml"});
+ File webAppDirectory = new File(getTestDirectory(), testId);
// configure mojo
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- mojo.setContainerConfigXML( new File( xmlSource, "config.xml" ) );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ mojo.setContainerConfigXML(new File(xmlSource, "config.xml"));
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedContainerConfigXMLFile = new File( webAppDirectory, "META-INF/config.xml" );
- File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
-
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
- assertTrue( "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(),
- expectedContainerConfigXMLFile.exists() );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedContainerConfigXMLFile = new File(webAppDirectory, "META-INF/config.xml");
+ File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF");
+
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
+ assertTrue(
+ "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(),
+ expectedContainerConfigXMLFile.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -226,41 +214,39 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithSimpleExternalWARFile()
- throws Exception
- {
+ public void testExplodedWar_WithSimpleExternalWARFile() throws Exception {
// setup test data
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
+ WarArtifactStub warArtifact = new WarArtifactStub(getBasedir());
String testId = "ExplodedWar_WithSimpleExternalWARFile";
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
File simpleWarFile = warArtifact.getFile();
- assertTrue( "simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists() );
+ assertTrue("simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists());
- createDir( workDirectory );
+ createDir(workDirectory);
// configure mojo
- project.addArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ project.addArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
// validate operation - META-INF is automatically excluded so remove the file from the list
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
- File expectedWARFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
+ File expectedWARFile = new File(webAppDirectory, "/org/sample/company/test.jsp");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
// check simple.war in the unit test dir under resources to verify the list of files
- assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
- assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() );
+ assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
+ assertTrue("war file not found: " + expectedWARFile.toString(), expectedWARFile.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -273,48 +259,47 @@ public class WarExplodedMojoTest
* Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
* @throws Exception in case of an error.
*/
- public void testExplodedWarMergeWarLocalFileOverride()
- throws Exception
- {
+ public void testExplodedWarMergeWarLocalFileOverride() throws Exception {
// setup test data
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
+ WarArtifactStub warArtifact = new WarArtifactStub(getBasedir());
String testId = "testExplodedWarMergeWarLocalFileOverride";
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = getWebAppSource( testId );
- File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
- createFile( simpleJSP );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = getWebAppSource(testId);
+ File simpleJSP = new File(webAppSource, "org/sample/company/test.jsp");
+ createFile(simpleJSP);
- File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
- createDir( workDirectory );
+ File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
+ createDir(workDirectory);
- File classesDir = createClassesDir( testId, true );
+ File classesDir = createClassesDir(testId, true);
// configure mojo
- project.addArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ project.addArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
// validate operation
- File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
+ File expectedFile = new File(webAppDirectory, "/org/sample/company/test.jsp");
- assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
- assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
+ assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists());
+ assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile));
// check when the merged war file is newer - so set an old time on the local file
- long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
- simpleJSP.setLastModified( time );
- expectedFile.setLastModified( time );
-
- project.addArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ long time =
+ new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2005-1-1").getTime();
+ simpleJSP.setLastModified(time);
+ expectedFile.setLastModified(time);
+
+ project.addArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
- assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
- assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
+ assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists());
+ assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile));
// house keeping
expectedFile.delete();
@@ -378,35 +363,33 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithEJB()
- throws Exception
- {
+ public void testExplodedWar_WithEJB() throws Exception {
// setup test data
String testId = "ExplodedWar_WithEJB";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
File ejbFile = ejbArtifact.getFile();
- assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
+ assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists());
// configure mojo
- project.addArtifact( ejbArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(ejbArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
+ File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar");
// File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -414,35 +397,33 @@ public class WarExplodedMojoTest
expectedEJBArtifact.delete();
}
- public void testExplodedWarWithJar()
- throws Exception
- {
+ public void testExplodedWarWithJar() throws Exception {
// setup test data
String testId = "ExplodedWarWithJar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
File jarFile = jarArtifact.getFile();
- assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
+ assertTrue("jar not found: " + jarFile.toString(), jarFile.exists());
// configure mojo
- project.addArtifact( jarArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(jarArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" );
+ File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -453,34 +434,32 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithEJBClient()
- throws Exception
- {
+ public void testExplodedWar_WithEJBClient() throws Exception {
// setup test data
String testId = "ExplodedWar_WithEJB";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir());
File ejbFile = ejbArtifact.getFile();
- assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
+ assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists());
// configure mojo
- project.addArtifact( ejbArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(ejbArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" );
+ File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -491,34 +470,32 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithTLD()
- throws Exception
- {
+ public void testExplodedWar_WithTLD() throws Exception {
// setup test data
String testId = "ExplodedWar_WithTLD";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir());
File tldFile = tldArtifact.getFile();
- assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() );
+ assertTrue("tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists());
// configure mojo
- project.addArtifact( tldArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(tldArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" );
+ File expectedTLDArtifact = new File(webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -529,34 +506,32 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithPAR()
- throws Exception
- {
+ public void testExplodedWar_WithPAR() throws Exception {
// setup test data
String testId = "ExplodedWar_WithPAR";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- PARArtifactStub parartifact = new PARArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ PARArtifactStub parartifact = new PARArtifactStub(getBasedir());
File parFile = parartifact.getFile();
- assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() );
+ assertTrue("par not found: " + parFile.getAbsolutePath(), parFile.exists());
// configure mojo
- project.addArtifact( parartifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(parartifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar" );
+ File expectedPARArtifact = new File(webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -567,36 +542,34 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithAar()
- throws Exception
- {
+ public void testExplodedWarWithAar() throws Exception {
// setup test data
String testId = "ExplodedWarWithAar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
// Fake here since the aar artifact handler does not exist: no biggie
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler );
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), artifactHandler);
File aarFile = aarArtifact.getFile();
- assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() );
+ assertTrue("jar not found: " + aarFile.toString(), aarFile.exists());
// configure mojo
- project.addArtifact( aarArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(aarArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" );
+ File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -607,36 +580,34 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithMar()
- throws Exception
- {
+ public void testExplodedWarWithMar() throws Exception {
// setup test data
String testId = "ExplodedWarWithMar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
// Fake here since the mar artifact handler does not exist: no biggie
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler );
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler);
File marFile = marArtifact.getFile();
- assertTrue( "jar not found: " + marFile.toString(), marFile.exists() );
+ assertTrue("jar not found: " + marFile.toString(), marFile.exists());
// configure mojo
- project.addArtifact( marArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(marArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar" );
+ File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -647,36 +618,34 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithXar()
- throws Exception
- {
+ public void testExplodedWarWithXar() throws Exception {
// setup test data
String testId = "ExplodedWarWithXar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
// Fake here since the xar artifact handler does not exist: no biggie
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- ArtifactStub xarArtifact = new XarArtifactStub( getBasedir(), artifactHandler );
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler);
File xarFile = xarArtifact.getFile();
- assertTrue( "jar not found: " + xarFile.toString(), xarFile.exists() );
+ assertTrue("jar not found: " + xarFile.toString(), xarFile.exists());
// configure mojo
- project.addArtifact( xarArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(xarArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar" );
+ File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -687,41 +656,39 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithDuplicateDependencies()
- throws Exception
- {
+ public void testExplodedWar_WithDuplicateDependencies() throws Exception {
// setup test data
String testId = "ExplodedWar_WithDuplicateDependencies";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
- EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
+ EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir());
File ejbFile = ejbArtifact.getFile();
// ejbArtifact has a hard coded file, only one assert is needed
- assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
+ assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists());
// configure mojo
- ejbArtifact.setGroupId( "org.sample.ejb" );
- ejbArtifactDup.setGroupId( "org.dup.ejb" );
- project.addArtifact( ejbArtifact );
- project.addArtifact( ejbArtifactDup );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ ejbArtifact.setGroupId("org.sample.ejb");
+ ejbArtifactDup.setGroupId("org.dup.ejb");
+ project.addArtifact(ejbArtifact);
+ project.addArtifact(ejbArtifactDup);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" );
- File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" );
+ File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar");
+ File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
- assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
+ assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -733,47 +700,45 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_DuplicateWithClassifier()
- throws Exception
- {
+ public void testExplodedWar_DuplicateWithClassifier() throws Exception {
// setup test data
String testId = "ExplodedWar_DuplicateWithClassifier";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
- EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
+ EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier(getBasedir());
File ejbFile = ejbArtifact.getFile();
// ejbArtifact has a hard coded file, only one assert is needed
- assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
+ assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists());
// configure mojo
- ejbArtifact.setGroupId( "org.sample.ejb" );
- ejbArtifactDup.setGroupId( "org.sample.ejb" );
+ ejbArtifact.setGroupId("org.sample.ejb");
+ ejbArtifactDup.setGroupId("org.sample.ejb");
- ejbArtifactDup.setClassifier( "classifier" );
+ ejbArtifactDup.setClassifier("classifier");
- project.addArtifact( ejbArtifact );
- project.addArtifact( ejbArtifactDup );
+ project.addArtifact(ejbArtifact);
+ project.addArtifact(ejbArtifactDup);
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
- File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
+ File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar");
+ File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
- assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
+ assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -785,29 +750,27 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithClasses()
- throws Exception
- {
+ public void testExplodedWar_WithClasses() throws Exception {
// setup test data
String testId = "ExplodedWar_WithClasses";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
// configure mojo
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
+ File expectedClass = new File(webAppDirectory, "WEB-INF/classes/sample-servlet.class");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("classes not found: " + expectedClass.toString(), expectedClass.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -818,32 +781,30 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithSourceIncludeExclude()
- throws Exception
- {
+ public void testExplodedWar_WithSourceIncludeExclude() throws Exception {
// setup test data
String testId = "ExplodedWar_WithSourceIncludeExclude";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File webAppDirectory = new File( getTestDirectory(), testId );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File webAppDirectory = new File(getTestDirectory(), testId);
// configure mojo
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
- setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "warSourceIncludes", "**/*sit.jsp");
+ setVariableValueToObject(mojo, "warSourceExcludes", "**/last*.*");
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
- File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedWEBXMLDir = new File(webAppDirectory, "WEB-INF");
+ File expectedMETAINFDir = new File(webAppDirectory, "META-INF");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertFalse("source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -855,46 +816,44 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWar_WithWarDependencyIncludeExclude()
- throws Exception
- {
+ public void testExplodedWar_WithWarDependencyIncludeExclude() throws Exception {
// setup test data
String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
+ IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir());
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
- assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
+ assertTrue("war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists());
- createDir( workDirectory );
+ createDir(workDirectory);
// configure mojo
- project.addArtifact( includeexcludeWarArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
- setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
- setVariableValueToObject( mojo, "workDirectory", workDirectory );
+ project.addArtifact(includeexcludeWarArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml");
+ setVariableValueToObject(mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF");
+ setVariableValueToObject(mojo, "workDirectory", workDirectory);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
- File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
- File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
- File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
- File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
-
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
+ File expectedManifestFile = new File(webAppDirectory, "META-INF/MANIFEST.MF");
+ File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml");
+ File expectedIncludedWARFile = new File(webAppDirectory, "/org/sample/company/testInclude.jsp");
+ File expectedExcludedWarfile = new File(webAppDirectory, "/org/sample/companyExclude/test.jsp");
+
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
// check include-exclude.war in the unit test dir under resources to verify the list of files
- assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
- assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
- assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
- assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
+ assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists());
+ assertFalse("manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists());
+ assertTrue("war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists());
+ assertFalse("war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -908,18 +867,16 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithSourceModificationCheck()
- throws Exception
- {
+ public void testExplodedWarWithSourceModificationCheck() throws Exception {
// setup test data
String testId = "ExplodedWarWithSourceModificationCheck";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File webAppDirectory = new File( getTestDirectory(), testId );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File webAppDirectory = new File(getTestDirectory(), testId);
// configure mojo
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
// destination file is already created manually containing an "error" string
// source is newer than the destination file
@@ -927,20 +884,22 @@ public class WarExplodedMojoTest
// validate operation
- File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
- File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF");
+ File expectedMETAINFDir = new File(webAppDirectory, "META-INF");
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
// 1st phase destination is older than source
// destination starts with a value of error replaced with a blank source
- assertNotEquals( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
- "error", FileUtils.fileRead( expectedWebSourceFile ) );
+ assertNotEquals(
+ "source files not updated with new copy: " + expectedWebSourceFile.toString(),
+ "error",
+ FileUtils.fileRead(expectedWebSourceFile));
// TODO: uncomment when lastModified problem is resolved
// FileWriter writer = new FileWriter(expectedWebSourceFile);
@@ -964,36 +923,34 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithOutputFileNameMapping()
- throws Exception
- {
+ public void testExplodedWarWithOutputFileNameMapping() throws Exception {
// setup test data
String testId = "ExplodedWarWithFileNameMapping";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
File jarFile = jarArtifact.getFile();
- assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
+ assertTrue("jar not found: " + jarFile.toString(), jarFile.exists());
// configure mojo
- project.addArtifact( jarArtifact );
- mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ project.addArtifact(jarArtifact);
+ mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@");
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
+ File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/lib/jarartifact.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
@@ -1004,42 +961,40 @@ public class WarExplodedMojoTest
/**
* @throws Exception in case of an error.
*/
- public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
- throws Exception
- {
+ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() throws Exception {
// setup test data
String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
- File webAppDirectory = new File( getTestDirectory(), testId );
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
- EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir());
+ EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir());
File ejbFile = ejbArtifact.getFile();
// ejbArtifact has a hard coded file, only one assert is needed
- assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
+ assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists());
// configure mojo
- ejbArtifact.setGroupId( "org.sample.ejb" );
- ejbArtifactDup.setGroupId( "org.dup.ejb" );
- project.addArtifact( ejbArtifact );
- project.addArtifact( ejbArtifactDup );
- mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
+ ejbArtifact.setGroupId("org.sample.ejb");
+ ejbArtifactDup.setGroupId("org.dup.ejb");
+ project.addArtifact(ejbArtifact);
+ project.addArtifact(ejbArtifactDup);
+ mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@");
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
+ File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
- File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
- File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
+ File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar");
+ File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
- assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists());
+ assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java
index 8cf4557..f35b355 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,73 +16,64 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
-import org.apache.maven.plugins.war.stub.ResourceStub;
+package org.apache.maven.plugins.war;
import java.io.File;
import java.util.LinkedList;
-public class WarInPlaceMojoTest
- extends AbstractWarMojoTest
-{
- protected static final String pomFilePath = getBasedir()
- + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml";
+import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
+import org.apache.maven.plugins.war.stub.ResourceStub;
+
+public class WarInPlaceMojoTest extends AbstractWarMojoTest {
+ protected static final String pomFilePath =
+ getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml";
- protected File getTestDirectory()
- throws Exception
- {
- return new File( getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir" );
+ protected File getTestDirectory() throws Exception {
+ return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir");
}
private WarInPlaceMojo mojo;
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- mojo = (WarInPlaceMojo) lookupMojo( "inplace", pomFilePath );
- assertNotNull( mojo );
+ mojo = (WarInPlaceMojo) lookupMojo("inplace", pomFilePath);
+ assertNotNull(mojo);
}
- public void testEnvironment()
- throws Exception
- {
+ public void testEnvironment() throws Exception {
// see setUp
}
- public void testSimpleExplodedInplaceWar()
- throws Exception
- {
+ public void testSimpleExplodedInplaceWar() throws Exception {
// setup test data
String testId = "SimpleExplodedInplaceWar";
MavenProjectBasicStub project = new MavenProjectBasicStub();
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File webAppResource = new File( getTestDirectory(), "resources" );
- File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
- ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File webAppResource = new File(getTestDirectory(), "resources");
+ File sampleResource = new File(webAppResource, "pix/panis_na.jpg");
+ ResourceStub[] resources = new ResourceStub[] {new ResourceStub()};
- createFile( sampleResource );
+ createFile(sampleResource);
// configure mojo
- resources[0].setDirectory( webAppResource.getAbsolutePath() );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, null, project );
- setVariableValueToObject( mojo, "webResources", resources );
+ resources[0].setDirectory(webAppResource.getAbsolutePath());
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, null, project);
+ setVariableValueToObject(mojo, "webResources", resources);
mojo.execute();
// validate operation
- File expectedWebSourceFile = new File( webAppSource, "pansit.jsp" );
- File expectedWebSource2File = new File( webAppSource, "org/web/app/last-exile.jsp" );
- File expectedWebResourceFile = new File( webAppSource, "pix/panis_na.jpg" );
- File expectedWEBINFDir = new File( webAppSource, "WEB-INF" );
- File expectedMETAINFDir = new File( webAppSource, "META-INF" );
+ File expectedWebSourceFile = new File(webAppSource, "pansit.jsp");
+ File expectedWebSource2File = new File(webAppSource, "org/web/app/last-exile.jsp");
+ File expectedWebResourceFile = new File(webAppSource, "pix/panis_na.jpg");
+ File expectedWEBINFDir = new File(webAppSource, "WEB-INF");
+ File expectedMETAINFDir = new File(webAppSource, "META-INF");
- assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
- assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
- assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
- assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
- assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
+ assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
+ assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
+ assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists());
+ assertTrue("WEB-INF not found", expectedWEBINFDir.exists());
+ assertTrue("META-INF not found", expectedMETAINFDir.exists());
}
}
diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
index 84a8ce8..597e29a 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.IOException;
@@ -41,495 +40,513 @@ import org.codehaus.plexus.util.IOUtil;
/**
* comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest
*/
-public class WarMojoTest
- extends AbstractWarMojoTest
-{
+public class WarMojoTest extends AbstractWarMojoTest {
WarMojo mojo;
- private static File pomFile = new File( getBasedir(),
- "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" );
+ private static File pomFile =
+ new File(getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml");
- protected File getTestDirectory()
- {
- return new File( getBasedir(), "target/test-classes/unit/warmojotest" );
+ protected File getTestDirectory() {
+ return new File(getBasedir(), "target/test-classes/unit/warmojotest");
}
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- mojo = (WarMojo) lookupMojo( "war", pomFile );
+ mojo = (WarMojo) lookupMojo("war", pomFile);
}
- public void testEnvironment()
- throws Exception
- {
+ public void testEnvironment() throws Exception {
// see setup
}
- public void testSimpleWar()
- throws Exception
- {
+ public void testSimpleWar() throws Exception {
String testId = "SimpleWar";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
- "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testSimpleWarPackagingExcludeWithIncludesRegEx()
- throws Exception
- {
+ public void testSimpleWarPackagingExcludeWithIncludesRegEx() throws Exception {
String testId = "SimpleWarPackagingExcludeWithIncludesRegEx";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
- setVariableValueToObject( mojo, "packagingIncludes", "%regex[(.(?!exile))+]" );
-// setVariableValueToObject( mojo, "packagingIncludes", "%regex" );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
+ setVariableValueToObject(mojo, "packagingIncludes", "%regex[(.(?!exile))+]");
+ // setVariableValueToObject( mojo, "packagingIncludes", "%regex" );
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
- mojo.getWebXml().toString(), null, null, null, }, new String[] { "org/web/app/last-exile.jsp" } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {
+ null, mojo.getWebXml().toString(), null, null, null,
+ },
+ new String[] {"org/web/app/last-exile.jsp"});
}
- public void testClassifier()
- throws Exception
- {
+ public void testClassifier() throws Exception {
String testId = "Classifier";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
ProjectHelperStub projectHelper = new ProjectHelperStub();
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "projectHelper", projectHelper );
- setVariableValueToObject( mojo, "classifier", "test-classifier" );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "projectHelper", projectHelper);
+ setVariableValueToObject(mojo, "classifier", "test-classifier");
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple-test-classifier.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
- "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple-test-classifier.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testPrimaryArtifact()
- throws Exception
- {
+ public void testPrimaryArtifact() throws Exception {
String testId = "PrimaryArtifact";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
ProjectHelperStub projectHelper = new ProjectHelperStub();
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- warArtifact.setFile( new File( "error.war" ) );
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "projectHelper", projectHelper );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ warArtifact.setFile(new File("error.war"));
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "projectHelper", projectHelper);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
- "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testNotPrimaryArtifact()
- throws Exception
- {
+ public void testNotPrimaryArtifact() throws Exception {
// use a different pom
- File pom = new File( getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml" );
- mojo = (WarMojo) lookupMojo( "war", pom );
+ File pom = new File(getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml");
+ mojo = (WarMojo) lookupMojo("war", pom);
String testId = "NotPrimaryArtifact";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
ProjectHelperStub projectHelper = new ProjectHelperStub();
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- warArtifact.setFile( new File( "error.war" ) );
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "projectHelper", projectHelper );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ warArtifact.setFile(new File("error.war"));
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "projectHelper", projectHelper);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp",
- "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testMetaInfContent()
- throws Exception
- {
+ public void testMetaInfContent() throws Exception {
String testId = "SimpleWarWithMetaInfContent";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
// Create the sample config.xml
- final File configFile = new File( webAppSource, "META-INF/config.xml" );
- createFile( configFile, "<config></config>" );
+ final File configFile = new File(webAppSource, "META-INF/config.xml");
+ createFile(configFile, "<config></config>");
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml",
- "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "META-INF/config.xml",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testMetaInfContentWithContainerConfig()
- throws Exception
- {
+ public void testMetaInfContentWithContainerConfig() throws Exception {
String testId = "SimpleWarWithContainerConfig";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
// Create the sample config.xml
- final File configFile = new File( webAppSource, "META-INF/config.xml" );
- createFile( configFile, "<config></config>" );
+ final File configFile = new File(webAppSource, "META-INF/config.xml");
+ createFile(configFile, "<config></config>");
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
- mojo.setContainerConfigXML( configFile );
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
+ mojo.setContainerConfigXML(configFile);
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml",
- "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
- mojo.getWebXml().toString(), null, null, null, null } );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "META-INF/config.xml",
+ "WEB-INF/web.xml",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null});
}
- public void testFailOnMissingWebXmlFalse()
- throws Exception
- {
+ public void testFailOnMissingWebXmlFalse() throws Exception {
String testId = "SimpleWarMissingWebXmlFalse";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
-
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setFailOnMissingWebXml( false );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setFailOnMissingWebXml(false);
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple.war" );
- final Map<String, JarEntry> jarContent =
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp",
- "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null,
- null, null, null } );
-
- assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) );
+ File expectedJarFile = new File(outputDir, "simple.war");
+ final Map<String, JarEntry> jarContent = assertJarContent(
+ expectedJarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, null, null, null, null});
+
+ assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml"));
}
- public void testFailOnMissingWebXmlTrue()
- throws Exception
- {
+ public void testFailOnMissingWebXmlTrue() throws Exception {
String testId = "SimpleWarMissingWebXmlTrue";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setFailOnMissingWebXml( true );
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setFailOnMissingWebXml(true);
- try
- {
+ try {
mojo.execute();
- fail( "Building of the war isn't possible because web.xml is missing" );
- }
- catch ( MojoExecutionException e )
- {
+ fail("Building of the war isn't possible because web.xml is missing");
+ } catch (MojoExecutionException e) {
// expected behaviour
}
}
-
- public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used()
- throws Exception
- {
+
+ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception {
String testId = "SimpleWarUnderServlet30";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
-
- final ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- JarArtifactStub jarArtifactStub = new JarArtifactStub( getBasedir(), artifactHandler );
- jarArtifactStub.setFile( new File( getBasedir(),
- "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar" ) );
- jarArtifactStub.setScope( Artifact.SCOPE_PROVIDED );
- project.addArtifact( jarArtifactStub );
-
- project.setArtifact( warArtifact );
- project.setFile( warArtifact.getFile() );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+
+ final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler);
+ jarArtifactStub.setFile(
+ new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar"));
+ jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED);
+ project.addArtifact(jarArtifactStub);
+
+ project.setArtifact(warArtifact);
+ project.setFile(warArtifact.getFile());
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
mojo.execute();
// validate war file
- File expectedWarFile = new File( outputDir, "simple.war" );
- final Map<String, JarEntry> jarContent =
- assertJarContent( expectedWarFile,
- new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
- "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" },
- new String[] { null, null, null, null, null } );
-
- assertFalse( "web.xml should be missing", jarContent.containsKey( "WEB-INF/web.xml" ) );
+ File expectedWarFile = new File(outputDir, "simple.war");
+ final Map<String, JarEntry> jarContent = assertJarContent(
+ expectedWarFile,
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "pansit.jsp",
+ "org/web/app/last-exile.jsp",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml",
+ "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties"
+ },
+ new String[] {null, null, null, null, null});
+
+ assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml"));
}
- public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed()
- throws Exception
- {
+ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() throws Exception {
String testId = "SimpleWarNotUnderServlet30";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
- project.setArtifact( warArtifact );
- project.setFile( warArtifact.getFile() );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
+ project.setArtifact(warArtifact);
+ project.setFile(warArtifact.getFile());
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
- try
- {
+ try {
mojo.execute();
- fail( "Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project "
- + "does not depend on Servlet 3.0" );
- }
- catch ( MojoExecutionException e )
- {
+ fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project "
+ + "does not depend on Servlet 3.0");
+ } catch (MojoExecutionException e) {
// expected behaviour
}
}
- public void testAttachClasses()
- throws Exception
- {
+ public void testAttachClasses() throws Exception {
String testId = "AttachClasses";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
- mojo.setAttachClasses( true );
- mojo.setClassesClassifier( "classes" );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
+ mojo.setAttachClasses(true);
+ mojo.setClassesClassifier("classes");
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple-classes.jar" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" },
- new String[] { null, null } );
+ File expectedJarFile = new File(outputDir, "simple-classes.jar");
+ assertJarContent(
+ expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.class"}, new String[] {null, null
+ });
}
- public void testAttachClassesWithCustomClassifier()
- throws Exception
- {
+ public void testAttachClassesWithCustomClassifier() throws Exception {
String testId = "AttachClassesCustomClassifier";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifact4CCStub warArtifact = new WarArtifact4CCStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, false );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
-
- project.setArtifact( warArtifact );
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
- mojo.setAttachClasses( true );
- mojo.setClassesClassifier( "mystuff" );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, false);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+
+ project.setArtifact(warArtifact);
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
+ mojo.setAttachClasses(true);
+ mojo.setClassesClassifier("mystuff");
mojo.execute();
// validate jar file
- File expectedJarFile = new File( outputDir, "simple-mystuff.jar" );
- assertJarContent( expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" },
- new String[] { null, null } );
+ File expectedJarFile = new File(outputDir, "simple-mystuff.jar");
+ assertJarContent(
+ expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.class"}, new String[] {null, null
+ });
}
- protected Map<String, JarEntry> assertJarContent( final File expectedJarFile, final String[] files,
- final String[] filesContent )
- throws IOException
- {
- return assertJarContent( expectedJarFile, files, filesContent, null );
+ protected Map<String, JarEntry> assertJarContent(
+ final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException {
+ return assertJarContent(expectedJarFile, files, filesContent, null);
}
- protected Map<String, JarEntry> assertJarContent( final File expectedJarFile, final String[] files,
- final String[] filesContent, final String[] mustNotBeInJar )
- throws IOException
- {
+ protected Map<String, JarEntry> assertJarContent(
+ final File expectedJarFile,
+ final String[] files,
+ final String[] filesContent,
+ final String[] mustNotBeInJar)
+ throws IOException {
// Sanity check
- assertEquals( "Could not test, files and filesContent length does not match", files.length, filesContent.length );
+ assertEquals("Could not test, files and filesContent length does not match", files.length, filesContent.length);
- assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
+ assertTrue("war file not created: " + expectedJarFile.toString(), expectedJarFile.exists());
final Map<String, JarEntry> jarContent = new HashMap<>();
- try ( JarFile jarFile = new JarFile( expectedJarFile ) ) {
+ try (JarFile jarFile = new JarFile(expectedJarFile)) {
Enumeration<JarEntry> enumeration = jarFile.entries();
- while ( enumeration.hasMoreElements() )
- {
+ while (enumeration.hasMoreElements()) {
JarEntry entry = enumeration.nextElement();
- Object previousValue = jarContent.put( entry.getName(), entry );
- assertNull( "Duplicate Entry in Jar File: " + entry.getName(), previousValue );
+ Object previousValue = jarContent.put(entry.getName(), entry);
+ assertNull("Duplicate Entry in Jar File: " + entry.getName(), previousValue);
}
-
- for ( int i = 0; i < files.length; i++ )
- {
+
+ for (int i = 0; i < files.length; i++) {
String file = files[i];
-
- assertTrue( "File[" + file + "] not found in archive", jarContent.containsKey( file ) );
- if ( filesContent[i] != null )
- {
- assertEquals( "Content of file[" + file + "] does not match", filesContent[i],
- IOUtil.toString( jarFile.getInputStream( jarContent.get( file ) ) ) );
+
+ assertTrue("File[" + file + "] not found in archive", jarContent.containsKey(file));
+ if (filesContent[i] != null) {
+ assertEquals(
+ "Content of file[" + file + "] does not match",
+ filesContent[i],
+ IOUtil.toString(jarFile.getInputStream(jarContent.get(file))));
}
}
- if ( mustNotBeInJar != null )
- {
- for ( String file : mustNotBeInJar )
- {
- assertFalse( "File[" + file + "] found in archive", jarContent.containsKey( file ) );
-
+ if (mustNotBeInJar != null) {
+ for (String file : mustNotBeInJar) {
+ assertFalse("File[" + file + "] found in archive", jarContent.containsKey(file));
}
}
return jarContent;
}
}
-
}
diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java
index d944e6f..5d7f17c 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,10 +16,7 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-import org.apache.maven.plugins.war.overlay.DefaultOverlay;
-import org.codehaus.plexus.util.FileUtils;
+package org.apache.maven.plugins.war;
import java.io.File;
import java.io.FileFilter;
@@ -30,228 +25,203 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugins.war.overlay.DefaultOverlay;
+import org.codehaus.plexus.util.FileUtils;
+
/**
* @author Stephane Nicoll
*/
-public class WarOverlaysTest
- extends AbstractWarExplodedMojoTest
-{
+public class WarOverlaysTest extends AbstractWarExplodedMojoTest {
- private static File pomFile = new File( getBasedir(), "target/test-classes/unit/waroverlays/default.xml" );
+ private static File pomFile = new File(getBasedir(), "target/test-classes/unit/waroverlays/default.xml");
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- generateFullOverlayWar( "overlay-full-1" );
- generateFullOverlayWar( "overlay-full-2" );
- generateFullOverlayWar( "overlay-full-3" );
+ generateFullOverlayWar("overlay-full-1");
+ generateFullOverlayWar("overlay-full-2");
+ generateFullOverlayWar("overlay-full-3");
}
- protected File getPomFile()
- {
+ protected File getPomFile() {
return pomFile;
}
- protected File getTestDirectory()
- {
- return new File( getBasedir(), "target/test-classes/unit/waroverlays" );
+ protected File getTestDirectory() {
+ return new File(getBasedir(), "target/test-classes/unit/waroverlays");
}
- public void testEnvironment()
- throws Exception
- {
+ public void testEnvironment() throws Exception {
// see setup
}
- public void testNoOverlay()
- throws Exception
- {
+ public void testNoOverlay() throws Exception {
// setup test data
final String testId = "no-overlay";
- final File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+ final File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
- final File webAppDirectory = setUpMojo( testId, null );
- try
- {
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ final File webAppDirectory = setUpMojo(testId, null);
+ try {
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// Validate content of the webapp
- assertDefaultContent( webAppDirectory );
- assertWebXml( webAppDirectory );
- }
- finally
- {
- cleanDirectory( webAppDirectory );
+ assertDefaultContent(webAppDirectory);
+ assertWebXml(webAppDirectory);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
}
- public void testDefaultOverlay()
- throws Exception
- {
+ public void testDefaultOverlay() throws Exception {
// setup test data
final String testId = "default-overlay";
// Add an overlay
- final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
+ final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
- final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay});
final List<File> assertedFiles = new ArrayList<>();
- try
- {
+ try {
mojo.execute();
- assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
- assertedFiles.addAll( assertWebXml( webAppDirectory ) );
- assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp" },
- "overlay file not found" ) );
+ assertedFiles.addAll(assertDefaultContent(webAppDirectory));
+ assertedFiles.addAll(assertWebXml(webAppDirectory));
+ assertedFiles.addAll(assertCustomContent(
+ webAppDirectory, new String[] {"index.jsp", "login.jsp"}, "overlay file not found"));
// index and login come from overlay1
- assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
+ assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
// Ok now check that there is no more files/directories
- final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
- assertWebAppContent( webAppDirectory, assertedFiles, filter );
- }
- finally
- {
- cleanDirectory( webAppDirectory );
+ final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH});
+ assertWebAppContent(webAppDirectory, assertedFiles, filter);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
}
- public void testDefaultOverlays()
- throws Exception
- {
+ public void testDefaultOverlays() throws Exception {
// setup test data
final String testId = "default-overlays";
// Add an overlay
- final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-two" );
+ final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two");
- final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay, overlay2 } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay, overlay2});
final List<File> assertedFiles = new ArrayList<>();
- try
- {
+ try {
mojo.execute();
- assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
- assertedFiles.addAll( assertWebXml( webAppDirectory ) );
- assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp",
- "admin.jsp" }, "overlay file not found" ) );
+ assertedFiles.addAll(assertDefaultContent(webAppDirectory));
+ assertedFiles.addAll(assertWebXml(webAppDirectory));
+ assertedFiles.addAll(assertCustomContent(
+ webAppDirectory, new String[] {"index.jsp", "login.jsp", "admin.jsp"}, "overlay file not found"));
// index and login come from overlay1
- assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
+ assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
// admin comes from overlay2
// index and login comes from overlay1
- assertOverlayedFile( webAppDirectory, "overlay-two", "admin.jsp" );
+ assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp");
// Ok now check that there is no more files/directories
- final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
- assertWebAppContent( webAppDirectory, assertedFiles, filter );
- }
- finally
- {
- cleanDirectory( webAppDirectory );
+ final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH});
+ assertWebAppContent(webAppDirectory, assertedFiles, filter);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
}
/**
* Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
- *
+ *
* It also tests completeness of the resulting war as well as the proper order of dependencies.
*
* @throws Exception if any error occurs
*/
- public void testScenarioOneWithDefaulSettings()
- throws Exception
- {
+ public void testScenarioOneWithDefaulSettings() throws Exception {
// setup test data
final String testId = "scenario-one-default-settings";
// Add an overlay
- final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
- final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
+ final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
+ final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
- final File webAppDirectory =
- setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
- "org/sample/company/test.jsp", "jsp/b.jsp" } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] {
+ "org/sample/company/test.jsp", "jsp/b.jsp"
+ });
- assertScenariOne( testId, webAppDirectory );
+ assertScenariOne(testId, webAppDirectory);
}
/**
* Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
- *
+ *
* The default project is not specified in this case so it is processed first by default
*
* @throws Exception if an error occurs
*/
- public void testScenarioOneWithOverlaySettings()
- throws Exception
- {
+ public void testScenarioOneWithOverlaySettings() throws Exception {
// setup test data
final String testId = "scenario-one-overlay-settings";
// Add an overlay
- final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
- final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
+ final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
+ final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
- final File webAppDirectory =
- setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
- "org/sample/company/test.jsp", "jsp/b.jsp" } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] {
+ "org/sample/company/test.jsp", "jsp/b.jsp"
+ });
// Add the tags
final List<Overlay> overlays = new ArrayList<>();
- overlays.add( new DefaultOverlay( overlay1 ) );
- overlays.add( new DefaultOverlay( overlay2 ) );
- overlays.add( new DefaultOverlay( overlay3 ) );
- mojo.setOverlays( overlays );
+ overlays.add(new DefaultOverlay(overlay1));
+ overlays.add(new DefaultOverlay(overlay2));
+ overlays.add(new DefaultOverlay(overlay3));
+ mojo.setOverlays(overlays);
// current project ignored. Should be on top of the list
- assertScenariOne( testId, webAppDirectory );
+ assertScenariOne(testId, webAppDirectory);
}
/**
* Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
- *
+ *
* The default project is explicitely specified so this should match the default.
*
* @throws Exception if an error occurs
*/
- public void testScenarioOneWithFullSettings()
- throws Exception
- {
+ public void testScenarioOneWithFullSettings() throws Exception {
// setup test data
final String testId = "scenario-one-full-settings";
// Add an overlay
- final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
- final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
+ final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
+ final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
- final File webAppDirectory =
- setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
- "org/sample/company/test.jsp", "jsp/b.jsp" } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] {
+ "org/sample/company/test.jsp", "jsp/b.jsp"
+ });
// Add the tags
final List<Overlay> overlays = new ArrayList<>();
// Add the default project explicitely
- overlays.add( mojo.getCurrentProjectOverlay() );
+ overlays.add(mojo.getCurrentProjectOverlay());
// Other overlays
- overlays.add( new DefaultOverlay( overlay1 ) );
- overlays.add( new DefaultOverlay( overlay2 ) );
- overlays.add( new DefaultOverlay( overlay3 ) );
- mojo.setOverlays( overlays );
+ overlays.add(new DefaultOverlay(overlay1));
+ overlays.add(new DefaultOverlay(overlay2));
+ overlays.add(new DefaultOverlay(overlay3));
+ mojo.setOverlays(overlays);
// current project ignored. Should be on top of the list
- assertScenariOne( testId, webAppDirectory );
+ assertScenariOne(testId, webAppDirectory);
}
/**
@@ -261,192 +231,218 @@ public class WarOverlaysTest
* @param webAppDirectory the webapp directory
* @throws Exception if an exception occurs
*/
- private void assertScenariOne( String testId, File webAppDirectory )
- throws Exception
- {
+ private void assertScenariOne(String testId, File webAppDirectory) throws Exception {
final List<File> assertedFiles = new ArrayList<>();
- try
- {
+ try {
mojo.execute();
- assertedFiles.addAll( assertWebXml( webAppDirectory ) );
- assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
- "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
- "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
- "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
+ assertedFiles.addAll(assertWebXml(webAppDirectory));
+ assertedFiles.addAll(assertCustomContent(
+ webAppDirectory,
+ new String[] {
+ "jsp/a.jsp",
+ "jsp/b.jsp",
+ "jsp/c.jsp",
+ "jsp/d/a.jsp",
+ "jsp/d/b.jsp",
+ "jsp/d/c.jsp",
+ "org/sample/company/test.jsp",
+ "WEB-INF/classes/a.class",
+ "WEB-INF/classes/b.class",
+ "WEB-INF/classes/c.class",
+ "WEB-INF/lib/a.jar",
+ "WEB-INF/lib/b.jar",
+ "WEB-INF/lib/c.jar"
+ },
+ "overlay file not found"));
// Those files should come from the source webapp without any config
- assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" );
- assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
+ assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp");
+ assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
// Everything else comes from overlay1 (order of addition in the dependencies)
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/a.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/c.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/a.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/b.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/web.xml" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar" );
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/a.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/c.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/a.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/b.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/web.xml");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar");
// Ok now check that there is no more files/directories
- final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
- assertWebAppContent( webAppDirectory, assertedFiles, filter );
- }
- finally
- {
- cleanDirectory( webAppDirectory );
+ final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH});
+ assertWebAppContent(webAppDirectory, assertedFiles, filter);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
}
- public void testOverlaysIncludesExcludesWithMultipleDefinitions()
- throws Exception
- {
+ public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception {
// setup test data
final String testId = "overlays-includes-excludes-multiple-defs";
// Add an overlay
- final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
- final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
+ final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
+ final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
- final File webAppDirectory =
- setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
- "org/sample/company/test.jsp", "jsp/b.jsp" } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] {
+ "org/sample/company/test.jsp", "jsp/b.jsp"
+ });
- Overlay over1 = new DefaultOverlay( overlay3 );
- over1.setExcludes( "**/a.*,**/c.*,**/*.xml" );
+ Overlay over1 = new DefaultOverlay(overlay3);
+ over1.setExcludes("**/a.*,**/c.*,**/*.xml");
- Overlay over2 = new DefaultOverlay( overlay1 );
- over2.setIncludes( "jsp/d/*" );
- over2.setExcludes( "jsp/d/a.jsp" );
+ Overlay over2 = new DefaultOverlay(overlay1);
+ over2.setIncludes("jsp/d/*");
+ over2.setExcludes("jsp/d/a.jsp");
- Overlay over3 = new DefaultOverlay( overlay3 );
- over3.setIncludes( "**/*.jsp" );
+ Overlay over3 = new DefaultOverlay(overlay3);
+ over3.setIncludes("**/*.jsp");
- Overlay over4 = new DefaultOverlay( overlay2 );
+ Overlay over4 = new DefaultOverlay(overlay2);
- mojo.setOverlays( new LinkedList<>() );
- mojo.addOverlay( over1 );
- mojo.addOverlay( over2 );
- mojo.addOverlay( over3 );
- mojo.addOverlay( mojo.getCurrentProjectOverlay() );
- mojo.addOverlay( over4 );
+ mojo.setOverlays(new LinkedList<>());
+ mojo.addOverlay(over1);
+ mojo.addOverlay(over2);
+ mojo.addOverlay(over3);
+ mojo.addOverlay(mojo.getCurrentProjectOverlay());
+ mojo.addOverlay(over4);
final List<File> assertedFiles = new ArrayList<>();
- try
- {
+ try {
mojo.execute();
- assertedFiles.addAll( assertWebXml( webAppDirectory ) );
- assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
- "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
- "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
- "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
-
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/b.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
- assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" );
+ assertedFiles.addAll(assertWebXml(webAppDirectory));
+ assertedFiles.addAll(assertCustomContent(
+ webAppDirectory,
+ new String[] {
+ "jsp/a.jsp",
+ "jsp/b.jsp",
+ "jsp/c.jsp",
+ "jsp/d/a.jsp",
+ "jsp/d/b.jsp",
+ "jsp/d/c.jsp",
+ "org/sample/company/test.jsp",
+ "WEB-INF/classes/a.class",
+ "WEB-INF/classes/b.class",
+ "WEB-INF/classes/c.class",
+ "WEB-INF/lib/a.jar",
+ "WEB-INF/lib/b.jar",
+ "WEB-INF/lib/c.jar"
+ },
+ "overlay file not found"));
+
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
+ assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
// Ok now check that there is no more files/directories
- final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
- assertWebAppContent( webAppDirectory, assertedFiles, filter );
- }
- finally
- {
- cleanDirectory( webAppDirectory );
+ final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH});
+ assertWebAppContent(webAppDirectory, assertedFiles, filter);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
}
- public void testOverlaysIncludesExcludesWithMultipleDefinitions2()
- throws Exception
- {
+ public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception {
// setup test data
final String testId = "overlays-includes-excludes-multiple-defs2";
// Add an overlay
- final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
- final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
- final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
+ final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
+ final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
+ final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
- final File webAppDirectory =
- setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
- "org/sample/company/test.jsp", "jsp/b.jsp" } );
+ final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] {
+ "org/sample/company/test.jsp", "jsp/b.jsp"
+ });
- Overlay over1 = new DefaultOverlay( overlay3 );
- over1.setExcludes( "**/a.*,**/c.*,**/*.xml,jsp/b.jsp" );
+ Overlay over1 = new DefaultOverlay(overlay3);
+ over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp");
- Overlay over2 = new DefaultOverlay( overlay1 );
- over2.setIncludes( "jsp/d/*" );
- over2.setExcludes( "jsp/d/a.jsp" );
+ Overlay over2 = new DefaultOverlay(overlay1);
+ over2.setIncludes("jsp/d/*");
+ over2.setExcludes("jsp/d/a.jsp");
- Overlay over3 = new DefaultOverlay( overlay3 );
- over3.setIncludes( "**/*.jsp" );
- over3.setExcludes( "jsp/b.jsp" );
+ Overlay over3 = new DefaultOverlay(overlay3);
+ over3.setIncludes("**/*.jsp");
+ over3.setExcludes("jsp/b.jsp");
- Overlay over4 = new DefaultOverlay( overlay2 );
+ Overlay over4 = new DefaultOverlay(overlay2);
- mojo.setOverlays( new LinkedList<>() );
- mojo.addOverlay( over1 );
- mojo.addOverlay( over2 );
- mojo.addOverlay( over3 );
- mojo.addOverlay( mojo.getCurrentProjectOverlay() );
- mojo.addOverlay( over4 );
+ mojo.setOverlays(new LinkedList<>());
+ mojo.addOverlay(over1);
+ mojo.addOverlay(over2);
+ mojo.addOverlay(over3);
+ mojo.addOverlay(mojo.getCurrentProjectOverlay());
+ mojo.addOverlay(over4);
final List<File> assertedFiles = new ArrayList<>();
- try
- {
+ try {
mojo.execute();
- assertedFiles.addAll( assertWebXml( webAppDirectory ) );
- assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
- "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
- "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
- "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
-
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" );
- assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
- assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" );
- assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" );
+ assertedFiles.addAll(assertWebXml(webAppDirectory));
+ assertedFiles.addAll(assertCustomContent(
+ webAppDirectory,
+ new String[] {
+ "jsp/a.jsp",
+ "jsp/b.jsp",
+ "jsp/c.jsp",
+ "jsp/d/a.jsp",
+ "jsp/d/b.jsp",
+ "jsp/d/c.jsp",
+ "org/sample/company/test.jsp",
+ "WEB-INF/classes/a.class",
+ "WEB-INF/classes/b.class",
+ "WEB-INF/classes/c.class",
+ "WEB-INF/lib/a.jar",
+ "WEB-INF/lib/b.jar",
+ "WEB-INF/lib/c.jar"
+ },
+ "overlay file not found"));
+
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
+ assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
+ assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
+ assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
// Ok now check that there is no more files/directories
- final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
- assertWebAppContent( webAppDirectory, assertedFiles, filter );
+ final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH});
+ assertWebAppContent(webAppDirectory, assertedFiles, filter);
+ } finally {
+ cleanDirectory(webAppDirectory);
}
- finally
- {
- cleanDirectory( webAppDirectory );
- }
-
}
// Helpers
/**
* Asserts that the content of an overlayed file is correct.
- *
+ *
* Note that the {@code filePath} is relative to both the webapp directory and the overlayed directory, defined by
* the {@code overlayId}.
*
@@ -455,19 +451,18 @@ public class WarOverlaysTest
* @param filePath the relative path
* @throws IOException if an error occurred while reading the files
*/
- protected void assertOverlayedFile( File webAppDirectory, String overlayId, String filePath )
- throws IOException
- {
- final File webAppFile = new File( webAppDirectory, filePath );
- final File overlayFile = getOverlayFile( overlayId, filePath );
- assertEquals( "Wrong content for overlayed file " + filePath, FileUtils.fileRead( overlayFile ),
- FileUtils.fileRead( webAppFile ) );
-
+ protected void assertOverlayedFile(File webAppDirectory, String overlayId, String filePath) throws IOException {
+ final File webAppFile = new File(webAppDirectory, filePath);
+ final File overlayFile = getOverlayFile(overlayId, filePath);
+ assertEquals(
+ "Wrong content for overlayed file " + filePath,
+ FileUtils.fileRead(overlayFile),
+ FileUtils.fileRead(webAppFile));
}
/**
* Asserts that the content of an overlayed file is correct.
- *
+ *
* Note that the {@code filePath} is relative to both the webapp directory and the overlayed directory, defined by
* the {@code overlayId}.
*
@@ -476,19 +471,14 @@ public class WarOverlaysTest
* @param filePath the relative path
* @throws IOException if an error occurred while reading the files
*/
- protected void assertDefaultFileContent( String testId, File webAppDirectory, String filePath )
- throws Exception
- {
- final File webAppFile = new File( webAppDirectory, filePath );
- final File sourceFile = new File( getWebAppSource( testId ), filePath );
+ protected void assertDefaultFileContent(String testId, File webAppDirectory, String filePath) throws Exception {
+ final File webAppFile = new File(webAppDirectory, filePath);
+ final File sourceFile = new File(getWebAppSource(testId), filePath);
final String expectedContent = sourceFile.toString();
- assertEquals( "Wrong content for file " + filePath, expectedContent, FileUtils.fileRead( webAppFile ) );
-
+ assertEquals("Wrong content for file " + filePath, expectedContent, FileUtils.fileRead(webAppFile));
}
- protected ArtifactStub generateSimpleWarArtifactStub( String id )
- throws Exception
- {
- return buildWarOverlayStub( id );
+ protected ArtifactStub generateSimpleWarArtifactStub(String id) throws Exception {
+ return buildWarOverlayStub(id);
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java
index cc61d2e..9450250 100644
--- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.war;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.plugins.war;
* "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
+ * 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
@@ -18,6 +16,10 @@ package org.apache.maven.plugins.war;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.war;
+
+import java.io.File;
+import java.util.LinkedList;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -27,156 +29,133 @@ import org.apache.maven.plugins.war.stub.WarArtifactStub;
import org.apache.maven.plugins.war.stub.ZipArtifactStub;
import org.codehaus.plexus.util.FileUtils;
-import java.io.File;
-import java.util.LinkedList;
-
/**
* @author Olivier Lamy
* @since 7 Oct 07
*/
-public class WarZipTest
- extends AbstractWarMojoTest
-{
+public class WarZipTest extends AbstractWarMojoTest {
WarMojo mojo;
- private static File pomFile = new File( getBasedir(), "src/test/resources/unit/warziptest/war-with-zip.xml" );
+ private static File pomFile = new File(getBasedir(), "src/test/resources/unit/warziptest/war-with-zip.xml");
- protected File getTestDirectory()
- {
- return new File( getBasedir(), "target/test-classes/unit/warziptest" );
+ protected File getTestDirectory() {
+ return new File(getBasedir(), "target/test-classes/unit/warziptest");
}
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- mojo = (WarMojo) lookupMojo( "war", pomFile );
+ mojo = (WarMojo) lookupMojo("war", pomFile);
}
- private Artifact buildZipArtifact()
- throws Exception
- {
- ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
- File zipFile = new File( getTestDirectory(), "foobar.zip" );
- return new ZipArtifactStub( "src/test/resources/unit/warziptest", artifactHandler, zipFile );
+ private Artifact buildZipArtifact() throws Exception {
+ ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
+ File zipFile = new File(getTestDirectory(), "foobar.zip");
+ return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile);
}
- private File configureMojo( String testId )
- throws Exception
- {
+ private File configureMojo(String testId) throws Exception {
MavenZipProject project = new MavenZipProject();
String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + testId + "-output";
// clean up
- File outputDirFile = new File( outputDir );
- if ( outputDirFile.exists() )
- {
- FileUtils.deleteDirectory( outputDirFile );
+ File outputDirFile = new File(outputDir);
+ if (outputDirFile.exists()) {
+ FileUtils.deleteDirectory(outputDirFile);
}
- File webAppDirectory = new File( getTestDirectory(), testId );
- WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
+ File webAppDirectory = new File(getTestDirectory(), testId);
+ WarArtifactStub warArtifact = new WarArtifactStub(getBasedir());
String warName = "simple";
- File webAppSource = createWebAppSource( testId );
- File classesDir = createClassesDir( testId, true );
- File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
- project.setArtifact( warArtifact );
+ File webAppSource = createWebAppSource(testId);
+ File classesDir = createClassesDir(testId, true);
+ File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"});
+ project.setArtifact(warArtifact);
- this.configureMojo( mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project );
- setVariableValueToObject( mojo, "outputDirectory", outputDir );
- setVariableValueToObject( mojo, "warName", warName );
- setVariableValueToObject( mojo, "workDirectory", new File( getTestDirectory(), "work" ) );
- mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+ this.configureMojo(mojo, new LinkedList<>(), classesDir, webAppSource, webAppDirectory, project);
+ setVariableValueToObject(mojo, "outputDirectory", outputDir);
+ setVariableValueToObject(mojo, "warName", warName);
+ setVariableValueToObject(mojo, "workDirectory", new File(getTestDirectory(), "work"));
+ mojo.setWebXml(new File(xmlSource, "web.xml"));
- project.getArtifacts().add( buildZipArtifact() );
+ project.getArtifacts().add(buildZipArtifact());
return webAppDirectory;
}
- public void testOneZipWithNoSkip()
- throws Exception
- {
- File webAppDirectory = configureMojo( "one-zip" );
+ public void testOneZipWithNoSkip() throws Exception {
+ File webAppDirectory = configureMojo("one-zip");
- Overlay overlay = new DefaultOverlay( buildZipArtifact() );
+ Overlay overlay = new DefaultOverlay(buildZipArtifact());
// overlay.setSkip( false );
- overlay.setType( "zip" );
- mojo.addOverlay( overlay );
+ overlay.setType("zip");
+ mojo.addOverlay(overlay);
mojo.execute();
- File foo = new File( webAppDirectory, "foo.txt" );
- assertTrue( "foo.txt not exists", foo.exists() );
- assertTrue( "foo.txt not a file", foo.isFile() );
+ File foo = new File(webAppDirectory, "foo.txt");
+ assertTrue("foo.txt not exists", foo.exists());
+ assertTrue("foo.txt not a file", foo.isFile());
- File barDirectory = new File( webAppDirectory, "bar" );
- assertTrue( "bar directory not exists", barDirectory.exists() );
- assertTrue( "bar not a directory", barDirectory.isDirectory() );
+ File barDirectory = new File(webAppDirectory, "bar");
+ assertTrue("bar directory not exists", barDirectory.exists());
+ assertTrue("bar not a directory", barDirectory.isDirectory());
- File bar = new File( barDirectory, "bar.txt" );
- assertTrue( "bar/bar.txt not exists", bar.exists() );
- assertTrue( "bar/bar.txt not a file", bar.isFile() );
+ File bar = new File(barDirectory, "bar.txt");
+ assertTrue("bar/bar.txt not exists", bar.exists());
+ assertTrue("bar/bar.txt not a file", bar.isFile());
}
- public void testOneZipWithTargetPathOverlay()
- throws Exception
- {
- File webAppDirectory = configureMojo( "one-zip-overlay-targetPath" );
+ public void testOneZipWithTargetPathOverlay() throws Exception {
+ File webAppDirectory = configureMojo("one-zip-overlay-targetPath");
- Overlay overlay = new DefaultOverlay( buildZipArtifact() );
- overlay.setSkip( false );
- overlay.setType( "zip" );
- overlay.setTargetPath( "overridePath" );
- mojo.addOverlay( overlay );
+ Overlay overlay = new DefaultOverlay(buildZipArtifact());
+ overlay.setSkip(false);
+ overlay.setType("zip");
+ overlay.setTargetPath("overridePath");
+ mojo.addOverlay(overlay);
mojo.execute();
- File foo = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt" );
- assertTrue( "foo.txt not exists", foo.exists() );
- assertTrue( "foo.txt not a file", foo.isFile() );
... 3080 lines suppressed ...