Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRRESOURCES-102] Implement MRRESOURCES-102 #2

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public class ProcessRemoteResourcesMojo
private String[] resolveScopes;

/**
* Comma separated list of Artifact names too exclude.
* Comma separated list of Artifact names to exclude.
*
* @since 1.0
*/
Expand Down Expand Up @@ -424,6 +424,12 @@ public class ProcessRemoteResourcesMojo
@Parameter( property = "excludeTransitive", defaultValue = "false" )
protected boolean excludeTransitive;

/**
* Should we use resource filtering when copying the remote resources?
*/
@Parameter( property = "useResourceFiltering", defaultValue = "false" )
protected boolean useResourceFiltering;

/**
*/
@Component( hint = "default" )
Expand Down Expand Up @@ -847,8 +853,7 @@ protected boolean copyResourceIfExists( File file, String relFileName, VelocityC
}
else if ( resource.isFiltering() )
{

MavenFileFilterRequest req = setupRequest( resource, source, file );
MavenFileFilterRequest req = setupRequest( source, file, resource.isFiltering() );
Jurrie marked this conversation as resolved.
Show resolved Hide resolved

try
{
Expand Down Expand Up @@ -939,12 +944,12 @@ private void fileWriteIfDiffers( DeferredFileOutputStream outStream )
}
}

private MavenFileFilterRequest setupRequest( Resource resource, File source, File file )
private MavenFileFilterRequest setupRequest( File source, File file, boolean isFiltering )
{
MavenFileFilterRequest req = new MavenFileFilterRequest();
req.setFrom( source );
req.setTo( file );
req.setFiltering( resource.isFiltering() );
req.setFiltering( isFiltering );

req.setMavenProject( project );
req.setMavenSession( mavenSession );
Expand Down Expand Up @@ -1271,13 +1276,13 @@ protected void processResourceBundles( ClassLoader classLoader, VelocityContext
writer = null;
fileWriteIfDiffers( os );
}
else if ( useResourceFiltering )
{
filterBundleResource( classLoader, bundleResource, f );
}
else
{
URL resUrl = classLoader.getResource( bundleResource );
if ( resUrl != null )
{
FileUtils.copyURLToFile( resUrl, f );
}
copyBundleResource( classLoader, bundleResource, f );
}

File appendedResourceFile = new File( appendedResourcesDirectory, projectResource );
Expand Down Expand Up @@ -1336,6 +1341,41 @@ else if ( appendedVmResourceFile.exists() )
}
}

private void copyBundleResource( ClassLoader classLoader, String bundleResource, File to )
throws IOException
{
URL resUrl = classLoader.getResource( bundleResource );
if ( resUrl != null )
{
FileUtils.copyURLToFile( resUrl, to );
}
}

private void filterBundleResource( ClassLoader classLoader, String bundleResource, File to )
throws IOException, MojoExecutionException
{
File tmpFile = null;
try
{
tmpFile = File.createTempFile( "maven-remote-resources-plugin", null );
tmpFile.deleteOnExit();
Jurrie marked this conversation as resolved.
Show resolved Hide resolved
copyBundleResource( classLoader, bundleResource, tmpFile );
MavenFileFilterRequest req = setupRequest( tmpFile, to, true );
fileFilter.copyFile( req );
}
catch ( MavenFilteringException e )
{
throw new MojoExecutionException( "Error filtering remote resource: " + bundleResource, e );
}
finally
{
if ( tmpFile != null && !tmpFile.delete() )
{
getLog().warn( "Unable to delete temporary file: " + tmpFile );
}
}
}

protected Model getSupplement( Xpp3Dom supplementModelXml )
throws MojoExecutionException
{
Expand Down