org.apache.tools.ant.taskdefs.optional.dotnet

Class DotnetCompile

Implemented Interfaces:
SelectorContainer
Known Direct Subclasses:
CSharp, JSharp, VisualBasicCompile

public abstract class DotnetCompile
extends DotnetBaseMatchingTask

Abstract superclass for dotnet compiler tasks. History
0.1 First creation Most of the code here was copied verbatim from v0.3 of Steve Loughran's CSharp optional task. Abstracted functionality to allow subclassing of other dotnet compiler types.
Version:
0.1

Nested Class Summary

static class
DotnetCompile.TargetTypes
Target types to build.

Field Summary

protected static String
REFERENCE_OPTION
protected String
additionalModules
list of extra modules to refer to
protected boolean
debug
debug flag.
protected Vector
definitionList
a list of definitions to support;
protected String
executable
executable
protected String
extraOptions
any extra command options?
protected String
mainClass
main class (or null for automatic choice)
protected Vector
referenceFilesets
filesets of references
protected Vector
resources
our resources
protected String
targetType
type of target.
protected boolean
utf8output
utf out flag

Fields inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask

filesets, outputFile, srcDir

Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask

fileset

Fields inherited from class org.apache.tools.ant.Task

description, location, target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

project

Constructor Summary

DotnetCompile()
constructor inits everything and set up the search pattern

Method Summary

protected abstract void
addCompilerSpecificOptions(NetCommand command)
add any compiler specifics
void
addDefine(DotnetDefine define)
add a define to the list of definitions
void
addReference(FileSet reference)
add a new reference fileset to the compilation
protected int
addReferenceFilesets(NetCommand command, long outputTimestamp)
run through the list of reference files and add them to the command
void
addResource(DotnetResource resource)
link or embed a resource
protected void
addResources(NetCommand command)
for every resource declared, we get the (language specific) resource setting
void
clear()
reset all contents.
protected NetCommand
createNetCommand()
create our helper command
protected abstract String
createResourceParameter(DotnetResource resource)
from a resource, get the
void
execute()
do the work by building the command line and then calling it
protected void
fillInSharedParameters(NetCommand command)
fill in the common information
protected String
getAdditionalModulesParameter()
get the argument or null for no argument needed
boolean
getDebug()
query the debug flag
protected String
getDebugParameter()
get the debug switch argument
String
getDefinitionsDelimiter()
override point for delimiting definitions.
protected String
getDefinitionsParameter()
get a list of definitions or null
protected String
getDestFileParameter()
get the argument or null for no argument needed
protected String
getExecutable()
This method gets the name of the executable.
String
getExtraOptions()
Gets the ExtraOptions attribute
protected String
getExtraOptionsParameter()
get any extra options or null for no argument needed
protected String[]
getExtraOptionsParameters()
get any extra options or null for no argument needed, split them if they represent multiple options.
boolean
getFailOnError()
query fail on error flag
abstract String
getFileExtension()
Get the extension of filenames to compile.
String
getFilePattern()
Get the pattern for files to compile.
boolean
getIncludeDefaultReferences()
query automatic reference inclusion flag
protected String
getIncludeDefaultReferencesParameter()
get the include default references flag or null for no argument needed
String
getMainClass()
Gets the MainClass attribute
protected String
getMainClassParameter()
get the /main argument or null for no argument needed
boolean
getOptimize()
query the optimise flag
protected String
getOptimizeParameter()
get the optimise flag or null for no argument needed
abstract String
getReferenceDelimiter()
Get the delimiter that the compiler uses between references.
protected String
getReferenceFilesParameter()
turn the path list into a list of files and a /references argument
protected String
getReferencesParameter()
get the reference string or null for no argument needed
String
getTargetType()
Gets the TargetType attribute
protected String
getTargetTypeParameter()
get the argument or null for no argument needed
protected String
getUtf8OutputParameter()
Gets the utf8OutpuParameter attribute of the CSharp object
int
getWarnLevel()
query warn level
protected String
getWarnLevelParameter()
get the warn level switch
protected String
getWin32IconParameter()
get the argument or null for no argument needed
File
getWin32Res()
Gets the file of the win32 .res file to include.
protected String
getWin32ResParameter()
get the argument or null for no argument needed
protected static boolean
isFileManagedBinary(File file)
test for a file being managed or not
boolean
isUseResponseFile()
getter for flag
protected boolean
notEmpty(String s)
test for a string containing something useful
void
setAdditionalModules(String params)
Semicolon separated list of modules to refer to.
void
setDebug(boolean f)
set the debug flag on or off.
void
setDestDir(File dirName)
Set the destination directory of files to be compiled.
void
setExecutable(String executable)
set the name of the program, overriding the defaults.
void
setExtraOptions(String extraOptions)
Any extra options which are not explicitly supported by this task.
void
setFailOnError(boolean b)
If true, fail on compilation errors.
void
setIncludeDefaultReferences(boolean f)
If true, automatically includes the common assemblies in dotnet, and tells the compiler to link in mscore.dll.
void
setMainClass(String mainClass)
Sets the name of main class for executables.
void
setOptimize(boolean f)
If true, enables optimization flag.
void
setReferenceFiles(Path path)
Path of references to include.
void
setReferences(String s)
Semicolon separated list of DLLs to refer to.
void
setTargetType(String ttype)
Set the type of target.
void
setTargetType(DotnetCompile.TargetTypes targetType)
set the target type to one of exe|library|module|winexe
void
setUseResponseFile(boolean useResponseFile)
Flag to turn on response file use; default=false.
void
setUtf8Output(boolean enabled)
If true, require all compiler output to be in UTF8 format.
void
setWarnLevel(int warnLevel)
Level of warning currently between 1 and 4 with 4 being the strictest.
void
setWin32Icon(File fileName)
Set the filename of icon to include.
void
setWin32Res(File fileName)
Sets the filename of a win32 resource (.RES) file to include.
protected void
validate()
validation code

