Introducing Schmant
Schmant is a tool for building software artifacts. It provides a runtime environment and a set of tools (tasks) for your build scripts.
By using the scripting support in Java 6, Schmant can support build scripts written in any scripting language that has a JSR 223-compatible scripting engine. This includes JavaScript, BeanShell and Jython. The runtime environment gives the scripts access to all Java classes and any number of user-supplied classes too, so build scripts can be made as complex as they need to be.
This simple JavaScript example is borrowed from User's guide. It shows how Java classes are compiled and then bundled in a Jar file.
// Compile files from the directory /home/me/myproject/src and put the resulting
// class files in a temporary directory. The source files have compilation
// dependencies to all Jar files in /home/me/myproject/lib and to the Jar file
// /home/me/myproject/optlib/opt.jar
// A temporary directory for the compiled classes. This, along with all of its
// contents, will be automatically deleted when Schmant exits (unless the -k
// flag is used).
var ctarget = TempFileUtil.createTempDir();
// This is the lib directory expressed as a (read only) EntityFS Directory.
// By using a Directory, the script can use the utility methods of
// Directories to extract the files it wants. See below.
var libDir = SchmantFileSystems.getEntityForDirectory(
new File("/home/me/myproject/lib"), true);
// Get all jar files from the lib directory. The jar files are returned as
// EntityFS EFile:s
var depjars = Directories.getAllFilesMatching(libDir, "*.jar");
// Add a dependency from the optlib directory. This is a Java File
depjars.add(new File("/home/me/myproject/optlib/opt.jar"));
// Compile the Java source files.
new Jdk6JavacTF().
addSource(new File("/home/me/myproject/src")).
addClasspathEntries(depjars).
setTarget(ctarget).run();
// A timestamp for the built archive
// java.text.SimpleDateFormat must be fully qualified since the java.text
// package classes are not automatically imported by Schmant. See the chapter on
// script language support in the User's Guide for more information.
var timestamp = new java.text.SimpleDateFormat("yyyyMMddHHmm").
format(new Date());
// Build the Jar file. Put it in /home/me/myproject
new JarTF().
addSource(ctarget).
setTarget(new File("/home/me/myproject/myproject" + timestamp + ".jar")).
run();
EntityFS integration
Schmant comes bundled with EntityFS for working with files and directories. The example below shows how Schmant tasks and EntityFS classes are used to copy all XML files in a directory hierarchy to a new directory hierarchy.
// Copy all XML files from the directory hierarchy under the (EntityFS)
// Directory d1 to a directory hierarchy under d2. Ignore all .svn directories.
new TreeCopyTF().
addSource(
new DirectoryAndFilter(
// This view hides all .svn directories
d1.newView(
DirectoryFilter.FILTER.and(
new EntityNameFilter(".svn")).not()),
// This filter selects all XML files
new EFileNameExtensionFilter("xml"))).
setTarget(d2).run();
Interpreted arguments
The
source and target properties of tasks that support
them, for instance, accept Object arguments. The task tries to
interpret an untyped argument as something useful (often using the
ArgumentInterpreter
class). This gives the build scripts great flexibility in what kinds of arguments they
throw at the tasks. The first example above used plain Java File arguments, and the
second example used Schmant's
DirectoryAndFilter.
All available tasks are listed in the Task factory reference. The user's guide explains the difference between tasks and task factories.
Task executors
Instead of running the tasks when they are defined, a Schmant script may choose to use one or several task executors for distributing the workload over several execution threads. This can often drastically reduce the time required for builds, but it introduces the need to handle dependencies between related tasks.
Project repositories
Schmant comes with tools for working with project repositories. A project repository contains a collection of projects. This can be an Eclipse workspace with java projects. Schmant has tools for resolving dependencies between projects and for filtering projects by, for instance, type or name.
Migration from Ant
To assist those daring enough to migrate away from Apache Ant, Schmant comes with the AntTF task. It can run whole Ant scripts or single Ant tasks.
Further reading
The next stop on the road to Schmant enlightenment is the User's guide.
