Skip to content

Commit

Permalink
o Change the semantics of file filtering so that when there are regex…
Browse files Browse the repository at this point in the history
…es specified, it doesn't include the property regexes.
  • Loading branch information
trygvis committed Feb 20, 2013
1 parent 806d9f9 commit dd21678
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
13 changes: 13 additions & 0 deletions unix-maven-plugin/src/it/test-zip-1/pom4test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<mode>0666</mode>
</attributes>
</copyArtifact>
<!-- Will result in a warning -->
<symlink>
<path>/var/log/hudson</path>
<value>/var/opt/hudson/log</value>
Expand All @@ -85,8 +86,20 @@
<include>/opt/hudson/etc/*</include>
</includes>
<excludes>
<exclude>/opt/hudson/etc/filter-2.conf</exclude>
<exclude>/opt/hudson/etc/unfiltered.properties</exclude>
</excludes>
<lineEnding>unix</lineEnding>
</filterFiles>
<filterFiles>
<includes>
<include>/opt/hudson/etc/*</include>
</includes>
<excludes>
<exclude>/opt/hudson/etc/filter-1.conf</exclude>
<exclude>/opt/hudson/etc/unfiltered.properties</exclude>
</excludes>
<lineEnding>unix</lineEnding>
<regexes>
<regex>
<!-- A simple regex -->
Expand Down
7 changes: 4 additions & 3 deletions unix-maven-plugin/src/it/test-zip-1/postbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ success &= assertZipEntries(zip, [
regularFile(r("/opt/hudson/hudson.war"), timestamps.hudsonWarTimestamp.timestamp, 20623413, EMPTY),

directory(r("/opt/hudson/etc"), START_OF_TIME, EMPTY),
regularFile(r("/opt/hudson/etc/app.conf"), timestamps.appConf.timestamp, 181, EMPTY),
regularFile(r("/opt/hudson/etc/config.properties"), timestamps.configProperties.timestamp, 14, EMPTY),
regularFile(r("/opt/hudson/etc/unfiltered.properties"), timestamps.configProperties.timestamp, 27, EMPTY),
regularFile(r("/opt/hudson/etc/filter-1.conf"), timestamps.filter1.timestamp, 237, EMPTY),
regularFile(r("/opt/hudson/etc/filter-2.conf"), timestamps.filter2.timestamp, 88, EMPTY),
regularFile(r("/opt/hudson/etc/filter-all.conf"), timestamps.filterAll.timestamp, 157, EMPTY),
regularFile(r("/opt/hudson/etc/unfiltered.properties"), timestamps.unfiltered.timestamp, 27, EMPTY),
])

return success

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Property specified in the project
my-property=${my-property}

# Property specified on the command line with -D
my-user-property=${my-user-property}

# System property. This is the most constant system property I could find.
java.class.version=${java.class.version}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
simple-regex=MY_PLACEHOLDER

# This should not be expanded
project.version=${project.version}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file is included in all <filterFiles>
# The ${double-test} will be expanded from the <property> in the pom, and again with a regex
double-test=${double-test}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import fj.data.List;
import org.apache.maven.plugin.*;
import org.codehaus.mojo.unix.*;
import org.codehaus.mojo.unix.core.*;
import org.codehaus.mojo.unix.io.*;

Expand Down Expand Up @@ -79,11 +80,27 @@ public void setRegexes( Regex[] regexes )
public AssemblyOperation createOperation( CreateOperationContext context )
throws MojoFailureException, UnknownArtifactException
{
try
LineEnding lineEnding1 = valueOf();

List<Replacer> replacers;
if ( regexes.length > 0 )
{
replacers = regexReplacers();
}
else
{
LineEnding lineEnding = LineEnding.valueOf( this.lineEnding );
replacers = propertyReplacers( context.project.properties );
}

return new FilterFilesOperation( includes, excludes, replacers, lineEnding1 );
}

return new FilterFilesOperation( includes, excludes, replacers( context.project.properties ), lineEnding );
private LineEnding valueOf()
throws MojoFailureException
{
try
{
return LineEnding.valueOf( lineEnding );
}
catch ( IllegalArgumentException e )
{
Expand All @@ -96,7 +113,7 @@ public AssemblyOperation createOperation( CreateOperationContext context )
*
* @see MavenProjectWrapper#mavenProjectWrapper
*/
private List<Replacer> replacers( Map<String, String> properties )
private List<Replacer> propertyReplacers( Map<String, String> properties )
throws MojoFailureException
{
List<Replacer> replacers = nil();
Expand All @@ -118,6 +135,13 @@ private List<Replacer> replacers( Map<String, String> properties )
}
}

return replacers;
}

private List<Replacer> regexReplacers()
{
List<Replacer> replacers = nil();

Replacer[] rs = new Replacer[regexes.length];
for ( int i = regexes.length - 1; i >= 0; i-- )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ class Deb1
class Zip1
extends Common
{
public final FileTimestamp appConf =
ft( "src/main/unix/files/opt/hudson/etc/app.conf", 2012, 2, 19, 10, 25, 2 );
public final FileTimestamp configProperties =
ft( "src/main/unix/files/opt/hudson/etc/config.properties", 2012, 1, 2, 3, 4, 6 );
public final FileTimestamp filter1 =
ft( "src/main/unix/files/opt/hudson/etc/filter-1.conf", 2013, 2, 19, 10, 25, 2 );
public final FileTimestamp filter2 =
ft( "src/main/unix/files/opt/hudson/etc/filter-2.conf", 2013, 1, 2, 3, 4, 6 );
public final FileTimestamp filterAll =
ft( "src/main/unix/files/opt/hudson/etc/filter-all.conf", 2013, 2, 20, 10, 37, 36 );
public final FileTimestamp unfiltered =
ft( "src/main/unix/files/opt/hudson/etc/unfiltered.properties", 2013, 2, 20, 10, 45, 20 );
}

public final Zip1 zip1;
Expand Down

0 comments on commit dd21678

Please sign in to comment.