Example 2

Create a Zip 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 Zip file. The archive will be put in the Directory d.

JavaScript

enableTaskPackage("org.at4j"); noSvnFilter = new SuperParentOrFilter( new EntityNameFilter(".svn"), true).not(); new At4JZipTF(). addSource( new EntityAndAbsoluteLocation( new DirectoryAndFilter(d1, noSvnFilter), "/ds-1.0")). addSource( new EntityAndAbsoluteLocation( new DirectoryAndFilter(d2, noSvnFilter), "/ds-1.0")). setTarget( new FutureFile(d, "ds-1.0.zip")).run();

Example 3

Create a Zip archive with the sources set 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 At4JZipTF(). // // A file added in the root directory of the Zip archive addSource(new File(tmpDir, "f1")). // // The contents of /tmp/d1 directory added under the d1 directory in the // Zip 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.zip")).run();

Example 4

Create a Zip archive with custom metadata and a non-standard compression method 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.zip.comp.BZip2CompressionMethod import org.at4j.zip.builder.ZipEntrySettings import org.at4j.zip.extattrs.UnixExternalFileAttributesFactory import org.entityfs.el.AbsoluteLocation import org.entityfs.entityattrs.unix.UnixEntityMode import org.entityfs.util.CharSequenceReadableFile import org.schmant.arg.EntityAndAbsoluteLocation import org.schmant.support.FutureFile import org.schmant.task.at4j.zip.* new At4JZipTF(). // // Use bzip2 compression for files. setDefaultFileEntrySettings( new ZipEntrySettings(). setCompressionMethod(BZip2CompressionMethod.INSTANCE)). // // 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 ZipEntrySettings(). // // Use Unix external attributes instead of the default MS/DOS // attributes. This makes it possible to set the permission mode to // world executable for the file. setExternalFileAttributesFactory( new UnixExternalFileAttributesFactory( // // Files are world executable (mode 0755). UnixEntityMode.forCode(0755), // // Directories are world executable. (No directories will be matched // by the filter, however.) UnixEntityMode.forCode(0755))), // // The filter that determines which entries that the rules will be applied // to. At4J comes with several predefined EntityToArchiveFilter:s. // // Groovy lets us combine the filters using &. FileETAF.FILTER & 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 to avoid Groovy interpreting $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 use the // default external file attributes (MsDosExternalFileAttributes). addSource( new EntityAndAbsoluteLocation( new ZipEntryAndSettings( new CharSequenceReadableFile( // // By repeating ourself we ensure that the file will be shorter when // compressed. (If it is, it will be compressed in the Zip file. // Otherwise not.) "Contents of doc/README.txt. Contents of doc/README.txt.\n" + "Contents of doc/README.txt. Contents of doc/README.txt."), new ZipEntrySettings(). setComment("Custom comment for README.txt")), new AbsoluteLocation("/doc/README.txt"))). setTarget(new FutureFile(d, "myApp-1.0.zip")).run()

JavaScript

enableTaskPackage("org.at4j"); new At4JZipTF(). // // Use bzip2 compression for files. setDefaultFileEntrySettings( new ZipEntrySettings(). setCompressionMethod(BZip2CompressionMethod.INSTANCE)). // // 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 ZipEntrySettings(). // // Use Unix external attributes instead of the default MS/DOS // attributes. This makes it possible to set the permission mode to // world executable for the file. setExternalFileAttributesFactory( new UnixExternalFileAttributesFactory( // // Files are world executable (mode 0755). UnixEntityMode.forCode(0755), // // Directories are world executable. (No directories will be matched // by the filter, however.) 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 use the // default external file attributes (MsDosExternalFileAttributes). addSource( new EntityAndAbsoluteLocation( new ZipEntryAndSettings( new CharSequenceReadableFile( // // By repeating ourself we ensure that the file will be shorter when // compressed. (If it is, it will be compressed in the Zip file. // Otherwise not.) "Contents of doc/README.txt. Contents of doc/README.txt.\n" + "Contents of doc/README.txt. Contents of doc/README.txt."), new ZipEntrySettings(). setComment("Custom comment for README.txt")), new AbsoluteLocation("/doc/README.txt"))). setTarget(new FutureFile(d, "myApp-1.0.zip")).run();

