From c1080f1b8a8469dc79a8f5f86b287544b0ad0b6b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 28 Nov 2000 13:35:48 +0000 Subject: [PATCH] Update of the .NET tasks. Submitted by: Steve Loughran git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268253 13f79535-47bb-0310-9956-ffa450edef68 --- docs/dotnet.html | 385 ++++++++- .../ant/taskdefs/optional/dotnet/CSharp.java | 750 +++++++++--------- .../ant/taskdefs/optional/dotnet/Ilasm.java | 397 +++++---- .../taskdefs/optional/dotnet/NetCommand.java | 99 +-- 4 files changed, 994 insertions(+), 637 deletions(-) diff --git a/docs/dotnet.html b/docs/dotnet.html index e1a887fdd..b81bfa136 100644 --- a/docs/dotnet.html +++ b/docs/dotnet.html @@ -1,12 +1,13 @@ - .Net classes for Ant +<title> .NET classes for Ant - -

.Net classes for Ant

+ +

dotnet classes for Ant

- -Vision: make ant the definative build tool for .net projects, just +

Steve Loughran; steve_l@iseran.com

+

Vision

+Make ant the definative build tool for .NET projects, just as it is becoming for java projects

@@ -44,9 +45,9 @@ removed from the build.xml files

  • ilasm - IL assembler - *.il ->.exe or .dll
  • ResX - ResXToResources.exe .resx -> .resources
  • al - assembly linker (.dll) -> -
  • Signcode - .exe + keys -> .exe' +
  • Signcode - .exe + keys -> .exe
  • Resgen - .properties -> .resources -
  • Type Library Exporter (TlbExp.exe- .dll -> .tlb +
  • Type Library Exporter (TlbExp.exe) .dll -> .tlb
  • TlbImp.exe Type Library Importer
  • RegAsm.exe Assembly Registration Tool .dll -> .reg | registration
  • WebServiceUtil -SOAP proxy import, SDL generation tool @@ -68,8 +69,9 @@ to be simple.
      -
    1. code up C sharp task and distribute for feedback & identify possible +
    2. code up C sharp task and distribute for feedback & identify possible aid +
    3. Use for a real end to end development task
    4. Add the next task I need (whatever that is)
    5. Refactor to produce a base class for .net tasks
    6. Leave it other people write all the other tasks @@ -88,15 +90,12 @@ and behaviours. Probability: 100%. Impact: 2 days.

      Using Ant in .net projects

      -

      -Setup

      - To use the net tasks one needs
        -
      • A win2K box (or any other platform which supports the .net build tools) +
      • A Win2K box (or any other platform which supports the .net build tools) -
      • JavaVM - Java1.1 or later +
      • JavaVM - Java1.1 or later; Java1.3 recommended.
      • Ant downloaded and the environment and path variables set up so that typing 'ant' invokes ant via a batch file. @@ -112,15 +111,363 @@ version parser.jar and jaxp.jar.
      • A build.xml file to describe the build process
      -An example build.xml file is included in the test directory. +
      +

      Change Log

      + +

      Version 0.3

      + +The changes here reflect Beta-1 of the dotnet SDK and experience of use in +more complex projects. This build does not work with the older SDK, +primarily because the automatic reference feature references libraries +only found in the new SDK version. +

      +External changes +

        +
      • Recursive inclusion of .cs and .il files + +
      • Documentation enhanced, includes examples and details of all parameters + +
      • The csc task automatically includes the common dotnet assemblies, so +there is no need to remember to refer to 'System.dll', 'System.Web.Services', + etc. This feature can be disabled by setting the 'includeDefaultReferences' + flag to false. + +
      • References can also be referred to using the ReferenceFiles parameter, which +is an ant path specification. The old 'references' string is still retained. +< +li> An 'extraoptions' attribute enables the build file to include any CSC options +which are not explicitly supported in the CSC task. +
      +Internal changes +
        +
      • Some minor refactoring (move common code a method) +
      • Application of Jedits JavaStyle task resulted in a major reshaping of +the codebase and the insertion of a blank line every second line. Significant +effort was required to revert some (but not all) changes. +
      • Removed throws clause from methods which can't throw exceptions +
      + +The test harness has been expanded to include unicode source file +(the build works but the rest of the system has 'issues' with high unicode +package and method names) + +

      Version 0.2

      +First public edition, added to the ant cvs tree. Tested on the PDC build of +the dotnet SDK only, and still immature. The command execution code was +refactored out into a 'NetCommand' class for re-use. The Ilasm task was added +at this time. + +

      Version 0.1

      +Initial proof of concept; very rudimentary support for CSC only. + +

      Task: CSC

      This task compiles CSharp source into executables or modules. -Consult the javadoc file for parameter details. -

      Task: ilasm

      -Task to assemble .il files. -Consult the javadoc file for parameter details. + +This task compiles CSharp source into executables or modules. +The task will only work on win2K until other platforms support csc.exe or +an equivalent. CSC.exe must be on the execute path too. + +

      +All parameters are optional: <csc/> should suffice to produce a debug +build of all *.cs files. References to external files do require explicit +enumeration, so are one of the first attributes to consider adding. + +

      + +The task is a directory based task, so attributes like includes="**/*.cs" and +excludes="broken.cs" can be used to control the files pulled in. By default, +all *.cs files from the project folder down are included in the command. +When this happens the output file -if not specified- +is taken as the first file in the list, which may be somewhat hard to control. +Specifying the output file with 'outfile' seems prudent. + +

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributeDescriptionExample Values
      additionalModules + Semicolon separated list of modules to refer to +
      defaultexcludesindicates whether default excludes should be used or not + "true"(default) or "false" +
      definitions + defined constants + "RELEASE;BETA1" +
      debug + include debug information + "true"(default) or "false" +
      docFile + name of file for documentation + "doc.xml" +
      excludescomma separated list of patterns of files that must be + excluded. No files (except default excludes) are excluded when omitted.
      excludesfilethe name of a file. Each line of this file is + taken to be an exclude pattern
      extraOptionsAny extra options which aren't explicitly + supported by the CSharp task "/warnaserror+ /baseaddress:0x12840000" +
      failOnError + Should a failed compile halt the build? + "true"(default) or "false" +
      includescomma separated list of patterns of files that must be + included. All files are included when omitted.
      includeDefaultReferencesFlag which when true automatically includes + the common assemblies in dotnet beta1, and tells the compiler to link in + mscore.dll + "true"(default) or "false" +
      includesfilethe name of a file. Each line of this file is + taken to be an include pattern
      incremental + Incremental build flag. Avoid till it works + "true" or "false"(default) +
      mainClass + name of main class for executables + "com.example.project.entrypoint" +
      optimize + optimisation flag + "true" or "false"(default) +
      outputFile + filename of output + "example.exe" +
      references + Semicolon separated list of dlls to refer to + "mylib.dll;nunit.dll"
      referenceFiles Ant Path descriptioon of references to include. + Wildcards should work. +
      srcDir + source directory (default = project directory) + "."
      targetType + Type of target + "exe","module","winexe" or "library" +
      unsafe + enable unsafe code + "true" or "false"(default) +
      warnLevel + level of warning currently between 1 and 4 with 4 + being the strictest. + "1"-"4" +
      win32Icon + filename of icon to include + "res/myicon.ico"
      +

      +Example +

      <csc
      +        optimize="true"
      +        debug="false"
      +        docFile="documentation.xml"
      +        warnLevel="4"
      +        unsafe="false"
      +        targetType="exe"
      +        incremental="false"
      +        definitions="RELEASE"
      +        excludes="src/unicode_class.cs"
      +        mainClass = "MainApp"
      +        outputFile="NetApp.exe"
      +        />   
      +
      +
      +

      Task: ilasm

      +Task to assemble .net 'Intermediate Language' files. +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. +

      + +

      +All parameters are optional: <il/> should suffice to produce a debug +build of all *.il files. +The option set is roughly compatible with the CSharp class; +even though the command line options are only vaguely +equivalent. [The low level commands take things like /OUT=file, +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 +tools consistent (and not as brittle as the java cmdline tools) + + +

      + +The task is a directory based task, so attributes like includes="*.il" and +excludes="broken.il" can be used to control the files pulled in. +Each file is built on its own, producing an appropriately named output file unless +manually specified with outfile + +

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      AttributeDescriptionExample
      defaultexcludesindicates whether default excludes should be used or not + ("yes"/"no"). Default excludes are used when omitted.
      debug + include debug information + true (default) +
      excludescomma separated list of patterns of files that must be + excluded. No files (except default excludes) are excluded when omitted.
      excludesfilethe name of a file. Each line of this file is + taken to be an exclude pattern
      extraOptionsAny extra options which aren't explicitly + supported by the ilasm task +
      failOnError + Should a failed compile halt the build? + "true"(default) +
      includescomma separated list of patterns of files that must be + included. All files are included when omitted.
      includesfilethe name of a file. Each line of this file is + taken to be an include pattern
      listing + Produce a listing (off by default). Listings go to the + current output stream + "on", "off" (default) +
      outputFile + filename of output + "example.exe" +
      owner + restrict disassembly by setting the 'owner' string + "secret" +
      resourceFile + name of resource file to include + "resources.res" +
      srcDir + source directory (default = project directory) + +
      targetType + Type of target. library means DLL is output. + "exe"(default),"library" +
      verbose + output progress messages + "on", "off" (default) +
      +

      +Example +

      <ilasm
      +        outputFile="app.exe"
      +        verbose="on"
      +        listing="on"
      +        owner="secret"
      +        />
      +
      +
      +

      Copyright © 2000 Apache Software Foundation. All rights +Reserved.

      - \ No newline at end of file + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java index a7ca03d75..e243fb650 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java @@ -67,11 +67,11 @@ /* build notes --The reference CD to listen to while editing this file is -nap: Underworld - Everything, Everything --variable naming policy from Fowler's refactoring book. --tested against the PDC pre-beta of csc.exe; future versions will -inevitably change things + -The reference CD to listen to while editing this file is + nap: Underworld - Everything, Everything + -variable naming policy from Fowler's refactoring book. + -tested against the PDC pre-beta of csc.exe; future versions will + inevitably change things */ // ==================================================================== @@ -85,12 +85,10 @@ package org.apache.tools.ant.taskdefs.optional.dotnet; // imports // ==================================================================== -import java.io.*; -import java.text.*; -import java.util.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; +import java.io.*; // ==================================================================== @@ -115,474 +113,507 @@ Specifying the output file with 'outfile' seems prudent.

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      AttributeDescriptionExample
      additionalModules - Semicolon separated list of modules to refer to -
      defaultexcludesindicates whether default excludes should be used or not - ("yes"/"no"). Default excludes are used when omitted.
      definitions - defined constants - "RELEASE;BETA1" -
      debug - include debug information - "true" or "false" -
      docFile - name of file for documentation - "doc.xml" -
      excludescomma separated list of patterns of files that must be - excluded. No files (except default excludes) are excluded when omitted.
      excludesfilethe name of a file. Each line of this file is - taken to be an exclude pattern
      failOnError - Should a failed compile halt the build? - "true" or "false" -
      includescomma separated list of patterns of files that must be - included. All files are included when omitted.
      includesfilethe name of a file. Each line of this file is - taken to be an include pattern
      incremental - Incremental build flag. Off by default - "false" -
      mainClass - name of main class for executables - com.example.project.entrypoint -
      optimize - optimisation flag - "true" or "false" -
      outputFile - filename of output - "example.exe" -
      references - Semicolon separated list of dlls to refer to -
      srcDir - source directory (default = project directory) - -
      targetType - Type of target - "exe","module","winexe","library" -
      unsafe - enable unsafe code - "true" or "false" -
      warnLevel - level of warning - 1-4 -
      win32Icon - filename of icon to include - -
      - - -

      -The first pass is just a proof of concept; enough to test.

      TODO

        -
      1. get PATH incorporated into reference/module lookup +
      2. is incremental build still broken in beta-1?
      3. is Win32Icon broken?
      4. all the missing options

      History - - - - - - - +
      0.2 Slightly different Split command execution to a separate class; -
      0.1 "I can't believe it's so rudimentary" First pass; minimal builds only support; -
      + + + + + + + + -
      0.3 Beta 1 edition To avoid having to remember which assemblies to include, + the task automatically refers to the main dotnet libraries in Beta1. + +
      0.2 Slightly different Split command execution to a separate class; +
      0.1 "I can't believe it's so rudimentary" First pass; minimal builds only support; +
      -@version 0.2 + +@version 0.3 @author Steve Loughran steve_l@iseran.com */ -// ==================================================================== public class CSharp extends org.apache.tools.ant.taskdefs.MatchingTask { - //============================================================================= /** constructor inits everything and set up the search pattern - */ - + */ + public CSharp () { Clear(); setIncludes(csc_file_pattern); } - - - //----------------------------------------------------------------------------- + /** name of the executable. the .exe suffix is deliberately not included * in anticipation of the unix version */ protected static final String csc_exe_name="csc"; - + /** what is the file extension we search on? */ protected static final String csc_file_ext="cs"; - - /** and now derive the search pattern from the extension + + /** derive the search pattern from the extension */ - protected static final String csc_file_pattern="*."+csc_file_ext; - - - //============================================================================= + protected static final String csc_file_pattern="**/*."+csc_file_ext; + /** list of reference classes. (pretty much a classpath equivalent) */ - protected String _references; - + /** - * Set the reference list to be used for this compilation. + * Set the reference list to be used for this compilation. + * + * @param s The new References value */ - public void setReferences(String s) { _references=s; } - - /** get the argument or null for no argument needed + + /** + * get the reference string or null for no argument needed + * + * @return The References Parameter to CSC */ protected String getReferencesParameter() { //bail on no references - if (_references==null ||_references.length()==0) + if (notEmpty(_references)) + return "/reference:"+_references; + else + return null; + } + + /** + using the path approach didnt work as it could not handle the implicit + execution path. Perhaps that could be extracted from the runtime and then + the path approach would be viable + */ + protected Path _referenceFiles; + + /** + * add another path to the reference file path list + * @param path another path to append + */ + public void setReferenceFiles(Path path) { + //demand create pathlist + if(_referenceFiles==null) + _referenceFiles=new Path(this.project); + _referenceFiles.append(path); + } + + /** + turn the path list into a list of files and a /references argument + @return null or a string of references. + */ + 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 + String refpath=_references.toString(); + + //bail on no references listed + if (refpath.length()==0) return null; + + StringBuffer s=new StringBuffer("/reference:"); + s.append(refpath); + return new String(s); + } + + /** + * C# is really dumb in how it handles inclusion. You have to list + * every 'assembly' -read DLL that is imported. So already you are + * making a platform assumption -shared libraries have a .dll extension + * and the poor developer has to know every library which is included + * why the compiler cant find classes on the path or in a directory, + * is a mystery. + * + * To reduce the need to be explicit, here is a long list of + * the core libraries used in Beta-1 of .NET + * ommitting the blatantly non portable (MS.win32.interop) + * and the .designer libraries. (ripping out Com was tempting) + * Casing is chosen to match that of the file system exactly + * so may work on a unix box too. + */ + protected static final String DEFAULT_REFERENCE_LIST + ="System.dll;System.Drawing.dll;System.Data.dll;"+ + "System.Diagnostics.dll;"+ + "System.DirectoryServices.dll;"+ + "System.IO.dll;"+ + "System.Management.dll;"+ + "System.Messaging.dll;"+ + "System.Net.dll;"+ + "System.Runtime.Remoting.dll;"+ + "System.Runtime.Serialization.Formatters.Soap.dll;"+ + "System.Security.dll;"+ + "System.ServiceProcess.dll;"+ + "System.Text.RegularExpressions.dll;"+ + "System.Timers.dll;"+ + "System.Web.dll;"+ + "System.Web.Services.dll;"+ + "System.WinForms.dll;"+ + "System.XML.dll;"+ + "System.XML.Serialization.dll;"+ + "Microsoft.ComServices.dll;"; + + /** + * get default reference list + * @return null or a string of references. + */ + protected String getDefaultReferenceParameter() { + if(_includeDefaultReferences) { + StringBuffer s=new StringBuffer("/reference:"); + s.append(DEFAULT_REFERENCE_LIST); + return new String(s); + } else - return "/reference:"+_references; + return null; } - - - /* using the path approach didnt work as it could not handle the implicit - execution path. Perhaps that could be extracted from the runtime and then - the path approach would be viable - - - protected Path _references; - - public void setReferences(Path s) { - //demand create pathlist - if(_references==null) - _references=new Path(this.project); - _references.append(s); - } - - protected String getReferencesParameter() - { - //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 - String refpath=_references.toString(); + + /** flag to enable automatic reference inclusion + * + */ + protected boolean _includeDefaultReferences; - //bail on no references listed - if (refpath.length()==0) - return null; - - StringBuffer s=new StringBuffer("/reference:"); - s.append(refpath); - return new String(s); - } + /** set the automatic reference inclusion flag on or off + * this flag controls the string of references and the + * /nostdlib option in CSC + @param f on/off flag */ - - //============================================================================= - /* optimise flag + public void setIncludeDefaultReferences(boolean f) { + _includeDefaultReferences=f; + } + + /** query the optimise flag + @return true if optimise is turned on + */ + public boolean getIncludeDefaultReferences() { + return _includeDefaultReferences; + } + + /** + * get the include default references flag or null for no argument needed + * + * @return The Parameter to CSC + */ + protected String getIncludeDefaultReferencesParameter() { + return "/nostdlib"+(_includeDefaultReferences?"-":"+"); + } + + /** optimise flag */ - protected boolean _optimize; - + /** set the optimise flag on or off - @param on/off flag + @param f on/off flag */ public void setOptimize(boolean f) { _optimize=f; } - + /** query the optimise flag - @return true if optimise is turned on - */ + @return true if optimise is turned on + */ public boolean getOptimize() { return _optimize; } - - /** get the argument or null for no argument needed + + /** + * get the optimise flag or null for no argument needed + * + * @return The Optimize Parameter to CSC */ protected String getOptimizeParameter() { return "/optimize"+(_optimize?"+":"-"); - } + } - //============================================================================= /** incremental build flag */ protected boolean _incremental; - + /** set the incremental compilation flag on or off - *@param on/off flag + * @param f on/off flag */ public void setIncremental(boolean f){ _incremental=f; } - + /** query the incrementalflag * @return true iff incremental compilation is turned on */ public boolean getIncremental() { return _incremental; } - - /** get the argument or null for no argument needed + + /** + * get the incremental build argument + * + * @return The Incremental Parameter to CSC */ protected String getIncrementalParameter() { return "/incremental"+(_incremental?"+":"-"); - } - - //============================================================================= + } + /** debug flag. Controls generation of debug information. */ - protected boolean _debug; - + /** set the debug flag on or off - * @param 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 * @return true if debug is turned on */ - public boolean getDebug() { return _debug; } - - /** get the argument or null for no argument needed + + /** + * get the debug switch argument + * + * @return The Debug Parameter to CSC */ protected String getDebugParameter() { return "/debug"+(_debug?"+":"-"); - } - - - //============================================================================= + } + /** output XML documentation flag - */ - + */ protected File _docFile; /** file for generated XML documentation - * @param output file + * @param f output file */ - public void setDocFile(String f) { _docFile=project.resolveFile(f); } - - - + /** get the argument or null for no argument needed + * @return The DocFile Parameter to CSC */ protected String getDocFileParameter() { if (_docFile!=null) return "/doc:"+_docFile.toString(); else return null; - } + } - //============================================================================= /** warning level: 0-4, with 4 being most verbose - */ + */ private int _warnLevel; - + /** set warn level (no range checking) - * @param warn level -see .net docs for valid range (probably 0-4) - */ + * @param warnLevel warn level -see .net docs for valid range (probably 0-4) + */ public void setWarnLevel(int warnLevel) - {this._warnLevel=warnLevel;} - + {this._warnLevel=warnLevel;} + /** query warn level * @return current value - */ + */ public int getWarnLevel() - {return _warnLevel;} - - /** get the argument or null for no argument needed + {return _warnLevel;} + + /** + * get the warn level switch + * + * @return The WarnLevel Parameter to CSC */ protected String getWarnLevelParameter() { return "/warn:"+_warnLevel; - } - - //============================================================================= + } + /** enable unsafe code flag. Clearly set to false by default */ - protected boolean _unsafe; - + + /** + * Sets the Unsafe attribute + * + * @param unsafe The new Unsafe value + */ public void setUnsafe(boolean unsafe) - {this._unsafe=unsafe;} - + {this._unsafe=unsafe;} + + /** + * query the Unsafe attribute + * + * @return The Unsafe value + */ public boolean getUnsafe() - {return this._unsafe;} - + {return this._unsafe;} + /** get the argument or null for no argument needed - */ + * @return The Unsafe Parameter to CSC + */ protected String getUnsafeParameter(){ return _unsafe?"/unsafe":null; - } + } - //============================================================================= /** main class (or null for automatic choice) */ protected String _mainClass; - + + /** + * Sets the MainClass attribute + * + * @param mainClass The new MainClass value + */ public void setMainClass(String mainClass) - {this._mainClass=mainClass;} - + {this._mainClass=mainClass;} + + /** + * Gets the MainClass attribute + * + * @return The MainClass value + */ public String getMainClass() - {return this._mainClass;} - - /** get the argument or null for no argument needed + {return this._mainClass;} + + /** + * get the /main argument or null for no argument needed + * + * @return The MainClass Parameter to CSC */ protected String getMainClassParameter(){ if (_mainClass!=null && _mainClass.length()!=0) return "/main:"+_mainClass; else return null; - } - - //============================================================================= + } + + /** any extra command options? + */ + protected String _extraOptions; + + /** + * Sets the ExtraOptions attribute + * + * @param extraOptions The new ExtraOptions value + */ + public void setExtraOptions(String extraOptions) + {this._extraOptions=extraOptions;} + + /** + * Gets the ExtraOptions attribute + * + * @return The ExtraOptions value + */ + public String getExtraOptions() + {return this._extraOptions;} + + /** + * get any extra options or null for no argument needed + * + * @return The ExtraOptions Parameter to CSC + */ + protected String getExtraOptionsParameter() { + if (_extraOptions!=null && _extraOptions.length()!=0) + return _extraOptions; + else + return null; + } + /** source directory upon which the search pattern is applied */ private File _srcDir; - + /** * Set the source dir to find the files to be compiled + * @param srcDirName The new SrcDir value */ public void setSrcDir(String srcDirName){ _srcDir = project.resolveFile(srcDirName); } - - //============================================================================= + /** destination directory (null means use the source directory) - */ + * NB: this is currently not used + */ private File _destDir; - + /** - * Set the source dir to find the files to be compiled + * Set the destination dir to find the files to be compiled + * @param dirName The new DestDir value */ public void setDestDir(String dirName) { _destDir = project.resolveFile(dirName); } - - - //============================================================================= + /** 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 - */ + default is exe; the actual value (if not null) is fed to the command line. +
      See /target + */ protected String _targetType; - + /** define the target - * param target. - * @throws BuildException if target is not one of exe|library|module|winexe + * @param targetType The new TargetType value + * @exception BuildException if target is not one of exe|library|module|winexe */ - public void setTargetType(String targetType) throws BuildException { targetType=targetType.toLowerCase(); if(targetType.equals("exe") || targetType.equals("library") || - targetType.equals("module") ||targetType.equals("winexe") ) { - _targetType=targetType; + targetType.equals("module") ||targetType.equals("winexe") ) { + _targetType=targetType; } else throw new BuildException("targetType " +targetType+" is not a valid type"); } - + + /** + * Gets the TargetType attribute + * + * @return The TargetType value + */ public String getTargetType() { - return _targetType; - } - - /** get the argument or null for no argument needed + return _targetType; + } + + /** + * get the argument or null for no argument needed + * + * @return The TargetType Parameter to CSC */ protected String getTargetTypeParameter() { - if (_targetType!=null) + if (notEmpty(_targetType)) return "/target:"+_targetType; else return null; - } - - - //============================================================================= - /* icon for incorporation into apps - */ - - protected File _win32icon; - + } + + /** icon for incorporation into apps + */ + protected File _win32icon; + /** * Set the win32 icon - * @param path to the file. Can be relative, absolute, whatever. + * @param fileName path to the file. Can be relative, absolute, whatever. */ public void setWin32Icon(String fileName) { _win32icon = project.resolveFile(fileName); } - - /** get the argument or null for no argument needed + + /** + * get the argument or null for no argument needed + * + * @return The Win32Icon Parameter to CSC */ protected String getWin32IconParameter() { if (_win32icon!=null) @@ -590,14 +621,12 @@ public class CSharp else return null; } - - //============================================================================= - /** defines list 'RELEASE;WIN32;NO_SANITY_CHECKS;;SOMETHING_ELSE' - * - */ - + + /** defines list + * something like 'RELEASE;WIN32;NO_SANITY_CHECKS;;SOMETHING_ELSE' + */ String _definitions; - + /** * Set the definitions * @param list of definitions split by ; or , or even : @@ -605,22 +634,24 @@ public class CSharp public void setDefinitions(String params) { _definitions=params; } - - /** get the argument or null for no argument needed - */ + + /** + * get the argument or null for no argument needed + * + * @return The Definitions Parameter to CSC + */ protected String getDefinitionsParameter() { - if (_definitions==null || _definitions.length()==0) + if (notEmpty(_definitions)) + return "/define:" + _definitions; + else return null; - else return "/DEFINE:"+_definitions; } - - //============================================================================= + /** list of extra modules to refer to * - */ - + */ String _additionalModules; - + /** * Set the definitions * @param list of definitions split by ; or , or even : @@ -628,22 +659,22 @@ public class CSharp public void setAdditionalModules(String params) { _additionalModules=params; } - + /** get the argument or null for no argument needed + * @return The AdditionalModules Parameter to CSC */ protected String getAdditionalModulesParameter() { - if (_additionalModules==null || _additionalModules.length()==0) + if (notEmpty(_additionalModules)) + return "/addmodule:" + _additionalModules; + else return null; - else return "/addmodule:"+_additionalModules; } - - //============================================================================= + /** output file. If not supplied this is derived from the * source file - */ - + */ protected String _outputFile; - + /** * Set the definitions * @param list of definitions split by ; or , or even : @@ -651,37 +682,39 @@ public class CSharp public void setOutputFile(String params) { _outputFile=params; } - + /** get the argument or null for no argument needed - */ + * @return The OutputFile Parameter to CSC + */ protected String getOutputFileParameter() { - if (_outputFile==null || _outputFile.length()==0) + if (notEmpty(_outputFile)) { + File f=project.resolveFile(_outputFile); + return "/out:"+f.toString(); + } + else return null; - File f=project.resolveFile(_outputFile); - return "/out:"+f.toString(); } - - //============================================================================= + /** flag to control action on execution trouble - */ - + */ protected boolean _failOnError; - + /**set fail on error flag - */ + * @param b The new FailOnError value + */ public void setFailOnError(boolean b){ _failOnError=b; } - + /** query fail on error flag - */ + * @return The FailFailOnError value + */ public boolean getFailFailOnError() { - return _failOnError; + return _failOnError; } - - //============================================================================= + /** reset all contents. - */ + */ public void Clear() { _targetType=null; _win32icon=null; @@ -698,18 +731,27 @@ public class CSharp _failOnError=true; _definitions=null; _additionalModules=null; + _includeDefaultReferences=true; + _extraOptions=null; } - - - //============================================================================= - /** do the work by building the command line and then calling it + + /** + * test for a string containing something useful + * + * @param s string in + * @return true if the argument is not null or empty */ - + protected boolean notEmpty(String s) { + return s != null && s.length() != 0; + } + + /** do the work by building the command line and then calling it + */ public void execute() throws BuildException { if (_srcDir == null) _srcDir=project.resolveFile("."); - + NetCommand command=new NetCommand(this,"CSC",csc_exe_name); command.setFailOnError(getFailFailOnError()); //DEBUG helper @@ -729,12 +771,10 @@ public class CSharp command.addArgument(getWarnLevelParameter()); command.addArgument(getWin32IconParameter()); command.addArgument(getOutputFileParameter()); - /* space for more argumentativeness - command.addArgument(); - command.addArgument(); - */ - - + command.addArgument(getIncludeDefaultReferencesParameter()); + command.addArgument(getDefaultReferenceParameter()); + command.addArgument(getExtraOptionsParameter()); + //get dependencies list. DirectoryScanner scanner = super.getDirectoryScanner(_srcDir); String[] dependencies = scanner.getIncludedFiles(); @@ -746,11 +786,9 @@ public class CSharp targetFile=baseDir+File.separator+targetFile; command.addArgument(targetFile); } - + //now run the command of exe + settings + files command.runCommand(); } // end execute - - - + } //end class diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java index 5ebdb628d..55caee8d8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java @@ -67,11 +67,11 @@ /* build notes --The reference CD to listen to while editing this file is -nap: Underworld - Everything, Everything --variable naming policy from Fowler's refactoring book. --tested against the PDC pre-beta of csc.exe; future versions will -inevitably change things + -The reference CD to listen to while editing this file is + nap: Underworld - Everything, Everything + -variable naming policy from Fowler's refactoring book. + -tested against the PDC pre-beta of csc.exe; future versions will + inevitably change things */ // ==================================================================== @@ -93,157 +93,64 @@ import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; /** - Task to assemble .net 'Intermediate Language' files. - 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. -

      +Task to assemble .net 'Intermediate Language' files. +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. +

      -

      - All parameters are optional: <il/> should suffice to produce a debug - build of all *.il files. - The option set is roughly compatible with the CSharp class; - even though the command line options are only vaguely - equivalent. [The low level commands take things like /OUT=file, - 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 - tools consistent (and not as brittle as the java cmdline tools) +

      +All parameters are optional: <il/> should suffice to produce a debug +build of all *.il files. +The option set is roughly compatible with the CSharp class; +even though the command line options are only vaguely +equivalent. [The low level commands take things like /OUT=file, +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 +tools consistent (and not as brittle as the java cmdline tools) -

      - - The task is a directory based task, so attributes like includes="*.il" and - excludes="broken.il" can be used to control the files pulled in. - Each file is built on its own, producing an appropriately named output file unless - manually specified with outfile - -

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      AttributeDescriptionExample
      defaultexcludesindicates whether default excludes should be used or not - ("yes"/"no"). Default excludes are used when omitted.
      debug - include debug information - true (default) -
      excludescomma separated list of patterns of files that must be - excluded. No files (except default excludes) are excluded when omitted.
      excludesfilethe name of a file. Each line of this file is - taken to be an exclude pattern
      failOnError - Should a failed compile halt the build? - true(default) -
      includescomma separated list of patterns of files that must be - included. All files are included when omitted.
      includesfilethe name of a file. Each line of this file is - taken to be an include pattern
      listing - Produce a listing (off by default) - off (default) -
      outputFile - filename of output - "example.exe" -
      owner - restrict disassembly by setting the 'owner' string - "secret" -
      resourceFile - name of resource file to include - "resources.res" -
      srcDir - source directory (default = project directory) - -
      targetType - Type of target. library means DLL is output. - "exe","library" -
      verbose - output progress messages - off (default) -
      +

      +The task is a directory based task, so attributes like includes="*.il" and +excludes="broken.il" can be used to control the files pulled in. +Each file is built on its own, producing an appropriately named output file unless +manually specified with outfile +@author Steve Loughran steve_l@iseran.com +@version 0.2 + */ - @author Steve Loughran steve_l@iseran.com - @version 0.1 -*/ -// ==================================================================== public class Ilasm extends org.apache.tools.ant.taskdefs.MatchingTask { - //============================================================================= /** constructor inits everything and set up the search pattern - */ - + */ public Ilasm () { Clear(); setIncludes(file_pattern); } - - //----------------------------------------------------------------------------- /** name of the executable. the .exe suffix is deliberately not included * in anticipation of the unix version */ protected static final String exe_name="ilasm"; - + /** what is the file extension we search on? */ protected static final String file_ext="il"; - + /** and now derive the search pattern from the extension */ - protected static final String file_pattern="*."+file_ext; - + protected static final String file_pattern="**/*."+file_ext; + /** title of task for external presentation */ protected static final String exe_title="ilasm"; - - //============================================================================= + /** reset all contents. - */ + */ public void Clear() { _targetType=null; _srcDir=null; @@ -255,49 +162,56 @@ public class Ilasm _failOnError=true; _resourceFile=null; _owner=null; + _extraOptions=null; } - //============================================================================= /** source directory upon which the search pattern is applied */ private File _srcDir; - + /** * Set the source dir to find the files to be compiled + * @param srcDirName The new SrcDir value */ public void setSrcDir(String srcDirName){ _srcDir = project.resolveFile(srcDirName); } + - - //============================================================================= /** 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 - */ + default is exe; the actual value (if not null) is fed to the command line. +
      See /target + */ protected String _targetType; - + /** define the target - * param target. - * @throws BuildException if target is not one of exe|library|module|winexe + * @param targetType one of exe|library| + * @exception BuildException if target is not one of exe|library|module|winexe */ - + public void setTargetType(String targetType) throws BuildException { targetType=targetType.toLowerCase(); if(targetType.equals("exe") || targetType.equals("library")) { - _targetType=targetType; + _targetType=targetType; } else throw new BuildException("targetType " +targetType+" is not a valid type"); } + /** + * accessor method for target type + * @return the current target option + */ public String getTargetType() { return _targetType; - } - - /** get the argument or null for no argument needed - */ + } + + /** g + * get the target type or null for no argument needed + * + * @return The TargetTypeParameter value + */ protected String getTargetTypeParameter() { if(!notEmpty(_targetType)) @@ -305,72 +219,96 @@ public class Ilasm if (_targetType.equals("exe")) return "/exe"; else - if (_targetType.equals("library")) - return "/dll"; - else - return null; - } + if (_targetType.equals("library")) + return "/dll"; + else + return null; + } - //============================================================================= /** owner string is a slightly trivial barrier to disassembly - */ - + */ + protected String _owner; - + + /** + * Sets the Owner attribute + * + * @param s The new Owner value + */ + public void setOwner(String s) { _owner=s; - } + } + /** + * Gets the Owner switch for ilasm + * + * @return The Owner string + */ protected String getOwnerParameter() { if(notEmpty(_owner)) return "/owner="+_owner; else return null; } - - //============================================================================= + /** test for a string containing something useful * @param string to test * @returns true if the argument is not null or empty - */ + */ protected boolean notEmpty(String s) - {return s!=null && s.length()!=0;} - - //============================================================================= + {return s!=null && s.length()!=0;} + /** verbose flag */ - protected boolean _verbose; + /** + * enable/disable verbose ILASM output + * @param b flag set to true for verbose on + */ public void setVerbose(boolean b) { _verbose=b; } - + + /** + * turn the verbose flag into a parameter for ILASM + * @return null or the appropriate command line string + */ protected String getVerboseParameter() { return _verbose?null:"/quiet"; } - - //============================================================================= + + /** listing flag */ - + protected boolean _listing; + /** + * enable/disable listing + * @param b flag set to true for listing on + */ public void setListing(boolean b) { _listing=b; } - + + /** + * turn the listing flag into a parameter for ILASM + * @return the appropriate string from the state of the listing flag + */ protected String getListingParameter() { 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 */ - + protected String _outputFile; - + /** * Set the definitions * @param list of definitions split by ; or , or even : @@ -378,89 +316,119 @@ public class Ilasm public void setOutputFile(String params) { _outputFile=params; } - - /** get the argument or null for no argument needed - */ + + /** + * get the output file + * @return the argument string or null for no argument + */ protected String getOutputFileParameter() { if (_outputFile==null || _outputFile.length()==0) return null; File f=project.resolveFile(_outputFile); return "/output="+f.toString(); } - - //============================================================================= + /** resource file (.res format) to include in the app. */ - - protected String _resourceFile; - - public void setResourceFile(String s) { - _resourceFile=s; - } + protected File _resourceFile; + /** + * Set the resource file + * @param fileName path to the file. Can be relative, absolute, whatever. + */public void setResourceFile(String fileName) { + _resourceFile = project.resolveFile(fileName); + } + protected String getResourceFileParameter() { - if(notEmpty(_resourceFile)) { - return "/resource="+_resourceFile; + if(_resourceFile!=null) { + return "/resource="+_resourceFile.toString(); } - else + else { return null; + } } - - //============================================================================= + /** flag to control action on execution trouble - */ - + */ protected boolean _failOnError; - + /**set fail on error flag - */ + */ public void setFailOnError(boolean b){ _failOnError=b; } - + /** query fail on error flag - */ + */ public boolean getFailFailOnError() { return _failOnError; } - - //============================================================================= + /** debug flag. Controls generation of debug information. */ - protected boolean _debug; - + /** set the debug flag on or off - * @param on/off flag + * @param f on/off flag */ - public void setDebug(boolean f) - {_debug=f;} + {_debug=f;} /** query the debug flag * @return true if debug is turned on */ - public boolean getDebug() { return _debug; } - + /** get the argument or null for no argument needed - */ + */ protected String getDebugParameter() { return _debug?"/debug":null; - } - - //============================================================================= + } + + /** any extra command options? + */ + protected String _extraOptions; + + /** + * Sets the ExtraOptions attribute + * + * @param extraOptions The new ExtraOptions value + */ + public void setExtraOptions(String extraOptions) + {this._extraOptions=extraOptions;} + + /** + * Gets the ExtraOptions attribute + * + * @return The ExtraOptions value + */ + public String getExtraOptions() + {return this._extraOptions;} + + /** + * get any extra options or null for no argument needed + * + * @return The ExtraOptions Parameter to CSC + */ + protected String getExtraOptionsParameter() { + if (_extraOptions!=null && _extraOptions.length()!=0) + return _extraOptions; + else + return null; + } + + /** This is the execution entry point. Build a list of files and * call ilasm on each of them. + * @throws BuildException if the assembly failed and FailOnError is true */ - public void execute() throws BuildException { if (_srcDir == null) - _srcDir=project.resolveFile("."); - + _srcDir=project.resolveFile("."); + //get dependencies list. DirectoryScanner scanner = super.getDirectoryScanner(_srcDir); String[] dependencies = scanner.getIncludedFiles(); @@ -472,13 +440,15 @@ public class Ilasm targetFile=baseDir+File.separator+targetFile; executeOneFile(targetFile); } - + } // end execute - - //============================================================================= - /** do the work by building the command line and 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 + * @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); @@ -493,8 +463,9 @@ public class Ilasm command.addArgument(getOwnerParameter()); command.addArgument(getResourceFileParameter()); command.addArgument(getVerboseParameter()); - + command.addArgument(getExtraOptionsParameter()); + /* space for more argumentativeness command.addArgument(); command.addArgument(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java index 3c50226e5..3f67dee5f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java @@ -70,7 +70,7 @@ The reference CD to listen to while editing this file is Underworld Everything, Everything variable naming policy from Fowler's refactoring book. -*/ + */ // place below the optional ant tasks package @@ -86,7 +86,6 @@ import org.apache.tools.ant.taskdefs.*; import org.apache.tools.ant.types.*; - /** This is a helper class to spawn net commands out. In its initial form it contains no .net specifics, just contains @@ -94,118 +93,118 @@ all the command line/exe construction stuff. However, it may be handy in future to have a means of setting the path to point to the dotnet bin directory; in which case the shared code should go in here. @author Steve Loughran steve_l@iseran.com - +@created 2000-11-01 +@version 0.3 */ - public class NetCommand { - + /** constructor - @param owning task - @param title (for logging/errors) - @param executable. Leave off the '.exe. for future portability + @param owning task + @param title (for logging/errors) + @param executable. Leave off the '.exe. for future portability */ - - public NetCommand(Task owner, String title, String program) - throws BuildException { + + public NetCommand(Task owner, String title, String program) { _owner=owner; _title=title; _program=program; _commandLine=new Commandline(); _commandLine.setExecutable(_program); prepareExecutor(); - } - + } + /** owner project */ protected Task _owner; - + /** executabe */ protected Execute _exe; - + /** what is the command line */ protected Commandline _commandLine; - + /** title of the command */ protected String _title; - + /** actual program to invoke */ protected String _program; - + /** trace flag */ protected boolean _traceCommandLine=false; - + + /** + * turn tracing on or off + * @param b trace flag + */ public void setTraceCommandLine(boolean b){ _traceCommandLine=b; } - + /** flag to control action on execution trouble - */ - + */ protected boolean _failOnError; - - /**set fail on error flag + + /** + * set fail on error flag + * @param b fail flag -set to true to cause an exception to be raised if + * the return value != 0 */ public void setFailOnError(boolean b){ _failOnError=b; } - + /** query fail on error flag - */ + */ public boolean getFailFailOnError() { return _failOnError; } - - - - /** verbose text log - * @param string to add to log iff verbose is defined for the build + + /** + * verbose text log + * @param msg string to add to log iff verbose is defined for the build */ protected void logVerbose(String msg){ _owner.getProject().log(msg,Project.MSG_VERBOSE); - } - - - /** error text log - * @param string to add to the error log + } + + + /** + * error text log + * @param msg message to display as an error */ protected void logError(String msg) { _owner.getProject().log(msg,Project.MSG_ERR); } - - /* + + /** * add an argument to a command line; do nothing if the arg is null or empty string - * @param commandline to extend - * @param next arg + * @param argument The feature to be added to the Argument attribute */ public void addArgument(String argument){ if(argument!=null && argument.length()!=0) { _commandLine.createArgument().setValue(argument); } } - + /** * set up the command sequence.. */ - protected void prepareExecutor() throws BuildException { + protected void prepareExecutor() { // default directory to the project's base directory File dir = _owner.getProject().getBaseDir(); ExecuteStreamHandler handler=new LogStreamHandler(_owner, - Project.MSG_INFO, Project.MSG_WARN); + Project.MSG_INFO, Project.MSG_WARN); _exe = new Execute(handler, null); _exe.setAntRun(_owner.getProject()); _exe.setWorkingDirectory(dir); - /* do nothing with env variables. REVISIT: SDK command line? - String[] environment = env.getVariables(); - exe.setEnvironment(environment); - */ } - + /** * Run the command using the given Execute instance. * @throws an exception of something goes wrong and the failOnError flag is true @@ -217,8 +216,10 @@ public class NetCommand { if(_traceCommandLine) { _owner.log(_commandLine.toString()); } - else + else { + //in verbose mode we always log stuff logVerbose(_commandLine.toString()); + } _exe.setCommandline(_commandLine.getCommandline()); err = _exe.execute(); if (err != 0) {