@@ -54,10 +54,10 @@
/* build notes
/* build notes
-The reference CD to listen to while editing this file is
-The reference CD to listen to while editing this file is
nap: Underworld - Everything, Everything
nap: Underworld - Everything, Everything
-variable naming policy from Fowler's refactoring book.
-variable naming policy from Fowler's refactoring book.
-tested against the PDC pre-beta of csc.exe; future versions will
-tested against the PDC pre-beta of csc.exe; future versions will
inevitably change things
inevitably change things
*/
*/
@@ -74,16 +74,15 @@ package org.apache.tools.ant.taskdefs.optional.dotnet;
import java.io.File;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
/**
/**
Task to assemble .net 'Intermediate Language' files.
Task to assemble .net 'Intermediate Language' files.
The task will only work on win2K until other platforms support csc.exe or
The task will only work on win2K until other platforms support csc.exe or
an equivalent. ilasm.exe must be on the execute path too.
an equivalent. ilasm.exe must be on the execute path too.
<p>
<p>
@@ -95,95 +94,94 @@ even though the command line options are only vaguely
equivalent. [The low level commands take things like /OUT=file,
equivalent. [The low level commands take things like /OUT=file,
csc wants /out:file ... /verbose is used some places; /quiet here in
csc wants /out:file ... /verbose is used some places; /quiet here in
ildasm... etc.] It would be nice if someone made all the command line
ildasm... etc.] It would be nice if someone made all the command line
tools consistent (and not as brittle as the java cmdline tools)
tools consistent (and not as brittle as the java cmdline tools)
<p>
<p>
The task is a directory based task, so attributes like <b>includes="*.il"</b> and
<b>excludes="broken.il"</b> can be used to control the files pulled in.
The task is a directory based task, so attributes like <b>includes="*.il"</b> and
<b>excludes="broken.il"</b> can be used to control the files pulled in.
Each file is built on its own, producing an appropriately named output file unless
Each file is built on its own, producing an appropriately named output file unless
manually specified with <b>outfile</b>
manually specified with <b>outfile</b>
@author Steve Loughran steve_l@iseran.com
@version 0.2
@author Steve Loughran steve_l@iseran.com
@version 0.2
*/
*/
public class Ilasm
public class Ilasm
extends org.apache.tools.ant.taskdefs. MatchingTask {
extends MatchingTask {
/** constructor inits everything and set up the search pattern
/** constructor inits everything and set up the search pattern
*/
public Ilasm () {
*/
public Ilasm() {
Clear();
Clear();
setIncludes(file_pattern);
setIncludes(file_pattern);
}
}
/** name of the executable. the .exe suffix is deliberately not included
/** name of the executable. the .exe suffix is deliberately not included
* in anticipation of the unix version
* in anticipation of the unix version
*/
*/
protected final static String exe_name="ilasm";
protected final static String exe_name = "ilasm";
/** what is the file extension we search on?
/** what is the file extension we search on?
*/
*/
protected final static String file_ext="il";
/** and now derive the search pattern from the extension
protected final static String file_ext = "il";
/** and now derive the search pattern from the extension
*/
*/
protected final static String file_pattern="**/*."+file_ext;
protected final static String file_pattern = "**/*." + file_ext;
/** title of task for external presentation
/** title of task for external presentation
*/
*/
protected final static String exe_title="ilasm";
/** reset all contents.
*/
protected final static String exe_title = "ilasm";
/** reset all contents.
*/
public void Clear() {
public void Clear() {
_targetType=null;
_srcDir=null;
_targetType = null;
_srcDir = null;
_listing = false;
_listing = false;
_verbose=false;
_debug=true;
_outputFile=null;
_failOnError=true;
_resourceFile=null;
_extraOptions=null;
_verbose = false;
_debug = true;
_outputFile = null;
_failOnError = true;
_resourceFile = null;
_extraOptions = null;
}
}
/** source directory upon which the search pattern is applied
/** source directory upon which the search pattern is applied
*/
*/
private File _srcDir;
private File _srcDir;
/**
/**
* Set the source dir to find the files to be compiled
* Set the source dir to find the files to be compiled
* @param srcDirName The new SrcDir value
* @param srcDirName The new SrcDir value
*/
*/
public void setSrcDir(File srcDirName){
public void setSrcDir(File srcDirName) {
_srcDir = srcDirName;
_srcDir = srcDirName;
}
}
/** type of target. Should be one of exe|library|module|winexe|(null)
/** type of target. Should be one of exe|library|module|winexe|(null)
default is exe; the actual value (if not null) is fed to the command line.
<br>See /target
default is exe; the actual value (if not null) is fed to the command line.
<br>See /target
*/
*/
protected String _targetType;
protected String _targetType;
/** define the target
/** define the target
* @param targetType one of exe|library|
* @param targetType one of exe|library|
* @exception BuildException if target is not one of exe|library|module|winexe
* @exception BuildException if target is not one of exe|library|module|winexe
*/
*/
public void setTargetType(String targetType)
public void setTargetType(String targetType)
throws BuildException {
targetType=targetType.toLowerCase();
if(targetType.equals("exe") || targetType.equals("library")) {
_targetType=targetType;
}
else {
throw new BuildException("targetType " +targetType+" is not a valid type");
throws BuildException {
targetType = targetType.toLowerCase();
if (targetType.equals("exe") || targetType.equals("library")) {
_targetType = targetType;
} else {
throw new BuildException("targetType " + targetType + " is not a valid type");
}
}
}
}
@@ -191,97 +189,97 @@ public class Ilasm
* accessor method for target type
* accessor method for target type
* @return the current target option
* @return the current target option
*/
*/
public String getTargetType() {
public String getTargetType() {
return _targetType;
return _targetType;
}
}
/** g
/** g
* get the target type or null for no argument needed
* get the target type or null for no argument needed
*
*
* @return The TargetTypeParameter value
*/
* @return The TargetTypeParameter value
*/
protected String getTargetTypeParameter() {
protected String getTargetTypeParameter() {
if(!notEmpty(_targetType)) {
if (!notEmpty(_targetType)) {
return null;
return null;
}
}
if (_targetType.equals("exe")) {
if (_targetType.equals("exe")) {
return "/exe";
return "/exe";
} else
if (_targetType.equals("library")) {
} else if (_targetType.equals("library")) {
return "/dll";
return "/dll";
} else {
} else {
return null;
return null;
}
}
}
}
/**
/**
* Sets the Owner attribute
* Sets the Owner attribute
*
*
* @param s The new Owner value
* @param s The new Owner value
*/
*/
public void setOwner(String s) {
public void setOwner(String s) {
log("This option is not supported by ILASM as of Beta-2, and will be ignored",Project.MSG_WARN);
}
log("This option is not supported by ILASM as of Beta-2, and will be ignored", Project.MSG_WARN);
}
/** test for a string containing something useful
/** test for a string containing something useful
* @param string to test
* @param string to test
* @returns true if the argument is not null or empty
* @returns true if the argument is not null or empty
*/
protected boolean notEmpty(String s)
{return s!=null && s.length()!=0;}
*/
protected boolean notEmpty(String s) {
return s != null && s.length() != 0;
}
/** verbose flag
/** verbose flag
*/
*/
protected boolean _verbose;
protected boolean _verbose;
/**
/**
* enable/disable verbose ILASM output
* enable/disable verbose ILASM output
* @param b flag set to true for verbose on
* @param b flag set to true for verbose on
*/
*/
public void setVerbose(boolean b) {
public void setVerbose(boolean b) {
_verbose=b;
_verbose = b;
}
}
/**
/**
* turn the verbose flag into a parameter for ILASM
* turn the verbose flag into a parameter for ILASM
* @return null or the appropriate command line string
* @return null or the appropriate command line string
*/
*/
protected String getVerboseParameter() {
protected String getVerboseParameter() {
return _verbose?null:"/quiet";
return _verbose?null:"/quiet";
}
}
/** listing flag
/** listing flag
*/
*/
protected boolean _listing;
protected boolean _listing;
/**
/**
* enable/disable listing
* enable/disable listing
* @param b flag set to true for listing on
* @param b flag set to true for listing on
*/
*/
public void setListing(boolean b) {
public void setListing(boolean b) {
_listing=b;
_listing = b;
}
}
/**
/**
* turn the listing flag into a parameter for ILASM
* turn the listing flag into a parameter for ILASM
* @return the appropriate string from the state of the listing flag
* @return the appropriate string from the state of the listing flag
*/
*/
protected String getListingParameter() {
protected String getListingParameter() {
return _listing?"/listing":"/nolisting";
return _listing?"/listing":"/nolisting";
}
}
/**
/**
* output file. If not supplied this is derived from the
* output file. If not supplied this is derived from the
* source file
* source file
*/
*/
protected File _outputFile;
protected File _outputFile;
/**
/**
* Set the definitions
* Set the definitions
* @param list of definitions split by ; or , or even :
* @param list of definitions split by ; or , or even :
@@ -289,164 +287,167 @@ public class Ilasm
public void setOutputFile(File params) {
public void setOutputFile(File params) {
_outputFile = params;
_outputFile = params;
}
}
/**
/**
* get the output file
* get the output file
* @return the argument string or null for no argument
* @return the argument string or null for no argument
*/
*/
protected String getOutputFileParameter() {
protected String getOutputFileParameter() {
if (_outputFile==null || _outputFile.length()==0) {
if (_outputFile == null || _outputFile.length() == 0) {
return null;
return null;
}
}
File f = _outputFile;
File f = _outputFile;
return "/output="+f.toString();
return "/output=" + f.toString();
}
}
/** resource file (.res format) to include in the app.
/** resource file (.res format) to include in the app.
*/
*/
protected File _resourceFile;
protected File _resourceFile;
/**
/**
* Set the resource file
* Set the resource file
* @param fileName path to the file. Can be relative, absolute, whatever.
* @param fileName path to the file. Can be relative, absolute, whatever.
*/public void setResourceFile(File fileName) {
*/
public void setResourceFile(File fileName) {
_resourceFile = fileName;
_resourceFile = fileName;
}
}
protected String getResourceFileParameter() {
protected String getResourceFileParameter() {
if(_resourceFile!=null) {
return "/resource="+_resourceFile.toString();
}
else {
if (_resourceFile != null) {
return "/resource=" + _resourceFile.toString();
} else {
return null;
return null;
}
}
}
}
/** flag to control action on execution trouble
/** flag to control action on execution trouble
*/
*/
protected boolean _failOnError;
protected boolean _failOnError;
/**set fail on error flag
/**set fail on error flag
*/
public void setFailOnError(boolean b){
_failOnError=b;
*/
public void setFailOnError(boolean b) {
_failOnError = b;
}
}
/** query fail on error flag
/** query fail on error flag
*/
*/
public boolean getFailFailOnError() {
public boolean getFailFailOnError() {
return _failOnError;
return _failOnError;
}
}
/** debug flag. Controls generation of debug information.
/** debug flag. Controls generation of debug information.
*/
*/
protected boolean _debug;
protected boolean _debug;
/** set the debug flag on or off
/** set the debug flag on or off
* @param f on/off flag
* @param f on/off flag
*/
*/
public void setDebug(boolean f)
{_debug=f;}
public void setDebug(boolean f) {
_debug = f;
}
/** query the debug flag
/** query the debug flag
* @return true if debug is turned on
* @return true if debug is turned on
*/
*/
public boolean getDebug() {
public boolean getDebug() {
return _debug;
return _debug;
}
}
/** get the argument or null for no argument needed
/** get the argument or null for no argument needed
*/
*/
protected String getDebugParameter() {
protected String getDebugParameter() {
return _debug?"/debug":null;
return _debug?"/debug":null;
}
}
/** file containing private key
/** file containing private key
*/
*/
private File _keyfile;
private File _keyfile;
public void setKeyfile(File keyfile) {
public void setKeyfile(File keyfile) {
this._keyfile=keyfile;
this._keyfile = keyfile;
}
}
/** get the argument or null for no argument needed
/** get the argument or null for no argument needed
*/
*/
protected String getKeyfileParameter() {
protected String getKeyfileParameter() {
if(_keyfile!=null) {
return "/keyfile:"+_keyfile.toString();
if (_keyfile != null) {
return "/keyfile:" + _keyfile.toString();
} else {
} else {
return null;
return null;
}
}
}
}
/** any extra command options?
/** any extra command options?
*/
*/
protected String _extraOptions;
protected String _extraOptions;
/**
/**
* Sets the ExtraOptions attribute
* Sets the ExtraOptions attribute
*
*
* @param extraOptions The new ExtraOptions value
* @param extraOptions The new ExtraOptions value
*/
*/
public void setExtraOptions(String extraOptions)
{this._extraOptions=extraOptions;}
public void setExtraOptions(String extraOptions) {
this._extraOptions = extraOptions;
}
/**
/**
* Gets the ExtraOptions attribute
* Gets the ExtraOptions attribute
*
*
* @return The ExtraOptions value
* @return The ExtraOptions value
*/
*/
public String getExtraOptions()
{return this._extraOptions;}
public String getExtraOptions() {
return this._extraOptions;
}
/**
/**
* get any extra options or null for no argument needed
* get any extra options or null for no argument needed
*
*
* @return The ExtraOptions Parameter to CSC
* @return The ExtraOptions Parameter to CSC
*/
*/
protected String getExtraOptionsParameter() {
protected String getExtraOptionsParameter() {
if (_extraOptions!=null && _extraOptions.length()!=0) {
if (_extraOptions != null && _extraOptions.length() != 0) {
return _extraOptions;
return _extraOptions;
} else {
} else {
return null;
return null;
}
}
}
}
/** This is the execution entry point. Build a list of files and
/** This is the execution entry point. Build a list of files and
* call ilasm on each of them.
* call ilasm on each of them.
* @throws BuildException if the assembly failed and FailOnError is true
* @throws BuildException if the assembly failed and FailOnError is true
*/
*/
public void execute()
throws BuildException {
public void execute()
throws BuildException {
if (_srcDir == null) {
if (_srcDir == null) {
_srcDir=project.resolveFile(".");
_srcDir = project.resolveFile(".");
}
}
//get dependencies list.
//get dependencies list.
DirectoryScanner scanner = super.getDirectoryScanner(_srcDir);
DirectoryScanner scanner = super.getDirectoryScanner(_srcDir);
String[] dependencies = scanner.getIncludedFiles();
String[] dependencies = scanner.getIncludedFiles();
log("assembling "+dependencies.length+" file"+((dependencies.length==1)?"":"s"));
String baseDir=scanner.getBasedir().toString();
log("assembling " + dependencies.length + " file" + ((dependencies.length == 1)?"":"s"));
String baseDir = scanner.getBasedir().toString();
//add to the command
//add to the command
for (int i = 0; i < dependencies.length; i++) {
for (int i = 0; i < dependencies.length; i++) {
String targetFile=dependencies[i];
targetFile=baseDir+File.separator+targetFile;
String targetFile = dependencies[i];
targetFile = baseDir + File.separator + targetFile;
executeOneFile(targetFile);
executeOneFile(targetFile);
}
}
} // end execute
} // end execute
/**
/**
* do the work for one file by building the command line then calling it
* do the work for one file by building the command line then calling it
* @param targetFile name of the the file to assemble
* @param targetFile name of the the file to assemble
* @throws BuildException if the assembly failed and FailOnError is true
* @throws BuildException if the assembly failed and FailOnError is true
*/
*/
public void executeOneFile(String targetFile)
throws BuildException {
NetCommand command=new NetCommand(this,exe_title,exe_name);
public void executeOneFile(String targetFile)
throws BuildException {
NetCommand command = new NetCommand(this, exe_title, exe_name);
command.setFailOnError(getFailFailOnError());
command.setFailOnError(getFailFailOnError());
//DEBUG helper
//DEBUG helper
command.setTraceCommandLine(true);
command.setTraceCommandLine(true);
@@ -454,18 +455,18 @@ public class Ilasm
command.addArgument(getDebugParameter());
command.addArgument(getDebugParameter());
command.addArgument(getTargetTypeParameter());
command.addArgument(getTargetTypeParameter());
command.addArgument(getListingParameter());
command.addArgument(getListingParameter());
command.addArgument(getOutputFileParameter());
command.addArgument(getOutputFileParameter());
command.addArgument(getResourceFileParameter());
command.addArgument(getResourceFileParameter());
command.addArgument(getVerboseParameter());
command.addArgument(getVerboseParameter());
command.addArgument(getKeyfileParameter());
command.addArgument(getKeyfileParameter());
command.addArgument(getExtraOptionsParameter());
command.addArgument(getExtraOptionsParameter());
/* space for more argumentativeness
/* space for more argumentativeness
command.addArgument();
command.addArgument();
command.addArgument();
command.addArgument();
*/
*/
command.addArgument(targetFile);
command.addArgument(targetFile);
//now run the command of exe + settings + file
//now run the command of exe + settings + file
command.runCommand();
command.runCommand();