Example 2

Create a Tar archive from the contents of directory hierarchies d1 and d2, ignoring all .svn directories. Both directory hierarchies are stored under the directory ds-1.0 in the Tar file. The Tar archive will be written to two files in the directory d: the gzip compressed ds-1.0.tar.gz and the bzip2 compressed ds-1.0.tar.bz2.

JavaScript

enableTaskPackage("org.at4j"); noSvnFilter = new SuperParentOrFilter( new EntityNameFilter(".svn"), true).not(); new TarTF(). addSource( new EntityAndAbsoluteLocation( new DirectoryAndFilter(d1, noSvnFilter), "/ds-1.0")). addSource( new EntityAndAbsoluteLocation( new DirectoryAndFilter(d2, noSvnFilter), "/ds-1.0")). setTarget( // // Use a MultiplexingNewWritableFileProxy to make the task write the archive // to two different files. new MultiplexingNewWritableFileProxy( DontOverwriteAndThrowException.INSTANCE, // // An array containing the target files [ // // Use a GZipNewWritableFileProxy to create a gzipped file. new GZipNewWritableFileProxy( new FutureFile(d, "ds-1.0.tar.gz"), DontOverwriteAndThrowException.INSTANCE), // // Use a BZip2NewWritableFileProxy to create a bzipped file. new BZip2NewWritableFileProxy( new FutureFile(d, "ds-1.0.tar.bz2"), DontOverwriteAndThrowException.INSTANCE)])).run();

Example 3

Create a Tar archive with sources added in many different ways. The archive will be put in the directory d.

JavaScript

enableTaskPackage("org.at4j"); tmpDir = new File(Packages.java.lang.System.getProperty("java.io.tmpdir")); new TarTF(). // // A file added in the root directory of the Tar archive addSource(new File(tmpDir, "f1")). // // The contents of /tmp/d1 directory added under the d1 directory in the // Tar archive addSource( new EntityAndAbsoluteLocation( new File(tmpDir, "d1"), "/d1")). // // The contents of the string added as the file /doc/README addSource( new EntityAndAbsoluteLocation( new CharSequenceReadableFile( "This is the contents of the README file."), "/doc/README")). setTarget( new FutureFile(d, "misc.tar")).run();

Example 4

Create a Tar archive with custom metadata for its entries. For more information on custom metadata, read the At4J Programmer's Guide.

Groovy

// Enable the task package in the script header // enableTaskPackage org.at4j import org.at4j.archive.builder.* import org.at4j.tar.builder.TarEntrySettings import org.entityfs.el.AbsoluteLocation import org.entityfs.util.CharSequenceReadableFile import org.schmant.arg.EntityAndAbsoluteLocation import org.schmant.support.FutureFile import org.schmant.task.at4j.tar.* new TarTF(). // // Use an entity strategy that creates POSIX 1003.1-2001 (pax) entries. setEntryStrategy( // // Use the UTF-8 character encoding for encoding contents of the Tar file. new PaxTarEntryStrategy( Charset.forName("utf8"))). // // Set a user and group name for the tar entries' owner setDefaultFileEntrySettings( new TarEntrySettings(). setOwnerUserName("karl"). setOwnerGroupName("builders")). setDefaultDirectoryEntrySettings( new TarEntrySettings(). setOwnerUserName("karl"). setOwnerGroupName("builders")). // // Add a rule that says that all script files (taken as files with the file // name extension .sh) should be made Unix executable. addRule( new ArchiveEntrySettingsRule( new TarEntrySettings(). setEntityMode( // // World executable (mode 0755). UnixEntityMode.forCode(0755)), // // The filter that determines which entries that the rules will be applied // to. At4J comes with several predefined EntityToArchiveFilter:s. FileETAF.FILTER.and( new NameGlobETAF("*.sh")))). // // Add a script file. This will fall under the rule added above. addSource( new EntityAndAbsoluteLocation( new CharSequenceReadableFile( // Have to use single quotes here to avoid Groovy trying to interpret // $JAVA_HOME as a GString placeholder. '#!/bin/sh\n' + '$JAVA_HOME/bin/java -jar myApp.jar'), new AbsoluteLocation("/bin/start.sh"))). // // Add a file with a custom comment. // Since it is not matched by the rule's filter, this entry will have the // default entity mode for files (0644). addSource( new EntityAndAbsoluteLocation( new TarEntryAndSettings( new CharSequenceReadableFile( "Contents of doc/README.txt"), new TarEntrySettings(). // // Set another owner name setOwnerUserName("nellie")), new AbsoluteLocation("/doc/README.txt"))). setTarget(new FutureFile(d, "myApp-1.0.tar")).run()

JavaScript

enableTaskPackage("org.at4j"); new TarTF(). // // Use an entity strategy that creates POSIX 1003.1-2001 (pax) entries. setEntryStrategy( // // Use the UTF-8 character encoding for encoding contents of the Tar file. new PaxTarEntryStrategy( Charset.forName("utf8"))). // // Set a user and group name for the tar entries' owner setDefaultFileEntrySettings( new TarEntrySettings(). setOwnerUserName("karl"). setOwnerGroupName("builders")). setDefaultDirectoryEntrySettings( new TarEntrySettings(). setOwnerUserName("karl"). setOwnerGroupName("builders")). // // Add a rule that says that all script files (taken as files with the file // name extension .sh) should be made Unix executable. addRule( new ArchiveEntrySettingsRule( new TarEntrySettings(). setEntityMode( // // World executable (mode 0755). UnixEntityMode.forCode(0755)), // // The filter that determines which entries that the rules will be applied // to. At4J comes with several predefined EntityToArchiveFilter:s. FileETAF.FILTER.and( new NameGlobETAF("*.sh")))). // // Add a script file. This will fall under the rule added above. addSource( new EntityAndAbsoluteLocation( new CharSequenceReadableFile( "#!/bin/sh\n" + "$JAVA_HOME/bin/java -jar myApp.jar"), new AbsoluteLocation("/bin/start.sh"))). // // Add a file with a custom comment. // Since it is not matched by the rule's filter, this entry will have the // default entity mode for files (0644). addSource( new EntityAndAbsoluteLocation( new TarEntryAndSettings( new CharSequenceReadableFile( "Contents of doc/README.txt"), new TarEntrySettings(). // // Set another owner name setOwnerUserName("nellie")), new AbsoluteLocation("/doc/README.txt"))). setTarget(new FutureFile(d, "myApp-1.0.tar")).run();

JRuby

enableTaskPackage "org.at4j" Schmant::TarTF.new. # # Use an entity strategy that creates POSIX 1003.1-2001 (pax) entries. setEntryStrategy( # # Use the UTF-8 character encoding for encoding contents of the Tar file. Schmant::PaxTarEntryStrategy.new( Java::JavaNioCharset::Charset.forName("utf8"))). # # Set a user and group name for the tar entries' owner setDefaultFileEntrySettings( Schmant::TarEntrySettings.new. setOwnerUserName("karl"). setOwnerGroupName("builders")). setDefaultDirectoryEntrySettings( Schmant::TarEntrySettings.new. setOwnerUserName("karl"). setOwnerGroupName("builders")). # # Add a rule that says that all script files (taken as files with the file # name extension .sh) should be made Unix executable. addRule( Schmant::ArchiveEntrySettingsRule.new( Schmant::TarEntrySettings.new. setEntityMode( # # World executable (mode 0755). Schmant::UnixEntityMode.forCode(0755)), # # The filter that determines which entries that the rules will be applied # to. At4J comes with several predefined EntityToArchiveFilter:s. Schmant::FileETAF::FILTER.and( Schmant::NameGlobETAF.new("*.sh")))). # # Add a script file. This will fall under the rule added above. addSource( Schmant::EntityAndAbsoluteLocation.new( Schmant::CharSequenceReadableFile.new( "#!/bin/sh\n" + "$JAVA_HOME/bin/java -jar myApp.jar"), Schmant::AbsoluteLocation.new("/bin/start.sh"))). # # Add a file with a custom comment. # Since it is not matched by the rule's filter, this entry will have the # default entity mode for files (0644). addSource( Schmant::EntityAndAbsoluteLocation.new( Schmant::TarEntryAndSettings.new( Schmant::CharSequenceReadableFile.new( "Contents of doc/README.txt"), Schmant::TarEntrySettings.new. # # Set another owner name setOwnerUserName("nellie")), Schmant::AbsoluteLocation.new("/doc/README.txt"))). setTarget(Schmant::FutureFile.new($d, "myApp-1.0.tar")).run

Jython

enableTaskPackage("org.at4j") t = TarTF() # Use an entity strategy that creates POSIX 1003.1-2001 (pax) entries. # # Use the UTF-8 character encoding for encoding contents of the Tar file. from java.nio.charset import Charset t.setEntryStrategy( PaxTarEntryStrategy( Charset.forName("utf8"))) # # Set a user and group name for the tar entries' owner t.setDefaultFileEntrySettings( TarEntrySettings(). \ setOwnerUserName("karl"). \ setOwnerGroupName("builders")) t.setDefaultDirectoryEntrySettings( TarEntrySettings(). \ setOwnerUserName("karl"). \ setOwnerGroupName("builders")) # Add a rule that says that all script files (taken as files with the file # name extension .sh) should be made Unix executable with mode 0755. # # The FileETAF filter is used to determine which entries that the rules # will be applied to. At4J comes with several predefined # EntityToArchiveFilter:s. t.addRule( ArchiveEntrySettingsRule( TarEntrySettings(). \ setEntityMode( UnixEntityMode.forCode(0755)), \ FileETAF.FILTER.and( NameGlobETAF("*.sh")))) # Add a script file. This will fall under the rule added above. t.addSource( EntityAndAbsoluteLocation( CharSequenceReadableFile( "#!/bin/sh\n" + \ "$JAVA_HOME/bin/java -jar myApp.jar"), \ AbsoluteLocation("/bin/start.sh"))) # Add a file with a custom comment. # Since it is not matched by the rule's filter, this entry will have the # default entity mode for files (0644). # # Set another owner name. t.addSource( EntityAndAbsoluteLocation( TarEntryAndSettings( CharSequenceReadableFile( "Contents of doc/README.txt"), \ TarEntrySettings(). \ setOwnerUserName("nellie")), \ AbsoluteLocation("/doc/README.txt"))) t.setTarget(FutureFile(d, "myApp-1.0.tar")).run()

Example 5

Create a Tar archive containing the contents of the src and bin directories. It uses a directory-specific rule for the bin directory.

JavaScript

enableTaskPackage("org.at4j"); new TarTF(). // // Add a custom rule for this directory addSource( new TarDirectoryWithRules( new EntityAndAbsoluteLocation( bin, new AbsoluteLocation("/bin")), new ArchiveEntrySettingsRule( new TarEntrySettings(). // // Make the files in bin Unix world executable. setEntityMode( UnixEntityMode.forCode(0755)), // // A filter that matches file entries. FileETAF.FILTER))). // // No custom rules for this directory. addSource( new EntityAndAbsoluteLocation( src, new AbsoluteLocation("/src"))). setTarget(new FutureFile(d, "project-1.0.tar")).run();


* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.