Methods inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask

addFilesAndExecute, addFilesToCommand, addSrc, buildFileList, getDestFile, getOutputFileTimestamp, getSrcDir, setDestFile, setSrcDir

Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask

XsetIgnore, XsetItems, add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject

Methods inherited from class org.apache.tools.ant.Task

execute, getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

getProject, log, log, setProject

Field Details

REFERENCE_OPTION

protected static final String REFERENCE_OPTION

additionalModules

protected String additionalModules
list of extra modules to refer to

debug

protected boolean debug
debug flag. Controls generation of debug information.

definitionList

protected Vector definitionList
a list of definitions to support;

executable

protected String executable
executable

extraOptions

protected String extraOptions
any extra command options?

mainClass

protected String mainClass
main class (or null for automatic choice)

referenceFilesets

protected Vector referenceFilesets
filesets of references

resources

protected Vector resources
our resources

targetType

protected String targetType
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.
See /target

utf8output

protected boolean utf8output
utf out flag

Constructor Details

DotnetCompile

public DotnetCompile()
constructor inits everything and set up the search pattern

Method Details

addCompilerSpecificOptions

protected abstract void addCompilerSpecificOptions(NetCommand command)
add any compiler specifics
Parameters:
command -

addDefine

public void addDefine(DotnetDefine define)
add a define to the list of definitions
Parameters:
define -

addReference

public void addReference(FileSet reference)
add a new reference fileset to the compilation
Parameters:
reference -

addReferenceFilesets

protected int addReferenceFilesets(NetCommand command,
                                   long outputTimestamp)
run through the list of reference files and add them to the command
Parameters:
outputTimestamp - timestamp to compare against
Returns:
number of files out of date

addResource

public void addResource(DotnetResource resource)
link or embed a resource
Parameters:
resource -

addResources

protected void addResources(NetCommand command)
for every resource declared, we get the (language specific) resource setting

clear

public void clear()
reset all contents.

createNetCommand

