| Method from org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile Detail: |
abstract protected void addCompilerSpecificOptions(NetCommand command)
add any compiler specifics |
public void addDefine(DotnetDefine define) {
definitionList.addElement(define);
}
add a define to the list of definitions |
public void addReference(FileSet reference) {
referenceFilesets.add(reference);
}
add a new reference fileset to the compilation |
protected int addReferenceFilesets(NetCommand command,
long outputTimestamp) {
int filesOutOfDate = 0;
Hashtable filesToBuild = new Hashtable();
for (int i = 0; i < referenceFilesets.size(); i++) {
FileSet fs = (FileSet) referenceFilesets.elementAt(i);
filesOutOfDate += command.scanOneFileset(
fs.getDirectoryScanner(getProject()),
filesToBuild,
outputTimestamp);
}
//bail out early if there were no files
if (filesToBuild.size() == 0) {
return 0;
}
//now scan the hashtable and add the files
Enumeration files = filesToBuild.elements();
while (files.hasMoreElements()) {
File file = (File) files.nextElement();
if (isFileManagedBinary(file)) {
if (isWindows) {
command.addArgument(
'"" + REFERENCE_OPTION + file.toString() + '"");
} else {
command.addArgument(REFERENCE_OPTION + file.toString());
}
} else {
log("ignoring " + file + " as it is not a managed executable",
Project.MSG_VERBOSE);
}
}
return filesOutOfDate;
}
run through the list of reference files and add them to the command |
public void addResource(DotnetResource resource) {
resources.add(resource);
}
|
protected void addResources(NetCommand command) {
Enumeration e = resources.elements();
while (e.hasMoreElements()) {
DotnetResource resource = (DotnetResource) e.nextElement();
createResourceParameter(command, resource);
}
}
for every resource declared, we get the (language specific)
resource setting |
public void clear() {
targetType = null;
win32icon = null;
srcDir = null;
mainClass = null;
warnLevel = DEFAULT_WARN_LEVEL;
optimize = false;
debug = true;
references = null;
failOnError = true;
additionalModules = null;
includeDefaultReferences = true;
extraOptions = null;
}
|
protected NetCommand createNetCommand() {
NetCommand command = new NetCommand(this, getTaskName(), getExecutable());
return command;
}
create our helper command |
abstract protected void createResourceParameter(NetCommand command,
DotnetResource resource)
Build a C# style parameter. |
public void execute() throws BuildException {
log("This task is deprecated and will be removed in a future version\n"
+ "of Ant. It is now part of the .NET Antlib:\n"
+ "http://ant.apache.org/antlibs/dotnet/index.html",
Project.MSG_WARN);
validate();
NetCommand command = createNetCommand();
//set up response file options
command.setAutomaticResponseFileThreshold(AUTOMATIC_RESPONSE_FILE_THRESHOLD);
command.setUseResponseFile(useResponseFile);
//fill in args
fillInSharedParameters(command);
addResources(command);
addCompilerSpecificOptions(command);
int referencesOutOfDate
= addReferenceFilesets(command, getOutputFileTimestamp());
//if the refs are out of date, force a build.
boolean forceBuild = referencesOutOfDate > 0;
addFilesAndExecute(command, forceBuild);
}
do the work by building the command line and then calling it |
protected void fillInSharedParameters(NetCommand command) {
command.setFailOnError(getFailOnError());
//fill in args
command.addArgument("/nologo");
command.addArgument(getAdditionalModulesParameter());
command.addArgument(getDebugParameter());
command.addArgument(getDefinitionsParameter());
command.addArguments(getExtraOptionsParameters());
command.addArgument(getMainClassParameter());
command.addArgument(getOptimizeParameter());
command.addArgument(getDestFileParameter());
command.addArgument(getReferencesParameter());
command.addArgument(getTargetTypeParameter());
command.addArgument(getUtf8OutputParameter());
command.addArgument(getWin32IconParameter());
command.addArgument(getWin32ResParameter());
}
fill in the common information |
protected String getAdditionalModulesParameter() {
if (notEmpty(additionalModules)) {
return "/addmodule:" + additionalModules;
} else {
return null;
}
}
get the argument or null for no argument needed |
public boolean getDebug() {
return debug;
}
|
protected String getDebugParameter() {
return "/debug" + (debug ? "+" : "-");
}
get the debug switch argument |
public String getDefinitionsDelimiter() {
return ";";
}
override point for delimiting definitions. |
protected String getDefinitionsParameter() throws BuildException {
StringBuffer defines = new StringBuffer();
Enumeration defEnum = definitionList.elements();
boolean firstDefinition = true;
while (defEnum.hasMoreElements()) {
//loop through all definitions
DotnetDefine define = (DotnetDefine) defEnum.nextElement();
if (define.isSet(this)) {
//add those that are set, and a delimiter
if (!firstDefinition) {
defines.append(getDefinitionsDelimiter());
}
defines.append(define.getValue(this));
firstDefinition = false;
}
}
if (defines.length() == 0) {
return null;
} else {
return "/d:" + defines;
}
}
get a list of definitions or null |
protected String getDestFileParameter() {
if (outputFile != null) {
return "/out:" + outputFile.toString();
} else {
return null;
}
}
get the argument or null for no argument needed |
protected String getExecutable() {
return executable;
}
This method gets the name of the executable. |
public String getExtraOptions() {
return this.extraOptions;
}
Gets the ExtraOptions attribute |
protected String getExtraOptionsParameter() {
if (extraOptions != null && extraOptions.length() != 0) {
return extraOptions;
} else {
return null;
}
}
get any extra options or null for no argument needed |
protected String[] getExtraOptionsParameters() {
String extra = getExtraOptionsParameter();
return extra == null ? null : Commandline.translateCommandline(extra);
}
get any extra options or null for no argument needed, split
them if they represent multiple options. |
public boolean getFailOnError() {
return failOnError;
}
|
abstract public String getFileExtension()
Get the extension of filenames to compile. |
public String getFilePattern() {
return "**/*." + getFileExtension();
}
Get the pattern for files to compile. |
public boolean getIncludeDefaultReferences() {
return includeDefaultReferences;
}
query automatic reference inclusion flag |
protected String getIncludeDefaultReferencesParameter() {
return "/nostdlib" + (includeDefaultReferences ? "-" : "+");
}
get the include default references flag or null for no argument needed |
public String getMainClass() {
return this.mainClass;
}
Gets the MainClass attribute |
protected String getMainClassParameter() {
if (mainClass != null && mainClass.length() != 0) {
return "/main:" + mainClass;
} else {
return null;
}
}
get the /main argument or null for no argument needed |
public boolean getOptimize() {
return optimize;
}
|
protected String getOptimizeParameter() {
return "/optimize" + (optimize ? "+" : "-");
}
get the optimise flag or null for no argument needed |
abstract public String getReferenceDelimiter()
Get the delimiter that the compiler uses between references.
For example, c# will return ";"; VB.NET will return "," |
protected String getReferenceFilesParameter() {
//bail on no references
if (references == null) {
return null;
}
//iterate through the ref list & generate an entry for each
//or just rely on the fact that the toString operator does this, but
//noting that the separator is ';' on windows, ':' on unix
//bail on no references listed
if (references.length() == 0) {
return null;
}
StringBuffer s = new StringBuffer(REFERENCE_OPTION);
if (isWindows) {
s.append('\"");
}
s.append(references);
if (isWindows) {
s.append('\"");
}
return s.toString();
}
turn the path list into a list of files and a /references argument |
protected String getReferencesParameter() {
//bail on no references
if (notEmpty(references)) {
if (isWindows) {
return '\"" + REFERENCE_OPTION + references + '\"";
} else {
return REFERENCE_OPTION + references;
}
} else {
return null;
}
}
get the reference string or null for no argument needed |
public String getTargetType() {
return targetType;
}
Gets the TargetType attribute |
protected String getTargetTypeParameter() {
if (notEmpty(targetType)) {
return "/target:" + targetType;
} else {
return null;
}
}
get the argument or null for no argument needed |
protected String getUtf8OutputParameter() {
return utf8output ? "/utf8output" : null;
}
Gets the utf8OutpuParameter attribute of the CSharp object |
public int getWarnLevel() {
return warnLevel;
}
|
protected String getWarnLevelParameter() {
return "/warn:" + warnLevel;
}
get the warn level switch |
protected String getWin32IconParameter() {
if (win32icon != null) {
return "/win32icon:" + win32icon.toString();
} else {
return null;
}
}
get the argument or null for no argument needed |
public File getWin32Res() {
return win32res;
}
Gets the file of the win32 .res file to include. |
protected String getWin32ResParameter() {
if (win32res != null) {
return "/win32res:" + win32res.toString();
} else {
return null;
}
}
get the argument or null for no argument needed |
protected static boolean isFileManagedBinary(File file) {
String filename = file.toString().toLowerCase();
return filename.endsWith(".exe") || filename.endsWith(".dll")
|| filename.endsWith(".netmodule");
}
test for a file being managed or not |
public boolean isUseResponseFile() {
return useResponseFile;
}
|
protected boolean notEmpty(String s) {
return s != null && s.length() != 0;
}
test for a string containing something useful |
public void setAdditionalModules(String params) {
additionalModules = params;
}
Semicolon separated list of modules to refer to. |
public void setDebug(boolean f) {
debug = f;
}
set the debug flag on or off. |
public void setDestDir(File dirName) {
log("DestDir currently unused", Project.MSG_WARN);
}
Set the destination directory of files to be compiled. |
public void setExecutable(String executable) {
this.executable = executable;
}
set the name of the program, overriding the defaults.
Can be used to set the full path to a program, or to switch
to an alternate implementation of the command, such as the Mono or Rotor
versions -provided they use the same command line arguments as the
.NET framework edition |
public void setExtraOptions(String extraOptions) {
this.extraOptions = extraOptions;
}
Any extra options which are not explicitly supported
by this task. |
public void setFailOnError(boolean b) {
failOnError = b;
}
If true, fail on compilation errors. |
public void setIncludeDefaultReferences(boolean f) {
includeDefaultReferences = f;
}
If true, automatically includes the common assemblies
in dotnet, and tells the compiler to link in mscore.dll.
set the automatic reference inclusion flag on or off this flag controls
the /nostdlib option in CSC |
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
Sets the name of main class for executables. |
public void setOptimize(boolean f) {
optimize = f;
}
If true, enables optimization flag. |
public void setReferenceFiles(Path path) {
//demand create pathlist
if (referenceFiles == null) {
referenceFiles = new Path(this.getProject());
}
referenceFiles.append(path);
}
Path of references to include.
Wildcards should work. |
public void setReferences(String s) {
references = s;
}
Semicolon separated list of DLLs to refer to. |
public void setTargetType(DotnetCompile.TargetTypes targetType) {
this.targetType = targetType.getValue();
}
set the target type to one of exe|library|module|winexe |
public void setTargetType(String ttype) throws BuildException {
ttype = ttype.toLowerCase();
if (ttype.equals("exe") || ttype.equals("library")
|| ttype.equals("module") || ttype.equals("winexe")) {
targetType = ttype;
} else {
throw new BuildException("targetType " + ttype
+ " is not one of 'exe', 'module', 'winexe' or 'library'");
}
}
|
public void setUseResponseFile(boolean useResponseFile) {
this.useResponseFile = useResponseFile;
}
Flag to turn on response file use; default=false.
When set the command params are saved to a file and
this is passed in with @file. The task automatically switches
to this mode with big commands; this option is here for
testing and emergencies |
public void setUtf8Output(boolean enabled) {
utf8output = enabled;
}
If true, require all compiler output to be in UTF8 format. |
public void setWarnLevel(int warnLevel) {
this.warnLevel = warnLevel;
}
Level of warning currently between 1 and 4
with 4 being the strictest. |
public void setWin32Icon(File fileName) {
win32icon = fileName;
}
Set the filename of icon to include. |
public void setWin32Res(File fileName) {
win32res = fileName;
}
Sets the filename of a win32 resource (.RES) file to include.
This is not a .NET resource, but what Windows is used to. |
protected void validate() throws BuildException {
if (outputFile != null && outputFile.isDirectory()) {
throw new BuildException("destFile cannot be a directory");
}
if (getExecutable() == null) {
throw new BuildException("There is no executable defined for this task");
}
}
|