org.codehaus.enunciate.main
Class Enunciate

java.lang.Object
  extended by org.codehaus.enunciate.main.Enunciate

public class Enunciate
extends Object

Main enunciate entry point.

Author:
Ryan Heaton

Nested Class Summary
 class Enunciate.Stepper
          Mechansim for stepping through the Enunciate build process.
static class Enunciate.Target
          The targets for the project.
 
Constructor Summary
protected Enunciate()
          Protected to ensure the source files are set.
  Enunciate(List<String> sourceFiles)
          Construct an enunciate mechanism on the specified source files.
  Enunciate(String[] sourceFiles)
          Construct an enunciate mechanism on the specified source files.
  Enunciate(String[] sourceFiles, EnunciateConfiguration config)
          Construct an enunciate mechanism on the specified source files with the specified config.
 
Method Summary
 boolean addArtifact(Artifact artifact)
          Adds the specified artifact.
 void addExport(String artifactId, File destination)
          Adds an export.
protected  void buildFileList(List<File> list, File... dirs)
          Adds all files in specified directories to a list.
 void copyDir(File from, File to)
          Copy an entire directory from one place to another.
 void copyFile(File from, File to)
          Copy a file from one location to another.
 void copyFile(File src, File fromDir, File toDir)
          Copy a file from one directory to another, preserving directory structure.
 void copyResource(String resource, File to)
          Copies a resource on the classpath to a file.
 void copyResource(URL url, File to)
          Copies a resource to a file.
 File createTempDir()
          Creates a temporary directory.
 void debug(String message, Object... formatArgs)
          Handle a debug-level message.
protected  void doBuild(List<DeploymentModule> deploymentModules)
          Do the build logic.
protected  void doClose(List<DeploymentModule> deploymentModules)
          Logic for handling the closing of the Enunciate mechanism.
protected  void doCompile(List<DeploymentModule> deploymentModules)
          Do the compile logic.
protected  void doGenerate(List<DeploymentModule> deploymentModules)
          Do the generate logic.
protected  List<DeploymentModule> doInit()
          Do the initialization logic.
protected  void doPackage(List<DeploymentModule> deploymentModules)
          Do the package logic.
 void execute()
          Execute the mechanism.
 void extractBase(InputStream baseIn, File toDir)
          Extracts the (zipped up) base to the specified directory.
 Artifact findArtifact(String artifactId)
          Finds the artifact of the given id.
 Set<Artifact> getArtifacts()
          The artifacts exportable by enunciate.
 File getBuildDir()
          The directory to use to build the war.
 String getClasspath()
          The classpath.
 File getCompileDir()
          The destination directory for the compiled classes.
 EnunciateConfiguration getConfig()
           
 File getConfigFile()
          The enunciate config file.
protected  long getEarliestTimestamp(List<File> files)
          Get the earliest timestamp of the specified files.
 String getEnunciateClasspath()
          The enunciate classpath to use for javac and apt.
 Collection<String> getFiles(File basedir, FileFilter filter)
          Finds all files in the specified base directory using the specified filter.
 File getGenerateDir()
          The preprocessor directory (-s).
 Collection<String> getJavaFiles(File basedir)
          Finds all java files in the specified base directory.
protected  long getLatestTimestamp(List<File> files)
          Get the latest timestamp of the specified files.
 File getPackageDir()
          The package directory.
 Object getProperty(String property)
          Get a property value.
 String[] getSourceFiles()
          Get the source files for this enunciate mechanism.
 Enunciate.Stepper getStepper()
          Get a stepper that can be used to step through the Enunciate mechanism, which will be initialized.
 Enunciate.Target getTarget()
          The target.
 String getVersion()
          The version of the Enunciate mechanism.
 void info(String message, Object... formatArgs)
          Handle an info-level message.
protected  void initModules(List<DeploymentModule> deploymentModules)
          Initialize each module.
