From 062f6d49bf629d9246c999548727a97e7b150ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 27 Jun 2020 23:02:16 +0200 Subject: [PATCH] [MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default --- .../src/main/webapp/{index.html => root.html} | 0 .../verify.groovy | 2 +- .../maven/plugins/war/AbstractWarMojo.java | 22 ++++++++++++++++++- .../plugins/war/AbstractWarMojoTest.java | 7 +++--- 4 files changed, 26 insertions(+), 5 deletions(-) rename src/it/MWAR-427_update-without-clean/src/main/webapp/{index.html => root.html} (100%) 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 5fdf4744..ef9327d2 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 5595124c..0bded3cd 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 @@ else if ( getWarSourceDirectory().toPath().equals( webappDirectory.toPath() ) ) outdatedResources = new ArrayList<>(); try { + if ( '\\' == File.separatorChar ) + { + outdatedCheckPath = outdatedCheckPath.replace( '/', '\\' ); + } Files.walkFileTree( webappDirectory.toPath(), new SimpleFileVisitor() { @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 87344ad2..46403f7f 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 @@ protected void configureMojo( AbstractWarMojo mojo, List filters, File c 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 );