Browse Source

updated to release 1.0 of .NET.

stuck through jedit jstyle and idea variable renaming ops too


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272328 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 23 years ago
parent
commit
d328f5e4ea
3 changed files with 1079 additions and 768 deletions
  1. +628
    -417
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
  2. +301
    -229
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java
  3. +150
    -122
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java

+ 628
- 417
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
File diff suppressed because it is too large
View File


+ 301
- 229
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/Ilasm.java View File

@@ -1,66 +1,64 @@
/* /*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
* *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* *
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* *
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
* *
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* 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
*/ */

/* 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
*/

// ==================================================================== // ====================================================================
// place in the optional ant tasks package // place in the optional ant tasks package
// but in its own dotnet group // but in its own dotnet group
@@ -79,134 +77,187 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.MatchingTask;



/** /**
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: &lt;il/&gt; 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>
*
*@author Steve Loughran steve_l@iseran.com
*@version 0.5
*/


<p>
All parameters are optional: &lt;il/&gt; 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)
public class Ilasm
extends MatchingTask {


/**
* Name of the executable. The .exe suffix is deliberately not included in
* anticipation of the unix version
*/
protected final static String exe_name = "ilasm";


<p>
/**
* what is the file extension we search on?
*/
protected final static String file_ext = "il";


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>
/**
* and now derive the search pattern from the extension
*/
protected final static String file_pattern = "**/*." + file_ext;


/**
* title of task for external presentation
*/
protected final static String exe_title = "ilasm";


@author Steve Loughran steve_l@iseran.com
@version 0.2
*/
/**
* source directory upon which the search pattern is applied
*/
private File srcDir;

/**
* 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
*/
protected String targetType;


/**
* verbose flag
*/
protected boolean verbose;


public class Ilasm
extends MatchingTask {
/**
* listing flag
*/

protected boolean listing;


/** constructor inits everything and set up the search pattern
/**
* output file. If not supplied this is derived from the source file
*/ */
public Ilasm() {
Clear();
setIncludes(file_pattern);
}
protected File outputFile;


/**
* Name of the executable. The .exe suffix is deliberately not included
* in anticipation of the unix version
/**
* resource file (.res format) to include in the app.
*/ */
protected final static String exe_name = "ilasm";
protected File resourceFile;


/** what is the file extension we search on?
/**
* flag to control action on execution trouble
*/ */
protected final static String file_ext = "il";
protected boolean failOnError;


/** and now derive the search pattern from the extension
/**
* debug flag. Controls generation of debug information.
*/ */
protected final static String file_pattern = "**/*." + file_ext;
protected boolean debug;


/** title of task for external presentation
/**
* file containing private key
*/ */
protected final static String exe_title = "ilasm";


/** reset all contents.
private File keyfile;

/**
* any extra command options?
*/ */
public void Clear() {
_targetType = null;
_srcDir = null;
_listing = false;
_verbose = false;
_debug = true;
_outputFile = null;
_failOnError = true;
_resourceFile = null;
_extraOptions = null;
}
protected String extraOptions;



/** source directory upon which the search pattern is applied
/**
* constructor inits everything and set up the search pattern
*/ */
private File _srcDir;
public Ilasm() {
Clear();
setIncludes(file_pattern);
}



/** /**
* Set the source dir to find the files to be compiled
* @param srcDirName The new SrcDir value
* reset all contents.
*/ */
public void setSrcDir(File srcDirName) {
_srcDir = srcDirName;
public void Clear() {
targetType = null;
srcDir = null;
listing = false;
verbose = false;
debug = true;
outputFile = null;
failOnError = true;
resourceFile = null;
extraOptions = 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
/**
* Set the source dir to find the files to be compiled
*
*@param srcDirName The new SrcDir value
*/ */
protected String _targetType;
public void setSrcDir(File srcDirName) {
srcDir = srcDirName;
}


/** define the target
* @param targetType one of exe|library|
* @exception BuildException if target is not one of exe|library|module|winexe

/**
* define the target
*
*@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
* accessor method for target type
*
*@return the current target option
*/ */
public String getTargetType() { public String getTargetType() {
return _targetType;
return targetType;
} }


/** g
* get the target type or null for no argument needed

/**
* g get the target type or null for no argument needed
* *
* @return The TargetTypeParameter value
*@return The TargetTypeParameter value
*/ */


protected String getTargetTypeParameter() { protected String getTargetTypeParameter() {
if (!notEmpty(_targetType)) {
if (!notEmpty(targetType)) {
return null; return null;
} }
if (_targetType.equals("exe")) {
if (targetType.equals("exe")) {
return "/exe"; return "/exe";
} else if (_targetType.equals("library")) {
} else if (targetType.equals("library")) {
return "/dll"; return "/dll";
} else { } else {
return null; return null;
@@ -217,219 +268,237 @@ public class Ilasm
/** /**
* Sets the Owner attribute * Sets the Owner attribute
* *
* @param s The new Owner value
*@param s The new Owner value
*/ */


public void setOwner(String s) { public void setOwner(String s) {
log("This option is not supported by ILASM as of Beta-2, and will be ignored", Project.MSG_WARN); log("This option is not supported by ILASM as of Beta-2, and will be ignored", Project.MSG_WARN);
} }


/** test for a string containing something useful
* @param string to test
* @return true if the argument is not null or empty

/**
* test for a string containing something useful
*
*@param s any string
*@return 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
*/
protected boolean _verbose;


/** /**
* enable/disable verbose ILASM output
* @param b flag set to true for verbose on
* 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
* 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
*/

protected boolean _listing;

/** /**
* enable/disable listing
* @param b flag set to true for listing on
* 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
* 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
* source file
*/
protected File _outputFile;

/**
* Set the definitions
* @param list of definitions split by ; or , or even :
* Set the output file
*
*@param params The new outputFile value
*/ */
public void setOutputFile(File params) { public void setOutputFile(File params) {
_outputFile = params;
outputFile = params;
} }



/** /**
* get the output file
* @return the argument string or null for no argument
* 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 = _outputFile;
File f = outputFile;
return "/output=" + f.toString(); return "/output=" + f.toString();
} }


/** resource file (.res format) to include in the app.
*/
protected File _resourceFile;


/** /**
* Set the resource file
* @param fileName path to the file. Can be relative, absolute, whatever.
* Set the resource file
*
*@param fileName path to the file. Can be relative, absolute, whatever.
*/ */
public void setResourceFile(File fileName) { public void setResourceFile(File fileName) {
_resourceFile = fileName;
resourceFile = fileName;
} }



/**
* Gets the resourceFileParameter attribute of the Ilasm task
*
*@return The resourceFileParameter value
*/
protected String getResourceFileParameter() { protected String getResourceFileParameter() {
if (_resourceFile != null) {
return "/resource=" + _resourceFile.toString();
if (resourceFile != null) {
return "/resource=" + resourceFile.toString();
} else { } else {
return null; return null;
} }
} }


/** flag to control action on execution trouble
*/
protected boolean _failOnError;


/**set fail on error flag
/**
* set fail on error flag
*
*@param b The new failOnError value
*/ */
public void setFailOnError(boolean b) { public void setFailOnError(boolean b) {
_failOnError = b;
failOnError = b;
} }


/** query fail on error flag

/**
* query fail on error flag
*
*@return The failFailOnError value
*/ */
public boolean getFailFailOnError() { public boolean getFailFailOnError() {
return _failOnError;
return failOnError;
} }


/** debug flag. Controls generation of debug information.
*/
protected boolean _debug;


/** set the debug flag on or off
* @param f on/off flag
/**
* set the debug flag on or off
*
*@param f on/off flag
*/ */
public void setDebug(boolean f) { public void setDebug(boolean f) {
_debug = f;
debug = f;
} }


/** query the debug flag
* @return true if debug is turned on

/**
* query the debug flag
*
*@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
*
*@return The debugParameter value
*/ */
protected String getDebugParameter() { protected String getDebugParameter() {
return _debug?"/debug":null;
return debug ? "/debug" : null;
} }


/** file containing private key
*/

private File _keyfile;


/**
* Sets the keyfile attribute of the Ilasm object
*
*@param keyfile The new keyfile value
*/
public void setKeyfile(File keyfile) { public void setKeyfile(File keyfile) {
this._keyfile = keyfile;
this.keyfile = keyfile;
} }


/** get the argument or null for no argument needed

/**
* get the argument or null for no argument needed
*
*@return The keyfileParameter value
*/ */
protected String getKeyfileParameter() { protected String getKeyfileParameter() {
if (_keyfile != null) {
return "/keyfile:" + _keyfile.toString();
if (keyfile != null) {
return "/keyfile:" + keyfile.toString();
} else { } else {
return null; return null;
} }
} }


/** any extra command options?
*/
protected String _extraOptions;


/** /**
* Sets the ExtraOptions attribute * Sets the ExtraOptions attribute
* *
* @param extraOptions The new ExtraOptions value
*@param extraOptions The new ExtraOptions value
*/ */
public void setExtraOptions(String extraOptions) { public void setExtraOptions(String extraOptions) {
this._extraOptions = extraOptions;
this.extraOptions = extraOptions;
} }



/** /**
* Gets the ExtraOptions attribute * Gets the ExtraOptions attribute
* *
* @return The ExtraOptions value
*@return The ExtraOptions value
*/ */
public String getExtraOptions() { public String getExtraOptions() {
return this._extraOptions;
return this.extraOptions;
} }



/** /**
* get any extra options or null for no argument needed * get any extra options or null for no argument needed
* *
* @return The ExtraOptions Parameter to CSC
*@return The ExtraOptions Parameter to CSC
*/ */
protected String getExtraOptionsParameter() { protected String getExtraOptionsParameter() {
if (_extraOptions != null && _extraOptions.length() != 0) {
return _extraOptions;
if (extraOptions != null && extraOptions.length() != 0) {
return extraOptions;
} else { } else {
return null; 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
/**
* 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() public void execute()
throws BuildException {
if (_srcDir == null) {
_srcDir = project.resolveFile(".");
throws BuildException {
if (srcDir == null) {
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();
log("assembling " + dependencies.length + " file" + ((dependencies.length == 1)?"":"s"));
log("assembling " + dependencies.length + " file" + ((dependencies.length == 1) ? "" : "s"));
String baseDir = scanner.getBasedir().toString(); String baseDir = scanner.getBasedir().toString();
//add to the command //add to the command
for (int i = 0; i < dependencies.length; i++) { for (int i = 0; i < dependencies.length; i++) {
@@ -438,16 +507,18 @@ public class Ilasm
executeOneFile(targetFile); executeOneFile(targetFile);
} }


} // end execute
}
// end execute




/** /**
* 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
* 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);
command.setFailOnError(getFailFailOnError()); command.setFailOnError(getFailFailOnError());
//DEBUG helper //DEBUG helper
@@ -462,14 +533,15 @@ public class Ilasm
command.addArgument(getKeyfileParameter()); command.addArgument(getKeyfileParameter());
command.addArgument(getExtraOptionsParameter()); command.addArgument(getExtraOptionsParameter());



/* space for more argumentativeness
command.addArgument();
command.addArgument();
*/

/*
* space for more argumentativeness
* command.addArgument();
* command.addArgument();
*/
command.addArgument(targetFile); command.addArgument(targetFile);
//now run the command of exe + settings + file //now run the command of exe + settings + file
command.runCommand(); command.runCommand();
} // end executeOneFile
} //class
}
// end executeOneFile
}


+ 150
- 122
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java View File

@@ -1,64 +1,62 @@
/* /*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
* *
* Copyright (c) 2000,2002 The Apache Software Foundation. All rights
* reserved.
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
* *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* *
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* *
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
* *
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/ */

/* build notes

The reference CD to listen to while editing this file is
Underworld Everything, Everything
variable naming policy from Fowler's refactoring book.
/*
* build notes
* 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 // place below the optional ant tasks package


package org.apache.tools.ant.taskdefs.optional.dotnet; package org.apache.tools.ant.taskdefs.optional.dotnet;
@@ -76,150 +74,180 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;



/** /**
This is a helper class to spawn net commands out.
In its initial form it contains no .net specifics, just contains
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
@version 0.3
* This is a helper class to spawn net commands out. In its initial form it
* contains no .net specifics, just contains 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
*@version 0.5
*/ */


public class NetCommand { public class NetCommand {


/** constructor
@param owning task
@param title (for logging/errors)
@param executable. Leave off the '.exe. for future portability
/**
* owner project
*/ */
protected Task owner;


public NetCommand(Task owner, String title, String program) {
_owner = owner;
_title = title;
_program = program;
_commandLine = new Commandline();
_commandLine.setExecutable(_program);
prepareExecutor();
}
/**
* executabe
*/
protected Execute executable;


/** owner project
/**
* what is the command line
*/ */
protected Task _owner;
protected Commandline commandLine;


/** executabe
/**
* title of the command
*/ */
protected Execute _exe;
protected String title;


/** what is the command line
/**
* actual program to invoke
*/ */
protected Commandline _commandLine;
protected String program;


/** title of the command
/**
* trace flag
*/ */
protected String _title;
protected boolean traceCommandLine = false;


/** actual program to invoke
/**
* flag to control action on execution trouble
*/ */
protected String _program;
protected boolean failOnError;



/** trace flag
/**
* constructor
*
*@param title (for logging/errors)
*@param owner owner task
*@param program app we are to run
*/ */
protected boolean _traceCommandLine = false;

public NetCommand(Task owner, String title, String program) {
owner = owner;
title = title;
program = program;
commandLine = new Commandline();
commandLine.setExecutable(program);
prepareExecutor();
}



/** /**
* turn tracing on or off
* @param b trace flag
* 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
*/
protected boolean _failOnError;


/** /**
* set fail on error flag
* @param b fail flag -set to true to cause an exception to be raised if
* the return value != 0
* 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
*
*@return The failFailOnError value
*/ */
public boolean getFailFailOnError() { public boolean getFailFailOnError() {
return _failOnError;
return failOnError;
} }



/** /**
* verbose text log
* @param msg 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 msg message to display as an error
* 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
* @param argument The feature to be added to the Argument attribute
* add an argument to a command line; do nothing if the arg is null or
* empty string
*
*@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() { protected void prepareExecutor() {
// default directory to the project's base directory // default directory to the project's base directory
File dir = _owner.getProject().getBaseDir();
ExecuteStreamHandler handler = new LogStreamHandler(_owner,
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);
executable = new Execute(handler, null);
executable.setAntRun(owner.getProject());
executable.setWorkingDirectory(dir);
} }



/** /**
* Run the command using the given Execute instance.
* @throws an exception of something goes wrong and the failOnError flag is true
* Run the command using the given Execute instance.
*
*@exception BuildException iff something goes wrong and the
* failOnError flag is true
*/ */
public void runCommand() public void runCommand()
throws BuildException {
int err = -1; // assume the worst
throws BuildException {
int err = -1;
// assume the worst
try { try {
if (_traceCommandLine) {
_owner.log(_commandLine.toString());
if (traceCommandLine) {
owner.log(commandLine.toString());
} else { } else {
//in verbose mode we always log stuff //in verbose mode we always log stuff
logVerbose(_commandLine.toString());
logVerbose(commandLine.toString());
} }
_exe.setCommandline(_commandLine.getCommandline());
err = _exe.execute();
executable.setCommandline(commandLine.getCommandline());
err = executable.execute();
if (err != 0) { if (err != 0) {
if (_failOnError) {
throw new BuildException(_title + " returned: " + err, _owner.getLocation());
if (failOnError) {
throw new BuildException(title + " returned: " + err, owner.getLocation());
} else { } else {
_owner.log(_title + " Result: " + err, Project.MSG_ERR);
owner.log(title + " Result: " + err, Project.MSG_ERR);
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw new BuildException(_title + " failed: " + e, e, _owner.getLocation());
throw new BuildException(title + " failed: " + e, e, owner.getLocation());
} }
} }
} //class
}


Loading…
Cancel
Save