[MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default
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('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 @@
@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 @@
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 @@
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.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 @@
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 );