protected NetCommand createNetCommand()
create our helper command
Returns:
a command prefilled with the exe name and task name

createResourceParameter

protected abstract String createResourceParameter(DotnetResource resource)
from a resource, get the
Parameters:
resource -
Returns:
a string containing the resource param, or a null string to conditionally exclude a resource.

execute

public void execute()
            throws BuildException
do the work by building the command line and then calling it
Overrides:
execute in interface Task
Throws:
BuildException - if validation or execution failed

fillInSharedParameters

protected void fillInSharedParameters(NetCommand command)
fill in the common information
Parameters:
command -

getAdditionalModulesParameter

protected String getAdditionalModulesParameter()
get the argument or null for no argument needed
Returns:
The AdditionalModules Parameter to CSC

getDebug

public boolean getDebug()
query the debug flag
Returns:
true if debug is turned on

getDebugParameter

protected String getDebugParameter()
get the debug switch argument
Returns:
The Debug Parameter to CSC

getDefinitionsDelimiter

public String getDefinitionsDelimiter()
override point for delimiting definitions.
Returns:
The definitions limiter, i.e., ";"

getDefinitionsParameter

protected String getDefinitionsParameter()
            throws BuildException
get a list of definitions or null
Returns:
a string beginning /D: or null for no definitions

getDestFileParameter

protected String getDestFileParameter()
get the argument or null for no argument needed
Returns:
The OutputFile Parameter to CSC

getExecutable

protected String getExecutable()
This method gets the name of the executable.
Returns:
the name of the executable

getExtraOptions

public String getExtraOptions()
Gets the ExtraOptions attribute
Returns:
The ExtraOptions value

getExtraOptionsParameter

protected String getExtraOptionsParameter()
get any extra options or null for no argument needed
Returns:
The ExtraOptions Parameter to CSC

getExtraOptionsParameters

protected String[] getExtraOptionsParameters()
get any extra options or null for no argument needed, split them if they represent multiple options.
Returns:
The ExtraOptions Parameter to CSC

getFailOnError

public boolean getFailOnError()
query fail on error flag
Returns:
The FailFailOnError value

getFileExtension

public abstract String getFileExtension()
Get the extension of filenames to compile.
Returns:
The string extension of files to compile.

getFilePattern

public String getFilePattern()
Get the pattern for files to compile.
Returns:
The compilation file pattern.

getIncludeDefaultReferences

public boolean getIncludeDefaultReferences()
query automatic reference inclusion flag
Returns:
true if flag is turned on

getIncludeDefaultReferencesParameter

protected String getIncludeDefaultReferencesParameter()
get the include default references flag or null for no argument needed
Returns:
The Parameter to CSC

getMainClass

public String getMainClass()
Gets the MainClass attribute
Returns:
The MainClass value

getMainClassParameter

protected String getMainClassParameter()
get the /main argument or null for no argument needed
Returns:
The MainClass Parameter to CSC

getOptimize

public boolean getOptimize()
query the optimise flag
Returns:
true if optimise is turned on

getOptimizeParameter

protected String getOptimizeParameter()
get the optimise flag or null for no argument needed
Returns:
The Optimize Parameter to CSC

getReferenceDelimiter

public abstract String getReferenceDelimiter()
Get the delimiter that the compiler uses between references. For example, c# will return ";"; VB.NET will return ","
Returns:
The string delimiter for the reference string.

getReferenceFilesParameter

protected String getReferenceFilesParameter()
turn the path list into a list of files and a /references argument
Returns:
null or a string of references.

getReferencesParameter

protected String getReferencesParameter()
get the reference string or null for no argument needed
Returns:
The References Parameter to CSC

getTargetType

public String getTargetType()
Gets the TargetType attribute
Returns:
The TargetType value

getTargetTypeParameter

protected String getTargetTypeParameter()
get the argument or null for no argument needed
Returns:
The TargetType Parameter to CSC

getUtf8OutputParameter

protected String getUtf8OutputParameter()
Gets the utf8OutpuParameter attribute of the CSharp object
Returns:
The utf8OutpuParameter value

