Fix ant build scripts and AptTask to build with new JDK and Ant

This commit is contained in:
moparisthebest 2014-04-21 08:56:24 -04:00
parent 69e0600052
commit 6ddf0ff69b
6 changed files with 316 additions and 247 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.idea/
**.iml
**/build
**/target
**~

View File

@ -162,6 +162,15 @@
<!-- Common Beehive Ant macros --> <!-- Common Beehive Ant macros -->
<!-- ======================================================================== --> <!-- ======================================================================== -->
<macrodef name="echo-fileset">
<attribute name="filesetref" />
<sequential>
<pathconvert pathsep="${line.separator}" property="@{filesetref}.echopath" refid="@{filesetref}"/>
<echo> ------- echoing fileset @{filesetref} -------</echo>
<echo>${@{filesetref}.echopath}</echo>
</sequential>
</macrodef>
<macrodef name="copy-junit"> <macrodef name="copy-junit">
<attribute name="todir"/> <attribute name="todir"/>
<sequential> <sequential>
@ -305,15 +314,19 @@
<!-- ======================================================================== --> <!-- ======================================================================== -->
<!-- Verify JDK version --> <!-- Verify JDK version -->
<!-- ======================================================================== --> <!-- ======================================================================== -->
<property name="required.jdk.version" value="1.5"/>
<condition property="jdk.version.okay"> <condition property="jdk.version.okay">
<contains string="${java.version}" substring="${required.jdk.version}"/> <or>
<contains string="${java.version}" substring="1.5"/>
<contains string="${java.version}" substring="1.6"/>
<contains string="${java.version}" substring="1.7"/>
<contains string="${java.version}" substring="1.8"/>
</or>
</condition> </condition>
<fail unless="jdk.version.okay"> <fail unless="jdk.version.okay">
Newer JDK required. Newer JDK required.
Building the project requires JDK ${required.jdk.version} Building the project requires JDK 1.5 or newer.
You are currently using the following JDK: You are currently using the following JDK:
@ -338,6 +351,7 @@ adjust your JAVA_HOME environment variable.
<!-- allow ant 1.7 for gump runs --> <!-- allow ant 1.7 for gump runs -->
<contains string="${ant.version}" substring="1.6"/> <contains string="${ant.version}" substring="1.6"/>
<contains string="${ant.version}" substring="1.7"/> <contains string="${ant.version}" substring="1.7"/>
<contains string="${ant.version}" substring="1.8"/>
</or> </or>
</condition> </condition>

View File

@ -108,6 +108,11 @@
<!-- Compiles the source code of the project. --> <!-- Compiles the source code of the project. -->
<!-- ==================================================================== --> <!-- ==================================================================== -->
<target name="classes" depends="dirs"> <target name="classes" depends="dirs">
<echo-fileset filesetref="api.classpath"/>
<echo-fileset filesetref="runtime.classpath"/>
<echo-fileset filesetref="test-container.classpath"/>
<!-- Build the API and SPI classes --> <!-- Build the API and SPI classes -->
<!-- These are built together because there are some cross-depencies --> <!-- These are built together because there are some cross-depencies -->
<!-- where API classes reference SPI interfaces --> <!-- where API classes reference SPI interfaces -->

View File

