You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/07/10 05:38:23 UTC

[maven-war-plugin] branch master updated: [MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-war-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 062f6d4  [MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default
062f6d4 is described below

commit 062f6d49bf629d9246c999548727a97e7b150ca5
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Jun 27 23:02:16 2020 +0200

    [MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default
---
 .../src/main/webapp/{index.html => root.html}      |  0
 src/it/MWAR-427_update-without-clean/verify.groovy |  2 +-
 .../apache/maven/plugins/war/AbstractWarMojo.java  | 22 +++++++++++++++++++++-
 .../maven/plugins/war/AbstractWarMojoTest.java     |  7 ++++---
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/it/MWAR-427_update-without-clean/src/main/webapp/index.html b/src/it/MWAR-427_update-without-clean/src/main/webapp/root.html
similarity index 100%
rename from src/it/MWAR-427_update-without-clean/src/main/webapp/index.html
rename to src/it/MWAR-427_update-without-clean/src/main/webapp/root.html
diff --git a/src/it/MWAR-427_update-without-clean/verify.groovy b/src/it/MWAR-427_update-without-clean/verify.groovy
index 5fdf474..ef9327d 100644
--- a/src/it/MWAR-427_update-without-clean/verify.groovy
+++ b/src/it/MWAR-427_update-without-clean/verify.groovy
@@ -23,4 +23,4 @@ assert warFile.getEntry('WEB-INF/lib/mwar427-1.0-SNAPSHOT.jar') != null
 assert warFile.getEntry('index.html') != null
 
 assert warFile.getEntry('WEB-INF/lib/plexus-utils-1.4.6.jar') == null
-assert warFile.getEntry('root.html') == null
\ No newline at end of file
+assert warFile.getEntry('root.html') != null // after MWAR-433, only WEB-INF/lib/ content is checked, other resources may be generated outside m-war-p
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
index 5595124..0bded3c 100644
--- a/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
@@ -362,6 +362,14 @@ public abstract class AbstractWarMojo
     @Parameter( defaultValue = "${project.build.outputTimestamp}" )
     protected String outputTimestamp;
 
+    /**
+     * Path prefix for resources that will be checked against outdated content.
+     *
+     * @since 3.3.1
+     */
+    @Parameter( defaultValue = "WEB-INF/lib/" )
+    private String outdatedCheckPath;
+
     private final Overlay currentProjectOverlay = Overlay.createInstance();
 
     /**
@@ -640,13 +648,25 @@ public abstract class AbstractWarMojo
                 outdatedResources = new ArrayList<>();
                 try
                 {
+                    if ( '\\' == File.separatorChar )
+                    {
+                        outdatedCheckPath = outdatedCheckPath.replace( '/', '\\' );
+                    }
                     Files.walkFileTree( webappDirectory.toPath(), new SimpleFileVisitor<Path>()
                     {
                         @Override
                         public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
                             throws IOException
                         {
-                            outdatedResources.add( webappDirectory.toPath().relativize( file ).toString() );
+                            if ( file.toFile().lastModified() < session.getStartTime().getTime() )
+                            {
+                                // resource older than session build start
+                                String path = webappDirectory.toPath().relativize( file ).toString();
+                                if ( path.startsWith( outdatedCheckPath ) )
+                                {
+                                    outdatedResources.add( path );
+                                }
+                            }
                             return super.visitFile( file, attrs );
                         }
                     } );
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 87344ad..46403f7 100644
--- a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.war;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 
 import org.apache.maven.execution.DefaultMavenExecutionRequest;
@@ -28,7 +29,6 @@ import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-import org.apache.maven.plugins.war.AbstractWarMojo;
 import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
 import org.apache.maven.plugins.war.stub.WarOverlayStub;
 import org.apache.maven.shared.filtering.MavenFileFilter;
@@ -71,12 +71,13 @@ public abstract class AbstractWarMojoTest
         setVariableValueToObject( mojo, "mavenFileFilter", lookup( MavenFileFilter.class.getName() ) );
         setVariableValueToObject( mojo, "useJvmChmod", Boolean.TRUE );
 
-        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
-        request.setSystemProperties( System.getProperties() );
+        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 );