From 12fe88eee8b04142d08f825626c0eed9afaaed60 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sun, 21 May 2023 13:06:17 +0200 Subject: [PATCH] [MWAR-463] Upgrade Parent to 39 - code reformat --- pom.xml | 44 +- .../maven/plugins/war/AbstractWarMojo.java | 547 +++++------- .../org/apache/maven/plugins/war/Overlay.java | 172 ++-- .../maven/plugins/war/WarExplodedMojo.java | 23 +- .../maven/plugins/war/WarInPlaceMojo.java | 19 +- .../org/apache/maven/plugins/war/WarMojo.java | 312 +++---- .../plugins/war/overlay/DefaultOverlay.java | 29 +- .../InvalidOverlayConfigurationException.java | 19 +- .../plugins/war/overlay/OverlayManager.java | 145 ++- .../packaging/AbstractWarPackagingTask.java | 415 ++++----- .../war/packaging/ArtifactsPackagingTask.java | 149 ++-- .../war/packaging/ClassesPackagingTask.java | 113 ++- .../war/packaging/CopyUserManifestTask.java | 40 +- .../war/packaging/OverlayPackagingTask.java | 109 +-- .../war/packaging/WarPackagingContext.java | 18 +- .../war/packaging/WarPackagingTask.java | 12 +- .../packaging/WarProjectPackagingTask.java | 317 +++---- .../plugins/war/util/ClassesPackager.java | 52 +- .../plugins/war/util/DependencyInfo.java | 36 +- .../maven/plugins/war/util/PathSet.java | 129 +-- .../maven/plugins/war/util/WarUtils.java | 56 +- .../plugins/war/util/WebappStructure.java | 214 ++--- .../war/AbstractWarExplodedMojoTest.java | 202 ++--- .../plugins/war/AbstractWarMojoTest.java | 231 +++-- .../war/WarExplodedMojoFilteringTest.java | 252 +++--- .../plugins/war/WarExplodedMojoTest.java | 843 +++++++++--------- .../maven/plugins/war/WarInPlaceMojoTest.java | 79 +- .../apache/maven/plugins/war/WarMojoTest.java | 663 +++++++------- .../maven/plugins/war/WarOverlaysTest.java | 544 ++++++----- .../apache/maven/plugins/war/WarZipTest.java | 183 ++-- .../war/overlay/OverlayManagerTest.java | 226 ++--- .../plugins/war/stub/AarArtifactStub.java | 44 +- .../war/stub/AbstractArtifactStub.java | 115 +-- .../plugins/war/stub/EJBArtifactStub.java | 51 +- .../stub/EJBArtifactStubWithClassifier.java | 57 +- .../war/stub/EJBClientArtifactStub.java | 54 +- .../stub/IncludeExcludeWarArtifactStub.java | 24 +- .../plugins/war/stub/JarArtifactStub.java | 93 +- .../plugins/war/stub/MarArtifactStub.java | 43 +- .../stub/MavenProject4CopyConstructor.java | 46 +- .../war/stub/MavenProjectArtifactsStub.java | 60 +- .../war/stub/MavenProjectBasicStub.java | 71 +- .../plugins/war/stub/MavenZipProject.java | 27 +- .../maven/plugins/war/stub/ModelStub.java | 44 +- .../plugins/war/stub/PARArtifactStub.java | 25 +- .../plugins/war/stub/ProjectHelperStub.java | 47 +- .../maven/plugins/war/stub/ResourceStub.java | 24 +- .../plugins/war/stub/TLDArtifactStub.java | 25 +- .../plugins/war/stub/WarArtifact4CCStub.java | 28 +- .../plugins/war/stub/WarArtifactStub.java | 68 +- .../plugins/war/stub/WarOverlayStub.java | 44 +- .../plugins/war/stub/XarArtifactStub.java | 44 +- .../plugins/war/stub/ZipArtifactStub.java | 46 +- .../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 859ab96e..0c26479b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - + - 4.0.0 - maven-plugins org.apache.maven.plugins + maven-plugins 39 @@ -36,6 +34,21 @@ Apache Maven WAR Plugin Builds a Web Application Archive (WAR) file from the project output and its dependencies. + + + Auke Schrijnen + + + Ludwig Magnusson + + + Hayarobi Park + + + Enrico Olivelli + + + ${mavenVersion} @@ -43,8 +56,8 @@ scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git scm:git:https://gitbox.apache.org/repos/asf/maven-war-plugin.git - https://github.com/apache/maven-war-plugin/tree/${project.scm.tag} HEAD + https://github.com/apache/maven-war-plugin/tree/${project.scm.tag} JIRA @@ -69,21 +82,6 @@ 2021-09-05T09:31:59Z - - - Auke Schrijnen - - - Ludwig Magnusson - - - Hayarobi Park - - - Enrico Olivelli - - - @@ -136,7 +134,7 @@ maven-shared-utils 3.3.4 - + commons-io commons-io @@ -172,7 +170,7 @@ org.eclipse.sisu.plexus provided - + org.apache.maven @@ -197,8 +195,8 @@ - src/main/resources-filtered true + src/main/resources-filtered 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 3812a92e..fbee0141 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 @@ * 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 @@ /** * 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 *

* So, the default filtering delimiters might be specified as: *

- * + * *
      * <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 Overlay getCurrentProjectOverlay()
      *
      * @return an array of tokens to exclude
      */
