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

Class DotnetCompile

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 classDotnetCompile.TargetTypes
Target types to build. valid build types are exe|library|module|winexe
Field Summary
protected StringadditionalModules
list of extra modules to refer to
protected booleandebug
debug flag.
protected VectordefinitionList
a list of definitions to support;
protected Stringexecutable
executable
protected StringextraOptions
any extra command options?
protected StringmainClass
main class (or null for automatic choice)
protected VectorreferenceFilesets
filesets of references
protected Vectorresources
our resources
protected static StringREFERENCE_OPTION
protected StringtargetType
type of target.
protected booleanutf8output
utf out flag
Constructor Summary
DotnetCompile()
constructor inits everything and set up the search pattern
Method Summary
protected abstract voidaddCompilerSpecificOptions(NetCommand command)
add any compiler specifics
voidaddDefine(DotnetDefine define)
add a define to the list of definitions
voidaddReference(FileSet reference)
add a new reference fileset to the compilation
protected intaddReferenceFilesets(NetCommand command, long outputTimestamp)
run through the list of reference files and add them to the command
voidaddResource(DotnetResource resource)
link or embed a resource
protected voidaddResources(NetCommand command)
for every resource declared, we get the (language specific) resource setting
voidclear()
reset all contents.
protected NetCommandcreateNetCommand()
create our helper command
protected abstract StringcreateResourceParameter(DotnetResource resource)
from a resource, get the
voidexecute()
do the work by building the command line and then calling it
protected voidfillInSharedParameters(NetCommand command)
fill in the common information
protected StringgetAdditionalModulesParameter()
get the argument or null for no argument needed
booleangetDebug()
query the debug flag
protected StringgetDebugParameter()
get the debug switch argument
StringgetDefinitionsDelimiter()
override point for delimiting definitions.
protected StringgetDefinitionsParameter()
get a list of definitions or null
protected StringgetDestFileParameter()
get the argument or null for no argument needed
protected StringgetExecutable()
This method gets the name of the executable.
StringgetExtraOptions()
Gets the ExtraOptions attribute
protected StringgetExtraOptionsParameter()
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.
booleangetFailOnError()
query fail on error flag
abstract StringgetFileExtension()
Get the extension of filenames to compile.
StringgetFilePattern()
Get the pattern for files to compile.
booleangetIncludeDefaultReferences()
query automatic reference inclusion flag
protected StringgetIncludeDefaultReferencesParameter()
get the include default references flag or null for no argument needed
StringgetMainClass()
Gets the MainClass attribute
protected StringgetMainClassParameter()
get the /main argument or null for no argument needed
booleangetOptimize()
query the optimise flag
protected StringgetOptimizeParameter()
get the optimise flag or null for no argument needed
abstract StringgetReferenceDelimiter()
Get the delimiter that the compiler uses between references.
protected StringgetReferenceFilesParameter()
turn the path list into a list of files and a /references argument
protected StringgetReferencesParameter()
get the reference string or null for no argument needed
StringgetTargetType()
Gets the TargetType attribute
protected StringgetTargetTypeParameter()
get the argument or null for no argument needed
protected StringgetUtf8OutputParameter()
Gets the utf8OutpuParameter attribute of the CSharp object
intgetWarnLevel()
query warn level
protected StringgetWarnLevelParameter()
get the warn level switch
protected StringgetWin32IconParameter()
get the argument or null for no argument needed
FilegetWin32Res()
Gets the file of the win32 .res file to include.
protected StringgetWin32ResParameter()
get the argument or null for no argument needed
protected static booleanisFileManagedBinary(File file)
test for a file being managed or not
booleanisUseResponseFile()
getter for flag
protected booleannotEmpty(String s)
test for a string containing something useful
voidsetAdditionalModules(String params)
Semicolon separated list of modules to refer to.
voidsetDebug(boolean f)
set the debug flag on or off.
voidsetDestDir(File dirName)
Set the destination directory of files to be compiled.
voidsetExecutable(String executable)
set the name of the program, overriding the defaults.
voidsetExtraOptions(String extraOptions)
Any extra options which are not explicitly supported by this task.
voidsetFailOnError(boolean b)
If true, fail on compilation errors.
voidsetIncludeDefaultReferences(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
voidsetMainClass(String mainClass)
Sets the name of main class for executables.
voidsetOptimize(boolean f)
If true, enables optimization flag.
voidsetReferenceFiles(Path path)
Path of references to include.
voidsetReferences(String s)
Semicolon separated list of DLLs to refer to.
voidsetTargetType(DotnetCompile.TargetTypes targetType)
set the target type to one of exe|library|module|winexe
voidsetTargetType(String ttype)
Set the type of target.
voidsetUseResponseFile(boolean useResponseFile)
Flag to turn on response file use; default=false.
voidsetUtf8Output(boolean enabled)
If true, require all compiler output to be in UTF8 format.
voidsetWarnLevel(int warnLevel)
Level of warning currently between 1 and 4 with 4 being the strictest.
voidsetWin32Icon(File fileName)
Set the filename of icon to include.
voidsetWin32Res(File fileName)
Sets the filename of a win32 resource (.RES) file to include.
protected voidvalidate()
validation code

Field Detail

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

REFERENCE_OPTION

protected static final String REFERENCE_OPTION

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 Detail

DotnetCompile

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

Method Detail

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()
do the work by building the command line and then calling it

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()
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

UNKNOWN: 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(DotnetCompile.TargetTypes targetType)
set the target type to one of exe|library|module|winexe

Parameters: targetType

setTargetType

public void setTargetType(String ttype)
Set the type of target.

Parameters: ttype The new TargetType value

Throws: BuildException if target is not one of exe|library|module|winexe

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()
validation code

Throws: BuildException if validation failed

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