Skip to content

Commit

Permalink
o Implementing filtering for rpm and pkg. The pkg part is not very we…
Browse files Browse the repository at this point in the history
…ll tested yet.

Should fix issue #1.
  • Loading branch information
trygvis committed Feb 15, 2013
1 parent f96f0cc commit c5dbf6a
Show file tree
Hide file tree
Showing 44 changed files with 431 additions and 287 deletions.
4 changes: 4 additions & 0 deletions TODO.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ o Make sure the result of setLastModified is asserted

o Make sure that timestamps are preserved for all assembly operations

o Perform all io operations (IOEffect's) in a thread pool for faster execution.
This might not be so easy for ZIP, but will be very useful for the other kinds that require copying of files to an
assembly area.

== Refactorings ==

== Functional Java ==
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<properties>
<version.functionaljava>3.0</version.functionaljava>
<version.maven-apis>3.0</version.maven-apis>
<version.maven-clean-plugin>2.5</version.maven-clean-plugin>
<version.maven-compiler-plugin>2.3.1</version.maven-compiler-plugin>
<version.maven-dependency-plugin>2.5</version.maven-dependency-plugin>
<version.maven-deploy-plugin>2.5</version.maven-deploy-plugin>
Expand Down Expand Up @@ -127,6 +128,10 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${version.maven-clean-plugin}</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
Expand Down Expand Up @@ -169,8 +174,6 @@
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>utf-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!--
Expand Down
3 changes: 1 addition & 2 deletions unix-common/src/main/java/org/codehaus/mojo/unix/UnixFileMode.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public int toInt()
return mode;
}

