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

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.MatchingTask
              extended by org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask
                  extended by org.apache.tools.ant.taskdefs.optional.dotnet.DotnetCompile
All Implemented Interfaces:
java.lang.Cloneable, SelectorContainer
Direct Known 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  java.lang.String additionalModules
          list of extra modules to refer to
protected  boolean debug
          debug flag.
protected  java.util.Vector definitionList
          a list of definitions to support;
protected  java.lang.String executable
          executable
protected  java.lang.String extraOptions
          any extra command options?
protected  java.lang.String mainClass
          main class (or null for automatic choice)
protected static java.lang.String REFERENCE_OPTION
           
protected  java.util.Vector referenceFilesets
          filesets of references
protected  java.util.Vector resources
          our resources
protected  java.lang.String targetType
          type of target.
protected  boolean utf8output
          utf out flag
 
Fields inherited from class org.apache.tools.ant.taskdefs.optional.dotnet.DotnetBaseMatchingTask
filesets, isWindows, outputFile, srcDir
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, 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  void createResourceParameter(NetCommand command, DotnetResource resource)
          Build a C# style parameter.
 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  java.lang.String getAdditionalModulesParameter()
          get the argument or null for no argument needed
 boolean getDebug()
          query the debug flag
protected  java.lang.String getDebugParameter()
          get the debug switch argument
 java.lang.String getDefinitionsDelimiter()
          override point for delimiting definitions.
protected  java.lang.String getDefinitionsParameter()
          get a list of definitions or null
protected  java.lang.String getDestFileParameter()
          get the argument or null for no argument needed
protected  java.lang.String getExecutable()
          This method gets the name of the executable.
 java.lang.String getExtraOptions()
          Gets the ExtraOptions attribute
protected  java.lang.String getExtraOptionsParameter()
          get any extra options or null for no argument needed
protected  java.lang.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  java.lang.String getFileExtension()
          Get the extension of filenames to compile.
 java.lang.String getFilePattern()
          Get the pattern for files to compile.
 boolean getIncludeDefaultReferences()
          query automatic reference inclusion flag
protected  java.lang.String getIncludeDefaultReferencesParameter()
          get the include default references flag or null for no argument needed
 java.lang.String getMainClass()
          Gets the MainClass attribute
protected  java.lang.String getMainClassParameter()
          get the /main argument or null for no argument needed
 boolean getOptimize()
          query the optimise flag
protected  java.lang.String getOptimizeParameter()
          get the optimise flag or null for no argument needed
abstract  java.lang.String getReferenceDelimiter()
          Get the delimiter that the compiler uses between references.
protected  java.lang.String getReferenceFilesParameter()
          turn the path list into a list of files and a /references argument
protected  java.lang.String getReferencesParameter()
          get the reference string or null for no argument needed
 java.lang.String getTargetType()
          Gets the TargetType attribute
protected  java.lang.String getTargetTypeParameter()
          get the argument or null for no argument needed
protected  java.lang.String getUtf8OutputParameter()
          Gets the utf8OutpuParameter attribute of the CSharp object
 int getWarnLevel()
          query warn level
protected  java.lang.String getWarnLevelParameter()
          get the warn level switch
protected  java.lang.String getWin32IconParameter()
          get the argument or null for no argument needed
 java.io.File getWin32Res()
          Gets the file of the win32 .res file to include.
protected  java.lang.String getWin32ResParameter()
          get the argument or null for no argument needed
protected static boolean isFileManagedBinary(java.io.File file)
          test for a file being managed or not
 boolean isUseResponseFile()
          getter for flag