protected  void invokeApt(String[] sourceFiles, String... additionalApiClasses)
          Invokes APT on the specified source files.
 void invokeJavac(File compileDir, String[] sourceFiles)
          Invokes javac on the specified source files.
 void invokeJavac(String classpath, File compileDir, String[] sourceFiles)
          Invokes javac on the specified source files.
 void invokeJavac(String classpath, String version, File compileDir, List<String> additionalArgs, String[] sourceFiles)
          Invokes javac on the specified source files.
 boolean isDebug()
          Whether to print debugging information.
 boolean isJavacCheck()
          Whether to do a javac check before invoking the Enunciate mechanism.
 boolean isModuleEnabled(String moduleName)
          Whether the specified module is enabled.
 boolean isUpToDate(File sourceFile, File destFile)
          Determines whether a destination file is newer than a source file.
protected  boolean isUpToDate(List<File> sourceFiles, File destFile)
          Whether a given destination file is newer than all the specified source files.
 boolean isUpToDateWithSources(File destDir)
          Whether all files in the specified directory are newer than all the source files.
 boolean isVerbose()
          Whether to be verbose.
protected  EnunciateConfiguration loadConfig()
          Reads the enunciate configuration from the specified file, if any.
static void main(String[] args)
           
 File resolvePath(String filePath)
          Resolves a path relative to the Enunciate config file, if present, otherwise the file will be a relative file to the current user directory.
 void setBuildDir(File buildDir)
          The directory to use to build the war.
 void setClasspath(String classpath)
          The classpath.
 void setCompileDir(File compileDir)
          The destination directory for the compiled classes.
 void setConfig(EnunciateConfiguration config)
          Set the configuration for the mechanism.
 void setConfigFile(File configFile)
          The enunciate config file.
 void setDebug(boolean debug)
          Whether to print debugging information.
 void setGenerateDir(File generateDir)
          The preprocessor directory (-s).
 void setJavacCheck(boolean javacCheck)
          Whether to do a javac check before invoking the Enunciate mechanism.
 void setPackageDir(File packageDir)
          The package directory.
 void setProperty(String property, Object value)
          Set a property value.
protected  void setSourceFiles(String[] sourceFiles)
          Protected to allow the source files to be set after construction.
 void setTarget(Enunciate.Target target)
          The target.
 void setVerbose(boolean verbose)
          Whether to be verbose.
 void warn(String message, Object... formatArgs)
          Handle a warn-level message.
 void zip(File toFile, File... dirs)
          zip up directories to a specified zip file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Enunciate

protected Enunciate()
Protected to ensure the source files are set.


Enunciate

public Enunciate(String[] sourceFiles)
Construct an enunciate mechanism on the specified source files.

Parameters:
sourceFiles - The source files.

Enunciate

public Enunciate(String[] sourceFiles,
                 EnunciateConfiguration config)
Construct an enunciate mechanism on the specified source files with the specified config.

Parameters:
sourceFiles - The source files.
config - The config

Enunciate

public Enunciate(List<String> sourceFiles)
Construct an enunciate mechanism on the specified source files.

Parameters:
sourceFiles - The source files.
Method Detail

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

setSourceFiles

protected void setSourceFiles(String[] sourceFiles)
Protected to allow the source files to be set after construction.

Parameters:
sourceFiles - The source files to enunciate.

getStepper

public Enunciate.Stepper getStepper()
                             throws EnunciateException,
                                    IOException
Get a stepper that can be used to step through the Enunciate mechanism, which will be initialized.

Returns:
A stepper.
Throws:
ConcurrentModificationException - If a stepper has already been retrieved.
EnunciateException - If there was an error initializing the Enunciate mechanism.
IOException - If there was an error initializing the Enunciate mechanism.

execute

public void execute()
             throws EnunciateException,
                    IOException
Execute the mechanism.

Throws:
EnunciateException
IOException

doClose

protected void doClose(List<DeploymentModule> deploymentModules)
                throws EnunciateException,
                       IOException
Logic for handling the closing of the Enunciate mechanism. Closes the modules and exports the artifacts.