JRuby

enableTaskPackage "org.at4j" Schmant::At4JZipTF.new. # # Use bzip2 compression for files. setDefaultFileEntrySettings( Schmant::ZipEntrySettings.new. setCompressionMethod(Schmant::BZip2CompressionMethod::INSTANCE)). # # 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::ZipEntrySettings.new. # # Use Unix external attributes instead of the default MS/DOS # attributes. This makes it possible to set the permission mode to # world executable for the file. setExternalFileAttributesFactory( Schmant::UnixExternalFileAttributesFactory.new( # # Files are world executable (mode 0755). Schmant::UnixEntityMode.forCode(0755), # # Directories are world executable. (No directories will be matched # by the filter, however.) 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 use the # default external file attributes (MsDosExternalFileAttributes). addSource( Schmant::EntityAndAbsoluteLocation.new( Schmant::ZipEntryAndSettings.new( Schmant::CharSequenceReadableFile.new( # # By repeating ourself we ensure that the file will be shorter when # compressed. (If it is, it will be compressed in the Zip file. # Otherwise not.) "Contents of doc/README.txt. Contents of doc/README.txt.\n" + "Contents of doc/README.txt. Contents of doc/README.txt."), Schmant::ZipEntrySettings.new. setComment("Custom comment for README.txt")), Schmant::AbsoluteLocation.new("/doc/README.txt"))). setTarget(Schmant::FutureFile.new($d, "myApp-1.0.zip")).run

Jython

enableTaskPackage("org.at4j") t = At4JZipTF() # Use bzip2 compression for files. t.setDefaultFileEntrySettings( ZipEntrySettings(). \ setCompressionMethod(BZip2CompressionMethod.INSTANCE)) # Add a rule that says that all script files (taken as files with the file # name extension .sh) should be made Unix executable. # # Use Unix external attributes instead of the default MS/DOS attributes. This # makes it possible to set the permission mode to world executable for the file. # # The FileETAF filter determines which entries that the rules will be # applied to. At4J comes with several predefined EntityToArchiveFilter:s. t.addRule( ArchiveEntrySettingsRule( ZipEntrySettings(). setExternalFileAttributesFactory( UnixExternalFileAttributesFactory( UnixEntityMode.forCode(0755), \ 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 use the # default external file attributes (MsDosExternalFileAttributes). # # By repeating ourself in the CharSequenceReadableFile, we ensure that the # file will be shorter when compressed. (If it is, it will be compressed in the # Zip file. Otherwise not.) t.addSource( EntityAndAbsoluteLocation( ZipEntryAndSettings( CharSequenceReadableFile( "Contents of doc/README.txt. Contents of doc/README.txt.\n" + "Contents of doc/README.txt. Contents of doc/README.txt."), \ ZipEntrySettings(). \ setComment("Custom comment for README.txt")), \ AbsoluteLocation("/doc/README.txt"))) t.setTarget(FutureFile(d, "myApp-1.0.zip")).run()

Example 5

Create a Zip archive containing the contents of the src and bin directories. It uses a directory-specific rule for the bin directory. Use maximum compression for the files.

JavaScript

enableTaskPackage("org.at4j"); new At4JZipTF(). // // Use maximum compression for the files. setDefaultFileEntrySettings( new ZipEntrySettings(). setCompressionMethod( DeflatedCompressionMethod.MAXIMUM_COMPRESSION)). // // Add a custom rule for this directory addSource( new ZipDirectoryWithRules( new EntityAndAbsoluteLocation( bin, new AbsoluteLocation("/bin")), new ArchiveEntrySettingsRule( new ZipEntrySettings(). // // Make the files in bin Unix world executable. setExternalFileAttributesFactory( new UnixExternalFileAttributesFactory( // // Files are world executable. UnixEntityMode.forCode(0755), // // Directories are world executable. (No directories will be // matched by the filter, though.) 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.zip")).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.