Skip to content

Commit

Permalink
refactor outdated resource management internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jun 13, 2020
1 parent 6e4a16a commit c748932
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Expand Up @@ -801,9 +801,19 @@ public Boolean isFailOnMissingWebXml()
}

@Override
public Collection<String> getOutdatedResources()
public void addResource( String resource )
{
return outdatedResources;
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();
}
}
}

Expand Down
Expand Up @@ -242,7 +242,7 @@ protected boolean copyFilteredFile( String sourceId, final WarPackagingContext c
String targetFilename )
throws IOException, MojoExecutionException
{
context.getOutdatedResources().remove( targetFilename.replace( '/', File.separatorChar ) );
context.addResource( targetFilename );

if ( context.getWebappStructure().registerFile( sourceId, targetFilename ) )
{
Expand Down Expand Up @@ -335,7 +335,7 @@ protected boolean copyFile( WarPackagingContext context, File source, File desti
boolean onlyIfModified )
throws IOException
{
context.getOutdatedResources().remove( targetFilename.replace( '/', File.separatorChar ) );
context.addResource( targetFilename );

if ( onlyIfModified && destination.lastModified() >= source.lastModified() )
{
Expand Down
Expand Up @@ -110,7 +110,7 @@ protected void generateJarArchive( WarPackagingContext context )

if ( context.getWebappStructure().registerFile( currentProjectOverlay.getId(), targetFilename ) )
{
context.getOutdatedResources().remove( targetFilename.replace( '/', File.separatorChar ) );
context.addResource( targetFilename );

final File libDirectory = new File( context.getWebappDirectory(), LIB_PATH );
final File jarFile = new File( libDirectory, archiveName );
Expand Down
Expand Up @@ -20,7 +20,6 @@
*/

import java.io.File;
import java.util.Collection;
import java.util.List;

import org.apache.maven.archiver.MavenArchiveConfiguration;
Expand Down Expand Up @@ -223,12 +222,24 @@ public interface WarPackagingContext
Boolean isFailOnMissingWebXml();

/**
* Add a live resource to the war.
* Used to keep track of existing resources and all copied files.
* All others are outdated and should be removed.
* This prevent calling <code>clean</code> when resources are removed.
* All others are outdated and will be removed.
* This prevent calling <code>mvn clean</code> when resources are removed.
*
* @return the outdated resources
* @since 3.2.4
* @param resource the resource that is to me marked as not outdated
* @since 3.3.0
* @see #deleteOutdatedResources()
*/
Collection<String> getOutdatedResources();
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 <code>mvn clean</code> when resources are removed.
*
* @since 3.3.0
* @see #addResource
*/
void deleteOutdatedResources();
}
Expand Up @@ -112,11 +112,7 @@ public void performPackaging( WarPackagingContext context )

if ( !context.getWebappDirectory().mkdirs() )
{
for ( String resource : context.getOutdatedResources() )
{
context.getLog().info( "deleting outdated resource " + resource );
new File( context.getWebappDirectory(), resource ).delete();
}
context.deleteOutdatedResources();
}
}

Expand Down

0 comments on commit c748932

Please sign in to comment.