Parameters:
deploymentModules - The deployment modules to close.
Throws:
EnunciateException
IOException

doPackage

protected void doPackage(List<DeploymentModule> deploymentModules)
                  throws IOException,
                         EnunciateException
Do the package logic.

Parameters:
deploymentModules - The deployment modules to use.
Throws:
IOException
EnunciateException

doBuild

protected void doBuild(List<DeploymentModule> deploymentModules)
                throws IOException,
                       EnunciateException
Do the build logic.

Parameters:
deploymentModules - The deployment modules to use.
Throws:
IOException
EnunciateException

doCompile

protected void doCompile(List<DeploymentModule> deploymentModules)
                  throws IOException,
                         EnunciateException
Do the compile logic.

Parameters:
deploymentModules - The deployment modules to use.
Throws:
IOException
EnunciateException

doGenerate

protected void doGenerate(List<DeploymentModule> deploymentModules)
                   throws IOException,
                          EnunciateException
Do the generate logic.

Parameters:
deploymentModules - The deployment modules to use.
Throws:
IOException
EnunciateException

doInit

protected List<DeploymentModule> doInit()
                                 throws EnunciateException,
                                        IOException
Do the initialization logic. Loads and initializes the deployment modules.

Returns:
The deployment modules that were loaded and initialized.
Throws:
EnunciateException
IOException

initModules

protected void initModules(List<DeploymentModule> deploymentModules)
                    throws EnunciateException,
                           IOException
Initialize each module.

Parameters:
deploymentModules - The deployment modules.
Throws:
EnunciateException
IOException

info

public void info(String message,
                 Object... formatArgs)
Handle an info-level message.

Parameters:
message - The info message.
formatArgs - The format args of the message.

debug

public void debug(String message,
                  Object... formatArgs)
Handle a debug-level message.

Parameters:
message - The debug message.
formatArgs - The format args of the message.

warn

public void warn(String message,
                 Object... formatArgs)
Handle a warn-level message.

Parameters:
message - The warn message.
formatArgs - The format args of the message.

createTempDir

public File createTempDir()
                   throws IOException
Creates a temporary directory.

Returns:
A temporary directory.
Throws:
IOException

getSourceFiles

public String[] getSourceFiles()
Get the source files for this enunciate mechanism.

Returns:
The source files.

loadConfig

protected EnunciateConfiguration loadConfig()
                                     throws IOException
Reads the enunciate configuration from the specified file, if any.

Returns:
The configuration, or null if none is specified.
Throws:
IOException

getJavaFiles

public Collection<String> getJavaFiles(File basedir)
Finds all java files in the specified base directory.

Parameters:
basedir - The base directory.
Returns:
The collection of java files.

getFiles

public Collection<String> getFiles(File basedir,
                                   FileFilter filter)
Finds all files in the specified base directory using the specified filter.

Parameters:
basedir - The base directory.
filter - The filter to use.
Returns:
The collection of files.

getEnunciateClasspath

public String getEnunciateClasspath()
The enunciate classpath to use for javac and apt.

Returns:
The enunciate classpath to use for javac and apt.

invokeApt

protected void invokeApt(String[] sourceFiles,
                         String... additionalApiClasses)
                  throws IOException,
                         EnunciateException
Invokes APT on the specified source files.

Parameters:
sourceFiles - The source files.
additionalApiClasses - The FQNs of additional classes (should be found on the Enunciate classpath) that comprise the API.
Throws:
IOException
EnunciateException

invokeJavac

public void invokeJavac(File compileDir,
                        String[] sourceFiles)
                 throws EnunciateException
Invokes javac on the specified source files. The classpath will be the classpath for this enunciate mechanism, if specified, otherwise the system classpath.

Parameters:
compileDir - The compile directory.
sourceFiles - The source files.
Throws:
EnunciateException - if the compile fails.

invokeJavac

public void invokeJavac(String classpath,
                        File compileDir,
                        String[] sourceFiles)
                 throws EnunciateException