getWarnLevel

public int getWarnLevel()
query warn level
Returns:
current value

getWarnLevelParameter

protected String getWarnLevelParameter()
get the warn level switch
Returns:
The WarnLevel Parameter to CSC

getWin32IconParameter

protected String getWin32IconParameter()
get the argument or null for no argument needed
Returns:
The Win32Icon Parameter to CSC

getWin32Res

public File getWin32Res()
Gets the file of the win32 .res file to include.
Returns:
path to the file.

getWin32ResParameter

protected String getWin32ResParameter()
get the argument or null for no argument needed
Returns:
The Win32Res Parameter to CSC

isFileManagedBinary

protected static boolean isFileManagedBinary(File file)
test for a file being managed or not
Returns:
true if we think this is a managed executable, and thus OK for linking
To do:
look at the PE header of the exe and see if it is managed or not.

isUseResponseFile

public boolean isUseResponseFile()
getter for flag
Returns:
The flag indicating whether the compilation is using a response file.

notEmpty

protected boolean notEmpty(String s)
test for a string containing something useful
Parameters:
s - string in
Returns:
true if the argument is not null or empty

setAdditionalModules

public void setAdditionalModules(String params)
Semicolon separated list of modules to refer to.
Parameters:
params - The new additionalModules value

setDebug

public void setDebug(boolean f)
set the debug flag on or off.
Parameters:
f - on/off flag

setDestDir

public void setDestDir(File dirName)
Set the destination directory of files to be compiled.
Parameters:
dirName - The new DestDir value

setExecutable

public void setExecutable(String 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
Parameters:
executable -

setExtraOptions

public void setExtraOptions(String extraOptions)
Any extra options which are not explicitly supported by this task.
Parameters:
extraOptions - The new ExtraOptions value

setFailOnError

public void setFailOnError(boolean b)
If true, fail on compilation errors.
Parameters:
b - The new FailOnError value

setIncludeDefaultReferences

public void setIncludeDefaultReferences(boolean 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
Parameters:
f - on/off flag

setMainClass

public void setMainClass(String mainClass)
Sets the name of main class for executables.
Parameters:
mainClass - The new MainClass value

setOptimize

public void setOptimize(boolean f)
If true, enables optimization flag.
Parameters:
f - on/off flag

setReferenceFiles

public void setReferenceFiles(Path path)
Path of references to include. Wildcards should work.
Parameters:
path - another path to append

setReferences

public void setReferences(String s)
Semicolon separated list of DLLs to refer to.
Parameters:
s - The new References value

setTargetType

public void setTargetType(String ttype)
            throws BuildException
Set the type of target.
Parameters:
ttype - The new TargetType value
Throws:
BuildException - if target is not one of exe|library|module|winexe

setTargetType

public void setTargetType(DotnetCompile.TargetTypes targetType)
set the target type to one of exe|library|module|winexe
Parameters:
targetType -

setUseResponseFile

public void setUseResponseFile(boolean 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
Parameters:
useResponseFile -

setUtf8Output

public void setUtf8Output(boolean enabled)
If true, require all compiler output to be in UTF8 format.
Parameters:
enabled - The new utf8Output value

setWarnLevel

public void setWarnLevel(int warnLevel)
Level of warning currently between 1 and 4 with 4 being the strictest.
Parameters:
warnLevel - warn level -see .net docs for valid range (probably 0-4)

setWin32Icon

public void setWin32Icon(File fileName)
Set the filename of icon to include.
Parameters:
fileName - path to the file. Can be relative, absolute, whatever.

setWin32Res

public void setWin32Res(File fileName)
Sets the filename of a win32 resource (.RES) file to include. This is not a .NET resource, but what Windows is used to.
Parameters:
fileName - path to the file. Can be relative, absolute, whatever.

validate

protected void validate()
            throws BuildException
validation code
Throws:
BuildException - if validation failed

Copyright B) 2000-2006 Apache Software Foundation. All Rights Reserved.