Skip to content

Commit

Permalink
[MWAR-433] add outdatedCheckPath parameter with WEB-INF/lib/ default
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jul 10, 2020
1 parent 14d5d46 commit 062f6d4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/it/MWAR-427_update-without-clean/verify.groovy
Expand Up @@ -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
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
22 changes: 21 additions & 1 deletion src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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<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 );
}
} );
Expand Down
Expand Up @@ -21,14 +21,14 @@

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;

import org.apache.maven.execution.DefaultMavenExecutionRequest;
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;
Expand Down Expand Up @@ -71,12 +71,13 @@ protected void configureMojo( AbstractWarMojo mojo, List<String> 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 );
Expand Down

0 comments on commit 062f6d4

Please sign in to comment.