Invokes javac on the specified source files.

Parameters:
classpath - The classpath.
compileDir - The compile directory.
sourceFiles - The source files.
Throws:
EnunciateException - if the compile fails.

invokeJavac

public void invokeJavac(String classpath,
                        String version,
                        File compileDir,
                        List<String> additionalArgs,
                        String[] sourceFiles)
                 throws EnunciateException
Invokes javac on the specified source files.

Parameters:
classpath - The classpath.
version - The Java version to compile to.
compileDir - The compile directory.
additionalArgs - Any additional arguments to the compiler.
sourceFiles - The source files. @throws EnunciateException if the compile fails.
Throws:
EnunciateException

copyDir

public void copyDir(File from,
                    File to)
             throws IOException
Copy an entire directory from one place to another.

Parameters:
from - The source directory.
to - The destination directory.
Throws:
IOException

extractBase

public void extractBase(InputStream baseIn,
                        File toDir)
                 throws IOException
Extracts the (zipped up) base to the specified directory.

Parameters:
baseIn - The stream to the base.
toDir - The directory to extract to.
Throws:
IOException

copyFile

public void copyFile(File src,
                     File fromDir,
                     File toDir)
              throws IOException
Copy a file from one directory to another, preserving directory structure.

Parameters:
src - The source file.
fromDir - The from directory.
toDir - The to directory.
Throws:
IOException

copyFile

public void copyFile(File from,
                     File to)
              throws IOException
Copy a file from one location to another.

Parameters:
from - The source file.
to - The destination file.
Throws:
IOException

copyResource

public void copyResource(String resource,
                         File to)
                  throws IOException
Copies a resource on the classpath to a file.

Parameters:
resource - The resource to copy.
to - The file to copy to.
Throws:
IOException

copyResource

public void copyResource(URL url,
                         File to)
                  throws IOException
Copies a resource to a file.

Parameters:
url - The url of the resource.
to - The file to copy to.
Throws:
IOException

zip

public void zip(File toFile,
                File... dirs)
         throws IOException
zip up directories to a specified zip file.

Parameters:
toFile - The file to zip to.
dirs - The directories to zip up.
Throws:
IOException

resolvePath

public File resolvePath(String filePath)
Resolves a path relative to the Enunciate config file, if present, otherwise the file will be a relative file to the current user directory.

Parameters:
filePath - The file path to resolve.
Returns:
The resolved file.

isUpToDate

public boolean isUpToDate(File sourceFile,
                          File destFile)
Determines whether a destination file is newer than a source file. If a source file is a directory, its timestamp is the timestamp of the latest file. If a destination file is a directory, its timestamp is the timestamp of the earliest file.

Parameters:
sourceFile - The source file.
destFile - The destination file.
Returns:
Whether the destination file is up-to-date.

isUpToDateWithSources

public boolean isUpToDateWithSources(File destDir)
Whether all files in the specified directory are newer than all the source files.

Parameters:
destDir - The directory.
Returns:
Whether the destination directory is up-to-date.

isUpToDate

protected boolean isUpToDate(List<File> sourceFiles,
                             File destFile)
Whether a given destination file is newer than all the specified source files. If the destination file is a directory its timestamp is the timestamp of the earliest-modified file.

Parameters:
sourceFiles - The specified source files.
destFile - The destination file.
Returns:
Whether the destination file is up-to-date.

getLatestTimestamp

protected long getLatestTimestamp(List<File> files)
Get the latest timestamp of the specified files.

Parameters:
files - The files.
Returns:
The latest timestamp.

getEarliestTimestamp

protected long getEarliestTimestamp(List<File> files)
Get the earliest timestamp of the specified files.

Parameters:
files - The files.
Returns:
The earliest timestamp.

buildFileList

protected void buildFileList(List<File> list,
                             File... dirs)
Adds all files in specified directories to a list.

Parameters:
list - The list.
dirs - The directories.

isVerbose

