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 * 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 * (of the form <i>option</i> or <i>option</i><code>=</code><i>value</i>) to be passed to
* APT. * APT.
*/ */
public void setProcessorOptions(String processorOptions) public void setProcessorOptions(String processorOptions)
{ {
StringTokenizer tok = new StringTokenizer(processorOptions, ","); StringTokenizer tok = new StringTokenizer(processorOptions, ",");
while (tok.hasMoreTokens()) while (tok.hasMoreTokens())
_processorOptions.add(tok.nextToken()); _processorOptions.add(tok.nextToken());
} }
/** /**
* The gendir attribute specifies the name of the output directory for any files generated * The gendir attribute specifies the name of the output directory for any files generated
* as a result of calling APT. * as a result of calling APT.
*/ */
public void setGendir(File genDir) public void setGendir(File genDir)
{ {
_genDir = genDir; _genDir = genDir;
} }
/** /**
* The nocompile attribute disables compilation of the input source file list and any * The nocompile attribute disables compilation of the input source file list and any
* generated sources that are derived from them. The default value is 'false'. * generated sources that are derived from them. The default value is 'false'.
*/ */
public void setNocompile(boolean nocompile) public void setNocompile(boolean nocompile)
{ {
_nocompile = nocompile; _nocompile = nocompile;
} }
/** /**
* The compileByExtension attribute causes each input source extension to be compiled * The compileByExtension attribute causes each input source extension to be compiled
* independently (and sequentially). This is useful when one type of extensio can * independently (and sequentially). This is useful when one type of extensio can
* possibly depend upon the generation output from another. The default value 'false'. * possibly depend upon the generation output from another. The default value 'false'.
*/ */
public void setCompileByExtension(boolean compileByExt) public void setCompileByExtension(boolean compileByExt)
{ {
_compileByExt = compileByExt; _compileByExt = compileByExt;
} }
/** public void setFactory(String factory) {
* Override the implementation of scanDir, to look for additional files based upon any _factory = factory;
* 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);
Path sp = getSourcepath();
sp.append(srcPath);
setSourcepath(sp);
}
GlobPatternMapper m = new GlobPatternMapper(); public void setFactorypath(String factorypath) {
m.setFrom(ext); _factorypath = factorypath;
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); * Override the implementation of scanDir, to look for additional files based upon any
fileUtils.copyFile(srcFile, dstFile, null, true, true); * specified source extensions
newCompileList[compileList.length + j] = dstFile; */
} protected void scanDir(File srcDir, File destDir, String[] files, String ext)
} {
catch (IOException ioe) // 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.
throw new BuildException("Unable to copy " + ext + " file", ioe, if (!_hasSourcepath)
getLocation()); {
} Path srcPath = new Path(getProject());
compileList = newCompileList; srcPath.setLocation(srcDir);
} setSourcepath(srcPath);
} }
}
public void execute() throws BuildException GlobPatternMapper m = new GlobPatternMapper();
{ m.setFrom(ext);
// Ensure that the gendir attribute was specified m.setTo("*.class");
if (_genDir == null) SourceFileScanner sfs = new SourceFileScanner(this);
throw new BuildException("Missing genDir attribute: must be set to codegen output directory", getLocation()); 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 // 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. // 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", // 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". // then the sourcepath for compilation should include "<gen-dir>;<gen-dir>\WEB-INF\src".
if ( _hasSourcepath ) if ( _hasSourcepath )
{ {
String srcDirPath = (getSrcdir().list())[0]; // TODO: handle multiple srcdirs String srcDirPath = (getSrcdir().list())[0]; // TODO: handle multiple srcdirs
for ( String p: userSourcepaths ) for ( String p: userSourcepaths )
{ {
if ( p.startsWith( srcDirPath ) && p.length() > srcDirPath.length() ) if ( p.startsWith( srcDirPath ) && p.length() > srcDirPath.length() )
{ {
File genDirElem = new File( _genDir, p.substring( srcDirPath.length()+1 )); File genDirElem = new File( _genDir, p.substring( srcDirPath.length()+1 ));
Path gp = new Path(getProject()); Path gp = new Path(getProject());
gp.setLocation( genDirElem ); gp.setLocation( genDirElem );
setSourcepath(gp); setSourcepath(gp);
} }
} }
} }
// // Select the executable (apt) and set fork = true
// Select the executable (apt) and set fork = true setExecutable("apt");
// setFork(true);
setExecutable("apt");
setFork(true);
// // Specify the code generation output directory to APT
// Specify the code generation output directory to APT Commandline.Argument arg = createCompilerArg();
// arg.setValue("-s");
Commandline.Argument arg = createCompilerArg(); arg = createCompilerArg();
arg.setValue("-s"); arg.setFile(_genDir);
arg = createCompilerArg();
arg.setFile(_genDir);
//add the -nocompile flag if set to true // Add the -nocompile flag if set to true
if(_nocompile) if(_nocompile)
{ {
Commandline.Argument ncarg = createCompilerArg(); Commandline.Argument ncarg = createCompilerArg();
ncarg.setValue("-nocompile"); ncarg.setValue("-nocompile");
} }
// // Add processor options.
// Add processor options. for (Object i : _processorOptions)
// {
for (Object i : _processorOptions) Commandline.Argument optionArg = createCompilerArg();
{ optionArg.setValue("-A" + i);
Commandline.Argument optionArg = createCompilerArg(); }
optionArg.setValue("-A" + i);
}
checkParameters(); checkParameters();
resetFileLists(); resetFileLists();
// Iterate through the list of input extensions, matching/dependency checking based //
// upon the input list. // Allow user to define apt specific options for the name of an
for (int j = 0; j < _srcExts.size(); j++) // annotation processor (AP) factory to use or the factory path
{ // for finding the AP factories. This allows apt to bypass the
String ext = (String)_srcExts.get(j); // default discovery process or specify where to find AP factories.
Vector<File> inputFiles = new Vector<File>(); //
// This can help resolve build issues users may experience when
// multiple annotation processors conflict. For example,...
// 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
// 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.
// A user running the build through the Beehive AptTask and using
// Java 6, would see APT fail on JAX-RPC services thinking they are
// invalid JAX-WS services.
//
// 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);
}
// scan source directories and dest directory to build up if (_factory != null && _factory.trim().length() > 0) {
// compile lists Commandline.Argument factoryArg = createCompilerArg();
String[] list = getSrcdir().list(); factoryArg.setValue("-factory");
File destDir = getDestdir(); factoryArg = createCompilerArg();
for (int i = 0; i < list.length; i++) factoryArg.setValue(_factory);
{ }
File srcFile = getProject().resolveFile(list[i]);
if (!srcFile.exists()) {
throw new BuildException("srcdir \""
+ srcFile.getPath()
+ "\" does not exist!", getLocation());
}
// // Iterate through the list of input extensions, matching/dependency
// The base <javac> algorithm is tweaked here, to allow <src> elements // checking based upon the input list.
// to contain a list of files _or_ a list of directories to scan. for (int j = 0; j < _srcExts.size(); j++)
// {
if (srcFile.isDirectory()) String ext = (String)_srcExts.get(j);
{ Vector<File> inputFiles = new Vector<File>();
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) // scan source directories and dest directory to build up
{ // compile lists
File[] newCompileList = new File[compileList.length + inputFiles.size()]; String[] list = getSrcdir().list();
inputFiles.toArray(newCompileList); File destDir = getDestdir();
System.arraycopy(compileList, 0, newCompileList, inputFiles.size(), for (int i = 0; i < list.length; i++)
compileList.length); {
compileList = newCompileList; File srcFile = getProject().resolveFile(list[i]);
} if (!srcFile.exists()) {
throw new BuildException("srcdir \""
+ srcFile.getPath()
+ "\" does not exist!", getLocation());
}
// //
// If processing/compiling on a per-extension basis, then handle the current list, // The base <javac> algorithm is tweaked here, to allow <src> elements
// then reset the list fo files to compile before moving to the next extension // to contain a list of files _or_ a list of directories to scan.
// //
if (_compileByExt) if (srcFile.isDirectory())
{ {
compile(); DirectoryScanner ds = this.getDirectoryScanner(srcFile);
resetFileLists(); 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)
// If not processing on a per-extension basis, then compile the entire aggregated list {
// File[] newCompileList = new File[compileList.length + inputFiles.size()];
if (!_compileByExt) inputFiles.toArray(newCompileList);
compile(); System.arraycopy(compileList, 0, newCompileList, inputFiles.size(),
} compileList.length);
compileList = newCompileList;
}
protected boolean _nocompile = false; //
protected boolean _compileByExt = false; // If processing/compiling on a per-extension basis, then handle the current list,
protected boolean _hasSourcepath; // then reset the list fo files to compile before moving to the next extension
protected File _genDir; //
protected Vector/*<String>*/ _srcExts = new Vector/*<String>*/(); if (_compileByExt)
protected Vector/*<String>*/ _processorOptions = new Vector/*<String>*/(); {
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}"/>