import org.entityfs.util.Directories
import org.entityfs.util.filter.entity.*
import org.schmant.arg.DirectoryAndFilter
import org.schmant.project.eclipse.*
import org.schmant.project.java.*
import org.schmant.run.*
import org.schmant.support.io.TempFileUtil
import org.schmant.task.jdk.jar.JarTF
import org.schmant.task.jdk.javac.jdk6.Jdk6JavacTF
import org.schmant.task.meta.RecursiveProcessTF
import org.schmant.task.text.TextReplaceTF
// Create the Eclipse workspace object for the contents in the directory wos.
// wos may be a
File directory or an EntityFS
Directory.
// vars is a
Map of the values of classpath variables used in
// the workspace. These variables override the values parsed from the workspace
// metadata.
def settings = new
EclipseWorkspaceSettings().
addClasspathVariables(vars)
def eWos = new
EclipseWorkspace(wos, settings)
// Get all Java projects from the workspace
def javaProjects = eWos.getProjects().findAll{
proj ->
JavaProjectFilter.INSTANCE.matches(proj)}
// An
EntityFilter that hides Subversion .svn directories
def noSvnFilter = ~(
DirectoryFilter.FILTER &
new
EntityNameFilter(".svn"))
// Create a
JavaProjectDependencies object for keeping track of dependencies
// between different projects.
def projDeps = new
JavaProjectDependencies()
// This collection will contain all the directories with class files
def classDirs = []
// Create a
TaskExecutor and start it
def te = new
TaskExecutor().
setNumberOfThreads(props.getIntValue("noOfBuildThreads", 2)).
start()
try
{
// The tmpDir variable points to a directory where temporary files are kept
// during the build. It can for instance be created by calling
// def tmpDir =
TempFileUtil.createTempDirectory()
// Create compile tasks for each Java project
javaProjects.each{
proj ->
def projName = proj.name
// Create a temporary directory to put the preprocessed source files in
def sourceDir =
Directories.newDirectory(tmpDir, projName + "_src")
// Create the preprocess task for all source files
def ppt = new
RecursiveProcessTF().
// Preprocess all files in the directory hierarchy. Ignore Subversion's
// .svn directories.
addSources(
DirectoryAndFilter.listWithFilter(
Directories.newViews(proj.sourceDirectories, noSvnFilter),
EFileFilter.FILTER)).
setTarget(sourceDir).
setTaskFactory(
new
TextReplaceTF().
addReplace("!!!VERSION!!!", "1.0").
// (For the documentation's unit tests. Pretend it's not here...)
addReplace("232", "233")).
create()
te.add(ppt)
// Create a temporary directory for compiled files
def classDir =
Directories.newDirectory(tmpDir, projName)
classDirs.add(classDir)
// Create the compilation task
def javacTask = new
Jdk6JavacTF().
addSource(sourceDir).
setTarget(classDir).
// Add a
JavaProjectClasspathDecorator that uses the
//
JavaProjectDependencies object created above to give the compile
// task its classpath
addClasspathDecorator(
new
JavaProjectClasspathDecorator().
setProject(proj).
setDependencies(projDeps)).create()
// Register the compile task as the dependency that this project hinges on.
// (If we would post process the compiled class files in any way, for
// instance Emma instrument them, the post process task would (probably) be
// the one that was registered here.)
projDeps.registerDependency(proj, javacTask)
// Also register the class directory so that it can be found by projects
// that depend on this project.
projDeps.registerClassDirectory(proj, classDir)
// Add the compile task to the task executor. Now the compile task hinges
// on both it's dependent projects and the preprocess task
te.add(
javacTask,
new
CompoundTaskDependency().
addAll(projDeps.getDependencies(proj)).
add(ppt))
}
// Create a Jar file with all the compiled classes
te.add(
new
JarTF().
// targetFile is a
File or a
FutureFile
setTarget(targetFile).
addSources(classDirs),
// This is also a dependency object for all compilation tasks.
projDeps)
// Wait for all tasks to complete
te.waitFor()
}
finally
{
te.shutdown()
}
// Create the Eclipse workspace object for the contents in the directory wos.
// wos may be a
File directory or an EntityFS
Directory.
// vars is a
Map of the values of classpath variables used in
// the workspace. These variables override the values parsed from the workspace
// metadata.
settings = new
EclipseWorkspaceSettings().
addClasspathVariables(vars);
eWos = new
EclipseWorkspace(wos, settings);
// Get all Java projects from the workspace
javaProjects = eWos.getProjects(
JavaProjectFilter.INSTANCE);
// An
EntityFilter that hides Subversion .svn directories
noSvnFilter =
DirectoryFilter.FILTER.and(
new
EntityNameFilter(".svn")).not();
// Create a
JavaProjectDependencies object for keeping track of dependencies
// between different projects.
projDeps = new
JavaProjectDependencies();
// This collection will contain all the directories with class files
classDirs = new
ArrayList();
// Create a
TaskExecutor and start it
te = new
TaskExecutor().
setNumberOfThreads(props.getIntValue("noOfBuildThreads", 2)).
start();
try {
// The tmpDir variable points to a directory where temporary files are kept
// during the build. It can for instance be created by calling
// var tmpDir =
TempFileUtil.createTempDirectory();
// Iterate over all Java projects and create compile tasks for them
itr = javaProjects.iterator();
while(itr.hasNext()) {
proj = itr.next();
projName = proj.getName();
// Create a temporary directory to put the preprocessed source files in
sourceDir =
Directories.newDirectory(tmpDir, projName + "_src");
// Create the preprocess task for all source files
ppt = new
RecursiveProcessTF().
// Preprocess all files in the directory hierarchy. Ignore Subversion's
// .svn directories.
addSources(
DirectoryAndFilter.listWithFilter(
Directories.newViews(proj.getSourceDirectories(), noSvnFilter),
EFileFilter.FILTER)).
setTarget(sourceDir).
setTaskFactory(
new
TextReplaceTF().
addReplace("!!!VERSION!!!", "1.0").
// (For the documentation's unit tests. Pretend it's not here...)
addReplace("232", "233")).
create();
te.add(ppt);
// Create a temporary directory for compiled files
classDir =
Directories.newDirectory(tmpDir, projName);
classDirs.add(classDir);
// Create the compilation task
javacTask = new
Jdk6JavacTF().
addSource(sourceDir).
setTarget(classDir).
// Add a
JavaProjectClasspathDecorator that uses the
//
JavaProjectDependencies object created above to give the compile
// task its classpath
addClasspathDecorator(
new
JavaProjectClasspathDecorator().
setProject(proj).
setDependencies(projDeps)).create();
// Register the compile task as the dependency that this project hinges on.
// (If we would post process the compiled class files in any way, for
// instance Emma instrument them, the post process task would (probably) be
// the one that was registered here.)
projDeps.registerDependency(proj, javacTask);
// Also register the class directory so that it can be found by projects
// that depend on this project.
projDeps.registerClassDirectory(proj, classDir);
// Add the compile task to the task executor. Now the compile task hinges
// on both it's dependent projects and the preprocess task
te.add(
javacTask,
new
CompoundTaskDependency().
addAll(projDeps.getDependencies(proj)).
add(ppt));
}
// Create a Jar file with all the compiled classes
te.add(
new
JarTF().
// targetFile is a
File or a
FutureFile
setTarget(targetFile).
addSources(classDirs),
// This is also a dependency object for all compilation tasks.
projDeps);
// Wait for all tasks to complete
te.waitFor();
} finally {
te.shutdown();
}
# Create the Eclipse workspace object for the contents in the directory wos.
# wos may be a
File directory or an EntityFS
Directory.
# vars is a
Map of the values of classpath variables used in
# the workspace. These variables override the values parsed from the workspace
# metadata.
settings = Schmant::
EclipseWorkspaceSettings.new.
addClasspathVariables($vars)
eWos = Schmant::
EclipseWorkspace.new($wos, settings)
# Get all Java projects from the workspace
javaProjects = eWos.getProjects Schmant::
JavaProjectFilter::INSTANCE
# An
EntityFilter that hides Subversion .svn directories
noSvnFilter = Schmant::
DirectoryFilter::FILTER.and(
Schmant::
EntityNameFilter.new(".svn")).not
# Create a
JavaProjectDependencies object for keeping track of dependencies
# between different projects.
projDeps = Schmant::
JavaProjectDependencies.new
# This list will contain all the directories with class files
classDirs = []
# Create a
TaskExecutor and start it
te = Schmant::
TaskExecutor.new.
setNumberOfThreads($props.getIntValue("noOfBuildThreads", 2)).
start
begin
# The tmpDir variable points to a directory where temporary files are kept
# during the build. It can for instance be created by calling
# tmpDir =
TempFileUtil.createTempDirectory
# Iterate over all Java projects and create compile tasks for them
javaProjects.each do |proj|
projName = proj.name
# Create a temporary directory to put the preprocessed source files in
sourceDir = Schmant::
Directories.newDirectory($tmpDir, projName + "_src")
# Create the preprocess task for all source files
ppt = Schmant::RecursiveProcessTF.new.
# Preprocess all files in the directory hierarchy. Ignore Subversion's
# .svn directories.
addSources(
Schmant::
DirectoryAndFilter.listWithFilter(
Schmant::
Directories.newViews(proj.sourceDirectories, noSvnFilter),
Schmant::
EFileFilter::FILTER)).
setTarget(sourceDir).
setTaskFactory(
Schmant::TextReplaceTF.new.
addReplace("!!!VERSION!!!", "1.0").
# (For the documentation's unit tests. Pretend it's not here...)
addReplace("232", "233")).create
te.add ppt
# Create a temporary directory for compiled files
classDir = Schmant::
Directories.newDirectory($tmpDir, projName)
classDirs.push classDir
# Create the compilation task
javacTask = Schmant::Jdk6JavacTF.new.
addSource(sourceDir).
setTarget(classDir).
# Add a
JavaProjectClasspathDecorator that uses the
#
JavaProjectDependencies object created above to give the compile
# task its classpath
addClasspathDecorator(
Schmant::
JavaProjectClasspathDecorator.new.
setProject(proj).
setDependencies(projDeps)).create
# Register the compile task as the dependency that this project hinges on.
# (If we would post process the compiled class files in any way, for
# instance Emma instrument them, the post process task would (probably) be
# the one that was registered here.)
projDeps.registerDependency(proj, javacTask)
# Also register the class directory so that it can be found by projects
# that depend on this project.
projDeps.registerClassDirectory(proj, classDir)
# Add the compile task to the task executor. Now the compile task hinges
# on both it's dependent projects and the preprocess task
te.add(
javacTask,
Schmant::
CompoundTaskDependency.new.
addAll(projDeps.getDependencies(proj)).
add(ppt))
end
# Create a Jar file with all the compiled classes
te.add(
Schmant::JarTF.new.
# targetFile is a
File or a
FutureFile
setTarget($targetFile).
addSources(classDirs),
# This is also a dependency object for all compilation tasks.
projDeps)
# Wait for all tasks to complete
te.waitFor
ensure
te.shutdown
end
# Create the Eclipse workspace object for the contents in the directory wos.
# wos may be a
File directory or an EntityFS
Directory.
# vars is a
Map of the values of classpath variables used in
# the workspace. These variables override the values parsed from the workspace
# metadata.
settings =
EclipseWorkspaceSettings(). \
addClasspathVariables(vars)
eWos =
EclipseWorkspace(wos, settings)
# Get all Java projects from the workspace
javaProjects = eWos.getProjects(
JavaProjectFilter.INSTANCE)
# An
EntityFilter that hides Subversion .svn directories
noSvnFilter =
DirectoryFilter.FILTER.and(
EntityNameFilter(".svn")).not()
# Create a
JavaProjectDependencies object for keeping track of dependencies
# between different projects.
projDeps =
JavaProjectDependencies()
# This collection will contain all the directories with class files
classDirs = []
# Create a
TaskExecutor and start it
te =
TaskExecutor(). \
setNumberOfThreads(props.getIntValue("noOfBuildThreads", 2)). \
start()
try:
# The tmpDir variable points to a directory where temporary files are
# kept during the build. It can for instance be created by calling
# tmpDir =
TempFileUtil.createTempDirectory()
# Iterate over all Java projects and create compile tasks for them
itr = javaProjects.iterator()
while(itr.hasNext()):
proj = itr.next()
projName = proj.getName()
# Create a temporary directory to put the preprocessed source
# files in.
sourceDir =
Directories.newDirectory(tmpDir, projName + "_src")
# Create the preprocess task for all source files
#
# Preprocess all files in the directory hierarchy. Ignore
# Subversion's .svn directories.
#
# The replace 232 -> 233 is for the documentation's unit tests.
# Pretend that it's not there...
ppt = RecursiveProcessTF(). \
addSources(
DirectoryAndFilter.listWithFilter(
Directories.newViews(
proj.getSourceDirectories(), \
noSvnFilter), \
EFileFilter.FILTER)). \
setTarget(sourceDir). \
setTaskFactory(
TextReplaceTF(). \
addReplace("!!!VERSION!!!", "1.0"). \
addReplace("232", "233")). \
create()
te.add(ppt)
# Create a temporary directory for compiled files
classDir =
Directories.newDirectory(tmpDir, projName)
classDirs.append(classDir)
# Create the compilation task
#
# Add a
JavaProjectClasspathDecorator that uses
# the
JavaProjectDependencies object created above to give the
# compile task its classpath
javacTask = Jdk6JavacTF(). \
addSource(sourceDir). \
setTarget(classDir). \
addClasspathDecorator(
JavaProjectClasspathDecorator(). \
setProject(proj). \
setDependencies(projDeps)).create()
# Register the compile task as the dependency that this project
# hinges on. (If we would post process the compiled class files
# in any way, for instance Emma instrument them, the post
# process task would (probably) be the one that was registered
# here.)
projDeps.registerDependency(proj, javacTask)
# Also register the class directory so that it can be found by
# projects that depend on this project.
projDeps.registerClassDirectory(proj, classDir)
# Add the compile task to the task executor. Now the compile
# task hinges on both it's dependent projects and the preprocess
# task.
te.add(
javacTask, \
CompoundTaskDependency(). \
addAll(projDeps.getDependencies(proj)). \
add(ppt))
# End while
# Create a Jar file with all the compiled classes
#
# targetFile is a
File or a
FutureFile
#
# projDeps is also a dependency object for all compilation tasks.
te.add(
JarTF(). \
setTarget(targetFile). \
addSources(classDirs), \
projDeps)
# Wait for all tasks to complete
te.waitFor()
finally:
te.shutdown()