Example 2

Replace "!!!VERSION!!!" for the contents of the variable version in all text files in a directory hierarchy under d1. The TextReplaceTF would normally need a RecursiveProcessTF to be run recursively, but the ReplaceSourceFileTF is used to apply the modifications directly to the source files, making the operation an "action" rather than a "process".

JavaScript

new RecursiveActionTF(). addSource( new DirectoryAndFilter(d1, new EFileNameExtensionFilter("txt"))). setTaskFactory( new ReplaceSourceFileTF(). setTaskFactory( new TextReplaceTF(). addReplace("!!!VERSION!!!", version))).run();

Example 3

This does the same as the previous example, but schedules the tasks in a TaskExecutor instead of running them right away.

JavaScript

new RecursiveActionTF(). addSource(new DirectoryAndFilter( d1, new EFileNameExtensionFilter("txt"))). // te is a TaskExecutor setTaskExecutor(te). setTaskFactory( new ReplaceSourceFileTF(). setTaskFactory( new TextReplaceTF(). addReplace("!!!VERSION!!!", version))).run();

Example 4

Compress all text and html files in a directory hierarchy under the directory d using gzip compression.

Groovy

import org.entityfs.util.filter.entity.EFileNameExtensionFilter import org.schmant.arg.DirectoryAndFilter import org.schmant.task.io.gzip.GZipTF import org.schmant.task.meta.RecursiveActionTF new RecursiveActionTF(). addSource(new DirectoryAndFilter( d, // Compress HTML and text files new EFileNameExtensionFilter(["html", "txt"]))). // te is a TaskExecutor setTaskExecutor(te). setTaskFactory( // The default target for the gzip task is a file with the same name as the // source file with the extension .gz appended. new GZipTF()).run() te.waitFor()

JavaScript

// Rhino bug #476041 prevents us from using a plain JavaScript array when // creating the EFileNameExtensionFilter below if we are running Mozilla Rhino // 1.7 (in the Rhino implementation bundled with Sun's Java 6 JDK it works fine) // Use a Java set instead. var fileNameExtensions = new HashSet(); fileNameExtensions.add("html"); fileNameExtensions.add("txt"); new RecursiveActionTF(). addSource(new DirectoryAndFilter( d, // Compress HTML and text files new EFileNameExtensionFilter(fileNameExtensions))). // te is a TaskExecutor setTaskExecutor(te). setTaskFactory( // The default target for the gzip task is a file with the same name as the // source file with the extension .gz appended. new GZipTF()).run(); te.waitFor();

JRuby

# $te is a TaskExecutor # The default target for the gzip task is a file with the same name as the # source file with the extension .gz appended. Schmant::RecursiveActionTF.new. addSource(Schmant::DirectoryAndFilter.new( $d, Schmant::EFileNameExtensionFilter.new(["html", "txt"]))). setTaskExecutor($te). setTaskFactory(Schmant::GZipTF.new).run $te.waitFor

Jython

# te is a TaskExecutor # The default target for the gzip task is a file with the same name as the # source file with the extension .gz appended. RecursiveActionTF(). \ addSource(DirectoryAndFilter( d, \ EFileNameExtensionFilter(["html", "txt"]))). \ setTaskExecutor(te). \ setTaskFactory(GZipTF()).run() te.waitFor()

Example 5

Use a closure to compress all text and html files in a directory hierarchy under the directory d using gzip compression, and then delete the original files.

Groovy

import org.entityfs.util.Entities import org.entityfs.util.filter.entity.EFileNameExtensionFilter import org.schmant.arg.DirectoryAndFilter import org.schmant.task.io.gzip.GZipTF import org.schmant.task.meta.RecursiveActionTF new RecursiveActionTF(). addSource(new DirectoryAndFilter( d, // Compress HTML and text files new EFileNameExtensionFilter(["html", "txt"]))). // te is a TaskExecutor setTaskExecutor(te). // Set a closure that gzip:s the file and deletes the original file. Note that // this could be accomplished without a closure using GZipTF's // deleteSourceFile property. // Note the curly brackets. setTaskFactory { cParams -> // The default target for the gzip task is a file with the same name as the // source file with the extension .gz appended. new GZipTF(). setSource(cParams.source).run() Entities.delete(cParams.source) }.run() te.waitFor()

JavaScript

// Rhino bug #476041 prevents us from using a plain JavaScript array when // creating the EFileNameExtensionFilter below if we are running Mozilla Rhino // 1.7 (in the Rhino implementation bundled with Sun's Java 6 JDK it works fine) // Use a Java set instead. var fileNameExtensions = new HashSet(); fileNameExtensions.add("html"); fileNameExtensions.add("txt"); new RecursiveActionTF(). addSource(new DirectoryAndFilter( d, // Compress HTML and text files new EFileNameExtensionFilter(fileNameExtensions))). // te is a TaskExecutor setTaskExecutor(te). // Set a closure that gzip:s the file and deletes the original file. Note that // this could be accomplished without a closure using GZipTF's // deleteSourceFile property. setTaskFactory( function(cParams) { // gzip the file. // The default target for the gzip task is a file with the same name as the // source file with the extension .gz appended. new GZipTF(). setSource(cParams.source).run(); // Delete the original file Entities.deleteEntity(cParams.source); }).run(); te.waitFor();

JRuby

# $te is a TaskExecutor Schmant::RecursiveActionTF.new. addSource(Schmant::DirectoryAndFilter.new( $d, Schmant::EFileNameExtensionFilter.new(["html", "txt"]))). setTaskExecutor($te). setTaskFactory( # Set a closure that gzip:s the file and deletes the original file. Note # that this could be accomplished without a closure using GZipTF's # deleteSourceFile property. Proc.new { |cParams| # The default target for the gzip task is a file with the same name as the # source file with the extension .gz appended. Schmant::GZipTF.new. setSource(cParams.source).run Schmant::Entities.delete(cParams.source) } ).run $te.waitFor

Jython

# The function used to compress and delete the files. # Note that this could be accomplished without a separate function using # GZipTF's deleteSourceFile property. def gzipFile(cParams): # The default target for the gzip task is a file with the same name as the # source file with the extension .gz appended. GZipTF(). \ setSource(cParams.source).run() Entities.delete(cParams.source) # te is a TaskExecutor RecursiveActionTF(). \ addSource(DirectoryAndFilter( d, \ EFileNameExtensionFilter(["html", "txt"]))). \ setTaskExecutor(te). \ setTaskFactory(gzipFile).run() te.waitFor()


* 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.