Submitted by: Steve Loughran <steve_l@iseran.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268253 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,12 +1,13 @@ | |||||
| <html> | <html> | ||||
| <head> | <head> | ||||
| <title> .Net classes for Ant | |||||
| <title> .NET classes for Ant | |||||
| </title> | </title> | ||||
| <body> | |||||
| <h1>.Net classes for Ant</h1> | |||||
| <body bgcolor="#ffffff"> | |||||
| <h1>dotnet classes for Ant</h1> | |||||
| Vision: make ant the definative build tool for .net projects, just | |||||
| <h3>Steve Loughran; steve_l@iseran.com</h3> | |||||
| <h2>Vision</h2> | |||||
| Make ant the definative build tool for .NET projects, just | |||||
| as it is becoming for java projects | as it is becoming for java projects | ||||
| <p> | <p> | ||||
| @@ -44,9 +45,9 @@ removed from the build.xml files | |||||
| <li>ilasm - IL assembler - *.il ->.exe or .dll | <li>ilasm - IL assembler - *.il ->.exe or .dll | ||||
| <li>ResX - ResXToResources.exe .resx -> .resources | <li>ResX - ResXToResources.exe .resx -> .resources | ||||
| <li>al - assembly linker (.dll) -> | <li>al - assembly linker (.dll) -> | ||||
| <li>Signcode - .exe + keys -> .exe' | |||||
| <li>Signcode - .exe + keys -> .exe | |||||
| <li>Resgen - .properties -> .resources | <li>Resgen - .properties -> .resources | ||||
| <li>Type Library Exporter (TlbExp.exe- .dll -> .tlb | |||||
| <li>Type Library Exporter (TlbExp.exe) .dll -> .tlb | |||||
| <li>TlbImp.exe Type Library Importer | <li>TlbImp.exe Type Library Importer | ||||
| <li>RegAsm.exe Assembly Registration Tool .dll -> .reg | registration | <li>RegAsm.exe Assembly Registration Tool .dll -> .reg | registration | ||||
| <li>WebServiceUtil -SOAP proxy import, SDL generation tool | <li>WebServiceUtil -SOAP proxy import, SDL generation tool | ||||
| @@ -68,8 +69,9 @@ to be simple. | |||||
| <ol> | <ol> | ||||
| <li>code up C sharp task and distribute for feedback & identify possible | |||||
| <li>code up C sharp task and distribute for feedback & identify possible | |||||
| aid | aid | ||||
| <li>Use for a real end to end development task | |||||
| <li>Add the next task I need (whatever that is) | <li>Add the next task I need (whatever that is) | ||||
| <li>Refactor to produce a base class for .net tasks | <li>Refactor to produce a base class for .net tasks | ||||
| <li>Leave it other people write all the other tasks | <li>Leave it other people write all the other tasks | ||||
| @@ -88,15 +90,12 @@ and behaviours. Probability: 100%. Impact: 2 days. | |||||
| <hr> | <hr> | ||||
| <h2>Using Ant in .net projects</h2> | <h2>Using Ant in .net projects</h2> | ||||
| <h3> | |||||
| Setup</h3> | |||||
| To use the net tasks one needs | To use the net tasks one needs | ||||
| <ul> | <ul> | ||||
| <li> A win2K box (or any other platform which supports the .net build tools) | |||||
| <li> A Win2K box (or any other platform which supports the .net build tools) | |||||
| <li> JavaVM - Java1.1 or later | |||||
| <li> JavaVM - Java1.1 or later; Java1.3 recommended. | |||||
| <li> Ant downloaded and the environment and path variables set up so | <li> Ant downloaded and the environment and path variables set up so | ||||
| that typing 'ant' invokes ant via a batch file. | that typing 'ant' invokes ant via a batch file. | ||||
| @@ -112,15 +111,363 @@ version parser.jar and jaxp.jar. | |||||
| <li> A build.xml file to describe the build process | <li> A build.xml file to describe the build process | ||||
| </ul> | </ul> | ||||
| An example build.xml file is included in the test directory. | |||||
| <hr> | |||||
| <h2> Change Log </h2> | |||||
| <h4>Version 0.3</h4> | |||||
| 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. | |||||
| <p> | |||||
| External changes | |||||
| <ul> | |||||
| <li>Recursive inclusion of .cs and .il files | |||||
| <li>Documentation enhanced, includes examples and details of all parameters | |||||
| <li>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. | |||||
| <li> 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. | |||||
| </ul> | |||||
| Internal changes | |||||
| <ul> | |||||
| <li>Some minor refactoring (move common code a method) | |||||
| <li>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. | |||||
| <li>Removed throws clause from methods which can't throw exceptions | |||||
| </ul> | |||||
| 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) | |||||
| <h4>Version 0.2</h4> | |||||
| 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. | |||||
| <h4>Version 0.1</h4> | |||||
| Initial proof of concept; very rudimentary support for CSC only. | |||||
| <hr> | |||||
| <h2>Task: CSC</h2> | <h2>Task: CSC</h2> | ||||
| This task compiles CSharp source into executables or modules. | This task compiles CSharp source into executables or modules. | ||||
| Consult the javadoc file for parameter details. | |||||
| <h2> Task: ilasm <h2> | |||||
| 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. | |||||
| <p> | |||||
| 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. | |||||
| <p> | |||||
| The task is a directory based task, so attributes like <b>includes="**/*.cs"</b> and | |||||
| <b>excludes="broken.cs"</b> 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 <b>'outfile'</b> seems prudent. | |||||
| <p> | |||||
| <table border="1" cellpadding="2" cellspacing="0"> | |||||
| <tr> | |||||
| <td valign="top"><b>Attribute</b></td> | |||||
| <td valign="top"><b>Description</b></td> | |||||
| <td align="center" valign="top"><b>Example Values</b></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">additionalModules | |||||
| <td valign="top">Semicolon separated list of modules to refer to | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">defaultexcludes</td> | |||||
| <td valign="top">indicates whether default excludes should be used or not | |||||
| </td> | |||||
| <td valign="top">"true"(default) or "false" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">definitions | |||||
| <td valign="top">defined constants | |||||
| <td valign="top"> "RELEASE;BETA1" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">debug | |||||
| <td valign="top">include debug information | |||||
| <td valign="top">"true"(default) or "false" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">docFile | |||||
| <td valign="top">name of file for documentation | |||||
| <td valign="top">"doc.xml" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">excludes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| excluded. No files (except default excludes) are excluded when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">excludesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an exclude pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">extraOptions</td> | |||||
| <td valign="top">Any extra options which aren't explicitly | |||||
| supported by the CSharp task </td> | |||||
| <td>"/warnaserror+ /baseaddress:0x12840000" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">failOnError | |||||
| <td valign="top">Should a failed compile halt the build? | |||||
| <td valign="top">"true"(default) or "false" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| included. All files are included when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includeDefaultReferences</td> | |||||
| <td valign="top">Flag which when true automatically includes | |||||
| the common assemblies in dotnet beta1, and tells the compiler to link in | |||||
| mscore.dll | |||||
| </td> | |||||
| <td valign="top">"true"(default) or "false" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an include pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">incremental | |||||
| <td valign="top">Incremental build flag. Avoid till it works | |||||
| <td valign="top">"true" or "false"(default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">mainClass | |||||
| <td valign="top">name of main class for executables | |||||
| <td valign="top">"com.example.project.entrypoint" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">optimize | |||||
| <td valign="top">optimisation flag | |||||
| <td valign="top">"true" or "false"(default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">outputFile | |||||
| <td valign="top">filename of output | |||||
| <td valign="top">"example.exe" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">references | |||||
| <td valign="top">Semicolon separated list of dlls to refer to | |||||
| <td valign="top">"mylib.dll;nunit.dll"</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">referenceFiles </td> | |||||
| <td valign="top">Ant Path descriptioon of references to include. | |||||
| Wildcards should work. | |||||
| <td valign="top"></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">srcDir | |||||
| <td valign="top">source directory (default = project directory) | |||||
| <td valign="top">"."</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">targetType | |||||
| <td valign="top">Type of target | |||||
| <td valign="top">"exe","module","winexe" or "library" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">unsafe | |||||
| <td valign="top">enable unsafe code | |||||
| <td valign="top">"true" or "false"(default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">warnLevel | |||||
| <td valign="top">level of warning currently between 1 and 4 with 4 | |||||
| being the strictest. | |||||
| <td valign="top">"1"-"4" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">win32Icon | |||||
| <td valign="top">filename of icon to include | |||||
| <td valign="top">"res/myicon.ico"</td> | |||||
| </tr> | |||||
| </table> | |||||
| <p> | |||||
| Example | |||||
| <pre><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" | |||||
| /> | |||||
| </pre> | |||||
| <hr> | |||||
| <h2> Task: ilasm </h2> | |||||
| 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. | |||||
| <p> | |||||
| <p> | |||||
| 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) | |||||
| <p> | |||||
| The task is a directory based task, so attributes like <b>includes="*.il"</b> and | |||||
| <b>excludes="broken.il"</b> 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 <b>outfile</b> | |||||
| <p> | |||||
| <table border="1" cellpadding="2" cellspacing="0"> | |||||
| <tr> | |||||
| <td valign="top"><b>Attribute</b></td> | |||||
| <td valign="top"><b>Description</b></td> | |||||
| <td align="center" valign="top"><b>Example</b></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <tr> | |||||
| <td valign="top">defaultexcludes</td> | |||||
| <td valign="top">indicates whether default excludes should be used or not | |||||
| ("yes"/"no"). Default excludes are used when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">debug | |||||
| <td valign="top">include debug information | |||||
| <td valign="top">true (default) | |||||
| </tr> | |||||
| <tr> | |||||
| <tr> | |||||
| <td valign="top">excludes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| excluded. No files (except default excludes) are excluded when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">excludesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an exclude pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">extraOptions</td> | |||||
| <td valign="top">Any extra options which aren't explicitly | |||||
| supported by the ilasm task </td> | |||||
| <td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">failOnError | |||||
| <td valign="top">Should a failed compile halt the build? | |||||
| <td valign="top">"true"(default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| included. All files are included when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an include pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">listing | |||||
| <td valign="top">Produce a listing (off by default). Listings go to the | |||||
| current output stream | |||||
| <td valign="top">"on", "off" (default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">outputFile | |||||
| <td valign="top">filename of output | |||||
| <td valign="top">"example.exe" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">owner | |||||
| <td valign="top">restrict disassembly by setting the 'owner' string | |||||
| <td valign="top">"secret" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">resourceFile | |||||
| <td valign="top">name of resource file to include | |||||
| <td valign="top">"resources.res" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">srcDir | |||||
| <td valign="top">source directory (default = project directory) | |||||
| <td valign="top"> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">targetType | |||||
| <td valign="top">Type of target. library means DLL is output. | |||||
| <td valign="top">"exe"(default),"library" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">verbose | |||||
| <td valign="top">output progress messages | |||||
| <td valign="top">"on", "off" (default) | |||||
| </tr> | |||||
| </table> | |||||
| <p> | |||||
| Example | |||||
| <pre><ilasm | |||||
| outputFile="app.exe" | |||||
| verbose="on" | |||||
| listing="on" | |||||
| owner="secret" | |||||
| /> | |||||
| </pre> | |||||
| <hr> | |||||
| <p align="center">Copyright © 2000 Apache Software Foundation. All rights | |||||
| Reserved.</p> | |||||
| </body> | </body> | ||||
| </html> | |||||
| </html> | |||||
| @@ -67,11 +67,11 @@ | |||||
| /* build notes | /* 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.*; | 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. | |||||
| <p> | |||||
| 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. | |||||
| <p> | |||||
| <p> | |||||
| 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) | |||||
| <p> | |||||
| 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) | |||||
| <p> | |||||
| The task is a directory based task, so attributes like <b>includes="*.il"</b> and | |||||
| <b>excludes="broken.il"</b> 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 <b>outfile</b> | |||||
| <p> | |||||
| <table border="1" cellpadding="2" cellspacing="0"> | |||||
| <tr> | |||||
| <td valign="top"><b>Attribute</b></td> | |||||
| <td valign="top"><b>Description</b></td> | |||||
| <td align="center" valign="top"><b>Example</b></td> | |||||
| </tr> | |||||
| <tr> | |||||
| <tr> | |||||
| <td valign="top">defaultexcludes</td> | |||||
| <td valign="top">indicates whether default excludes should be used or not | |||||
| ("yes"/"no"). Default excludes are used when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">debug | |||||
| <td valign="top">include debug information | |||||
| <td valign="top">true (default) | |||||
| </tr> | |||||
| <tr> | |||||
| <tr> | |||||
| <td valign="top">excludes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| excluded. No files (except default excludes) are excluded when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">excludesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an exclude pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">failOnError | |||||
| <td valign="top">Should a failed compile halt the build? | |||||
| <td valign="top">true(default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includes</td> | |||||
| <td valign="top">comma separated list of patterns of files that must be | |||||
| included. All files are included when omitted.</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">includesfile</td> | |||||
| <td valign="top">the name of a file. Each line of this file is | |||||
| taken to be an include pattern</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">listing | |||||
| <td valign="top">Produce a listing (off by default) | |||||
| <td valign="top">off (default) | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">outputFile | |||||
| <td valign="top">filename of output | |||||
| <td valign="top">"example.exe" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">owner | |||||
| <td valign="top">restrict disassembly by setting the 'owner' string | |||||
| <td valign="top">"secret" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">resourceFile | |||||
| <td valign="top">name of resource file to include | |||||
| <td valign="top">"resources.res" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">srcDir | |||||
| <td valign="top">source directory (default = project directory) | |||||
| <td valign="top"> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">targetType | |||||
| <td valign="top">Type of target. library means DLL is output. | |||||
| <td valign="top">"exe","library" | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">verbose | |||||
| <td valign="top">output progress messages | |||||
| <td valign="top">off (default) | |||||
| </tr> | |||||
| </table> | |||||
| <p> | |||||
| The task is a directory based task, so attributes like <b>includes="*.il"</b> and | |||||
| <b>excludes="broken.il"</b> 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 <b>outfile</b> | |||||
| @author Steve Loughran steve_l@iseran.com | |||||
| @version 0.2 | |||||
| */ | |||||
| @author Steve Loughran steve_l@iseran.com | |||||
| @version 0.1 | |||||
| */ | |||||
| // ==================================================================== | |||||
| public class Ilasm | public class Ilasm | ||||
| extends org.apache.tools.ant.taskdefs.MatchingTask { | extends org.apache.tools.ant.taskdefs.MatchingTask { | ||||
| //============================================================================= | |||||
| /** constructor inits everything and set up the search pattern | /** constructor inits everything and set up the search pattern | ||||
| */ | |||||
| */ | |||||
| public Ilasm () { | public Ilasm () { | ||||
| Clear(); | Clear(); | ||||
| setIncludes(file_pattern); | setIncludes(file_pattern); | ||||
| } | } | ||||
| //----------------------------------------------------------------------------- | |||||
| /** name of the executable. the .exe suffix is deliberately not included | /** name of the executable. the .exe suffix is deliberately not included | ||||
| * in anticipation of the unix version | * in anticipation of the unix version | ||||
| */ | */ | ||||
| protected static final String exe_name="ilasm"; | protected static final String exe_name="ilasm"; | ||||
| /** what is the file extension we search on? | /** what is the file extension we search on? | ||||
| */ | */ | ||||
| protected static final String file_ext="il"; | protected static final String file_ext="il"; | ||||
| /** and now derive the search pattern from the extension | /** 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 | /** title of task for external presentation | ||||
| */ | */ | ||||
| protected static final String exe_title="ilasm"; | protected static final String exe_title="ilasm"; | ||||
| //============================================================================= | |||||
| /** reset all contents. | /** reset all contents. | ||||
| */ | |||||
| */ | |||||
| public void Clear() { | public void Clear() { | ||||
| _targetType=null; | _targetType=null; | ||||
| _srcDir=null; | _srcDir=null; | ||||
| @@ -255,49 +162,56 @@ public class Ilasm | |||||
| _failOnError=true; | _failOnError=true; | ||||
| _resourceFile=null; | _resourceFile=null; | ||||
| _owner=null; | _owner=null; | ||||
| _extraOptions=null; | |||||
| } | } | ||||
| //============================================================================= | |||||
| /** source directory upon which the search pattern is applied | /** source directory upon which the search pattern is applied | ||||
| */ | */ | ||||
| private File _srcDir; | private File _srcDir; | ||||
| /** | /** | ||||
| * Set the source dir to find the files to be compiled | * Set the source dir to find the files to be compiled | ||||
| * @param srcDirName The new SrcDir value | |||||
| */ | */ | ||||
| public void setSrcDir(String srcDirName){ | public void setSrcDir(String srcDirName){ | ||||
| _srcDir = project.resolveFile(srcDirName); | _srcDir = project.resolveFile(srcDirName); | ||||
| } | } | ||||
| //============================================================================= | |||||
| /** type of target. Should be one of exe|library|module|winexe|(null) | /** 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. | |||||
| <br>See /target | |||||
| */ | |||||
| default is exe; the actual value (if not null) is fed to the command line. | |||||
| <br>See /target | |||||
| */ | |||||
| protected String _targetType; | protected String _targetType; | ||||
| /** define the target | /** 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) | public void setTargetType(String targetType) | ||||
| throws BuildException { | throws BuildException { | ||||
| targetType=targetType.toLowerCase(); | targetType=targetType.toLowerCase(); | ||||
| if(targetType.equals("exe") || targetType.equals("library")) { | if(targetType.equals("exe") || targetType.equals("library")) { | ||||
| _targetType=targetType; | |||||
| _targetType=targetType; | |||||
| } | } | ||||
| else | else | ||||
| throw new BuildException("targetType " +targetType+" is not a valid type"); | throw new BuildException("targetType " +targetType+" is not a valid type"); | ||||
| } | } | ||||
| /** | |||||
| * accessor method for target type | |||||
| * @return the current target option | |||||
| */ | |||||
| public String getTargetType() { | public String getTargetType() { | ||||
| return _targetType; | 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() { | protected String getTargetTypeParameter() { | ||||
| if(!notEmpty(_targetType)) | if(!notEmpty(_targetType)) | ||||
| @@ -305,72 +219,96 @@ public class Ilasm | |||||
| if (_targetType.equals("exe")) | if (_targetType.equals("exe")) | ||||
| return "/exe"; | return "/exe"; | ||||
| else | 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 | /** owner string is a slightly trivial barrier to disassembly | ||||
| */ | |||||
| */ | |||||
| protected String _owner; | protected String _owner; | ||||
| /** | |||||
| * Sets the Owner attribute | |||||
| * | |||||
| * @param s The new Owner value | |||||
| */ | |||||
| public void setOwner(String s) { | public void setOwner(String s) { | ||||
| _owner=s; | _owner=s; | ||||
| } | |||||
| } | |||||
| /** | |||||
| * Gets the Owner switch for ilasm | |||||
| * | |||||
| * @return The Owner string | |||||
| */ | |||||
| protected String getOwnerParameter() { | protected String getOwnerParameter() { | ||||
| if(notEmpty(_owner)) | if(notEmpty(_owner)) | ||||
| return "/owner="+_owner; | return "/owner="+_owner; | ||||
| else | else | ||||
| return null; | return null; | ||||
| } | } | ||||
| //============================================================================= | |||||
| /** test for a string containing something useful | /** test for a string containing something useful | ||||
| * @param string to test | * @param string to test | ||||
| * @returns true if the argument is not null or empty | * @returns true if the argument is not null or empty | ||||
| */ | |||||
| */ | |||||
| protected boolean notEmpty(String s) | protected boolean notEmpty(String s) | ||||
| {return s!=null && s.length()!=0;} | |||||
| //============================================================================= | |||||
| {return s!=null && s.length()!=0;} | |||||
| /** verbose flag | /** verbose flag | ||||
| */ | */ | ||||
| protected boolean _verbose; | protected boolean _verbose; | ||||
| /** | |||||
| * enable/disable verbose ILASM output | |||||
| * @param b flag set to true for verbose on | |||||
| */ | |||||
| public void setVerbose(boolean b) { | public void setVerbose(boolean b) { | ||||
| _verbose=b; | _verbose=b; | ||||
| } | } | ||||
| /** | |||||
| * turn the verbose flag into a parameter for ILASM | |||||
| * @return null or the appropriate command line string | |||||
| */ | |||||
| protected String getVerboseParameter() { | protected String getVerboseParameter() { | ||||
| return _verbose?null:"/quiet"; | return _verbose?null:"/quiet"; | ||||
| } | } | ||||
| //============================================================================= | |||||
| /** listing flag | /** listing flag | ||||
| */ | */ | ||||
| protected boolean _listing; | protected boolean _listing; | ||||
| /** | |||||
| * enable/disable listing | |||||
| * @param b flag set to true for listing on | |||||
| */ | |||||
| public void setListing(boolean b) { | public void setListing(boolean b) { | ||||
| _listing=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() { | protected String getListingParameter() { | ||||
| return _listing?"/listing":"/nolisting"; | 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 | * source file | ||||
| */ | */ | ||||
| protected String _outputFile; | protected String _outputFile; | ||||
| /** | /** | ||||
| * Set the definitions | * Set the definitions | ||||
| * @param list of definitions split by ; or , or even : | * @param list of definitions split by ; or , or even : | ||||
| @@ -378,89 +316,119 @@ public class Ilasm | |||||
| public void setOutputFile(String params) { | public void setOutputFile(String params) { | ||||
| _outputFile=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() { | protected String getOutputFileParameter() { | ||||
| if (_outputFile==null || _outputFile.length()==0) | if (_outputFile==null || _outputFile.length()==0) | ||||
| return null; | return null; | ||||
| File f=project.resolveFile(_outputFile); | File f=project.resolveFile(_outputFile); | ||||
| return "/output="+f.toString(); | return "/output="+f.toString(); | ||||
| } | } | ||||
| //============================================================================= | |||||
| /** resource file (.res format) to include in the app. | /** 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() { | protected String getResourceFileParameter() { | ||||
| if(notEmpty(_resourceFile)) { | |||||
| return "/resource="+_resourceFile; | |||||
| if(_resourceFile!=null) { | |||||
| return "/resource="+_resourceFile.toString(); | |||||
| } | } | ||||
| else | |||||
| else { | |||||
| return null; | return null; | ||||
| } | |||||
| } | } | ||||
| //============================================================================= | |||||
| /** flag to control action on execution trouble | /** flag to control action on execution trouble | ||||
| */ | |||||
| */ | |||||
| protected boolean _failOnError; | protected boolean _failOnError; | ||||
| /**set fail on error flag | /**set fail on error flag | ||||
| */ | |||||
| */ | |||||
| public void setFailOnError(boolean b){ | public void setFailOnError(boolean b){ | ||||
| _failOnError=b; | _failOnError=b; | ||||
| } | } | ||||
| /** query fail on error flag | /** query fail on error flag | ||||
| */ | |||||
| */ | |||||
| public boolean getFailFailOnError() { | public boolean getFailFailOnError() { | ||||
| return _failOnError; | return _failOnError; | ||||
| } | } | ||||
| //============================================================================= | |||||
| /** debug flag. Controls generation of debug information. | /** debug flag. Controls generation of debug information. | ||||
| */ | */ | ||||
| protected boolean _debug; | protected boolean _debug; | ||||
| /** set the debug flag on or off | /** set the debug flag on or off | ||||
| * @param on/off flag | |||||
| * @param f on/off flag | |||||
| */ | */ | ||||
| public void setDebug(boolean f) | public void setDebug(boolean f) | ||||
| {_debug=f;} | |||||
| {_debug=f;} | |||||
| /** query the debug flag | /** query the debug flag | ||||
| * @return true if debug is turned on | * @return true if debug is turned on | ||||
| */ | */ | ||||
| public boolean getDebug() { | public boolean getDebug() { | ||||
| return _debug; | return _debug; | ||||
| } | } | ||||
| /** get the argument or null for no argument needed | /** get the argument or null for no argument needed | ||||
| */ | |||||
| */ | |||||
| protected String getDebugParameter() { | protected String getDebugParameter() { | ||||
| return _debug?"/debug":null; | 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 | /** This is the execution entry point. Build a list of files and | ||||
| * call ilasm on each of them. | * call ilasm on each of them. | ||||
| * @throws BuildException if the assembly failed and FailOnError is true | |||||
| */ | */ | ||||
| public void execute() | public void execute() | ||||
| throws BuildException { | throws BuildException { | ||||
| if (_srcDir == null) | if (_srcDir == null) | ||||
| _srcDir=project.resolveFile("."); | |||||
| _srcDir=project.resolveFile("."); | |||||
| //get dependencies list. | //get dependencies list. | ||||
| DirectoryScanner scanner = super.getDirectoryScanner(_srcDir); | DirectoryScanner scanner = super.getDirectoryScanner(_srcDir); | ||||
| String[] dependencies = scanner.getIncludedFiles(); | String[] dependencies = scanner.getIncludedFiles(); | ||||
| @@ -472,13 +440,15 @@ public class Ilasm | |||||
| targetFile=baseDir+File.separator+targetFile; | targetFile=baseDir+File.separator+targetFile; | ||||
| executeOneFile(targetFile); | executeOneFile(targetFile); | ||||
| } | } | ||||
| } // end execute | } // 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) | public void executeOneFile(String targetFile) | ||||
| throws BuildException { | throws BuildException { | ||||
| NetCommand command=new NetCommand(this,exe_title,exe_name); | NetCommand command=new NetCommand(this,exe_title,exe_name); | ||||
| @@ -493,8 +463,9 @@ public class Ilasm | |||||
| command.addArgument(getOwnerParameter()); | command.addArgument(getOwnerParameter()); | ||||
| command.addArgument(getResourceFileParameter()); | command.addArgument(getResourceFileParameter()); | ||||
| command.addArgument(getVerboseParameter()); | command.addArgument(getVerboseParameter()); | ||||
| command.addArgument(getExtraOptionsParameter()); | |||||
| /* space for more argumentativeness | /* space for more argumentativeness | ||||
| command.addArgument(); | command.addArgument(); | ||||
| command.addArgument(); | command.addArgument(); | ||||
| @@ -70,7 +70,7 @@ | |||||
| The reference CD to listen to while editing this file is | The reference CD to listen to while editing this file is | ||||
| Underworld Everything, Everything | Underworld Everything, Everything | ||||
| variable naming policy from Fowler's refactoring book. | variable naming policy from Fowler's refactoring book. | ||||
| */ | |||||
| */ | |||||
| // place below the optional ant tasks package | // place below the optional ant tasks package | ||||
| @@ -86,7 +86,6 @@ import org.apache.tools.ant.taskdefs.*; | |||||
| import org.apache.tools.ant.types.*; | import org.apache.tools.ant.types.*; | ||||
| /** | /** | ||||
| This is a helper class to spawn net commands out. | This is a helper class to spawn net commands out. | ||||
| In its initial form it contains no .net specifics, just contains | 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 | 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. | case the shared code should go in here. | ||||
| @author Steve Loughran steve_l@iseran.com | @author Steve Loughran steve_l@iseran.com | ||||
| @created 2000-11-01 | |||||
| @version 0.3 | |||||
| */ | */ | ||||
| public class NetCommand { | public class NetCommand { | ||||
| /** constructor | /** 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; | _owner=owner; | ||||
| _title=title; | _title=title; | ||||
| _program=program; | _program=program; | ||||
| _commandLine=new Commandline(); | _commandLine=new Commandline(); | ||||
| _commandLine.setExecutable(_program); | _commandLine.setExecutable(_program); | ||||
| prepareExecutor(); | prepareExecutor(); | ||||
| } | |||||
| } | |||||
| /** owner project | /** owner project | ||||
| */ | */ | ||||
| protected Task _owner; | protected Task _owner; | ||||
| /** executabe | /** executabe | ||||
| */ | */ | ||||
| protected Execute _exe; | protected Execute _exe; | ||||
| /** what is the command line | /** what is the command line | ||||
| */ | */ | ||||
| protected Commandline _commandLine; | protected Commandline _commandLine; | ||||
| /** title of the command | /** title of the command | ||||
| */ | */ | ||||
| protected String _title; | protected String _title; | ||||
| /** actual program to invoke | /** actual program to invoke | ||||
| */ | */ | ||||
| protected String _program; | protected String _program; | ||||
| /** trace flag | /** trace flag | ||||
| */ | */ | ||||
| protected boolean _traceCommandLine=false; | protected boolean _traceCommandLine=false; | ||||
| /** | |||||
| * turn tracing on or off | |||||
| * @param b trace flag | |||||
| */ | |||||
| public void setTraceCommandLine(boolean b){ | public void setTraceCommandLine(boolean b){ | ||||
| _traceCommandLine=b; | _traceCommandLine=b; | ||||
| } | } | ||||
| /** flag to control action on execution trouble | /** flag to control action on execution trouble | ||||
| */ | |||||
| */ | |||||
| protected boolean _failOnError; | 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){ | public void setFailOnError(boolean b){ | ||||
| _failOnError=b; | _failOnError=b; | ||||
| } | } | ||||
| /** query fail on error flag | /** query fail on error flag | ||||
| */ | |||||
| */ | |||||
| public boolean getFailFailOnError() { | public boolean getFailFailOnError() { | ||||
| return _failOnError; | 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){ | protected void logVerbose(String msg){ | ||||
| _owner.getProject().log(msg,Project.MSG_VERBOSE); | _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) { | protected void logError(String msg) { | ||||
| _owner.getProject().log(msg,Project.MSG_ERR); | _owner.getProject().log(msg,Project.MSG_ERR); | ||||
| } | } | ||||
| /* | |||||
| /** | |||||
| * add an argument to a command line; do nothing if the arg is null or empty string | * 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){ | public void addArgument(String argument){ | ||||
| if(argument!=null && argument.length()!=0) { | if(argument!=null && argument.length()!=0) { | ||||
| _commandLine.createArgument().setValue(argument); | _commandLine.createArgument().setValue(argument); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * set up the command sequence.. | * set up the command sequence.. | ||||
| */ | */ | ||||
| protected void prepareExecutor() throws BuildException { | |||||
| protected void prepareExecutor() { | |||||
| // default directory to the project's base directory | // default directory to the project's base directory | ||||
| File dir = _owner.getProject().getBaseDir(); | File dir = _owner.getProject().getBaseDir(); | ||||
| ExecuteStreamHandler handler=new LogStreamHandler(_owner, | ExecuteStreamHandler handler=new LogStreamHandler(_owner, | ||||
| Project.MSG_INFO, Project.MSG_WARN); | |||||
| Project.MSG_INFO, Project.MSG_WARN); | |||||
| _exe = new Execute(handler, null); | _exe = new Execute(handler, null); | ||||
| _exe.setAntRun(_owner.getProject()); | _exe.setAntRun(_owner.getProject()); | ||||
| _exe.setWorkingDirectory(dir); | _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. | * Run the command using the given Execute instance. | ||||
| * @throws an exception of something goes wrong and the failOnError flag is true | * @throws an exception of something goes wrong and the failOnError flag is true | ||||
| @@ -217,8 +216,10 @@ public class NetCommand { | |||||
| if(_traceCommandLine) { | if(_traceCommandLine) { | ||||
| _owner.log(_commandLine.toString()); | _owner.log(_commandLine.toString()); | ||||
| } | } | ||||
| else | |||||
| else { | |||||
| //in verbose mode we always log stuff | |||||
| logVerbose(_commandLine.toString()); | logVerbose(_commandLine.toString()); | ||||
| } | |||||
| _exe.setCommandline(_commandLine.getCommandline()); | _exe.setCommandline(_commandLine.getCommandline()); | ||||
| err = _exe.execute(); | err = _exe.execute(); | ||||
| if (err != 0) { | if (err != 0) { | ||||