-    protected String[] getExcludes()
-    {
+    protected String[] getExcludes() {
         List 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 @@ protected String[] getExcludes()
      *
      * @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 @@ protected String[] getIncludes()
      *
      * @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 @@ protected String[] getDependentWarExcludes()
      *
      * @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 @@ protected String[] getDependentWarIncludes()
      * @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 void buildExplodedWebapp( File webapplicationDirectory )
      * @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 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 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 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 void buildWebapp( MavenProject mavenProject, File webapplicationDirectory
      * @return the list of packaging tasks
      * @throws MojoExecutionException if the packaging tasks could not be built
      */
-    private List getPackagingTasks( OverlayManager overlayManager )
-        throws MojoExecutionException
-    {
+    private List getPackagingTasks(OverlayManager overlayManager) throws MojoExecutionException {
         final List packagingTasks = new ArrayList<>();
 
-        packagingTasks.add( new CopyUserManifestTask() );
+        packagingTasks.add(new CopyUserManifestTask());
 
         final List 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 @@ private List getPackagingTasks( OverlayManager overlayManager
     /**
      * 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 @@ private class DefaultWarPackagingContext
          * @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 filterWrappers,
-                                           List 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 filterWrappers,
+                List 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 @@ private class DefaultWarPackagingContext
             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()
-                    {
+                    Files.walkFileTree(webappDirectory.toPath(), new SimpleFileVisitor() {
                         @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 getFilters()
-        {
+        public List getFilters() {
             return filters;
         }
 
         @Override
-        public WebappStructure getWebappStructure()
-        {
+        public WebappStructure getWebappStructure() {
             return webappStructure;
         }
 
         @Override
-        public List getOwnerIds()
-        {
+        public List getOwnerIds() {
             return overlayManager.getOverlayIds();
         }
 
         @Override
-        public MavenFileFilter getMavenFileFilter()
-        {
+        public MavenFileFilter getMavenFileFilter() {
             return mavenFileFilter;
         }
 
         @Override
-        public List getFilterWrappers()
-        {
+        public List 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 String getOutputTimestamp()
     /**
      * @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 getOverlays()
-    {
+    public List getOverlays() {
         return overlays;
     }
 
     /**
      * @param overlays {@link #overlays}
      */
-    public void setOverlays( List overlays )
-    {
+    public void setOverlays(List 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 getFilters()
-    {
+    public List getFilters() {
         return filters;
     }
 
     /**
      * @param filters {@link #filters}
      */
-    public void setFilters( List filters )
-    {
+    public void setFilters(List 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 getNonFilteredFileExtensions()
-    {
+    public List getNonFilteredFileExtensions() {
         return nonFilteredFileExtensions;
     }
 
     /**
      * @param nonFilteredFileExtensions {@link #nonFilteredFileExtensions}
      */
-    public void setNonFilteredFileExtensions( List nonFilteredFileExtensions )
-    {
+    public void setNonFilteredFileExtensions(List 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 c42f1c79..9ad4b013 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 @@
  * 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;
+
 /**
  * 

* An overlay is a skeleton WAR added to another WAR project in order to inject a functionality, resources or any other * shared component.

- * + * *

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.

- * + * *

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.

* * @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 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 Overlay( String groupId, String artifactId ) * * @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 static Overlay createInstance() /** * @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 String getId() /** * @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 boolean equals( Object o ) } @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 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 1327068c..7e543ffd 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 @@ * 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 @@ * 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 9cfe02c6..01906012 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 @@ * 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 @@ * 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 3241c75b..861a10b2 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 @@ * 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 @@ * * @author Emmanuel Venisse */ -@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 false 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 void execute() * @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 @@ else if ( artifact.getFile() == null || artifact.getFile().isDirectory() ) * @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 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 @@ private static boolean hasClassInClasspath( ClassLoader loader, String clazz ) * @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 @@ protected File getTargetClassesFile() /** * @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 void setFailOnMissingWebXml( boolean failOnMissingWebXml ) * 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 831a53a1..ec9be9f3 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 @@ * 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 @@ * * @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 DefaultOverlay( Artifact a ) * @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 3470ef57..e4b0ec59 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 @@ * 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 @@ * * @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 ae0ee8e3..bf4193bf 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 @@ * 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 @@ * * @author Stephane Nicoll */ -public class OverlayManager -{ +public class OverlayManager { private final List 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 overlays, MavenProject project, String[] defaultIncludes, - String[] defaultExcludes, Overlay currentProjectOverlay ) - throws InvalidOverlayConfigurationException - { + public OverlayManager( + List 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 OverlayManager( List overlays, MavenProject project, String[] de * * @return the overlays */ - public List getOverlays() - { + public List getOverlays() { return overlays; } @@ -89,15 +87,12 @@ public List getOverlays() * * @return the overlay ids */ - public List getOverlayIds() - { + public List getOverlayIds() { final List 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 List getOverlayIds() * @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 configuredWarArtifacts = new ArrayList<>(); final ListIterator 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 @@ void initialize( String[] defaultIncludes, String[] defaultExcludes, Overlay cur * @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 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 @@ Artifact getAssociatedArtifact( final Overlay overlay ) * @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 @@ private boolean compareOverlayWithArtifact( Overlay overlay, Artifact artifact ) * * @return the overlays as artifacts objects */ - private List getOverlaysAsArtifacts() - { - ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + private List getOverlaysAsArtifacts() { + ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); final Set artifacts = project.getArtifacts(); final List 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 171275f3..7e4e5f6d 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 @@ * 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 @@ /** * @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 @@ protected void copyFiles( String sourceId, WarPackagingContext context, File sou * @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 @@ protected void copyFiles( String sourceId, WarPackagingContext context, File sou * @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 @@ else if ( !targetFile.exists() && !targetFile.mkdirs() ) * @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 @@ else if ( isPropertiesFile( file ) && StringUtils.isNotEmpty( context.getPropert * @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 @@ protected void doUnpack( WarPackagingContext context, File file, File unpackDire * @throws IOException if source does not exist, destination 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 @@ protected boolean copyFile( WarPackagingContext context, File source, File desti * @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 @@ protected String getEncoding( File webXml ) * @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 @@ protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] * @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 @@ protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] /** * 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 @@ protected PathSet getFilesToIncludes( File baseDir, String[] includes, String[] * @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 @@ protected String getArtifactFinalName( WarPackagingContext context, Artifact art * @return true if the file is a file of the specified type, otherwise false * @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 @@ private boolean isFileOfType( File file, String extension ) * @return true if the file is a properties file, otherwise false * @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 @@ private boolean isPropertiesFile( File file ) * @return true if the file is an xml-file, otherwise false * @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 2fa484d6..6b6755a1 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 @@ * 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 @@ * * @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 artifacts, Overlay currentProjectOverlay ) - { + public ArtifactsPackagingTask(Set 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 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 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 @@ else if ( "zip".equals( type ) ) * @param artifacts set of artifacts * @return List of duplicated artifacts as bundling file names */ - private List findDuplicates( WarPackagingContext context, Set artifacts ) - throws InterpolationException - { + private List findDuplicates(WarPackagingContext context, Set artifacts) + throws InterpolationException { List duplicates = new ArrayList<>(); List 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 654469ea..6f71048a 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 @@ * 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.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 void performPackaging( WarPackagingContext context ) * @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 f98a7c56..9b1be7aa 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 @@ * 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 @@ * @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 Log getLog() * * @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 df7f2b40..c46d9bb3 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 @@ * 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 void performPackaging( WarPackagingContext context ) * @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 @@ protected File unpackOverlay( WarPackagingContext context, Overlay overlay ) * @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 6480114f..873409b3 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 @@ * 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 @@ * * @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 mvn clean when resources are removed. - * + * This prevent calling mvn clean 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 mvn clean 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 4260e1de..2539b86f 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 @@ * 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 @@ * * @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 59937062..f6a960d2 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 @@ * 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.StringUtils; /** - * Handles the project own resources, that is: + * Handles the project own resources, that is: *
    *
  • The list of web resources, if any
  • *
  • The content of the webapp directory if it exists
  • @@ -44,9 +43,7 @@ * * @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 WarProjectPackagingTask( Resource[] webResources, File webXml, File conta } @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 void performPackaging( WarPackagingContext context ) * @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 tag is missing from the tag." ); + if (resource.getDirectory() == null) { + throw new MojoExecutionException("The tag is missing from the 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 @@ protected void handleWebResources( WarPackagingContext context ) * @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 @@ else if ( !context.getWebappSourceDirectory().getAbsolutePath().equals( context. * @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 @@ protected void handleArtifacts( WarPackagingContext context ) * @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 @@ protected void handleClassesDirectory( WarPackagingContext context ) * @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 @@ protected void handleDeploymentDescriptors( WarPackagingContext context, File we * @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 . 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 void copyResources( WarPackagingContext context, Resource resource ) * @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 cdcdd963..19c2c9b9 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 @@ * 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.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 void packageClasses( File classesDirectory, File targetFile, JarArchiver * @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 ece99ddc..78906eb8 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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.util; import java.util.Objects; @@ -28,8 +27,7 @@ * * @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 DependencyInfo( Dependency dependency ) * * @return the dependency */ - public Dependency getDependency() - { + public Dependency getDependency() { return dependency; } @@ -60,8 +56,7 @@ public Dependency getDependency() * * @return the target file name or {@code null} */ - public String getTargetFileName() - { + public String getTargetFileName() { return targetFileName; } @@ -70,34 +65,29 @@ public String getTargetFileName() * * @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 23da7b37..4d414184 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 @@ * 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.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 -{ +public class PathSet implements Iterable { 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 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 @@ static String normalizeSubPath( String path ) /** * Creates an empty paths set */ - public PathSet() - { + public PathSet() { /* Empty default constructor */ } @@ -82,9 +72,8 @@ public PathSet() * * @param paths to be added */ - public PathSet( Collection paths ) - { - addAll( paths ); + public PathSet(Collection paths) { + addAll(paths); } /** @@ -92,9 +81,8 @@ public PathSet( Collection paths ) * * @param paths to be added */ - public PathSet( String[] paths ) - { - addAll( paths ); + public PathSet(String[] paths) { + addAll(paths); } /** @@ -102,9 +90,8 @@ public PathSet( String[] paths ) * * @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 void add( String path ) * @param paths - collection of strings to be added * @param prefix added to all given paths */ - public void addAll( Collection paths, String prefix ) - { - for ( String val : paths ) - { - add( prefix + SEPARATOR + val ); + public void addAll(Collection paths, String prefix) { + for (String val : paths) { + add(prefix + SEPARATOR + val); } } @@ -127,11 +112,9 @@ public void addAll( Collection paths, String prefix ) * @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 void addAll( String[] paths, String prefix ) * @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 void addAll( PathSet paths, String prefix ) * * @param paths - collection of strings to be added */ - public void addAll( Collection paths ) - { - addAll( paths, "" ); + public void addAll(Collection paths) { + addAll(paths, ""); } /** @@ -164,9 +144,8 @@ public void addAll( Collection paths ) * * @param paths to be added */ - public void addAll( String[] paths ) - { - addAll( paths, "" ); + public void addAll(String[] paths) { + addAll(paths, ""); } /** @@ -174,9 +153,8 @@ public void addAll( String[] paths ) * * @param paths to be added */ - public void addAll( PathSet paths ) - { - addAll( paths, "" ); + public void addAll(PathSet paths) { + addAll(paths, ""); } /** @@ -185,9 +163,8 @@ public void addAll( PathSet paths ) * @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 boolean contains( String path ) * @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 @@ boolean remove( String path ) * @return iterator of normalized paths (strings) */ @Override - public Iterator iterator() - { + public Iterator iterator() { return pathsSet.iterator(); } /** * @return {@link #pathsSet} */ - public Collection paths() - { + public Collection 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 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 void addPrefix( String prefix ) * * @return count of the paths in the set */ - public int size() - { + public int size() { return pathsSet.size(); } @@ -253,12 +224,10 @@ public int size() * @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 19dbb798..a8313bda 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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.util; import java.util.Objects; @@ -28,29 +27,22 @@ /** * @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 @@ else if ( dependency.getClassifier() != null * @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 b48e1e6e..e2cb735c 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 @@ * 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.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 registeredFiles; @@ -52,9 +50,8 @@ public class WebappStructure * * @param dependencies the dependencies of the project */ - public WebappStructure( List dependencies ) - { - this.dependenciesInfo = createDependenciesInfoList( dependencies ); + public WebappStructure(List dependencies) { + this.dependenciesInfo = createDependenciesInfoList(dependencies); this.registeredFiles = new HashMap<>(); } @@ -63,8 +60,7 @@ public WebappStructure( List dependencies ) * * @return the dependencies information of the project */ - public List getDependenciesInfo() - { + public List getDependenciesInfo() { return dependenciesInfo; } @@ -73,16 +69,13 @@ public List getDependenciesInfo() * * @return the dependencies of the project */ - public List getDependencies() - { + public List getDependencies() { final List 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 List getDependencies() * @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 boolean isRegistered( String path ) * @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 boolean registerFile( String id, String path ) * @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 boolean registerFileForced( String id, String path ) * @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 @@ else if ( getOwners().contains( getOwner( path ) ) ) * @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 String getOwner( String path ) * * @return the list of owners */ - public Set getOwners() - { + public Set getOwners() { return registeredFiles.keySet(); } @@ -235,8 +199,7 @@ public Set getOwners() * * @return all registered path */ - public PathSet getFullStructure() - { + public PathSet getFullStructure() { return allFiles; } @@ -246,34 +209,26 @@ public PathSet getFullStructure() * @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 void registerTargetFileName( Artifact artifact, String targetFileName ) // 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 createDependenciesInfoList( List dependencies ) - { - if ( dependencies == null ) - { + private List createDependenciesInfoList(List dependencies) { + if (dependencies == null) { return Collections.emptyList(); } final List 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 @@ private Object readResolve() /** * 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; /** *

    * 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}. - *

    + *

    * This means that the {@code targetFilename} was known and does not belong to the specified owner. * * @param ownerId the ownerId @@ -354,13 +300,12 @@ void alreadyRegistered( String ownerId, String targetFilename ) * @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 @@ void refused( String ownerId, String targetFilename, String actualOwnerId ) * @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 @@ void superseded( String ownerId, String targetFilename, String deprecatedOwnerId * @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 f1409409..1c872f8e 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 @@ * "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 @@ * 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.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 void setUp() /** * 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 void setUp() * @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 @@ protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs, Str * @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 @@ protected File setUpMojo( final String testId, ArtifactStub[] artifactStubs ) * @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 @@ protected void cleanDirectory( File directory ) * @param webAppDirectory the webapp directory * @return a list of File objects that have been asserted */ - protected List assertDefaultContent( File webAppDirectory ) - { + protected List 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 content = new ArrayList<>(); - content.add( expectedWebSourceFile ); - content.add( expectedWebSource2File ); + content.add(expectedWebSourceFile); + content.add(expectedWebSource2File); return content; } @@ -172,13 +151,12 @@ protected List assertDefaultContent( File webAppDirectory ) * @param webAppDirectory the webapp directory * @return a list with the web.xml File object */ - protected List assertWebXml( File webAppDirectory ) - { - File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" ); - assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() ); + protected List assertWebXml(File webAppDirectory) { + File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); + assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); final List content = new ArrayList<>(); - content.add( expectedWEBXMLFile ); + content.add(expectedWEBXMLFile); return content; } @@ -191,21 +169,16 @@ protected List assertWebXml( File webAppDirectory ) * @param customMessage a custom message if an assertion fails * @return a list of File objects that have been inspected */ - protected List assertCustomContent( File webAppDirectory, String[] filePaths, String customMessage ) - { + protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { final List 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 @@ protected List assertCustomContent( File webAppDirectory, String[] filePat * @param expectedFiles the expected files * @param filter an optional filter to ignore some resources */ - protected void assertWebAppContent( File webAppDirectory, List expectedFiles, FileFilter filter ) - { + protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { final List 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 @@ protected void assertWebAppContent( File webAppDirectory, List expectedFil * @param filter the filter * @param content the current content, updated recursively */ - private void buildFilesList( final File dir, FileFilter filter, final List content ) - { + private void buildFilesList(final File dir, FileFilter filter, final List 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 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 3de518f8..23053c72 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 @@ * "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 @@ * 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.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 @@ protected abstract File getTestDirectory() * @param project The Maven project. * @throws Exception in case of errors */ - protected void configureMojo( AbstractWarMojo mojo, List 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 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 @@ protected void configureMojo( AbstractWarMojo mojo, List filters, File c * @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 @@ protected File createXMLConfigDir( String id, String[] xmlFiles ) * @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 @@ protected File getWebAppSource( String id ) * @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 @@ protected File createWebAppSource( String id ) * @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 @@ protected void createFile( File testFile ) * @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 @@ protected File generateFullOverlayWar( String id ) * @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 9997f4d6..1837a5e6 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 @@ * @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 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 void testExplodedWar_WithResourceFiltering() 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 void testExplodedWar_WithResourceFiltering() 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 45faf0fd..04352699 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 @@ * "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 @@ * 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.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 void testSimpleExplodedWar() /** * @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 void testSimpleExplodedWarWTargetPath() /** * @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 void testExplodedWar_WithCustomWebXML() /** * @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 void testExplodedWar_WithContainerConfigXML() /** * @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 void testExplodedWar_WithSimpleExternalWARFile() * 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 void testExplodedWarMergeWarLocalFileOverride() /** * @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 -. - 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 void testExplodedWar_WithEJB() 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 -. - 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 void testExplodedWarWithJar() /** * @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 -. - 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 void testExplodedWar_WithEJBClient() /** * @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 -. - 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 void testExplodedWar_WithTLD() /** * @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 -. - 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 void testExplodedWar_WithPAR() /** * @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 -. - 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 void testExplodedWarWithAar() /** * @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 -. - 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 void testExplodedWarWithMar() /** * @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 -. - 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 void testExplodedWarWithXar() /** * @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 -. - 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 void testExplodedWar_WithDuplicateDependencies() /** * @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 -. - 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 void testExplodedWar_DuplicateWithClassifier() /** * @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 -. - 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 void testExplodedWar_WithClasses() /** * @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 void testExplodedWar_WithSourceIncludeExclude() /** * @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 void testExplodedWar_WithWarDependencyIncludeExclude() /** * @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 void testExplodedWarWithSourceModificationCheck() // 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 void testExplodedWarWithSourceModificationCheck() /** * @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 -. - 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 void testExplodedWarWithOutputFileNameMapping() /** * @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 -. - 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 8cf45573..f35b355f 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 @@ * "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 @@ * 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 84a8ce82..597e29a2 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 @@ * "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 @@ * 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 @@ /** * 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, "" ); + final File configFile = new File(webAppSource, "META-INF/config.xml"); + createFile(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" ) ); + 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, "" ); + final File configFile = new File(webAppSource, "META-INF/config.xml"); + createFile(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 ); + 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 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 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 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 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 assertJarContent( final File expectedJarFile, final String[] files, - final String[] filesContent ) - throws IOException - { - return assertJarContent( expectedJarFile, files, filesContent, null ); + protected Map assertJarContent( + final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException { + return assertJarContent(expectedJarFile, files, filesContent, null); } - protected Map assertJarContent( final File expectedJarFile, final String[] files, - final String[] filesContent, final String[] mustNotBeInJar ) - throws IOException - { + protected Map 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 jarContent = new HashMap<>(); - try ( JarFile jarFile = new JarFile( expectedJarFile ) ) { + try (JarFile jarFile = new JarFile(expectedJarFile)) { Enumeration 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 d944e6fa..5d7f17c7 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 @@ * "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 @@ * 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.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 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 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 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 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 void testScenarioOneWithFullSettings() * @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 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 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 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 void testOverlaysIncludesExcludesWithMultipleDefinitions2() * @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 @@ protected void assertOverlayedFile( File webAppDirectory, String overlayId, Stri * @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 cc61d2ea..94502503 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 @@ * "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 @@ * 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.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() ); + 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()); - File barDirectory = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar" ); - assertTrue( "bar directory not exists", barDirectory.exists() ); - assertTrue( "bar not a directory", barDirectory.isDirectory() ); + File barDirectory = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "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 testOneZipDefaultSkip() - throws Exception - { - File webAppDirectory = configureMojo( "one-zip-overlay-skip" ); + public void testOneZipDefaultSkip() throws Exception { + File webAppDirectory = configureMojo("one-zip-overlay-skip"); mojo.execute(); - assertZipContentNotHere( webAppDirectory ); + assertZipContentNotHere(webAppDirectory); } - public void testOneZipWithForceSkip() - throws Exception - { - File webAppDirectory = configureMojo( "one-zip-overlay-skip" ); - Overlay overlay = new DefaultOverlay( buildZipArtifact() ); - overlay.setSkip( true ); - overlay.setType( "zip" ); - mojo.addOverlay( overlay ); + public void testOneZipWithForceSkip() throws Exception { + File webAppDirectory = configureMojo("one-zip-overlay-skip"); + Overlay overlay = new DefaultOverlay(buildZipArtifact()); + overlay.setSkip(true); + overlay.setType("zip"); + mojo.addOverlay(overlay); mojo.execute(); - assertZipContentNotHere( webAppDirectory ); - + assertZipContentNotHere(webAppDirectory); } - protected void assertZipContentNotHere( File webAppDirectory ) - { - File foo = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt" ); - assertFalse( "foo.txt exists", foo.exists() ); - assertFalse( "foo.txt a file", foo.isFile() ); + protected void assertZipContentNotHere(File webAppDirectory) { + File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); + assertFalse("foo.txt exists", foo.exists()); + assertFalse("foo.txt a file", foo.isFile()); - File barDirectory = new File( webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar" ); - assertFalse( "bar directory exists", barDirectory.exists() ); - assertFalse( "bar is a directory", barDirectory.isDirectory() ); + File barDirectory = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar"); + assertFalse("bar directory exists", barDirectory.exists()); + assertFalse("bar is a directory", barDirectory.isDirectory()); - File bar = new File( barDirectory, "bar.txt" ); - assertFalse( "bar/bar.txt exists", bar.exists() ); - assertFalse( "bar/bar.txt is a file", bar.isFile() ); + File bar = new File(barDirectory, "bar.txt"); + assertFalse("bar/bar.txt exists", bar.exists()); + assertFalse("bar/bar.txt is a file", bar.isFile()); } } diff --git a/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java b/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java index 59ed9e0c..dec87809 100644 --- a/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.java +++ b/src/test/java/org/apache/maven/plugins/war/overlay/OverlayManagerTest.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 @@ -9,7 +7,7 @@ * "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,9 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.overlay; -import static org.apache.maven.plugins.war.Overlay.DEFAULT_INCLUDES; -import static org.apache.maven.plugins.war.Overlay.DEFAULT_EXCLUDES; +import java.util.ArrayList; +import java.util.List; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.Overlay; @@ -28,199 +27,160 @@ import org.apache.maven.plugins.war.stub.WarArtifactStub; import org.codehaus.plexus.PlexusTestCase; -import java.util.ArrayList; -import java.util.List; +import static org.apache.maven.plugins.war.Overlay.DEFAULT_EXCLUDES; +import static org.apache.maven.plugins.war.Overlay.DEFAULT_INCLUDES; /** * @author Stephane Nicoll */ -public class OverlayManagerTest - extends PlexusTestCase -{ +public class OverlayManagerTest extends PlexusTestCase { - - public void testEmptyProject() - throws Exception - { + public void testEmptyProject() throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); final List overlays = new ArrayList<>(); - try - { + try { final Overlay currentProjectOverlay = Overlay.createInstance(); - OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, - currentProjectOverlay ); - assertNotNull( manager.getOverlays() ); - assertEquals( 1, manager.getOverlays().size() ); - assertEquals( currentProjectOverlay, manager.getOverlays().get( 0 ) ); - } - catch ( InvalidOverlayConfigurationException e ) - { + OverlayManager manager = + new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay); + assertNotNull(manager.getOverlays()); + assertEquals(1, manager.getOverlays().size()); + assertEquals(currentProjectOverlay, manager.getOverlays().get(0)); + } catch (InvalidOverlayConfigurationException e) { e.printStackTrace(); - fail( "Should not have failed to validate a valid overly config " + e.getMessage() ); + fail("Should not have failed to validate a valid overly config " + e.getMessage()); } } - public void testAutodetectSimpleOverlay( Overlay currentProjectOverlay ) - throws Exception - { + public void testAutodetectSimpleOverlay(Overlay currentProjectOverlay) throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); - project.addArtifact( first ); + final ArtifactStub first = newWarArtifact("test", "test-webapp"); + project.addArtifact(first); final List overlays = new ArrayList<>(); - try - { + try { final Overlay overlay = currentProjectOverlay; - OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, - overlay ); - assertNotNull( manager.getOverlays() ); - assertEquals( 2, manager.getOverlays().size() ); - assertEquals( overlay, manager.getOverlays().get( 0 ) ); - assertEquals( new DefaultOverlay( first ), manager.getOverlays().get( 1 ) ); - } - catch ( InvalidOverlayConfigurationException e ) - { + OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, overlay); + assertNotNull(manager.getOverlays()); + assertEquals(2, manager.getOverlays().size()); + assertEquals(overlay, manager.getOverlays().get(0)); + assertEquals(new DefaultOverlay(first), manager.getOverlays().get(1)); + } catch (InvalidOverlayConfigurationException e) { e.printStackTrace(); - fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + fail("Should not have failed to validate a valid overlay config " + e.getMessage()); } } - public void testSimpleOverlay() - throws Exception - { + public void testSimpleOverlay() throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); - project.addArtifact( first ); + final ArtifactStub first = newWarArtifact("test", "test-webapp"); + project.addArtifact(first); final List overlays = new ArrayList<>(); - overlays.add( new DefaultOverlay( first ) ); + overlays.add(new DefaultOverlay(first)); - try - { + try { final Overlay currentProjectOverlay = Overlay.createInstance(); - OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, - currentProjectOverlay ); - assertNotNull( manager.getOverlays() ); - assertEquals( 2, manager.getOverlays().size() ); - assertEquals( Overlay.createInstance(), manager.getOverlays().get( 0 ) ); - assertEquals( overlays.get( 0 ), manager.getOverlays().get( 1 ) ); - } - catch ( InvalidOverlayConfigurationException e ) - { + OverlayManager manager = + new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay); + assertNotNull(manager.getOverlays()); + assertEquals(2, manager.getOverlays().size()); + assertEquals(Overlay.createInstance(), manager.getOverlays().get(0)); + assertEquals(overlays.get(0), manager.getOverlays().get(1)); + } catch (InvalidOverlayConfigurationException e) { e.printStackTrace(); - fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + fail("Should not have failed to validate a valid overlay config " + e.getMessage()); } } - public void testUnknownOverlay() - throws Exception - { + public void testUnknownOverlay() throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); - project.addArtifact( first ); + final ArtifactStub first = newWarArtifact("test", "test-webapp"); + project.addArtifact(first); final List overlays = new ArrayList<>(); - overlays.add( new Overlay( "test", "test-webapp-2" ) ); + overlays.add(new Overlay("test", "test-webapp-2")); - try - { + try { final Overlay currentProjectOverlay = Overlay.createInstance(); - new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay ); - fail( "Should have failed to validate an unknown overlay" ); - } - catch ( InvalidOverlayConfigurationException e ) - { + new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay); + fail("Should have failed to validate an unknown overlay"); + } catch (InvalidOverlayConfigurationException e) { // OK } } - public void testCustomCurrentProject() - throws Exception - { + public void testCustomCurrentProject() throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); - final ArtifactStub second = newWarArtifact( "test", "test-webapp-2" ); - project.addArtifact( first ); - project.addArtifact( second ); + final ArtifactStub first = newWarArtifact("test", "test-webapp"); + final ArtifactStub second = newWarArtifact("test", "test-webapp-2"); + project.addArtifact(first); + project.addArtifact(second); final List overlays = new ArrayList<>(); - overlays.add( new DefaultOverlay( first ) ); + overlays.add(new DefaultOverlay(first)); final Overlay currentProjectOverlay = Overlay.createInstance(); - overlays.add( currentProjectOverlay ); - - try - { - OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, - currentProjectOverlay ); - assertNotNull( manager.getOverlays() ); - assertEquals( 3, manager.getOverlays().size() ); - assertEquals( overlays.get( 0 ), manager.getOverlays().get( 0 ) ); - assertEquals( currentProjectOverlay, manager.getOverlays().get( 1 ) ); - assertEquals( new DefaultOverlay( second ), manager.getOverlays().get( 2 ) ); - - } - catch ( InvalidOverlayConfigurationException e ) - { + overlays.add(currentProjectOverlay); + + try { + OverlayManager manager = + new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay); + assertNotNull(manager.getOverlays()); + assertEquals(3, manager.getOverlays().size()); + assertEquals(overlays.get(0), manager.getOverlays().get(0)); + assertEquals(currentProjectOverlay, manager.getOverlays().get(1)); + assertEquals(new DefaultOverlay(second), manager.getOverlays().get(2)); + + } catch (InvalidOverlayConfigurationException e) { e.printStackTrace(); - fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + fail("Should not have failed to validate a valid overlay config " + e.getMessage()); } } - public void testOverlaysWithSameArtifactAndGroupId() - throws Exception - { + public void testOverlaysWithSameArtifactAndGroupId() throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final ArtifactStub first = newWarArtifact( "test", "test-webapp" ); - final ArtifactStub second = newWarArtifact( "test", "test-webapp", "my-classifier" ); + final ArtifactStub first = newWarArtifact("test", "test-webapp"); + final ArtifactStub second = newWarArtifact("test", "test-webapp", "my-classifier"); - project.addArtifact( first ); - project.addArtifact( second ); + project.addArtifact(first); + project.addArtifact(second); final List overlays = new ArrayList<>(); - overlays.add( new DefaultOverlay( first ) ); - overlays.add( new DefaultOverlay( second ) ); + overlays.add(new DefaultOverlay(first)); + overlays.add(new DefaultOverlay(second)); - try - { + try { final Overlay currentProjectOverlay = Overlay.createInstance(); - OverlayManager manager = new OverlayManager( overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, - currentProjectOverlay ); - assertNotNull( manager.getOverlays() ); - assertEquals( 3, manager.getOverlays().size() ); - assertEquals( currentProjectOverlay, manager.getOverlays().get( 0 ) ); - assertEquals( overlays.get( 0 ), manager.getOverlays().get( 1 ) ); - assertEquals( overlays.get( 1 ), manager.getOverlays().get( 2 ) ); - - } - catch ( InvalidOverlayConfigurationException e ) - { + OverlayManager manager = + new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOverlay); + assertNotNull(manager.getOverlays()); + assertEquals(3, manager.getOverlays().size()); + assertEquals(currentProjectOverlay, manager.getOverlays().get(0)); + assertEquals(overlays.get(0), manager.getOverlays().get(1)); + assertEquals(overlays.get(1), manager.getOverlays().get(2)); + + } catch (InvalidOverlayConfigurationException e) { e.printStackTrace(); - fail( "Should not have failed to validate a valid overlay config " + e.getMessage() ); + fail("Should not have failed to validate a valid overlay config " + e.getMessage()); } } - - protected ArtifactStub newWarArtifact( String groupId, String artifactId, String classifier ) - { - final WarArtifactStub a = new WarArtifactStub( getBasedir() ); - a.setGroupId( groupId ); - a.setArtifactId( artifactId ); - if ( classifier != null ) - { - a.setClassifier( classifier ); + protected ArtifactStub newWarArtifact(String groupId, String artifactId, String classifier) { + final WarArtifactStub a = new WarArtifactStub(getBasedir()); + a.setGroupId(groupId); + a.setArtifactId(artifactId); + if (classifier != null) { + a.setClassifier(classifier); } return a; } - protected ArtifactStub newWarArtifact( String groupId, String artifactId ) - { - return newWarArtifact( groupId, artifactId, null ); - + protected ArtifactStub newWarArtifact(String groupId, String artifactId) { + return newWarArtifact(groupId, artifactId, null); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java index db500496..1fb99104 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/AarArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,62 +16,50 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; +import java.io.File; import org.apache.maven.artifact.handler.ArtifactHandler; -import java.io.File; - /** * @author Stephane Nicoll */ -public class AarArtifactStub - extends AbstractArtifactStub -{ +public class AarArtifactStub extends AbstractArtifactStub { protected String groupId; private ArtifactHandler artifactHandler; - public AarArtifactStub( String basedir, ArtifactHandler artifactHandler ) - { - super( basedir ); + public AarArtifactStub(String basedir, ArtifactHandler artifactHandler) { + super(basedir); this.artifactHandler = artifactHandler; } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.aar"; } } - public String getType() - { + public String getType() { return "aar"; } - public String getArtifactId() - { + public String getArtifactId() { return "aarartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.aar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/simple.aar"); } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return artifactHandler; } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java index de6890ea..02d3603e 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/AbstractArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -25,94 +24,70 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.testing.stubs.ArtifactStub; -public abstract class AbstractArtifactStub - extends ArtifactStub -{ +public abstract class AbstractArtifactStub extends ArtifactStub { protected String basedir; - public AbstractArtifactStub( String _basedir ) - { + public AbstractArtifactStub(String _basedir) { basedir = _basedir; } - public String getVersion() - { + public String getVersion() { return "0.0-Test"; } @Override - public String getBaseVersion() - { + public String getBaseVersion() { return getVersion(); } - public String getScope() - { + public String getScope() { return Artifact.SCOPE_RUNTIME; } - public VersionRange getVersionRange() - { - return VersionRange.createFromVersion( getVersion()); + public VersionRange getVersionRange() { + return VersionRange.createFromVersion(getVersion()); } - public boolean isOptional() - { + public boolean isOptional() { return false; } - public ArtifactHandler getArtifactHandler() - { - return new DefaultArtifactHandler( getType() ); + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler(getType()); } /* * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... */ - public int compareTo( Artifact a ) - { + public int compareTo(Artifact a) { /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ int result; - if ( a.getGroupId() != null ) - { - result = getGroupId().compareTo( a.getGroupId() ); - } - else - { - result = ( getGroupId() == null ? 0 : -1 ); + if (a.getGroupId() != null) { + result = getGroupId().compareTo(a.getGroupId()); + } else { + result = (getGroupId() == null ? 0 : -1); } /* -- */ - if ( result == 0 ) - { - result = getArtifactId().compareTo( a.getArtifactId() ); - if ( result == 0 ) - { - result = getType().compareTo( a.getType() ); - if ( result == 0 ) - { - if ( getClassifier() == null ) - { - if ( a.getClassifier() != null ) - { + if (result == 0) { + result = getArtifactId().compareTo(a.getArtifactId()); + if (result == 0) { + result = getType().compareTo(a.getType()); + if (result == 0) { + if (getClassifier() == null) { + if (a.getClassifier() != null) { result = 1; } - } - else - { - if ( a.getClassifier() != null ) - { - result = getClassifier().compareTo( a.getClassifier() ); - } - else - { + } else { + if (a.getClassifier() != null) { + result = getClassifier().compareTo(a.getClassifier()); + } else { result = -1; } } - if ( result == 0 ) - { + if (result == 0) { // We don't consider the version range in the comparison, just the resolved version - result = getVersion().compareTo( a.getVersion() ); + result = getVersion().compareTo(a.getVersion()); } } } @@ -123,39 +98,29 @@ public int compareTo( Artifact a ) /* * TODO: Copied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging... */ - public boolean equals( Object o ) - { - if ( o == this ) - { + public boolean equals(Object o) { + if (o == this) { return true; } - if ( !( o instanceof Artifact ) ) - { + if (!(o instanceof Artifact)) { return false; } Artifact a = (Artifact) o; /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */ - if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) ) - { + if (a.getGroupId() == null ? (getGroupId() != null) : a.getGroupId().equals(getGroupId())) { return false; - } - else if ( !a.getArtifactId().equals( getArtifactId() ) ) - { + } else if (!a.getArtifactId().equals(getArtifactId())) { return false; - } - else if ( !a.getVersion().equals( getVersion() ) ) - { + } else if (!a.getVersion().equals(getVersion())) { return false; - } - else if ( !a.getType().equals( getType() ) ) - { + } else if (!a.getType().equals(getType())) { return false; - } - else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) ) - { + } else if (a.getClassifier() == null + ? getClassifier() != null + : !a.getClassifier().equals(getClassifier())) { return false; } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java index 7383715b..7414a7ae 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,60 +16,47 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; + +import java.io.File; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import java.io.File; - -public class EJBArtifactStub - extends AbstractArtifactStub -{ +public class EJBArtifactStub extends AbstractArtifactStub { protected String groupId; - public EJBArtifactStub( String _basedir ) - { - super( _basedir ); + public EJBArtifactStub(String _basedir) { + super(_basedir); } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.ejb"; } } - public String getType() - { + public String getType() { return "ejb"; } - public String getArtifactId() - { + public String getArtifactId() { return "ejbartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/ejb.jar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/ejb.jar"); } - public ArtifactHandler getArtifactHandler() - { - return new DefaultArtifactHandler() - { - public String getExtension() - { + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler() { + public String getExtension() { return "jar"; } }; diff --git a/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java b/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java index 35869c5e..99a91d6c 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/EJBArtifactStubWithClassifier.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,71 +16,56 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; + +import java.io.File; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import java.io.File; - -public class EJBArtifactStubWithClassifier - extends AbstractArtifactStub -{ +public class EJBArtifactStubWithClassifier extends AbstractArtifactStub { protected String groupId; protected String classifier; - public EJBArtifactStubWithClassifier( String _basedir ) - { - super( _basedir ); + public EJBArtifactStubWithClassifier(String _basedir) { + super(_basedir); } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.ejb"; } } - public String getType() - { + public String getType() { return "ejb"; } - public String getArtifactId() - { + public String getArtifactId() { return "ejbartifact"; } - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { this.classifier = classifier; } - public String getClassifier() - { + public String getClassifier() { return classifier; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/ejb.jar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/ejb.jar"); } - public ArtifactHandler getArtifactHandler() - { - return new DefaultArtifactHandler() - { - public String getExtension() - { + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler() { + public String getExtension() { return "jar"; } }; diff --git a/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java index 7e978967..089d5511 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/EJBClientArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,65 +16,51 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; + +import java.io.File; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import java.io.File; - -public class EJBClientArtifactStub - extends AbstractArtifactStub -{ +public class EJBClientArtifactStub extends AbstractArtifactStub { protected String groupId; - public EJBClientArtifactStub( String _basedir ) - { - super( _basedir ); + public EJBClientArtifactStub(String _basedir) { + super(_basedir); } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.ejb"; } } - public String getType() - { + public String getType() { return "ejb-client"; } - public String getClassifier() - { + public String getClassifier() { return "client"; } - public String getArtifactId() - { + public String getArtifactId() { return "ejbclientartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/ejbclient.jar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/ejbclient.jar"); } - public ArtifactHandler getArtifactHandler() - { - return new DefaultArtifactHandler() - { - public String getExtension() - { + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler() { + public String getExtension() { return "jar"; } }; diff --git a/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java index 9f879b3c..666d07e3 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/IncludeExcludeWarArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,25 +16,21 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; -public class IncludeExcludeWarArtifactStub - extends WarArtifactStub -{ - public IncludeExcludeWarArtifactStub( String id ) - { - super( id ); - setGroupId( "wartests" ); +public class IncludeExcludeWarArtifactStub extends WarArtifactStub { + public IncludeExcludeWarArtifactStub(String id) { + super(id); + setGroupId("wartests"); } - public String getArtifactId() - { + public String getArtifactId() { return "war-include-exclude"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/include-exclude.war" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/include-exclude.war"); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java index 4b089951..d6af1e59 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,14 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.artifact.handler.ArtifactHandler; +package org.apache.maven.plugins.war.stub; import java.io.File; -public class JarArtifactStub - extends AbstractArtifactStub -{ +import org.apache.maven.artifact.handler.ArtifactHandler; + +public class JarArtifactStub extends AbstractArtifactStub { protected String groupId; @@ -41,111 +38,83 @@ public class JarArtifactStub private ArtifactHandler artifactHandler; - public JarArtifactStub( String basedir, ArtifactHandler artifactHandler ) - { - super( basedir ); + public JarArtifactStub(String basedir, ArtifactHandler artifactHandler) { + super(basedir); this.artifactHandler = artifactHandler; } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.jar"; } } - public String getType() - { + public String getType() { return "jar"; } - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } - public String getArtifactId() - { - if ( artifactId != null ) - { + public String getArtifactId() { + if (artifactId != null) { return artifactId; - } - else - { + } else { return "jarartifact"; } } - public String getVersion() - { - if ( version != null ) - { + public String getVersion() { + if (version != null) { return version; - } - else - { + } else { return super.getVersion(); } } - public void setVersion( String version ) - { + public void setVersion(String version) { this.version = version; } - public boolean isOptional() - { + public boolean isOptional() { return optional; } - public void setOptional( boolean optional ) - { + public void setOptional(boolean optional) { this.optional = optional; } - public String getScope() - { - if ( scope != null ) - { + public String getScope() { + if (scope != null) { return scope; - } - else - { + } else { return super.getScope(); } } - public void setScope( String scope ) - { + public void setScope(String scope) { this.scope = scope; } - public File getFile() - { - if ( file == null ) - { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.jar" ); + public File getFile() { + if (file == null) { + return new File(basedir, "/target/test-classes/unit/sample_wars/simple.jar"); } return file; } - public void setFile( File file ) - { + public void setFile(File file) { this.file = file; } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return artifactHandler; } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java index e2665574..d49fddf4 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/MarArtifactStub.java @@ -7,7 +7,7 @@ * "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,61 +18,48 @@ */ package org.apache.maven.plugins.war.stub; -import org.apache.maven.artifact.handler.ArtifactHandler; - import java.io.File; +import org.apache.maven.artifact.handler.ArtifactHandler; + /** * @author Stephane Nicoll */ -public class MarArtifactStub - extends AbstractArtifactStub -{ +public class MarArtifactStub extends AbstractArtifactStub { protected String groupId; private ArtifactHandler artifactHandler; - public MarArtifactStub( String basedir, ArtifactHandler artifactHandler ) - { - super( basedir ); + public MarArtifactStub(String basedir, ArtifactHandler artifactHandler) { + super(basedir); this.artifactHandler = artifactHandler; } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.mar"; } } - public String getType() - { + public String getType() { return "mar"; } - public String getArtifactId() - { + public String getArtifactId() { return "marartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.mar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/simple.mar"); } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return artifactHandler; } } - diff --git a/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java b/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java index 831ddba5..4e45fd56 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/MavenProject4CopyConstructor.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; import java.util.HashSet; @@ -25,40 +24,31 @@ import java.util.List; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Profile; -import org.apache.maven.project.MavenProject; -public class MavenProject4CopyConstructor - extends MavenProjectBasicStub -{ +public class MavenProject4CopyConstructor extends MavenProjectBasicStub { protected ModelStub model; - public MavenProject4CopyConstructor() - throws Exception - { + public MavenProject4CopyConstructor() throws Exception { initializeParentFields(); } - public List getAttachedArtifacts() - { + public List getAttachedArtifacts() { return new LinkedList<>(); } // to prevent the MavenProject copy constructor from blowing up - private void initializeParentFields() - { - // the pom should be located in the isolated dummy root - super.setFile( new File( getBasedir(), "pom.xml" ) ); - super.setDependencyArtifacts( new HashSet<>() ); - super.setArtifacts( new HashSet<>() ); - super.setExtensionArtifacts( new HashSet<>() ); - super.setRemoteArtifactRepositories( new LinkedList<>() ); - super.setPluginArtifactRepositories( new LinkedList<>() ); - super.setCollectedProjects( new LinkedList<>() ); - super.setActiveProfiles( new LinkedList<>() ); - super.setOriginalModel( null ); - super.setExecutionProject( this ); - super.setBuild( getBuild() ); + private void initializeParentFields() { + // the pom should be located in the isolated dummy root + super.setFile(new File(getBasedir(), "pom.xml")); + super.setDependencyArtifacts(new HashSet<>()); + super.setArtifacts(new HashSet<>()); + super.setExtensionArtifacts(new HashSet<>()); + super.setRemoteArtifactRepositories(new LinkedList<>()); + super.setPluginArtifactRepositories(new LinkedList<>()); + super.setCollectedProjects(new LinkedList<>()); + super.setActiveProfiles(new LinkedList<>()); + super.setOriginalModel(null); + super.setExecutionProject(this); + super.setBuild(getBuild()); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java b/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java index a8e21192..4c4a621c 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectArtifactsStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,67 +16,57 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; +package org.apache.maven.plugins.war.stub; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; -public class MavenProjectArtifactsStub - extends MavenProjectBasicStub -{ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public class MavenProjectArtifactsStub extends MavenProjectBasicStub { TreeSet artifacts; - public MavenProjectArtifactsStub() - throws Exception - { + public MavenProjectArtifactsStub() throws Exception { artifacts = new TreeSet<>(); } - public void addArtifact( ArtifactStub stub ) - { - artifacts.add( stub ); + public void addArtifact(ArtifactStub stub) { + artifacts.add(stub); } - public Set getArtifacts() - { + public Set getArtifacts() { return artifacts; } - public List getDependencies() - { - if ( getArtifacts() == null ) - { + public List getDependencies() { + if (getArtifacts() == null) { return new ArrayList<>(); } final List dependencies = new ArrayList<>(); - for ( Artifact a : getArtifacts() ) - { + for (Artifact a : getArtifacts()) { Dependency dependency = new Dependency(); - dependency.setArtifactId( a.getArtifactId() ); - dependency.setGroupId( a.getGroupId() ); - dependency.setVersion( a.getVersion() ); - dependency.setScope( a.getScope() ); - dependency.setType( a.getType() ); - dependency.setClassifier( a.getClassifier() ); - dependencies.add( dependency ); - + dependency.setArtifactId(a.getArtifactId()); + dependency.setGroupId(a.getGroupId()); + dependency.setVersion(a.getVersion()); + dependency.setScope(a.getScope()); + dependency.setType(a.getType()); + dependency.setClassifier(a.getClassifier()); + dependencies.add(dependency); } return dependencies; } - public List getRuntimeClasspathElements() - { + public List getRuntimeClasspathElements() { List artifacts = new ArrayList<>(); artifacts.add( - "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar" ); + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar"); artifacts.add( - "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar" ); + "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar"); return artifacts; } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java b/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java index 7b2ac300..c54a2384 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; import java.util.HashSet; @@ -32,99 +31,79 @@ /** * Stub */ -public class MavenProjectBasicStub - extends MavenProject -{ +public class MavenProjectBasicStub extends MavenProject { protected String testRootDir; protected Properties properties; - public MavenProjectBasicStub() - throws Exception - { - super( new ModelStub() ); + public MavenProjectBasicStub() throws Exception { + super(new ModelStub()); properties = new Properties(); } - public Set getArtifacts() - { + public Set getArtifacts() { return new HashSet<>(); } - public String getName() - { + public String getName() { return "Test Project "; } - public File getBasedir() - { + public File getBasedir() { // create an isolated environment // see setupTestEnvironment for details - //return new File( testRootDir ); + // return new File( testRootDir ); return null; } - public String getGroupId() - { + public String getGroupId() { return "org.apache.maven.plugin.test"; } - public String getArtifactId() - { + public String getArtifactId() { return "maven-war-plugin-test"; } - public String getPackaging() - { + public String getPackaging() { return "jar"; } - public String getVersion() - { + public String getVersion() { return "0.0-Test"; } - public void addProperty( String key, String value ) - { - properties.put( key, value ); + public void addProperty(String key, String value) { + properties.put(key, value); } - public Properties getProperties() - { + public Properties getProperties() { return properties; } - public String getDescription() - { + public String getDescription() { return "Test Description"; } - public Organization getOrganization() - { - return new Organization() - { - public String getName() - { + public Organization getOrganization() { + return new Organization() { + public String getName() { return "Test Name"; } }; } @Override - public Build getBuild() - { + public Build getBuild() { Build build = super.getBuild(); - build.setDirectory( System.getProperty( "project.build.directory" ) ); - build.setOutputDirectory( System.getProperty( "project.build.outputDirectory" ) ); + build.setDirectory(System.getProperty("project.build.directory")); + build.setOutputDirectory(System.getProperty("project.build.outputDirectory")); return build; } - + @Override - public MavenProject clone() - { + public MavenProject clone() { return this; } - } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java b/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java index c2ff1700..dd24999e 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/MavenZipProject.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.util.HashSet; import java.util.Set; @@ -28,31 +27,23 @@ * @author Olivier Lamy * @since 9 juin 07 */ -public class MavenZipProject - extends MavenProject4CopyConstructor -{ +public class MavenZipProject extends MavenProject4CopyConstructor { private Set artifacts; - public MavenZipProject() - throws Exception - { + public MavenZipProject() throws Exception { super(); this.artifacts = new HashSet<>(); } - public Set getArtifacts() - { + public Set getArtifacts() { return this.artifacts; } - - public Set getDependencyArtifacts() - { + + public Set getDependencyArtifacts() { return this.artifacts; } - public void addArtifact( Artifact artifact ) - { - this.artifacts.add( artifact ); + public void addArtifact(Artifact artifact) { + this.artifacts.add(artifact); } - } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java b/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java index 5802fbbb..cb164c9a 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/ModelStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.util.LinkedList; import java.util.List; @@ -30,64 +29,49 @@ /** * Stub */ -public class ModelStub - extends Model -{ +public class ModelStub extends Model { private static final long serialVersionUID = 7802402157311376304L; - public ModelStub() - { - - } + public ModelStub() {} - public String getVersion() - { + public String getVersion() { return "0.0-TEST"; } - public String getModelVersion() - { + public String getModelVersion() { return "0.0-TEST"; } - public String getName() - { + public String getName() { return "Test Model"; } - public String getGroupId() - { + public String getGroupId() { return "org.apache.maven.test"; } - public String getPackaging() - { + public String getPackaging() { return "jar"; } - public Parent getParent() - { + public Parent getParent() { return new Parent(); } - public String getArtifactId() - { + public String getArtifactId() { return "maven-test-plugin"; } - public Properties getProperties() - { + public Properties getProperties() { return new Properties(); } - public List getProfiles() - { + public List getProfiles() { return new LinkedList<>(); } - public List getModules() - { + public List getModules() { return new LinkedList<>(); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java index 588b22e2..d92b10b9 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/PARArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,29 +16,24 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; -public class PARArtifactStub - extends AbstractArtifactStub -{ - public PARArtifactStub( String _basedir ) - { - super( _basedir ); +public class PARArtifactStub extends AbstractArtifactStub { + public PARArtifactStub(String _basedir) { + super(_basedir); } - public String getType() - { + public String getType() { return "par"; } - public String getArtifactId() - { + public String getArtifactId() { return "parartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/sample.par" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/sample.par"); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java b/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java index 9fe114f9..65b3316a 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/ProjectHelperStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; import java.util.List; @@ -25,57 +24,39 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; -public class ProjectHelperStub - implements MavenProjectHelper -{ +public class ProjectHelperStub implements MavenProjectHelper { File artifactFile; String artifactType; String artifactClassifier; - public File getArtifactFile() - { + public File getArtifactFile() { return artifactFile; } - public String getArtifactType() - { + public String getArtifactType() { return artifactType; } - public String getArtifactClassifier() - { + public String getArtifactClassifier() { return artifactClassifier; } - public void attachArtifact( MavenProject project, File artifactFile, String artifactClassifier ) - { + public void attachArtifact(MavenProject project, File artifactFile, String artifactClassifier) {} - } - - public void attachArtifact( MavenProject project, String artifactType, File artifactFile ) - { + public void attachArtifact(MavenProject project, String artifactType, File artifactFile) {} - } - - public void attachArtifact( MavenProject project, String _artifactType, String _artifactClassifier, - File _artifactFile ) - { + public void attachArtifact( + MavenProject project, String _artifactType, String _artifactClassifier, File _artifactFile) { artifactType = _artifactType; artifactClassifier = _artifactClassifier; artifactFile = _artifactFile; } - @SuppressWarnings( "rawtypes" ) - public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes ) - { - - } + @SuppressWarnings("rawtypes") + public void addResource(MavenProject project, String resourceDirectory, List includes, List excludes) {} - @SuppressWarnings( "rawtypes" ) - public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes ) - { - - } + @SuppressWarnings("rawtypes") + public void addTestResource(MavenProject project, String resourceDirectory, List includes, List excludes) {} } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java b/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java index dbe22b0b..789dc9dc 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/ResourceStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,40 +16,34 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.util.ArrayList; import java.util.List; import org.apache.maven.model.Resource; -public class ResourceStub - extends Resource -{ +public class ResourceStub extends Resource { /** - * + * */ private static final long serialVersionUID = 7685068931840967662L; private String directory; - public List getIncludes() - { + public List getIncludes() { return new ArrayList<>(); } - public List getExcludes() - { + public List getExcludes() { return new ArrayList<>(); } - public void setDirectory( String _directory ) - { + public void setDirectory(String _directory) { directory = _directory; } - public String getDirectory() - { + public String getDirectory() { return directory; } - } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java index bd2c2fd6..8194431a 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/TLDArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,29 +16,24 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; -public class TLDArtifactStub - extends AbstractArtifactStub -{ - public TLDArtifactStub( String _basedir ) - { - super( _basedir ); +public class TLDArtifactStub extends AbstractArtifactStub { + public TLDArtifactStub(String _basedir) { + super(_basedir); } - public String getType() - { + public String getType() { return "tld"; } - public String getArtifactId() - { + public String getArtifactId() { return "tldartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/tld.jar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/tld.jar"); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java b/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java index c2b05b29..77c07d62 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/WarArtifact4CCStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -27,31 +26,24 @@ * stub for copy constructor * to prevent the copy constructor from blowing up */ -public class WarArtifact4CCStub - extends WarArtifactStub -{ - public WarArtifact4CCStub( String basedir ) - { - super( basedir ); +public class WarArtifact4CCStub extends WarArtifactStub { + public WarArtifact4CCStub(String basedir) { + super(basedir); } - public VersionRange getVersionRange() - { - return VersionRange.createFromVersion( getVersion() ); + public VersionRange getVersionRange() { + return VersionRange.createFromVersion(getVersion()); } - public String getGroupId() - { + public String getGroupId() { return "org.maven.plugin.test"; } - public String getClassifier() - { + public String getClassifier() { return "testclassifier"; } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return new DefaultArtifactHandler(); } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java index 9b4c63ea..a3ee43d9 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/WarArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; /** * Stub */ -public class WarArtifactStub - extends AbstractArtifactStub -{ +public class WarArtifactStub extends AbstractArtifactStub { private String groupId; @@ -36,80 +33,59 @@ public class WarArtifactStub private File file; - public WarArtifactStub( String _basedir ) - { - super( _basedir ); + public WarArtifactStub(String _basedir) { + super(_basedir); } - public String getType() - { + public String getType() { return "war"; } - public String getArtifactId() - { - if ( artifactId == null ) - { + public String getArtifactId() { + if (artifactId == null) { return "simple"; - } - else - { + } else { return artifactId; } } - public void setArtifactId( String _artifactId ) - { + public void setArtifactId(String _artifactId) { artifactId = _artifactId; } - - public String getGroupId() - { - if ( groupId == null ) - { + public String getGroupId() { + if (groupId == null) { return "wartests"; - } - else - { + } else { return groupId; } } - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { this.groupId = groupId; } - public File getFile() - { - if ( file == null ) - { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); - } - else - { + public File getFile() { + if (file == null) { + return new File(basedir, "/target/test-classes/unit/sample_wars/simple.war"); + } else { return file; } } - public void setFile( File _file ) - { + public void setFile(File _file) { file = _file; } - public String getClassifier() - { + public String getClassifier() { return classifier; } - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { this.classifier = classifier; } - public boolean hasClassifier() - { + public boolean hasClassifier() { return classifier != null; } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java b/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java index 892f9791..0f3d7ced 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/WarOverlayStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,59 +16,47 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; /** * @author Stephane Nicoll */ -public class WarOverlayStub - extends AbstractArtifactStub -{ - +public class WarOverlayStub extends AbstractArtifactStub { private final String artifactId; private File file; - public WarOverlayStub( String _basedir, String artifactId, File warFile ) - { - super( _basedir ); - if ( artifactId == null ) - { - throw new NullPointerException( "Id could not be null." ); + public WarOverlayStub(String _basedir, String artifactId, File warFile) { + super(_basedir); + if (artifactId == null) { + throw new NullPointerException("Id could not be null."); } - if ( warFile == null ) - { - throw new NullPointerException( "warFile could not be null." ); + if (warFile == null) { + throw new NullPointerException("warFile could not be null."); - } - else if ( !warFile.exists() ) - { - throw new IllegalStateException( "warFile[" + file.getAbsolutePath() + "] should exist." ); + } else if (!warFile.exists()) { + throw new IllegalStateException("warFile[" + file.getAbsolutePath() + "] should exist."); } this.artifactId = artifactId; this.file = warFile; } - public String getType() - { + public String getType() { return "war"; } - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } - public String getGroupId() - { + public String getGroupId() { return "wartests"; } - public File getFile() - { + public File getFile() { return file; } - } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java index 92e195f2..2365547d 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/XarArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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,62 +16,50 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; +import java.io.File; import org.apache.maven.artifact.handler.ArtifactHandler; -import java.io.File; - /** * @author Auke Schrijnen */ -public class XarArtifactStub - extends AbstractArtifactStub -{ +public class XarArtifactStub extends AbstractArtifactStub { protected String groupId; private ArtifactHandler artifactHandler; - public XarArtifactStub( String basedir, ArtifactHandler artifactHandler ) - { - super( basedir ); + public XarArtifactStub(String basedir, ArtifactHandler artifactHandler) { + super(basedir); this.artifactHandler = artifactHandler; } - public void setGroupId( String id ) - { + public void setGroupId(String id) { groupId = id; } - public String getGroupId() - { - if ( groupId != null ) - { + public String getGroupId() { + if (groupId != null) { return groupId; - } - else - { + } else { return "org.sample.xar"; } } - public String getType() - { + public String getType() { return "xar"; } - public String getArtifactId() - { + public String getArtifactId() { return "xarartifact"; } - public File getFile() - { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.xar" ); + public File getFile() { + return new File(basedir, "/target/test-classes/unit/sample_wars/simple.xar"); } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return artifactHandler; } } diff --git a/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java b/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java index 50c01d98..02092c07 100644 --- a/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java +++ b/src/test/java/org/apache/maven/plugins/war/stub/ZipArtifactStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.war.stub; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "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 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.stub; import java.io.File; @@ -27,63 +26,48 @@ * @author Olivier Lamy * @since 8 juin 07 */ -public class ZipArtifactStub - extends AbstractArtifactStub -{ +public class ZipArtifactStub extends AbstractArtifactStub { private File zip; - public ZipArtifactStub( String basedir, ArtifactHandler artifactHandler, File zipFile ) - { - super( basedir ); - super.setArtifactHandler( artifactHandler ); + public ZipArtifactStub(String basedir, ArtifactHandler artifactHandler, File zipFile) { + super(basedir); + super.setArtifactHandler(artifactHandler); this.zip = zipFile; } - - public String getId() - { + public String getId() { return null; } - public ArtifactHandler getArtifactHandler() - { + public ArtifactHandler getArtifactHandler() { return super.getArtifactHandler(); } - public String getScope() - { + public String getScope() { return super.getScope(); } - public String getVersion() - { + public String getVersion() { return "1.0"; } - public boolean isOptional() - { + public boolean isOptional() { return super.isOptional(); } - public File getFile() - { + public File getFile() { return this.zip; } - public String getType() - { + public String getType() { return "zip"; } - - public String getArtifactId() - { + public String getArtifactId() { return "zipId"; } - public String getGroupId() - { + public String getGroupId() { return "zipGroupId"; } - } diff --git a/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java b/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java index 6375109e..da8558e2 100644 --- a/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.java +++ b/src/test/java/org/apache/maven/plugins/war/util/PathSetTest.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 @@ -9,7 +7,7 @@ * "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,11 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import junit.framework.TestCase; - -import org.apache.maven.plugins.war.util.PathSet; -import org.codehaus.plexus.util.StringUtils; +package org.apache.maven.plugins.war.util; import java.io.File; import java.io.IOException; @@ -30,38 +24,36 @@ import java.util.Iterator; import java.util.Set; -public class PathSetTest - extends TestCase -{ +import junit.framework.TestCase; +import org.codehaus.plexus.util.StringUtils; + +public class PathSetTest extends TestCase { /* --------------- Normalization tests --------------*/ /** * Test method for 'org.apache.maven.plugin.war.PathSet.normalizeSubPath(String)' */ - public void testNormalizeSubPath() - { - assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "" ) ); - assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "/" ) ); - assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "////" ) ); - assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "\\" ) ); - assertEquals( "Normalized path error", "", PathSet.normalizeSubPath( "\\\\\\\\" ) ); - - assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "abc" ) ); - assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "/abc" ) ); - assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "////abc" ) ); - assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "\\abc" ) ); - assertEquals( "Normalized path error", "abc", PathSet.normalizeSubPath( "\\\\\\\\abc" ) ); - - assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "abc/def\\xyz\\" ) ); - assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "/abc/def/xyz/" ) ); - assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "////abc/def/xyz/" ) ); - assertEquals( "Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath( "\\abc/def/xyz/" ) ); - assertEquals( "Normalized path error", "abc/def/xyz", - PathSet.normalizeSubPath( "\\\\\\\\abc/def/xyz/" ) ); + public void testNormalizeSubPath() { + assertEquals("Normalized path error", "", PathSet.normalizeSubPath("")); + assertEquals("Normalized path error", "", PathSet.normalizeSubPath("/")); + assertEquals("Normalized path error", "", PathSet.normalizeSubPath("////")); + assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\")); + assertEquals("Normalized path error", "", PathSet.normalizeSubPath("\\\\\\\\")); + + assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("abc")); + assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("/abc")); + assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("////abc")); + assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\abc")); + assertEquals("Normalized path error", "abc", PathSet.normalizeSubPath("\\\\\\\\abc")); + + assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("abc/def\\xyz\\")); + assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("/abc/def/xyz/")); + assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("////abc/def/xyz/")); + assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\abc/def/xyz/")); + assertEquals("Normalized path error", "abc/def/xyz", PathSet.normalizeSubPath("\\\\\\\\abc/def/xyz/")); // MWAR-371 - assertEquals( "Normalized path error", "abc/def/ghi", - PathSet.normalizeSubPath( "///abc/////def////ghi//" ) ); + assertEquals("Normalized path error", "abc/def/ghi", PathSet.normalizeSubPath("///abc/////def////ghi//")); } /* -------------- Operations tests ------------------*/ @@ -78,27 +70,26 @@ public void testNormalizeSubPath() *
  • org.apache.maven.plugin.war.PathSet.addPrefix(String)
  • *
*/ - public void testPathsSetBasic() - { + public void testPathsSetBasic() { PathSet ps = new PathSet(); - assertEquals( "Unexpected PathSet size", ps.size(), 0 ); + assertEquals("Unexpected PathSet size", ps.size(), 0); Iterator iter = ps.iterator(); - assertNotNull( "Iterator is null", iter ); - assertFalse( "Can iterate on empty set", iter.hasNext() ); - - ps.add( "abc" ); - assertEquals( "Unexpected PathSet size", ps.size(), 1 ); - ps.add( "abc" ); - assertEquals( "Unexpected PathSet size", ps.size(), 1 ); - ps.add( "xyz/abc" ); - assertEquals( "Unexpected PathSet size", ps.size(), 2 ); - ps.add( "///abc" ); - assertEquals( "Unexpected PathSet size", ps.size(), 2 ); - ps.add( "///xyz\\abc" ); - assertEquals( "Unexpected PathSet size", ps.size(), 2 ); - - ps.addAll( ps ); - assertEquals( "Unexpected PathSet size", ps.size(), 2 ); + assertNotNull("Iterator is null", iter); + assertFalse("Can iterate on empty set", iter.hasNext()); + + ps.add("abc"); + assertEquals("Unexpected PathSet size", ps.size(), 1); + ps.add("abc"); + assertEquals("Unexpected PathSet size", ps.size(), 1); + ps.add("xyz/abc"); + assertEquals("Unexpected PathSet size", ps.size(), 2); + ps.add("///abc"); + assertEquals("Unexpected PathSet size", ps.size(), 2); + ps.add("///xyz\\abc"); + assertEquals("Unexpected PathSet size", ps.size(), 2); + + ps.addAll(ps); + assertEquals("Unexpected PathSet size", ps.size(), 2); int i = 0; for (String pathstr : ps) { @@ -109,9 +100,9 @@ public void testPathsSetBasic() assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a")); assertFalse(ps.contains("/a/" + StringUtils.replace(pathstr, '/', '\\'))); } - assertEquals( "Wrong count of iterations", 2, i ); + assertEquals("Wrong count of iterations", 2, i); - ps.addPrefix( "/ab/c/" ); + ps.addPrefix("/ab/c/"); i = 0; for (String pathstr : ps) { i++; @@ -123,7 +114,7 @@ public void testPathsSetBasic() assertFalse(ps.contains("/" + StringUtils.replace(pathstr, '/', '\\') + "/a")); assertFalse(ps.contains("/ab/" + StringUtils.replace(pathstr, '/', '\\'))); } - assertEquals( "Wrong count of iterations", 2, i ); + assertEquals("Wrong count of iterations", 2, i); } /** @@ -136,27 +127,26 @@ public void testPathsSetBasic() *
  • org.apache.maven.plugin.war.PathSet.AddAll(Collection,String)
  • * */ - public void testPathsSetAddAlls() - { + public void testPathsSetAddAlls() { Set s1set = new HashSet<>(); - s1set.add( "/a/b" ); - s1set.add( "a/b/c" ); - s1set.add( "a\\b/c" ); - s1set.add( "//1//2\3a" ); + s1set.add("/a/b"); + s1set.add("a/b/c"); + s1set.add("a\\b/c"); + s1set.add("//1//2\3a"); - String[] s2ar = new String[]{"/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a"}; + String[] s2ar = new String[] {"/a/b", "a2/b2/c2", "a2\\b2/c2", "//21//22\23a"}; - PathSet ps1 = new PathSet( s1set ); - assertEquals( "Unexpected PathSet size", 3, ps1.size() ); + PathSet ps1 = new PathSet(s1set); + assertEquals("Unexpected PathSet size", 3, ps1.size()); - PathSet ps2 = new PathSet( s2ar ); - assertEquals( "Unexpected PathSet size", 3, ps2.size() ); + PathSet ps2 = new PathSet(s2ar); + assertEquals("Unexpected PathSet size", 3, ps2.size()); - ps1.addAll( s2ar ); - assertEquals( "Unexpected PathSet size", 5, ps1.size() ); + ps1.addAll(s2ar); + assertEquals("Unexpected PathSet size", 5, ps1.size()); - ps2.addAll( s1set ); - assertEquals( "Unexpected PathSet size", 5, ps2.size() ); + ps2.addAll(s1set); + assertEquals("Unexpected PathSet size", 5, ps2.size()); for (String str : ps1) { assertTrue(str, ps2.contains(str)); @@ -172,11 +162,11 @@ public void testPathsSetAddAlls() assertTrue(ps2.contains("/" + str)); } - ps1.addAll( s2ar, "/pref/" ); - assertEquals( "Unexpected PathSet size", 8, ps1.size() ); + ps1.addAll(s2ar, "/pref/"); + assertEquals("Unexpected PathSet size", 8, ps1.size()); - ps2.addAll( s2ar, "/pref/" ); - assertEquals( "Unexpected PathSet size", 8, ps2.size() ); + ps2.addAll(s2ar, "/pref/"); + assertEquals("Unexpected PathSet size", 8, ps2.size()); for (String str : ps1) { assertTrue(str, ps2.contains(str)); @@ -193,8 +183,8 @@ public void testPathsSetAddAlls() } PathSet ps3 = new PathSet(); - ps3.addAll(new String[]{ "a/b/c" }, "d"); - assertTrue( "Unexpected PathSet path", ps3.contains( "d/a/b/c" ) ); + ps3.addAll(new String[] {"a/b/c"}, "d"); + assertTrue("Unexpected PathSet path", ps3.contains("d/a/b/c")); } /** @@ -202,34 +192,32 @@ public void testPathsSetAddAlls() * * @throws IOException if an io error occurred */ - public void testAddAllFilesInDirectory() - throws IOException - { + public void testAddAllFilesInDirectory() throws IOException { PathSet ps = new PathSet(); /* Preparing directory structure*/ - File testDir = new File( "target/testAddAllFilesInDirectory" ); + File testDir = new File("target/testAddAllFilesInDirectory"); testDir.mkdirs(); - File f1 = new File( testDir, "f1" ); + File f1 = new File(testDir, "f1"); f1.createNewFile(); - File f2 = new File( testDir, "f2" ); + File f2 = new File(testDir, "f2"); f2.createNewFile(); - File d1 = new File( testDir, "d1" ); - File d1d2 = new File( testDir, "d1/d2" ); + File d1 = new File(testDir, "d1"); + File d1d2 = new File(testDir, "d1/d2"); d1d2.mkdirs(); - File d1d2f1 = new File( d1d2, "f1" ); + File d1d2f1 = new File(d1d2, "f1"); d1d2f1.createNewFile(); - File d1d2f2 = new File( d1d2, "f2" ); + File d1d2f2 = new File(d1d2, "f2"); d1d2f2.createNewFile(); - ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); - assertEquals( "Unexpected PathSet size", 4, ps.size() ); + ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/"); + assertEquals("Unexpected PathSet size", 4, ps.size()); /*No changes after adding duplicates*/ - ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); - assertEquals( "Unexpected PathSet size", 4, ps.size() ); + ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/"); + assertEquals("Unexpected PathSet size", 4, ps.size()); /*Cleanup*/ @@ -237,8 +225,8 @@ public void testAddAllFilesInDirectory() f2.delete(); /*No changes after adding a subset of files*/ - ps.addAllFilesInDirectory( new File( "target/testAddAllFilesInDirectory" ), "123/" ); - assertEquals( "Unexpected PathSet size", 4, ps.size() ); + ps.addAllFilesInDirectory(new File("target/testAddAllFilesInDirectory"), "123/"); + assertEquals("Unexpected PathSet size", 4, ps.size()); d1d2f1.delete(); d1d2f2.delete(); @@ -246,12 +234,12 @@ public void testAddAllFilesInDirectory() d1.delete(); testDir.delete(); - assertTrue( ps.contains( "123/f1" ) ); - assertTrue( ps.contains( "/123/f1" ) ); - assertTrue( ps.contains( "123\\f1" ) ); - assertTrue( ps.contains( "123\\f2" ) ); - assertTrue( ps.contains( "\\123/d1\\d2/f1" ) ); - assertTrue( ps.contains( "123\\d1/d2\\f2" ) ); - assertFalse( ps.contains( "123\\f3" ) ); + assertTrue(ps.contains("123/f1")); + assertTrue(ps.contains("/123/f1")); + assertTrue(ps.contains("123\\f1")); + assertTrue(ps.contains("123\\f2")); + assertTrue(ps.contains("\\123/d1\\d2/f1")); + assertTrue(ps.contains("123\\d1/d2\\f2")); + assertFalse(ps.contains("123\\f3")); } } diff --git a/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java b/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java index 3b2b1859..6d13b1e6 100644 --- a/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.java +++ b/src/test/java/org/apache/maven/plugins/war/util/WebappStructureTest.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 @@ -9,7 +7,7 @@ * "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,97 +16,77 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.war.util; + +import java.util.ArrayList; import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; -import org.apache.maven.plugins.war.util.WebappStructure; - -import java.util.ArrayList; /** * @author Stephane Nicoll */ -public class WebappStructureTest - extends TestCase -{ - public void testUnknownFileNotAvailable() - { - final WebappStructure structure = new WebappStructure( new ArrayList<>() ); - assertFalse( structure.isRegistered( "/foo/bar.txt" ) ); +public class WebappStructureTest extends TestCase { + public void testUnknownFileNotAvailable() { + final WebappStructure structure = new WebappStructure(new ArrayList<>()); + assertFalse(structure.isRegistered("/foo/bar.txt")); } - public void testRegisterSamePathTwice() - { - final WebappStructure structure = new WebappStructure( new ArrayList<>() ); - structure.registerFile( "overlay1", "WEB-INF/web.xml" ); - assertFalse( structure.registerFile( "currentBuild", "WEB-INF/web.xml" ) ); + public void testRegisterSamePathTwice() { + final WebappStructure structure = new WebappStructure(new ArrayList<>()); + structure.registerFile("overlay1", "WEB-INF/web.xml"); + assertFalse(structure.registerFile("currentBuild", "WEB-INF/web.xml")); } - public void testRegisterForced() - { + public void testRegisterForced() { final String path = "WEB-INF/web.xml"; - final WebappStructure structure = new WebappStructure( new ArrayList<>() ); - assertFalse("New file should return false", - structure.registerFileForced( "overlay1", path )); - assertEquals( "overlay1", structure.getOwner( path ) ); + final WebappStructure structure = new WebappStructure(new ArrayList<>()); + assertFalse("New file should return false", structure.registerFileForced("overlay1", path)); + assertEquals("overlay1", structure.getOwner(path)); } - public void testRegisterSamePathTwiceForced() - { + public void testRegisterSamePathTwiceForced() { final String path = "WEB-INF/web.xml"; - final WebappStructure structure = new WebappStructure( new ArrayList<>() ); - structure.registerFile( "overlay1", path ); - assertEquals( "overlay1", structure.getOwner( path ) ); - assertTrue("owner replacement should have returned true", - structure.registerFileForced( "currentBuild", path )); - assertEquals("currentBuild", structure.getOwner( path )); + final WebappStructure structure = new WebappStructure(new ArrayList<>()); + structure.registerFile("overlay1", path); + assertEquals("overlay1", structure.getOwner(path)); + assertTrue("owner replacement should have returned true", structure.registerFileForced("currentBuild", path)); + assertEquals("currentBuild", structure.getOwner(path)); } - - protected Dependency createDependency( String groupId, String artifactId, String version, String type, String scope, - String classifier ) - { + protected Dependency createDependency( + String groupId, String artifactId, String version, String type, String scope, String classifier) { final Dependency dep = new Dependency(); - dep.setGroupId( groupId ); - dep.setArtifactId( artifactId ); - dep.setVersion( version ); - if ( type == null ) - { - dep.setType( "jar" ); - } - else - { - dep.setType( type ); - } - if ( scope != null ) - { - dep.setScope( scope ); + dep.setGroupId(groupId); + dep.setArtifactId(artifactId); + dep.setVersion(version); + if (type == null) { + dep.setType("jar"); + } else { + dep.setType(type); } - else - { - dep.setScope( Artifact.SCOPE_COMPILE ); + if (scope != null) { + dep.setScope(scope); + } else { + dep.setScope(Artifact.SCOPE_COMPILE); } - if ( classifier != null ) - { - dep.setClassifier( classifier ); + if (classifier != null) { + dep.setClassifier(classifier); } return dep; } - protected Dependency createDependency( String groupId, String artifactId, String version, String type, - String scope ) - { - return createDependency( groupId, artifactId, version, type, scope, null ); + protected Dependency createDependency( + String groupId, String artifactId, String version, String type, String scope) { + return createDependency(groupId, artifactId, version, type, scope, null); } - protected Dependency createDependency( String groupId, String artifactId, String version, String type ) - { - return createDependency( groupId, artifactId, version, type, null ); + protected Dependency createDependency(String groupId, String artifactId, String version, String type) { + return createDependency(groupId, artifactId, version, type, null); } - protected Dependency createDependency( String groupId, String artifactId, String version ) - { - return createDependency( groupId, artifactId, version, null ); + protected Dependency createDependency(String groupId, String artifactId, String version) { + return createDependency(groupId, artifactId, version, null); } }