@Override
public boolean equals( Object o )
{
if ( this == o )
Expand All @@ -105,7 +104,7 @@ public boolean equals( Object o )

public String toString()
{
StringBuffer buffer = new StringBuffer( " " );
StringBuilder buffer = new StringBuilder( " " );
buffer.setCharAt( 0, (mode & 0x100) > 0 ? 'r' : '-' );
buffer.setCharAt( 1, (mode & 0x080) > 0 ? 'w' : '-' );
buffer.setCharAt( 2, (mode & 0x040) > 0 ? 'x' : '-' );
Expand Down
10 changes: 8 additions & 2 deletions unix-common/src/main/java/org/codehaus/mojo/unix/UnixPackage.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
*/
public abstract class UnixPackage<UP extends UnixPackage<UP>>
public abstract class UnixPackage<UP extends UnixPackage<UP, PP>, PP extends UnixPackage.PreparedPackage>
implements FileCollector
{
private final String packageFileExtension;
Expand Down Expand Up @@ -93,7 +93,7 @@ public UP setVersion( PackageVersion version )
public abstract void beforeAssembly( FileAttributes defaultDirectoryAttributes, LocalDateTime timestamp )
throws IOException;

public abstract void packageToFile( File packageFile, ScriptUtil.Strategy strategy )
public abstract PP prepare( ScriptUtil.Strategy strategy )
throws Exception;

public final PackageVersion getVersion()
Expand All @@ -105,4 +105,10 @@ public String getPackageFileExtension()
{
return packageFileExtension;
}

public abstract class PreparedPackage
{
public abstract void packageToFile( File packageFile )
throws Exception;
}
}
4 changes: 2 additions & 2 deletions unix-core/src/main/java/org/codehaus/mojo/unix/core/FilterFilesOperation.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public void streamTo( LineStreamWriter streamWriter )
{
streamWriter.add( "Filter Files:" );
streamIncludesAndExcludes( streamWriter, includes, excludes );
streamWriter.add( "Replacers:" );
streamWriter.add( " Replacers:" );
for ( Replacer replacer : replacers )
{
streamWriter.add( " " + replacer.toString() );
streamWriter.add( " " + replacer.toString() );
}
}
}
35 changes: 23 additions & 12 deletions unix-core/src/main/java/org/codehaus/mojo/unix/core/FsFileCollector.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ public class FsFileCollector
{
private final List<IoEffect> operations = new ArrayList<IoEffect>();

private final List<F<UnixFsObject, Option<UnixFsObject>>> applications = new ArrayList<F<UnixFsObject, Option<UnixFsObject>>>();

public final LocalFs root;

public FsFileCollector( LocalFs root) throws IOException {
this.root = root;
mkdirs(root.file);
root.mkdir();
}

public void addDirectory( UnixFsObject.Directory directory )
Expand All @@ -72,11 +74,11 @@ public void addSymlink( UnixFsObject.Symlink symlink )

public void apply( F<UnixFsObject, Option<UnixFsObject>> f )
{
// Not implemented
applications.add( f );
}

public void collect()
throws IOException
throws Exception
{
for ( IoEffect operation : operations )
{
Expand Down Expand Up @@ -143,10 +145,17 @@ public CopyFileIoEffect( Fs from, UnixFsObject.RegularFile to )
public void run()
throws IOException
{
UnixFsObject adjustedTo = to;

for ( F<UnixFsObject, Option<UnixFsObject>> f : applications )
{
adjustedTo = f.f( adjustedTo ).orSome( adjustedTo );
}

P2<InputStream, Option<Long>> p2 =
filtersAndLineEndingHandingInputStream( to, from.inputStream() );
filtersAndLineEndingHandingInputStream( adjustedTo, from.inputStream() );

root.resolve( to.path ).copyFrom( from, p2._1() );
root.resolve( adjustedTo.path ).copyFrom( from, p2._1() );
}
}

Expand All @@ -161,7 +170,7 @@ public static P2<InputStream, Option<Long>> filtersAndLineEndingHandingInputStre
throws IOException
{
// With no filters *and* keeping the line endings we can stream the file directly. Like a BOSS!
if ( file.filters.isEmpty() && file.lineEnding.isKeep() )
if ( !needsFiltering( file ) )
{
return p( inputStream, Option.<Long>none() );
}
Expand Down Expand Up @@ -198,14 +207,11 @@ public static P2<InputStream, Option<Long>> filtersAndLineEndingHandingInputStre

while ( line != null )
{
fj.data.List<Replacer> filters = file.filters;
Iterable<Replacer> filters = file.filters;

if ( filters.isNotEmpty() )
for ( Replacer filter : filters )
{
for ( Replacer filter : filters )
{
line = filter.replace( line );
}
line = filter.replace( line );
}

output.write( line.getBytes() );
Expand All @@ -220,4 +226,9 @@ public static P2<InputStream, Option<Long>> filtersAndLineEndingHandingInputStre

return p( inputStream, some( size ) );
}

public static boolean needsFiltering( UnixFsObject file )
{
return file.filters.isNotEmpty() || !file.lineEnding.isKeep();
}
}
17 changes: 17 additions & 0 deletions unix-maven-plugin/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>src/it</directory>
<includes>
<include>*/target/**</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration-tests</id>
Expand Down
Empty file modified unix-maven-plugin/src/it/test-deb-1/pom4test.xml
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions unix-maven-plugin/src/it/test-rpm-1/pom4test.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
<path>/var/log/hudson</path>
<value>/var/opt/hudson/log</value>
</symlink>
<filterFiles>
<includes>
<include>/opt/hudson/etc/*</include>
</includes>
</filterFiles>
</assembly>
</configuration>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions unix-maven-plugin/src/it/test-rpm-1/postbuild.groovy
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ success &= assertRpmEntries(rpm, [
new RpmUtil.FileInfo("/opt", "root", "root", "drwxr-xr-x", 0, null),
new RpmUtil.FileInfo("/opt/hudson", "root", "root", "drwxr-xr-x", 0, null),
new RpmUtil.FileInfo("/opt/hudson/hudson.war", "hudson", "hudson", "-rw-r--r--", 20623413, null),
new RpmUtil.FileInfo("/opt/hudson/etc", "root", "root", "drwxr-xr-x", 0, null),
new RpmUtil.FileInfo("/opt/hudson/etc/config.properties", "root", "root", "-rw-r--r--", 14, null),
new RpmUtil.FileInfo("/usr", "root", "root", "drwxr-xr-x", 0, null),
new RpmUtil.FileInfo("/usr/share", "root", "root", "drwxr-xr-x", 0, null),
new RpmUtil.FileInfo("/usr/share/hudson", "root", "root", "drwxr-xr-x", 0, null),
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions unix-maven-plugin/src/it/test-sysvpkg-1/postbuild.groovy
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import static org.codehaus.mojo.unix.maven.plugin.ShittyUtil.*
import static org.codehaus.mojo.unix.sysvpkg.PkgchkUtil.*
import org.codehaus.mojo.unix.sysvpkg.PkginfoFile
import org.codehaus.mojo.unix.sysvpkg.Pkginfo
import org.codehaus.mojo.unix.sysvpkg.PkginfoUtil
import static fj.data.Option.*
import fj.data.Option
Expand All @@ -12,7 +12,7 @@ boolean success = true

File pkg = new File((File) basedir, "target/project-sysvpkg-1-1.1-2.pkg")

pkginfo = new PkginfoFile("all", "application", "Hudson", "project-sysvpkg-1", "1.1-2").
pkginfo = new Pkginfo("all", "application", "Hudson", "project-sysvpkg-1", "1.1-2").
email(some("[email protected]"))

success &= assertRelaxed(pkginfo, PkginfoUtil.getPackageInfoForDevice(pkg).some(), packageInfoEqual);
Expand Down
4 changes: 2 additions & 2 deletions unix-maven-plugin/src/it/test-sysvpkg-2/postbuild.groovy
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import static org.codehaus.mojo.unix.maven.plugin.ShittyUtil.*
import static org.codehaus.mojo.unix.sysvpkg.PkgchkUtil.*
import org.codehaus.mojo.unix.sysvpkg.PkginfoFile
import org.codehaus.mojo.unix.sysvpkg.Pkginfo
import org.codehaus.mojo.unix.sysvpkg.PkginfoUtil
import fj.data.Option
import org.joda.time.LocalDateTime
Expand All @@ -12,7 +12,7 @@ boolean success = true
File pkg = new File((File) basedir, "target/project-sysvpkg-2-1.1-2.pkg")

success &= assertRelaxed(
new PkginfoFile( "all", "application", "Hudson Slave", "project-sysvpkg-2", "1.1-2"),
new Pkginfo( "all", "application", "Hudson Slave", "project-sysvpkg-2", "1.1-2"),
PkginfoUtil.getPackageInfoForDevice(pkg).some(), packageInfoEqual);

success &= assertSysvPkgEntries(pkg, [
Expand Down
6 changes: 3 additions & 3 deletions unix-maven-plugin/src/it/test-sysvpkg-3/postbuild.groovy
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import static org.codehaus.mojo.unix.maven.plugin.ShittyUtil.*
import static org.codehaus.mojo.unix.sysvpkg.PkgchkUtil.*
import org.codehaus.mojo.unix.sysvpkg.PkginfoFile
import org.codehaus.mojo.unix.sysvpkg.Pkginfo
import org.codehaus.mojo.unix.sysvpkg.PkginfoUtil
import static fj.data.Option.*
import fj.data.Option
Expand All @@ -19,7 +19,7 @@ println "Hudson Master"
// No <description> inside <project>, no <description> inside <package> => null

success &= assertRelaxed(
new PkginfoFile( "all", "application", "Hudson Master", "project-sysvpkg-3", "1.1-2"),
new Pkginfo( "all", "application", "Hudson Master", "project-sysvpkg-3", "1.1-2"),
PkginfoUtil.getPackageInfoForDevice(main).some(), packageInfoEqual);

success &= assertSysvPkgEntries(main, [
Expand All @@ -45,7 +45,7 @@ println "Hudson Slave"
// This has the <description> set on <package> too
File slave = new File((File) basedir, "target/project-sysvpkg-3-slave-1.1-2.pkg")
success &= assertRelaxed(
new PkginfoFile( "all", "application", "Hudson Slave", "project-sysvpkg-3-slave", "1.1-2").desc(some("Hudson slave node")),
new Pkginfo( "all", "application", "Hudson Slave", "project-sysvpkg-3-slave", "1.1-2").desc(some("Hudson slave node")),
PkginfoUtil.getPackageInfoForDevice(slave).some(),
packageInfoEqual);

Expand Down
5 changes: 2 additions & 3 deletions unix-maven-plugin/src/it/test-sysvpkg-classes/postbuild.groovy
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import static org.codehaus.mojo.unix.maven.plugin.ShittyUtil.*
import static org.codehaus.mojo.unix.sysvpkg.PkgchkUtil.*
import org.codehaus.mojo.unix.sysvpkg.PkginfoUtil
import static fj.data.Option.*
import fj.data.Option
import org.joda.time.LocalDateTime
import org.codehaus.mojo.unix.sysvpkg.PkginfoFile;
import org.codehaus.mojo.unix.sysvpkg.Pkginfo;

Option<LocalDateTime> ldtNone = Option.none()

Expand All @@ -13,7 +12,7 @@ boolean success = true
File pkg = new File((File) basedir, "target/project-sysvpkg-classes-1.1.pkg")

success &= assertRelaxed(
new PkginfoFile("all", "application", "Hudson", "project-sysvpkg-classes", "1.1"),
new Pkginfo("all", "application", "Hudson", "project-sysvpkg-classes", "1.1"),
PkginfoUtil.getPackageInfoForDevice(pkg).some(), packageInfoEqual);

// Ignore dates for now
Expand Down
25 changes: 13 additions & 12 deletions unix-maven-plugin/src/main/java/org/codehaus/mojo/unix/maven/MojoHelper.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ public abstract class MojoHelper
public static final String DUPLICATE_CLASSIFIER = "Duplicate package classifier: '%s'.";
public static final String DUPLICATE_UNCLASSIFIED = "There can only be one package without an classifier.";

public static <UP extends UnixPackage<UP>> Execution create( Map platforms,
String platformType,
Map formats,
String formatType,
MavenProjectWrapper project,
boolean debug,
boolean attachedMode,
F<UP, UP> validateMojoSettingsAndApplyFormatSpecificSettingsToPackage,
PackagingMojoParameters mojoParameters,
final Log log )
public static <UP extends UnixPackage<UP, PP>, PP extends UnixPackage.PreparedPackage> Execution create(
Map platforms,
String platformType,
Map formats,
String formatType,
MavenProjectWrapper project,
boolean debug,
boolean attachedMode,
F<UP, UP> validateMojoSettingsAndApplyFormatSpecificSettingsToPackage,
PackagingMojoParameters mojoParameters,
final Log log )
throws MojoFailureException, MojoExecutionException
{
MavenCommonLoggingLogFactory.setMavenLogger( log );
Expand Down Expand Up @@ -290,8 +291,8 @@ private void execute_( String artifactType, MavenProject mavenProject, MavenProj

File packageFile = new File( project.buildDirectory, name );

unixPackage.
packageToFile( packageFile, strategy );
unixPackage.prepare( strategy ).
packageToFile( packageFile );

attach( pakke.classifier, artifactType, packageFile, mavenProject, mavenProjectHelper,
attachedMode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
*/
public class DebPackagingFormat
implements PackagingFormat
implements PackagingFormat<DebUnixPackage>
{
public DebUnixPackage start()
{
Expand Down
Loading

0 comments on commit c5dbf6a

Please sign in to comment.