protected  boolean notEmpty(java.lang.String s)
          test for a string containing something useful
 void setAdditionalModules(java.lang.String params)
          Semicolon separated list of modules to refer to.
 void setDebug(boolean f)
          set the debug flag on or off.
 void setDestDir(java.io.File dirName)
          Set the destination directory of files to be compiled.
 void setExecutable(java.lang.String executable)
          set the name of the program, overriding the defaults.
 void setExtraOptions(java.lang.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(java.lang.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(java.lang.String s)
          Semicolon separated list of DLLs to refer to.
 void setTargetType(DotnetCompile.TargetTypes targetType)
          set the target type to one of exe|library|module|winexe
 void setTargetType(java.lang.String ttype)
          Set the type of target.
 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(java.io.File fileName)
          Set the filename of icon to include.
 void setWin32Res(java.io.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
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, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

definitionList

protected java.util.Vector definitionList
a list of definitions to support;


resources

protected java.util.Vector resources
our resources


executable

protected java.lang.String executable
executable


REFERENCE_OPTION

protected static final java.lang.String REFERENCE_OPTION
See Also:
Constant Field Values

debug

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


mainClass

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


extraOptions

protected java.lang.String extraOptions
any extra command options?


targetType

protected java.lang.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


additionalModules

protected java.lang.String additionalModules
list of extra modules to refer to


referenceFilesets

protected java.util.Vector referenceFilesets
filesets of references

Constructor Detail

DotnetCompile

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

Method Detail

clear

public void clear()
reset all contents.


setReferences

public void setReferences(java.lang.String s)
Semicolon separated list of DLLs to refer to.

Parameters:
s - The new References value

getReferencesParameter

protected java.lang.String getReferencesParameter()
get the reference string or null for no argument needed

Returns:
The References Parameter to CSC

setReferenceFiles

public void setReferenceFiles(Path path)
Path of references to include. Wildcards should work.

Parameters:
path - another path to append

addReference

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

Parameters:
reference - the files to use.

getReferenceFilesParameter

protected java.lang.String getReferenceFilesParameter()
turn the path list into a list of files and a /references argument

Returns:
null or a string of references.

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

getIncludeDefaultReferences

public boolean getIncludeDefaultReferences()
query automatic reference inclusion flag

Returns:
true if flag is turned on

getIncludeDefaultReferencesParameter

protected java.lang.String getIncludeDefaultReferencesParameter()
get the include default references flag or null for no argument needed

Returns:
The Parameter to CSC

setOptimize

public void setOptimize(boolean f)
If true, enables optimization flag.

Parameters:
f - on/off flag

getOptimize

public boolean getOptimize()
query the optimise flag

Returns:
true if optimise is turned on

getOptimizeParameter

protected java.lang.String getOptimizeParameter()
get the optimise flag or null for no argument needed

Returns:
The Optimize Parameter to CSC

setDebug

public void setDebug(boolean f)
set the debug flag on or off.

Parameters:
f - on/off flag

getDebug

public boolean getDebug()
query the debug flag

Returns:
true if debug is turned on

getDebugParameter

protected java.lang.String getDebugParameter()
get the debug switch argument

Returns:
The Debug Parameter to CSC

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)

getWarnLevel

public int getWarnLevel()
query warn level

Returns:
current value

getWarnLevelParameter

protected java.lang.String getWarnLevelParameter()
get the warn level switch

Returns:
The WarnLevel Parameter to CSC

setMainClass

public void setMainClass(java.lang.String mainClass)
Sets the name of main class for executables.

Parameters:
mainClass - The new MainClass value

getMainClass

public java.lang.String getMainClass()
Gets the MainClass attribute

Returns:
The MainClass value

getMainClassParameter

protected java.lang.String getMainClassParameter()
get the /main argument or null for no argument needed

Returns:
The MainClass Parameter to CSC

setExtraOptions

public void setExtraOptions(java.lang.String extraOptions)
Any extra options which are not explicitly supported by this task.

Parameters:
extraOptions - The new ExtraOptions value

getExtraOptions

public java.lang.String getExtraOptions()
Gets the ExtraOptions attribute

Returns:
The ExtraOptions value

getExtraOptionsParameter

protected java.lang.String getExtraOptionsParameter()
get any extra options or null for no argument needed

Returns:
The ExtraOptions Parameter to CSC

getExtraOptionsParameters

protected java.lang.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

setDestDir

public void setDestDir(java.io.File dirName)
Set the destination directory of files to be compiled.

Parameters:
dirName - The new DestDir value

setTargetType

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

Parameters:
targetType - the enumerated value.

setTargetType

public void setTargetType(java.lang.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

getTargetType

public java.lang.String getTargetType()
Gets the TargetType attribute

Returns:
The TargetType value

getTargetTypeParameter

protected java.lang.String getTargetTypeParameter()
get the argument or null for no argument needed

Returns:
The TargetType Parameter to CSC

setWin32Icon

public void setWin32Icon(java.io.File fileName)
Set the filename of icon to include.

Parameters:
fileName - path to the file. Can be relative, absolute, whatever.

getWin32IconParameter

protected java.lang.String getWin32IconParameter()
get the argument or null for no argument needed

Returns:
The Win32Icon Parameter to CSC

setWin32Res

public void setWin32Res(java.io.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.

getWin32Res

public java.io.File getWin32Res()
Gets the file of the win32 .res file to include.

Returns:
path to the file.

getWin32ResParameter

protected java.lang.String getWin32ResParameter()
get the argument or null for no argument needed

Returns:
The Win32Res Parameter to CSC

setUtf8Output

public void setUtf8Output(boolean enabled)
If true, require all compiler output to be in UTF8 format.

Parameters:
enabled - The new utf8Output value

getUtf8OutputParameter

protected java.lang.String getUtf8OutputParameter()
Gets the utf8OutpuParameter attribute of the CSharp object

Returns:
The utf8OutpuParameter value

addDefine

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

Parameters:
define - the define value.

getDefinitionsParameter

protected java.lang.String getDefinitionsParameter()
                                            throws BuildException
get a list of definitions or null

Returns:
a string beginning /D: or null for no definitions
Throws:
BuildException - if there is an error.

setAdditionalModules

public void setAdditionalModules(java.lang.String params)
Semicolon separated list of modules to refer to.

Parameters:
params - The new additionalModules value

getAdditionalModulesParameter

protected java.lang.String getAdditionalModulesParameter()
get the argument or null for no argument needed

Returns:
The AdditionalModules Parameter to CSC

getDestFileParameter

protected java.lang.String getDestFileParameter()
get the argument or null for no argument needed

Returns:
The OutputFile Parameter to CSC

setFailOnError

public void setFailOnError(boolean b)
If true, fail on compilation errors.

Parameters:
b - The new FailOnError value

getFailOnError

public boolean getFailOnError()
query fail on error flag

Returns:
The FailFailOnError value

addResource

public void addResource(DotnetResource resource)
link or embed a resource

Parameters:
resource - the resource to use.

getExecutable

protected java.lang.String getExecutable()
This method gets the name of the executable.

Returns:
the name of the executable

setExecutable

public void setExecutable(java.lang.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 - the name of the program.

notEmpty

protected boolean notEmpty(java.lang.String s)
test for a string containing something useful

Parameters:
s - string in
Returns:
true if the argument is not null or empty

validate

protected void validate()
                 throws BuildException
validation code

Throws:
BuildException - if validation failed

getFilePattern

public java.lang.String getFilePattern()
Get the pattern for files to compile.

Returns:
The compilation file pattern.

isUseResponseFile

public boolean isUseResponseFile()
getter for flag

Returns:
The flag indicating whether the compilation is using a response file.

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 - a boolean value.

execute

public void execute()
             throws BuildException
do the work by building the command line and then calling it

Overrides:
execute in class Task
Throws:
BuildException - if validation or execution failed

getReferenceDelimiter

public abstract java.lang.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.

getFileExtension

public abstract java.lang.String getFileExtension()
Get the extension of filenames to compile.

Returns:
The string extension of files to compile.

fillInSharedParameters

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

Parameters:
command - the net command.

addResources

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

Parameters:
command - the net command.

createResourceParameter

protected abstract void createResourceParameter(NetCommand command,
                                                DotnetResource resource)
Build a C# style parameter.

Parameters:
command - the command.
resource - the resource.

addReferenceFilesets

protected int addReferenceFilesets(NetCommand command,
                                   long outputTimestamp)
run through the list of reference files and add them to the command

Parameters:
command - the command to use.
outputTimestamp - timestamp to compare against
Returns:
number of files out of date

createNetCommand

protected NetCommand createNetCommand()
create our helper command

Returns:
a command prefilled with the exe name and task name

addCompilerSpecificOptions

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

Parameters:
command - the command to use.

getDefinitionsDelimiter

public java.lang.String getDefinitionsDelimiter()
override point for delimiting definitions.

Returns:
The definitions limiter, i.e., ";"

isFileManagedBinary

protected static boolean isFileManagedBinary(java.io.File file)
test for a file being managed or not

Parameters:
file - the file to test.
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.