@ -48,269 +48,309 @@ import java.util.Vector;
*/ */
public class AptTask extends Javac public class AptTask extends Javac
{ {
/** /**
* The srcExtensions attribute can be set to a comma-separated list of source filename * The srcExtensions attribute can be set to a comma-separated list of source filename
* extensions that are considered to be valid inputs to APT processing. * extensions that are considered to be valid inputs to APT processing.
* The default value is "*.java". * The default value is "*.java".
*/ */
public void setSrcExtensions(String srcExts) public void setSrcExtensions(String srcExts)
{ {
StringTokenizer tok = new StringTokenizer(srcExts, ","); StringTokenizer tok = new StringTokenizer(srcExts, ",");
while (tok.hasMoreTokens()) while (tok.hasMoreTokens())
_srcExts.add(tok.nextToken()); _srcExts.add(tok.nextToken());
} }
/**
* The srcExtensions attribute can be set to a comma-separated list of processor options
* (of the form <i>option</i> or <i>option</i><code>=</code><i>value</i>) to be passed to
* APT.
*/
public void setProcessorOptions(String processorOptions)
{
StringTokenizer tok = new StringTokenizer(processorOptions, ",");
while (tok.hasMoreTokens())
_processorOptions.add(tok.nextToken());
}
/** /**
* The gendir attribute specifies the name of the output directory for any files generated * The srcExtensions attribute can be set to a comma-separated list of processor options
* as a result of calling APT. * (of the form <i>option</i> or <i>option</i><code>=</code><i>value</i>) to be passed to
*/ * APT.
public void setGendir(File genDir) */
{ public void setProcessorOptions(String processorOptions)
_genDir = genDir; {
} StringTokenizer tok = new StringTokenizer(processorOptions, ",");
while (tok.hasMoreTokens())
_processorOptions.add(tok.nextToken());
}
/** /**
* The nocompile attribute disables compilation of the input source file list and any * The gendir attribute specifies the name of the output directory for any files generated
* generated sources that are derived from them. The default value is 'false'. * as a result of calling APT.
*/ */
public void setNocompile(boolean nocompile) public void setGendir(File genDir)
{ {
_nocompile = nocompile; _genDir = genDir;
} }
/** /**
* The compileByExtension attribute causes each input source extension to be compiled * The nocompile attribute disables compilation of the input source file list and any
* independently (and sequentially). This is useful when one type of extensio can * generated sources that are derived from them. The default value is 'false'.
* possibly depend upon the generation output from another. The default value 'false'. */
*/ public void setNocompile(boolean nocompile)
public void setCompileByExtension(boolean compileByExt) {
{ _nocompile = nocompile;
_compileByExt = compileByExt; }
}
/** /**
* Override the implementation of scanDir, to look for additional files based upon any * The compileByExtension attribute causes each input source extension to be compiled
* specified source extensions * independently (and sequentially). This is useful when one type of extensio can
*/ * possibly depend upon the generation output from another. The default value 'false'.
protected void scanDir(File srcDir, File destDir, String[] files, String ext) */
{ public void setCompileByExtension(boolean compileByExt)
// If no source path was specified, we effectively created one by adding the generation {
// path. Because of this, we need to be sure and add all source dirs to the path too. _compileByExt = compileByExt;
if (!_hasSourcepath) }
{
Path srcPath = new Path(getProject());
srcPath.setLocation(srcDir);
Path sp = getSourcepath();
sp.append(srcPath);
setSourcepath(sp);
}
GlobPatternMapper m = new GlobPatternMapper(); public void setFactory(String factory) {
m.setFrom(ext); _factory = factory;
m.setTo("*.class"); }
SourceFileScanner sfs = new SourceFileScanner(this);
if (ext.equals("*.java"))
{
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
if (newFiles.length > 0)
{
File[] newCompileList = new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
System.arraycopy(newFiles, 0, newCompileList, compileList.length,
newFiles.length);
compileList = newCompileList;
}
}
else
{
String [] newSources = sfs.restrict(files, srcDir, destDir, m);
int extLen = ext.length() - 1; // strip wildcard
if (newSources.length > 0)
{
File[] newCompileList = new File[compileList.length + newSources.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
try
{
FileUtils fileUtils = FileUtils.newFileUtils();
for (int j = 0; j < newSources.length; j++)
{
String toName =
newSources[j].substring(0, newSources[j].length() - extLen) +
".java";
File srcFile = new File(srcDir, newSources[j]);
File dstFile = new File(_genDir, toName);
fileUtils.copyFile(srcFile, dstFile, null, true, true);
newCompileList[compileList.length + j] = dstFile;
}
}
catch (IOException ioe)
{
throw new BuildException("Unable to copy " + ext + " file", ioe,
getLocation());
}
compileList = newCompileList;
}
}
}
public void execute() throws BuildException public void setFactorypath(String factorypath) {
{ _factorypath = factorypath;
// Ensure that the gendir attribute was specified }
if (_genDir == null)
throw new BuildException("Missing genDir attribute: must be set to codegen output directory", getLocation()); /**
* Override the implementation of scanDir, to look for additional files based upon any
* specified source extensions
*/
protected void scanDir(File srcDir, File destDir, String[] files, String ext)
{
// If no source path was specified, we effectively created one by adding the generation
// path. Because of this, we need to be sure and add all source dirs to the path too.
if (!_hasSourcepath)
{
Path srcPath = new Path(getProject());
srcPath.setLocation(srcDir);
setSourcepath(srcPath);
}
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom(ext);
m.setTo("*.class");
SourceFileScanner sfs = new SourceFileScanner(this);
if (ext.equals("*.java"))
{
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
if (newFiles.length > 0)
{
File[] newCompileList = new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
System.arraycopy(newFiles, 0, newCompileList, compileList.length,
newFiles.length);
compileList = newCompileList;
}
}
else
{
String [] newSources = sfs.restrict(files, srcDir, destDir, m);
int extLen = ext.length() - 1; // strip wildcard
if (newSources.length > 0)
{
File[] newCompileList = new File[compileList.length + newSources.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
try
{
FileUtils fileUtils = FileUtils.newFileUtils();
for (int j = 0; j < newSources.length; j++)
{
String toName =
newSources[j].substring(0, newSources[j].length() - extLen) +
".java";
File srcFile = new File(srcDir, newSources[j]);
File dstFile = new File(_genDir, toName);
fileUtils.copyFile(srcFile, dstFile, null, true, true);
newCompileList[compileList.length + j] = dstFile;
}
}
catch (IOException ioe)
{
throw new BuildException("Unable to copy " + ext + " file", ioe,
getLocation());
}
compileList = newCompileList;
}
}
}
public void execute() throws BuildException
{
// Ensure that the gendir attribute was specified
if (_genDir == null)
throw new BuildException("Missing genDir attribute: must be set to codegen output directory", getLocation());
// If no source extension specified, then just process .java files // If no source extension specified, then just process .java files
if (_srcExts.size() == 0) if (_srcExts.size() == 0)
_srcExts.add("*.java"); _srcExts.add("*.java");
// Save whether a user sourcepath was provided, and if so, the paths // Save whether a user sourcepath was provided, and if so, the paths
String[] userSourcepaths = null; String[] userSourcepaths = null;
_hasSourcepath = getSourcepath() != null; _hasSourcepath = getSourcepath() != null;
if ( _hasSourcepath ) if ( _hasSourcepath )
userSourcepaths = getSourcepath().list(); userSourcepaths = getSourcepath().list();
// The generation dir is always added to the source path for compilation // The generation dir is always added to the source path for compilation
Path genPath = new Path(getProject()); Path genPath = new Path(getProject());
genPath.setLocation(_genDir); genPath.setLocation(_genDir);
setSourcepath(genPath); setSourcepath(genPath);
// If the user sourcepath specifies subdirs underneath the srcdir, then we need to add
// the corresponding subdirs under the gendir to the source path for compilation.
// For example, if the user sourcepath is "<webapp-root>;<webapp-root>\WEB-INF\src",
// then the sourcepath for compilation should include "<gen-dir>;<gen-dir>\WEB-INF\src".
if ( _hasSourcepath )
{
String srcDirPath = (getSrcdir().list())[0]; // TODO: handle multiple srcdirs
for ( String p: userSourcepaths )
{
if ( p.startsWith( srcDirPath ) && p.length() > srcDirPath.length() )
{
File genDirElem = new File( _genDir, p.substring( srcDirPath.length()+1 ));
Path gp = new Path(getProject());
gp.setLocation( genDirElem );
setSourcepath(gp);
}
}
}
// // If the user sourcepath specifies subdirs underneath the srcdir, then we need to add
// Select the executable (apt) and set fork = true // the corresponding subdirs under the gendir to the source path for compilation.
// // For example, if the user sourcepath is "<webapp-root>;<webapp-root>\WEB-INF\src",
setExecutable("apt"); // then the sourcepath for compilation should include "<gen-dir>;<gen-dir>\WEB-INF\src".
setFork(true); if ( _hasSourcepath )
{
String srcDirPath = (getSrcdir().list())[0]; // TODO: handle multiple srcdirs
for ( String p: userSourcepaths )
{
if ( p.startsWith( srcDirPath ) && p.length() > srcDirPath.length() )
{
File genDirElem = new File( _genDir, p.substring( srcDirPath.length()+1 ));
Path gp = new Path(getProject());
gp.setLocation( genDirElem );
setSourcepath(gp);
}
}
}
// // Select the executable (apt) and set fork = true
// Specify the code generation output directory to APT setExecutable("apt");
// setFork(true);
Commandline.Argument arg = createCompilerArg();
arg.setValue("-s");
arg = createCompilerArg();
arg.setFile(_genDir);
//add the -nocompile flag if set to true // Specify the code generation output directory to APT
if(_nocompile) Commandline.Argument arg = createCompilerArg();
{ arg.setValue("-s");
Commandline.Argument ncarg = createCompilerArg(); arg = createCompilerArg();
ncarg.setValue("-nocompile"); arg.setFile(_genDir);
}
//
// Add processor options.
//
for (Object i : _processorOptions)
{
Commandline.Argument optionArg = createCompilerArg();
optionArg.setValue("-A" + i);
}
checkParameters(); // Add the -nocompile flag if set to true
resetFileLists(); if(_nocompile)
{
Commandline.Argument ncarg = createCompilerArg();
ncarg.setValue("-nocompile");
}
// Iterate through the list of input extensions, matching/dependency checking based // Add processor options.
// upon the input list. for (Object i : _processorOptions)
for (int j = 0; j < _srcExts.size(); j++) {
{ Commandline.Argument optionArg = createCompilerArg();
String ext = (String)_srcExts.get(j); optionArg.setValue("-A" + i);
Vector<File> inputFiles = new Vector<File>(); }
// scan source directories and dest directory to build up checkParameters();
// compile lists resetFileLists();
String[] list = getSrcdir().list();
File destDir = getDestdir();
for (int i = 0; i < list.length; i++)
{
File srcFile = getProject().resolveFile(list[i]);
if (!srcFile.exists()) {
throw new BuildException("srcdir \""
+ srcFile.getPath()
+ "\" does not exist!", getLocation());
}
// //
// The base <javac> algorithm is tweaked here, to allow <src> elements // Allow user to define apt specific options for the name of an
// to contain a list of files _or_ a list of directories to scan. // annotation processor (AP) factory to use or the factory path
// // for finding the AP factories. This allows apt to bypass the
if (srcFile.isDirectory()) // default discovery process or specify where to find AP factories.
{ //
DirectoryScanner ds = this.getDirectoryScanner(srcFile); // This can help resolve build issues users may experience when
String[] files = ds.getIncludedFiles(); // multiple annotation processors conflict. For example,...
scanDir(srcFile, destDir != null ? destDir : srcFile, files, ext); // A project may contain JAX-RPC 1.1 Web Services annotations.
} // Starting with JDK1.6, JDK bundles the JAX-WS 2.0 AP in its
else // tool jar. JAX-RPC and JAX-WS use the same JSR 181 annotations
{ // but the JAX-WS 2.0 AP doesn't support the earlier JAX-RPC use
// // of the RPC/ENCODED soapbinding annotation on an endpoint.
// BUGBUG: Because these bypass scanning, they also bypass dependency chks :( // A user running the build through the Beehive AptTask and using
// // Java 6, would see APT fail on JAX-RPC services thinking they are
if (srcFile.getPath().endsWith(ext.substring(1))) // invalid JAX-WS services.
inputFiles.add(srcFile); //
} // In this example, using the -factorypath option does not disable the
} // built-in annotation processor because tools.jar is always in APT's
// class path. However, exposing the option to use a specific factory
// can solve this problem. There can only be one factory name when
// invoking APT, so a user of this task may want to pass a wrapper
// factory that is an aggregated annotation processor factory.
//
if (_factorypath != null && _factorypath.trim().length() > 0) {
Commandline.Argument factoryArg = createCompilerArg();
factoryArg.setValue("-factorypath");
factoryArg = createCompilerArg();
factoryArg.setValue(_factorypath);
}
if (inputFiles.size() != 0) if (_factory != null && _factory.trim().length() > 0) {
{ Commandline.Argument factoryArg = createCompilerArg();
File[] newCompileList = new File[compileList.length + inputFiles.size()]; factoryArg.setValue("-factory");
inputFiles.toArray(newCompileList); factoryArg = createCompilerArg();
System.arraycopy(compileList, 0, newCompileList, inputFiles.size(), factoryArg.setValue(_factory);
compileList.length); }
compileList = newCompileList;
}
// // Iterate through the list of input extensions, matching/dependency
// If processing/compiling on a per-extension basis, then handle the current list, // checking based upon the input list.
// then reset the list fo files to compile before moving to the next extension for (int j = 0; j < _srcExts.size(); j++)
// {
if (_compileByExt) String ext = (String)_srcExts.get(j);
{ Vector<File> inputFiles = new Vector<File>();
compile();
resetFileLists();
}
}
// // scan source directories and dest directory to build up
// If not processing on a per-extension basis, then compile the entire aggregated list // compile lists
// String[] list = getSrcdir().list();
if (!_compileByExt) File destDir = getDestdir();
compile(); for (int i = 0; i < list.length; i++)
} {
File srcFile = getProject().resolveFile(list[i]);
if (!srcFile.exists()) {
throw new BuildException("srcdir \""
+ srcFile.getPath()
+ "\" does not exist!", getLocation());
}
protected boolean _nocompile = false; //
protected boolean _compileByExt = false; // The base <javac> algorithm is tweaked here, to allow <src> elements
protected boolean _hasSourcepath; // to contain a list of files _or_ a list of directories to scan.
protected File _genDir; //
protected Vector/*<String>*/ _srcExts = new Vector/*<String>*/(); if (srcFile.isDirectory())
protected Vector/*<String>*/ _processorOptions = new Vector/*<String>*/(); {
DirectoryScanner ds = this.getDirectoryScanner(srcFile);
String[] files = ds.getIncludedFiles();
scanDir(srcFile, destDir != null ? destDir : srcFile, files, ext);
}
else
{
//
// BUGBUG: Because these bypass scanning, they also bypass dependency chks :(
//
if (srcFile.getPath().endsWith(ext.substring(1)))
inputFiles.add(srcFile);
}
}
if (inputFiles.size() != 0)
{
File[] newCompileList = new File[compileList.length + inputFiles.size()];
inputFiles.toArray(newCompileList);
System.arraycopy(compileList, 0, newCompileList, inputFiles.size(),
compileList.length);
compileList = newCompileList;
}
//
// If processing/compiling on a per-extension basis, then handle the current list,
// then reset the list fo files to compile before moving to the next extension
//
if (_compileByExt)
{
compile();
resetFileLists();
}
}
//
// If not processing on a per-extension basis, then compile the entire aggregated list
//
if (!_compileByExt)
compile();
}
protected boolean _nocompile = false;
protected boolean _compileByExt = false;
protected boolean _hasSourcepath;
protected File _genDir;
protected Vector/*<String>*/ _srcExts = new Vector/*<String>*/();
protected Vector/*<String>*/ _processorOptions = new Vector/*<String>*/();
protected String _factory = null;
protected String _factorypath = null;
} }

View File

@ -60,6 +60,7 @@
</copy> </copy>
<echo>Generate TLD</echo> <echo>Generate TLD</echo>
<echo-fileset filesetref="webdoclet.dependency.path"/>
<taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask" classpathref="webdoclet.dependency.path"/> <taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask" classpathref="webdoclet.dependency.path"/>
<webdoclet <webdoclet
destdir="${jars.dir}" destdir="${jars.dir}"

View File

@ -34,6 +34,10 @@
<target name="build" description="Builds the JMS control."> <target name="build" description="Builds the JMS control.">
<echo>compile module: ${module.name}</echo>
<property name="classpath" refid="module.classpath"/>
<echo>module classpath: ${classpath}</echo>
<mkdir dir="${classes.dir}/${module.name}"/> <mkdir dir="${classes.dir}/${module.name}"/>
<mkdir dir="${gen.src.dir}/${module.name}"/> <mkdir dir="${gen.src.dir}/${module.name}"/>