public boolean isVerbose()
Whether to be verbose.

Returns:
Whether to be verbose.

setVerbose

public void setVerbose(boolean verbose)
Whether to be verbose.

Parameters:
verbose - Whether to be verbose.

isDebug

public boolean isDebug()
Whether to print debugging information.

Returns:
Whether to print debugging information.

setDebug

public void setDebug(boolean debug)
Whether to print debugging information.

Parameters:
debug - Whether to print debugging information.

getVersion

public String getVersion()
The version of the Enunciate mechanism.

Returns:
The version of the Enunciate mechanism.

isJavacCheck

public boolean isJavacCheck()
Whether to do a javac check before invoking the Enunciate mechanism.

Returns:
Whether to do a javac check before invoking the Enunciate mechanism.

setJavacCheck

public void setJavacCheck(boolean javacCheck)
Whether to do a javac check before invoking the Enunciate mechanism.

Parameters:
javacCheck - Whether to do a javac check before invoking the Enunciate mechanism.

getConfigFile

public File getConfigFile()
The enunciate config file.

Returns:
The enunciate config file.

setConfigFile

public void setConfigFile(File configFile)
The enunciate config file.

Parameters:
configFile - The enunciate config file.

getCompileDir

public File getCompileDir()
The destination directory for the compiled classes.

Returns:
The destination directory for the compiled classes.

setCompileDir

public void setCompileDir(File compileDir)
The destination directory for the compiled classes.

Parameters:
compileDir - The destination directory for the compiled classes.

getBuildDir

public File getBuildDir()
The directory to use to build the war.

Returns:
The directory to use to build the war.

setBuildDir

public void setBuildDir(File buildDir)
The directory to use to build the war.

Parameters:
buildDir - The directory to use to build the war.

getPackageDir

public File getPackageDir()
The package directory.

Returns:
The package directory.

setPackageDir

public void setPackageDir(File packageDir)
The package directory.

Parameters:
packageDir - The package directory.

getGenerateDir

public File getGenerateDir()
The preprocessor directory (-s).

Returns:
The preprocessor directory (-s).

setGenerateDir

public void setGenerateDir(File generateDir)
The preprocessor directory (-s).

Parameters:
generateDir - The preprocessor directory (-s).

getClasspath

public String getClasspath()
The classpath.

Returns:
The classpath.

setClasspath

public void setClasspath(String classpath)
The classpath.

Parameters:
classpath - The classpath.

getTarget

public Enunciate.Target getTarget()
The target.

Returns:
The target.

setTarget

public void setTarget(Enunciate.Target target)
The target.

Parameters:
target - The target.

setProperty

public void setProperty(String property,
                        Object value)
Set a property value.

Parameters:
property - The property.
value - The value.

getArtifacts

public Set<Artifact> getArtifacts()
The artifacts exportable by enunciate.

Returns:
The artifacts exportable by enunciate.

findArtifact

public Artifact findArtifact(String artifactId)
Finds the artifact of the given id.

Parameters:
artifactId - The id of the artifact.
Returns:
The artifact, or null if the artifact wasn't found.

addArtifact

public boolean addArtifact(Artifact artifact)
Adds the specified artifact.

Parameters:
artifact - The artifact to add.
Returns:
Whether the artifact was successfully added.

addExport

public void addExport(String artifactId,
                      File destination)
Adds an export.

Parameters:
artifactId - The id of the artifact to export.
destination - The file or directory to export the artifact to.

getProperty

public Object getProperty(String property)
Get a property value.

Parameters:
property - The property whose value to retrieve.
Returns:
The property value.

getConfig

public EnunciateConfiguration getConfig()
Returns:
The configuration.

isModuleEnabled

public boolean isModuleEnabled(String moduleName)
Whether the specified module is enabled.

Parameters:
moduleName - The name of the module.
Returns:
Whether the module is enabled.

setConfig

public void setConfig(EnunciateConfiguration config)
Set the configuration for the mechanism.

Parameters:
config - The configuration.