Example 2

Build all Java projects in the workspace in /home/me/myproject. Preprocess the source files to make all public classes, variables and methods public final. Put the class files in /tmp/target.

JavaScript

// Create the Eclipse workspace object wos = new EclipseWorkspace( new File("/home/me/myproject")); // Build all Java projects new JavaWorkspaceBuilderTF(). setWorkspace(wos). // // Set a preprocessing task factory that makes all public stuff public // final... setPreprocessTaskFactory( new RecursiveProcessTF(). setTaskFactory( new TextReplaceTF(). // \\1 matches the first capturing group, \\2 the second addReplace("(\\p{Blank}+)public(\\p{Blank}+)","\\1public final\\2"))). setTarget(new File("/tmp/target")).run();

Example 3

Build all Java projects in the workspace in /home/me/myproject. Put the class files in project-specific target directories under /tmp/target.

JavaScript

// Create the Eclipse workspace object wos = new EclipseWorkspace( new File("/home/me/myproject")); // Build all Java projects new JavaWorkspaceBuilderTF(). setWorkspace(wos). // // Put class files for each project in a separate directory. setProjectSpecificTargetDirectories(true). // // Copy all non-Java source files to the target directories. setCopyNonJavaSourceFilesToTarget(true). setTarget(new File("/tmp/target")).run();

Example 4

For the workspace in /home/me/myproject containing four projects MyProject_foo, MyProject_foo_test, MyProject_bar and MyProject_bar_test, build the projects and bundle the built classes in three different Jar files.

JavaScript

// Create the Eclipse workspace object var wos = new EclipseWorkspace( new File("/home/me/myproject")); // Read information about which classes to put in which Jar files from a // property file. The example uses an inline file for pedagogic reasons. var buildProps = PropertiesUtil.loadFromFile( new CharSequenceReadableFile( "jar.foo.projects = MyProject_foo\n" + "jar.bar.projects = MyProject_bar\n" + "jar.test.projects = MyProject_*_test")); // Create a directory entity for the target directory. Make it read/write. var targetDir = SchmantFileSystems.getEntityForDirectory( new File("/tmp/target"), false); // Create a directory to put the Jar files in var libDir = Directories.newDirectory(targetDir, "lib"); // Create a TaskExecutor to use two threads for running the // tasks. var te = new TaskExecutor(). setNumberOfThreads(2); te.start(); try { // Build all Java projects var buildWorkspaceTask = new JavaWorkspaceBuilderTF(). setWorkspace(wos). // // Put class files for each project in a separate directory. setProjectSpecificTargetDirectories(true). setCopyNonJavaSourceFilesToTarget(true). // Set a task executor to spread out the compiling over several threads setTaskExecutor(te). setTarget(new File("/tmp/target")).create(); te.add(buildWorkspaceTask); // We have to wait for the workspace builder task to finish before we create // the Jar files var buildWorkspaceDependency = buildWorkspaceTask.getDependencyForTasksScheduledByThisTask(); // Get all build properties that have to do with where the classes should be // put var jarPropsItr = buildProps. getPropertiesMatching(new Glob("jar.*.projects")). propertyEntrySet(). iterator(); while(jarPropsItr.hasNext()) { var jarProp = jarPropsItr.next(); // The name of the Jar is the second segment of the property name var jarName = jarProp.getKey().split("\\.")[1]; var projectNamePattern = jarProp.getValue(); // Use a closure to get the source directories. It will be evaluated when // the task runs. Since the task depends on the workspace build task, all // target directories will be created by then. var jarTask = new JarTF(). addSources( function() { // Get all project names that match the Jar pattern return Directories.getAllDirectoriesMatching( targetDir, new Glob(projectNamePattern)); } ). setTarget(new FutureFile(libDir, "myproject-" + jarName + ".jar")). setLevel(9).create(); te.add(jarTask, buildWorkspaceDependency); } te.waitFor(); } finally { te.shutdown(); }


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