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 3 commits
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 @@ -145,7 +145,7 @@ public class ProcessRemoteResourcesMojo
* <p>
* So, the default filtering delimiters might be specified as:
* </p>
*
*
* <pre>
* &lt;delimiters&gt;
* &lt;delimiter&gt;${*}&lt/delimiter&gt;
Expand Down Expand Up @@ -378,14 +378,14 @@ public class ProcessRemoteResourcesMojo
* The default is the same as "includeScope" if there are no exclude scopes set.
* Otherwise, it defaults to "test" to grab all the dependencies so the
* exclude filters can filter out what is not needed.
*
*
* @since 1.5
*/
@Parameter
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 );

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 )
{
MavenFileFilterRequest req = new MavenFileFilterRequest();
req.setFrom( source );
req.setTo( file );
req.setFiltering( resource.isFiltering() );
req.setFiltering( true );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this filtering always active, is that what we want?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property useResourceFiltering is still adhered to. It's evaluated on line 1279.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rfscholte do we need more review here?


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 );
copyBundleResource( classLoader, bundleResource, tmpFile );
MavenFileFilterRequest req = setupRequest( tmpFile, to );
fileFilter.copyFile( req );
}
catch ( MavenFilteringException e )
{
throw new MojoExecutionException( "Error filtering remote resource: " + bundleResource, e );
}
finally
{
if ( tmpFile != null && !tmpFile.delete() )
{
tmpFile.deleteOnExit();
getLog().warn( "Unable to delete temporary file: " + tmpFile + ". Trying again when this VM exits." );
}
}
}

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