git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270641 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -54,10 +54,10 @@ | |||||
| /* build notes | /* build notes | ||||
| -The reference CD to listen to while editing this file is | |||||
| -The reference CD to listen to while editing this file is | |||||
| nap: Underworld - Everything, Everything | nap: Underworld - Everything, Everything | ||||
| -variable naming policy from Fowler's refactoring book. | -variable naming policy from Fowler's refactoring book. | ||||
| -tested against the PDC pre-beta of csc.exe; future versions will | |||||
| -tested against the PDC pre-beta of csc.exe; future versions will | |||||
| inevitably change things | inevitably change things | ||||
| */ | */ | ||||
| @@ -74,16 +74,15 @@ package org.apache.tools.ant.taskdefs.optional.dotnet; | |||||
| import java.io.File; | import java.io.File; | ||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.DirectoryScanner; | import org.apache.tools.ant.DirectoryScanner; | ||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||||
| /** | /** | ||||
| Task to assemble .net 'Intermediate Language' files. | Task to assemble .net 'Intermediate Language' files. | ||||
| The task will only work on win2K until other platforms support csc.exe or | |||||
| 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. | an equivalent. ilasm.exe must be on the execute path too. | ||||
| <p> | <p> | ||||
| @@ -95,95 +94,94 @@ even though the command line options are only vaguely | |||||
| equivalent. [The low level commands take things like /OUT=file, | equivalent. [The low level commands take things like /OUT=file, | ||||
| csc wants /out:file ... /verbose is used some places; /quiet here in | 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 | ildasm... etc.] It would be nice if someone made all the command line | ||||
| tools consistent (and not as brittle as the java cmdline tools) | |||||
| tools consistent (and not as brittle as the java cmdline tools) | |||||
| <p> | <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. | |||||
| 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 | Each file is built on its own, producing an appropriately named output file unless | ||||
| manually specified with <b>outfile</b> | 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.2 | |||||
| */ | */ | ||||
| public class Ilasm | public class Ilasm | ||||
| extends org.apache.tools.ant.taskdefs.MatchingTask { | |||||
| extends 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 final static String exe_name="ilasm"; | |||||
| protected final static String exe_name = "ilasm"; | |||||
| /** what is the file extension we search on? | /** what is the file extension we search on? | ||||
| */ | */ | ||||
| protected final static String file_ext="il"; | |||||
| /** and now derive the search pattern from the extension | |||||
| protected final static String file_ext = "il"; | |||||
| /** and now derive the search pattern from the extension | |||||
| */ | */ | ||||
| protected final static String file_pattern="**/*."+file_ext; | |||||
| protected final static String file_pattern = "**/*." + file_ext; | |||||
| /** title of task for external presentation | /** title of task for external presentation | ||||
| */ | */ | ||||
| protected final static String exe_title="ilasm"; | |||||
| /** reset all contents. | |||||
| */ | |||||
| protected final static String exe_title = "ilasm"; | |||||
| /** reset all contents. | |||||
| */ | |||||
| public void Clear() { | public void Clear() { | ||||
| _targetType=null; | |||||
| _srcDir=null; | |||||
| _targetType = null; | |||||
| _srcDir = null; | |||||
| _listing = false; | _listing = false; | ||||
| _verbose=false; | |||||
| _debug=true; | |||||
| _outputFile=null; | |||||
| _failOnError=true; | |||||
| _resourceFile=null; | |||||
| _extraOptions=null; | |||||
| _verbose = false; | |||||
| _debug = true; | |||||
| _outputFile = null; | |||||
| _failOnError = true; | |||||
| _resourceFile = 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 | |||||
| * @param srcDirName The new SrcDir value | |||||
| */ | */ | ||||
| public void setSrcDir(File srcDirName){ | |||||
| public void setSrcDir(File srcDirName) { | |||||
| _srcDir = srcDirName; | _srcDir = 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 targetType one of exe|library| | * @param targetType one of exe|library| | ||||
| * @exception BuildException if target is not one of exe|library|module|winexe | |||||
| * @exception BuildException if target is not one of exe|library|module|winexe | |||||
| */ | */ | ||||
| public void setTargetType(String targetType) | public void setTargetType(String targetType) | ||||
| throws BuildException { | |||||
| targetType=targetType.toLowerCase(); | |||||
| if(targetType.equals("exe") || targetType.equals("library")) { | |||||
| _targetType=targetType; | |||||
| } | |||||
| else { | |||||
| throw new BuildException("targetType " +targetType+" is not a valid type"); | |||||
| throws BuildException { | |||||
| targetType = targetType.toLowerCase(); | |||||
| if (targetType.equals("exe") || targetType.equals("library")) { | |||||
| _targetType = targetType; | |||||
| } else { | |||||
| throw new BuildException("targetType " + targetType + " is not a valid type"); | |||||
| } | } | ||||
| } | } | ||||
| @@ -191,97 +189,97 @@ public class Ilasm | |||||
| * accessor method for target type | * accessor method for target type | ||||
| * @return the current target option | * @return the current target option | ||||
| */ | */ | ||||
| public String getTargetType() { | |||||
| public String getTargetType() { | |||||
| return _targetType; | return _targetType; | ||||
| } | |||||
| } | |||||
| /** g | /** g | ||||
| * get the target type or null for no argument needed | |||||
| * 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; | ||||
| } | } | ||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * 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 | /** 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) | |||||
| {return s!=null && s.length()!=0;} | |||||
| */ | |||||
| protected boolean notEmpty(String s) { | |||||
| return s != null && s.length() != 0; | |||||
| } | |||||
| /** verbose flag | /** verbose flag | ||||
| */ | */ | ||||
| protected boolean _verbose; | protected boolean _verbose; | ||||
| /** | |||||
| /** | |||||
| * enable/disable verbose ILASM output | * enable/disable verbose ILASM output | ||||
| * @param b flag set to true for verbose on | * @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 | * turn the verbose flag into a parameter for ILASM | ||||
| * @return null or the appropriate command line string | * @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 | * enable/disable listing | ||||
| * @param b flag set to true for listing on | * @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 | * turn the listing flag into a parameter for ILASM | ||||
| * @return the appropriate string from the state of the listing flag | * @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 File _outputFile; | protected File _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 : | ||||
| @@ -289,164 +287,167 @@ public class Ilasm | |||||
| public void setOutputFile(File params) { | public void setOutputFile(File params) { | ||||
| _outputFile = params; | _outputFile = params; | ||||
| } | } | ||||
| /** | /** | ||||
| * get the output file | |||||
| * get the output file | |||||
| * @return the argument string or null for no argument | * @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. | |||||
| /** resource file (.res format) to include in the app. | |||||
| */ | */ | ||||
| protected File _resourceFile; | protected File _resourceFile; | ||||
| /** | /** | ||||
| * Set the resource file | |||||
| * Set the resource file | |||||
| * @param fileName path to the file. Can be relative, absolute, whatever. | * @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; | ||||
| } | } | ||||
| protected String getResourceFileParameter() { | protected String getResourceFileParameter() { | ||||
| if(_resourceFile!=null) { | |||||
| return "/resource="+_resourceFile.toString(); | |||||
| } | |||||
| else { | |||||
| if (_resourceFile != null) { | |||||
| return "/resource=" + _resourceFile.toString(); | |||||
| } 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){ | |||||
| _failOnError=b; | |||||
| */ | |||||
| public void setFailOnError(boolean 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 f 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 | /** 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; | ||||
| } | |||||
| } | |||||
| /** file containing private key | /** file containing private key | ||||
| */ | |||||
| */ | |||||
| private File _keyfile; | private File _keyfile; | ||||
| 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 | ||||
| */ | |||||
| */ | |||||
| 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? | /** any extra command options? | ||||
| */ | */ | ||||
| protected String _extraOptions; | 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) | |||||
| {this._extraOptions=extraOptions;} | |||||
| public void setExtraOptions(String extraOptions) { | |||||
| this._extraOptions = extraOptions; | |||||
| } | |||||
| /** | /** | ||||
| * Gets the ExtraOptions attribute | |||||
| * Gets the ExtraOptions attribute | |||||
| * | * | ||||
| * @return The ExtraOptions value | |||||
| * @return The ExtraOptions value | |||||
| */ | */ | ||||
| public String getExtraOptions() | |||||
| {return this._extraOptions;} | |||||
| public String getExtraOptions() { | |||||
| 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) { | |||||
| if (_extraOptions != null && _extraOptions.length() != 0) { | |||||
| return _extraOptions; | return _extraOptions; | ||||
| } else { | } else { | ||||
| return null; | 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 | * @throws BuildException if the assembly failed and FailOnError is true | ||||
| */ | */ | ||||
| public void execute() | |||||
| throws BuildException { | |||||
| public void execute() | |||||
| 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(); | ||||
| log("assembling "+dependencies.length+" file"+((dependencies.length==1)?"":"s")); | |||||
| String baseDir=scanner.getBasedir().toString(); | |||||
| log("assembling " + dependencies.length + " file" + ((dependencies.length == 1)?"":"s")); | |||||
| 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++) { | ||||
| String targetFile=dependencies[i]; | |||||
| targetFile=baseDir+File.separator+targetFile; | |||||
| String targetFile = dependencies[i]; | |||||
| targetFile = baseDir + File.separator + targetFile; | |||||
| executeOneFile(targetFile); | executeOneFile(targetFile); | ||||
| } | } | ||||
| } // end execute | } // end execute | ||||
| /** | /** | ||||
| * do the work for one file by building the command line 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 | * @param targetFile name of the the file to assemble | ||||
| * @throws BuildException if the assembly failed and FailOnError is true | * @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); | |||||
| public void executeOneFile(String targetFile) | |||||
| throws BuildException { | |||||
| NetCommand command = new NetCommand(this, exe_title, exe_name); | |||||
| command.setFailOnError(getFailFailOnError()); | command.setFailOnError(getFailFailOnError()); | ||||
| //DEBUG helper | //DEBUG helper | ||||
| command.setTraceCommandLine(true); | command.setTraceCommandLine(true); | ||||
| @@ -454,18 +455,18 @@ public class Ilasm | |||||
| command.addArgument(getDebugParameter()); | command.addArgument(getDebugParameter()); | ||||
| command.addArgument(getTargetTypeParameter()); | command.addArgument(getTargetTypeParameter()); | ||||
| command.addArgument(getListingParameter()); | command.addArgument(getListingParameter()); | ||||
| command.addArgument(getOutputFileParameter()); | |||||
| command.addArgument(getOutputFileParameter()); | |||||
| command.addArgument(getResourceFileParameter()); | command.addArgument(getResourceFileParameter()); | ||||
| command.addArgument(getVerboseParameter()); | command.addArgument(getVerboseParameter()); | ||||
| command.addArgument(getKeyfileParameter()); | command.addArgument(getKeyfileParameter()); | ||||
| command.addArgument(getExtraOptionsParameter()); | command.addArgument(getExtraOptionsParameter()); | ||||
| /* space for more argumentativeness | /* space for more argumentativeness | ||||
| command.addArgument(); | command.addArgument(); | ||||
| 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(); | ||||
| @@ -68,10 +68,9 @@ package org.apache.tools.ant.taskdefs.optional.dotnet; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import org.apache.tools.ant.Task; | |||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.Task; | |||||
| import org.apache.tools.ant.taskdefs.Execute; | import org.apache.tools.ant.taskdefs.Execute; | ||||
| import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; | import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; | ||||
| import org.apache.tools.ant.taskdefs.LogStreamHandler; | import org.apache.tools.ant.taskdefs.LogStreamHandler; | ||||
| @@ -79,136 +78,135 @@ import org.apache.tools.ant.types.Commandline; | |||||
| /** | /** | ||||
| 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 | ||||
| all the command line/exe construction stuff. However, it may be handy in future | 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 | |||||
| @created 2000-11-01 | |||||
| @version 0.3 | |||||
| @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) { | public NetCommand(Task owner, String title, String program) { | ||||
| _owner=owner; | |||||
| _title=title; | |||||
| _program=program; | |||||
| _commandLine=new Commandline(); | |||||
| _owner = owner; | |||||
| _title = title; | |||||
| _program = program; | |||||
| _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 | * turn tracing on or off | ||||
| * @param b trace flag | * @param b trace flag | ||||
| */ | */ | ||||
| public void setTraceCommandLine(boolean b){ | |||||
| _traceCommandLine=b; | |||||
| public void setTraceCommandLine(boolean 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 | * @param b fail flag -set to true to cause an exception to be raised if | ||||
| * the return value != 0 | * the return value != 0 | ||||
| */ | */ | ||||
| public void setFailOnError(boolean b){ | |||||
| _failOnError=b; | |||||
| public void setFailOnError(boolean 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 | * verbose text log | ||||
| * @param msg string to add to log iff verbose is defined for the build | * @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); | |||||
| } | |||||
| protected void logVerbose(String msg) { | |||||
| _owner.getProject().log(msg, Project.MSG_VERBOSE); | |||||
| } | |||||
| /** | /** | ||||
| * error text log | * error text log | ||||
| * @param msg message to display as an error | * @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 argument The feature to be added to the Argument attribute | |||||
| * @param argument The feature to be added to the Argument attribute | |||||
| */ | */ | ||||
| public void addArgument(String argument){ | |||||
| if(argument!=null && argument.length()!=0) { | |||||
| public void addArgument(String argument) { | |||||
| 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(); | File dir = _owner.getProject().getBaseDir(); | ||||
| ExecuteStreamHandler handler=new LogStreamHandler(_owner, | |||||
| Project.MSG_INFO, Project.MSG_WARN); | |||||
| ExecuteStreamHandler handler = new LogStreamHandler(_owner, | |||||
| 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); | ||||
| } | } | ||||
| /** | /** | ||||
| * 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 | ||||
| */ | */ | ||||
| public void runCommand() | public void runCommand() | ||||
| throws BuildException { | |||||
| throws BuildException { | |||||
| int err = -1; // assume the worst | int err = -1; // assume the worst | ||||
| try { | try { | ||||
| if(_traceCommandLine) { | |||||
| if (_traceCommandLine) { | |||||
| _owner.log(_commandLine.toString()); | _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()); | ||||
| } | } | ||||
| @@ -216,13 +214,13 @@ public class NetCommand { | |||||
| err = _exe.execute(); | err = _exe.execute(); | ||||
| if (err != 0) { | if (err != 0) { | ||||
| if (_failOnError) { | if (_failOnError) { | ||||
| throw new BuildException(_title+" returned: "+err, _owner.getLocation()); | |||||
| 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 | } //class | ||||
| @@ -65,6 +65,8 @@ import javax.xml.transform.TransformerFactory; | |||||
| import javax.xml.transform.dom.DOMSource; | import javax.xml.transform.dom.DOMSource; | ||||
| import javax.xml.transform.stream.StreamResult; | import javax.xml.transform.stream.StreamResult; | ||||
| import org.w3c.dom.Document; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| @@ -73,7 +75,6 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.w3c.dom.Document; | |||||
| /** | /** | ||||
| @@ -131,7 +132,7 @@ public class CovReport extends Task { | |||||
| /* | /* | ||||
| /** coverage home, mandatory */ | /** coverage home, mandatory */ | ||||
| private File home = null; | |||||
| private File home = null; | |||||
| /** format of generated report, optional */ | /** format of generated report, optional */ | ||||
| private String format = null; | private String format = null; | ||||
| @@ -227,7 +228,7 @@ public class CovReport extends Task { | |||||
| } | } | ||||
| //@todo to remove | //@todo to remove | ||||
| public Path createCoveragepath() { | |||||
| public Path createCoveragepath() { | |||||
| if (coveragePath == null) { | if (coveragePath == null) { | ||||
| coveragePath = new Path(project); | coveragePath = new Path(project); | ||||
| } | } | ||||
| @@ -77,7 +77,7 @@ public class Triggers { | |||||
| } | } | ||||
| // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X | ||||
| public String toString() { | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
| final int size = triggers.size(); | final int size = triggers.size(); | ||||
| for (int i = 0; i < size; i++) { | for (int i = 0; i < size; i++) { | ||||
| @@ -119,7 +119,7 @@ public class Triggers { | |||||
| } | } | ||||
| // return <name>:<event>:<action>[:param] | // return <name>:<event>:<action>[:param] | ||||
| public String toString() { | |||||
| public String toString() { | |||||
| StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
| buf.append(name).append(":"); //@todo name must not be null, check for it | buf.append(name).append(":"); //@todo name must not be null, check for it | ||||
| buf.append(eventMap.get(event)).append(":"); | buf.append(eventMap.get(event)).append(":"); | ||||
| @@ -62,17 +62,18 @@ import java.util.Vector; | |||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.w3c.dom.Document; | |||||
| import org.w3c.dom.Element; | |||||
| import org.w3c.dom.Node; | |||||
| import org.w3c.dom.NodeList; | |||||
| import org.xml.sax.InputSource; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassFile; | import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassFile; | ||||
| import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassPathLoader; | import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.ClassPathLoader; | ||||
| import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.MethodInfo; | import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.MethodInfo; | ||||
| import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.Utils; | import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.Utils; | ||||
| import org.w3c.dom.Document; | |||||
| import org.w3c.dom.Element; | |||||
| import org.w3c.dom.Node; | |||||
| import org.w3c.dom.NodeList; | |||||
| import org.xml.sax.InputSource; | |||||
| /** | /** | ||||
| * Little hack to process XML report from JProbe. It will fix | * Little hack to process XML report from JProbe. It will fix | ||||
| @@ -325,7 +326,7 @@ public class XMLReport { | |||||
| Element classElem = report.createElement("class"); | Element classElem = report.createElement("class"); | ||||
| classElem.setAttribute("name", classFile.getName()); | classElem.setAttribute("name", classFile.getName()); | ||||
| // source file possibly does not exist in the bytecode | // source file possibly does not exist in the bytecode | ||||
| if ( null != classFile.getSourceFile() ){ | |||||
| if (null != classFile.getSourceFile()) { | |||||
| classElem.setAttribute("source", classFile.getSourceFile()); | classElem.setAttribute("source", classFile.getSourceFile()); | ||||
| } | } | ||||
| // create the cov.data elem | // create the cov.data elem | ||||
| @@ -53,21 +53,21 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; | package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.io.BufferedInputStream; | import java.io.BufferedInputStream; | ||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
| import java.io.FilenameFilter; | |||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
| import java.io.FilenameFilter; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.util.Enumeration; | import java.util.Enumeration; | ||||
| import java.util.StringTokenizer; | |||||
| import java.util.Vector; | |||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
| import java.util.zip.ZipFile; | |||||
| import java.util.StringTokenizer; | |||||
| import java.util.Vector; | |||||
| import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
| import java.util.zip.ZipFile; | |||||
| /** | /** | ||||
| * Core of the bytecode analyzer. It loads classes from a given classpath. | * Core of the bytecode analyzer. It loads classes from a given classpath. | ||||
| @@ -86,10 +86,10 @@ public class ClassPathLoader { | |||||
| * separated by the platform specific path separator. | * separated by the platform specific path separator. | ||||
| * @param classPath the classpath to load all the classes from. | * @param classPath the classpath to load all the classes from. | ||||
| */ | */ | ||||
| public ClassPathLoader(String classPath){ | |||||
| public ClassPathLoader(String classPath) { | |||||
| StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); | StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); | ||||
| Vector entries = new Vector(); | Vector entries = new Vector(); | ||||
| while (st.hasMoreTokens()){ | |||||
| while (st.hasMoreTokens()) { | |||||
| File file = new File(st.nextToken()); | File file = new File(st.nextToken()); | ||||
| entries.addElement(file); | entries.addElement(file); | ||||
| } | } | ||||
| @@ -101,9 +101,9 @@ public class ClassPathLoader { | |||||
| * create a new instance with a given set of urls. | * create a new instance with a given set of urls. | ||||
| * @param entries valid file urls (either .jar, .zip or directory) | * @param entries valid file urls (either .jar, .zip or directory) | ||||
| */ | */ | ||||
| public ClassPathLoader(String[] entries){ | |||||
| public ClassPathLoader(String[] entries) { | |||||
| files = new File[entries.length]; | files = new File[entries.length]; | ||||
| for (int i = 0; i < entries.length; i++){ | |||||
| for (int i = 0; i < entries.length; i++) { | |||||
| files[i] = new File(entries[i]); | files[i] = new File(entries[i]); | ||||
| } | } | ||||
| } | } | ||||
| @@ -112,7 +112,7 @@ public class ClassPathLoader { | |||||
| * create a new instance with a given set of urls | * create a new instance with a given set of urls | ||||
| * @param entries file urls to look for classes (.jar, .zip or directory) | * @param entries file urls to look for classes (.jar, .zip or directory) | ||||
| */ | */ | ||||
| public ClassPathLoader(File[] entries){ | |||||
| public ClassPathLoader(File[] entries) { | |||||
| files = entries; | files = entries; | ||||
| } | } | ||||
| @@ -120,6 +120,7 @@ public class ClassPathLoader { | |||||
| public interface FileLoader { | public interface FileLoader { | ||||
| /** the file url that is looked for .class files */ | /** the file url that is looked for .class files */ | ||||
| public File getFile(); | public File getFile(); | ||||
| /** return the set of classes found in the file */ | /** return the set of classes found in the file */ | ||||
| public ClassFile[] getClasses() throws IOException; | public ClassFile[] getClasses() throws IOException; | ||||
| } | } | ||||
| @@ -127,7 +128,7 @@ public class ClassPathLoader { | |||||
| /** | /** | ||||
| * @return the set of <tt>FileLoader</tt> loaders matching the given classpath. | * @return the set of <tt>FileLoader</tt> loaders matching the given classpath. | ||||
| */ | */ | ||||
| public Enumeration loaders(){ | |||||
| public Enumeration loaders() { | |||||
| return new LoaderEnumeration(); | return new LoaderEnumeration(); | ||||
| } | } | ||||
| @@ -145,18 +146,18 @@ public class ClassPathLoader { | |||||
| public Hashtable getClasses() throws IOException { | public Hashtable getClasses() throws IOException { | ||||
| Hashtable map = new Hashtable(); | Hashtable map = new Hashtable(); | ||||
| Enumeration enum = loaders(); | Enumeration enum = loaders(); | ||||
| while ( enum.hasMoreElements() ){ | |||||
| FileLoader loader = (FileLoader)enum.nextElement(); | |||||
| while (enum.hasMoreElements()) { | |||||
| FileLoader loader = (FileLoader) enum.nextElement(); | |||||
| System.out.println("Processing " + loader.getFile()); | System.out.println("Processing " + loader.getFile()); | ||||
| long t0 = System.currentTimeMillis(); | long t0 = System.currentTimeMillis(); | ||||
| ClassFile[] classes = loader.getClasses(); | ClassFile[] classes = loader.getClasses(); | ||||
| long dt = System.currentTimeMillis() - t0; | long dt = System.currentTimeMillis() - t0; | ||||
| System.out.println("" + classes.length + " classes loaded in " + dt + "ms"); | System.out.println("" + classes.length + " classes loaded in " + dt + "ms"); | ||||
| for (int j = 0; j < classes.length; j++){ | |||||
| for (int j = 0; j < classes.length; j++) { | |||||
| String name = classes[j].getFullName(); | String name = classes[j].getFullName(); | ||||
| // do not allow duplicates entries to preserve 'classpath' behavior | // do not allow duplicates entries to preserve 'classpath' behavior | ||||
| // first class in wins | // first class in wins | ||||
| if ( !map.containsKey(name) ){ | |||||
| if (!map.containsKey(name)) { | |||||
| map.put(name, classes[j]); | map.put(name, classes[j]); | ||||
| } | } | ||||
| } | } | ||||
| @@ -167,21 +168,23 @@ public class ClassPathLoader { | |||||
| /** the loader enumeration that will return loaders */ | /** the loader enumeration that will return loaders */ | ||||
| protected class LoaderEnumeration implements Enumeration { | protected class LoaderEnumeration implements Enumeration { | ||||
| protected int index = 0; | protected int index = 0; | ||||
| public boolean hasMoreElements(){ | |||||
| public boolean hasMoreElements() { | |||||
| return index < files.length; | return index < files.length; | ||||
| } | } | ||||
| public Object nextElement(){ | |||||
| if (index >= files.length){ | |||||
| public Object nextElement() { | |||||
| if (index >= files.length) { | |||||
| throw new NoSuchElementException(); | throw new NoSuchElementException(); | ||||
| } | } | ||||
| File file = files[index++]; | File file = files[index++]; | ||||
| if ( !file.exists() ){ | |||||
| if (!file.exists()) { | |||||
| return new NullLoader(file); | return new NullLoader(file); | ||||
| } | } | ||||
| if ( file.isDirectory() ){ | |||||
| if (file.isDirectory()) { | |||||
| // it's a directory | // it's a directory | ||||
| return new DirectoryLoader(file); | return new DirectoryLoader(file); | ||||
| } else if ( file.getName().endsWith(".zip") || file.getName().endsWith(".jar") ){ | |||||
| } else if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) { | |||||
| // it's a jar/zip file | // it's a jar/zip file | ||||
| return new JarLoader(file); | return new JarLoader(file); | ||||
| } | } | ||||
| @@ -212,15 +215,19 @@ public class ClassPathLoader { | |||||
| /** a null loader to return when the file is not valid */ | /** a null loader to return when the file is not valid */ | ||||
| class NullLoader implements ClassPathLoader.FileLoader { | class NullLoader implements ClassPathLoader.FileLoader { | ||||
| private File file; | private File file; | ||||
| NullLoader(){ | |||||
| NullLoader() { | |||||
| this(null); | this(null); | ||||
| } | } | ||||
| NullLoader(File file){ | |||||
| NullLoader(File file) { | |||||
| this.file = file; | this.file = file; | ||||
| } | } | ||||
| public File getFile(){ | |||||
| public File getFile() { | |||||
| return file; | return file; | ||||
| } | } | ||||
| public ClassFile[] getClasses() throws IOException { | public ClassFile[] getClasses() throws IOException { | ||||
| return new ClassFile[0]; | return new ClassFile[0]; | ||||
| } | } | ||||
| @@ -233,19 +240,22 @@ class NullLoader implements ClassPathLoader.FileLoader { | |||||
| */ | */ | ||||
| class JarLoader implements ClassPathLoader.FileLoader { | class JarLoader implements ClassPathLoader.FileLoader { | ||||
| private File file; | private File file; | ||||
| JarLoader(File file){ | |||||
| JarLoader(File file) { | |||||
| this.file = file; | this.file = file; | ||||
| } | } | ||||
| public File getFile(){ | |||||
| public File getFile() { | |||||
| return file; | return file; | ||||
| } | } | ||||
| public ClassFile[] getClasses() throws IOException { | public ClassFile[] getClasses() throws IOException { | ||||
| ZipFile zipFile = new ZipFile(file); | ZipFile zipFile = new ZipFile(file); | ||||
| Vector v = new Vector(); | Vector v = new Vector(); | ||||
| Enumeration entries = zipFile.entries(); | Enumeration entries = zipFile.entries(); | ||||
| while (entries.hasMoreElements()){ | |||||
| ZipEntry entry = (ZipEntry)entries.nextElement(); | |||||
| if (entry.getName().endsWith(".class")){ | |||||
| while (entries.hasMoreElements()) { | |||||
| ZipEntry entry = (ZipEntry) entries.nextElement(); | |||||
| if (entry.getName().endsWith(".class")) { | |||||
| InputStream is = ClassPathLoader.getCachedStream(zipFile.getInputStream(entry)); | InputStream is = ClassPathLoader.getCachedStream(zipFile.getInputStream(entry)); | ||||
| ClassFile classFile = new ClassFile(is); | ClassFile classFile = new ClassFile(is); | ||||
| is.close(); | is.close(); | ||||
| @@ -266,17 +276,19 @@ class JarLoader implements ClassPathLoader.FileLoader { | |||||
| class DirectoryLoader implements ClassPathLoader.FileLoader { | class DirectoryLoader implements ClassPathLoader.FileLoader { | ||||
| private File directory; | private File directory; | ||||
| DirectoryLoader(File dir){ | |||||
| DirectoryLoader(File dir) { | |||||
| directory = dir; | directory = dir; | ||||
| } | } | ||||
| public File getFile(){ | |||||
| public File getFile() { | |||||
| return directory; | return directory; | ||||
| } | } | ||||
| public ClassFile[] getClasses() throws IOException { | public ClassFile[] getClasses() throws IOException { | ||||
| Vector v = new Vector(); | Vector v = new Vector(); | ||||
| Vector files = listFiles( directory, new ClassFilter(), true); | |||||
| for (int i = 0; i < files.size(); i++){ | |||||
| File file = (File)files.elementAt(i); | |||||
| Vector files = listFiles(directory, new ClassFilter(), true); | |||||
| for (int i = 0; i < files.size(); i++) { | |||||
| File file = (File) files.elementAt(i); | |||||
| InputStream is = null; | InputStream is = null; | ||||
| try { | try { | ||||
| is = ClassPathLoader.getCachedStream(new FileInputStream(file)); | is = ClassPathLoader.getCachedStream(new FileInputStream(file)); | ||||
| @@ -285,10 +297,11 @@ class DirectoryLoader implements ClassPathLoader.FileLoader { | |||||
| is = null; | is = null; | ||||
| v.addElement(classFile); | v.addElement(classFile); | ||||
| } finally { | } finally { | ||||
| if (is != null){ | |||||
| if (is != null) { | |||||
| try { | try { | ||||
| is.close(); | is.close(); | ||||
| } catch (IOException ignored){} | |||||
| } catch (IOException ignored) { | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -306,9 +319,9 @@ class DirectoryLoader implements ClassPathLoader.FileLoader { | |||||
| * @return the list of <tt>File</tt> objects that applies to the given | * @return the list of <tt>File</tt> objects that applies to the given | ||||
| * filter. | * filter. | ||||
| */ | */ | ||||
| public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse){ | |||||
| if (!directory.isDirectory()){ | |||||
| throw new IllegalArgumentException(directory + " is not a directory"); | |||||
| public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse) { | |||||
| if (!directory.isDirectory()) { | |||||
| throw new IllegalArgumentException(directory + " is not a directory"); | |||||
| } | } | ||||
| Vector list = new Vector(); | Vector list = new Vector(); | ||||
| listFilesTo(list, directory, filter, recurse); | listFilesTo(list, directory, filter, recurse); | ||||
| @@ -324,15 +337,15 @@ class DirectoryLoader implements ClassPathLoader.FileLoader { | |||||
| * @param recurse tells whether or not the listing is recursive. | * @param recurse tells whether or not the listing is recursive. | ||||
| * @return the list instance that was passed as the <tt>list</tt> argument. | * @return the list instance that was passed as the <tt>list</tt> argument. | ||||
| */ | */ | ||||
| private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse){ | |||||
| private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse) { | |||||
| String[] files = directory.list(filter); | String[] files = directory.list(filter); | ||||
| for (int i = 0; i < files.length; i++){ | |||||
| list.addElement( new File(directory, files[i]) ); | |||||
| for (int i = 0; i < files.length; i++) { | |||||
| list.addElement(new File(directory, files[i])); | |||||
| } | } | ||||
| files = null; // we don't need it anymore | files = null; // we don't need it anymore | ||||
| if (recurse){ | |||||
| String[] subdirs = directory.list( new DirectoryFilter() ); | |||||
| for (int i = 0; i < subdirs.length; i++){ | |||||
| if (recurse) { | |||||
| String[] subdirs = directory.list(new DirectoryFilter()); | |||||
| for (int i = 0; i < subdirs.length; i++) { | |||||
| listFilesTo(list, new File(directory, subdirs[i]), filter, recurse); | listFilesTo(list, new File(directory, subdirs[i]), filter, recurse); | ||||
| } | } | ||||
| } | } | ||||
| @@ -343,14 +356,15 @@ class DirectoryLoader implements ClassPathLoader.FileLoader { | |||||
| /** Convenient filter that accepts only directory <tt>File</tt> */ | /** Convenient filter that accepts only directory <tt>File</tt> */ | ||||
| class DirectoryFilter implements FilenameFilter { | class DirectoryFilter implements FilenameFilter { | ||||
| public boolean accept(File directory, String name){ | |||||
| public boolean accept(File directory, String name) { | |||||
| File pathname = new File(directory, name); | File pathname = new File(directory, name); | ||||
| return pathname.isDirectory(); | return pathname.isDirectory(); | ||||
| } | } | ||||
| } | } | ||||
| /** convenient filter to accept only .class files */ | /** convenient filter to accept only .class files */ | ||||
| class ClassFilter implements FilenameFilter { | class ClassFilter implements FilenameFilter { | ||||
| public boolean accept(File dir, String name){ | |||||
| public boolean accept(File dir, String name) { | |||||
| return name.endsWith(".class"); | return name.endsWith(".class"); | ||||
| } | } | ||||
| } | } | ||||
| @@ -78,7 +78,7 @@ public final class MethodInfo { | |||||
| access_flags = dis.readShort(); | access_flags = dis.readShort(); | ||||
| int name_index = dis.readShort(); | int name_index = dis.readShort(); | ||||
| name = Utils.getUTF8Value(constantPool, name_index); | |||||
| name = Utils.getUTF8Value(constantPool, name_index); | |||||
| int descriptor_index = dis.readShort(); | int descriptor_index = dis.readShort(); | ||||
| descriptor = Utils.getUTF8Value(constantPool, descriptor_index); | descriptor = Utils.getUTF8Value(constantPool, descriptor_index); | ||||
| @@ -99,7 +99,7 @@ public final class MethodInfo { | |||||
| protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException { | protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException { | ||||
| // skip max_stack (short), max_local (short) | // skip max_stack (short), max_local (short) | ||||
| dis.skipBytes(2*2); | |||||
| dis.skipBytes(2 * 2); | |||||
| // skip bytecode... | // skip bytecode... | ||||
| int bytecode_len = dis.readInt(); | int bytecode_len = dis.readInt(); | ||||
| @@ -54,9 +54,10 @@ | |||||
| package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; | package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; | ||||
| import java.util.Vector; | |||||
| import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool; | import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool; | ||||
| import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo; | import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo; | ||||
| import java.util.Vector; | |||||
| /** | /** | ||||
| * Utilities mostly to manipulate methods and access flags. | * Utilities mostly to manipulate methods and access flags. | ||||
| @@ -92,7 +93,7 @@ public class Utils { | |||||
| public final static short ACC_STRICT = 2048; | public final static short ACC_STRICT = 2048; | ||||
| /** private constructor */ | /** private constructor */ | ||||
| private Utils(){ | |||||
| private Utils() { | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -102,8 +103,8 @@ public class Utils { | |||||
| * @return the value of the string if it exists | * @return the value of the string if it exists | ||||
| * @throws ClassCastException if the index is not an UTF8 constant. | * @throws ClassCastException if the index is not an UTF8 constant. | ||||
| */ | */ | ||||
| public static String getUTF8Value(ConstantPool pool, int index){ | |||||
| return ((Utf8CPInfo)pool.getEntry(index)).getValue(); | |||||
| public static String getUTF8Value(ConstantPool pool, int index) { | |||||
| return ((Utf8CPInfo) pool.getEntry(index)).getValue(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -113,18 +114,18 @@ public class Utils { | |||||
| * represent a java object with its fully qualified classname or the | * represent a java object with its fully qualified classname or the | ||||
| * primitive name such as int, long, ... | * primitive name such as int, long, ... | ||||
| */ | */ | ||||
| public static String[] getMethodParams(String descriptor){ | |||||
| public static String[] getMethodParams(String descriptor) { | |||||
| int i = 0; | int i = 0; | ||||
| if (descriptor.charAt(i) != '('){ | |||||
| if (descriptor.charAt(i) != '(') { | |||||
| throw new IllegalArgumentException("Method descriptor should start with a '('"); | throw new IllegalArgumentException("Method descriptor should start with a '('"); | ||||
| } | } | ||||
| Vector params = new Vector(); | Vector params = new Vector(); | ||||
| StringBuffer param = new StringBuffer(); | StringBuffer param = new StringBuffer(); | ||||
| i++; | i++; | ||||
| while ( (i = descriptor2java(descriptor, i, param)) < descriptor.length() ){ | |||||
| while ((i = descriptor2java(descriptor, i, param)) < descriptor.length()) { | |||||
| params.add(param.toString()); | params.add(param.toString()); | ||||
| param.setLength(0); // reset | param.setLength(0); // reset | ||||
| if (descriptor.charAt(i) == ')'){ | |||||
| if (descriptor.charAt(i) == ')') { | |||||
| i++; | i++; | ||||
| break; | break; | ||||
| } | } | ||||
| @@ -139,7 +140,7 @@ public class Utils { | |||||
| * @param descriptor | * @param descriptor | ||||
| * @return get the return type objet of a given descriptor | * @return get the return type objet of a given descriptor | ||||
| */ | */ | ||||
| public static String getMethodReturnType(String descriptor){ | |||||
| public static String getMethodReturnType(String descriptor) { | |||||
| int pos = descriptor.indexOf(')'); | int pos = descriptor.indexOf(')'); | ||||
| StringBuffer rettype = new StringBuffer(); | StringBuffer rettype = new StringBuffer(); | ||||
| descriptor2java(descriptor, pos + 1, rettype); | descriptor2java(descriptor, pos + 1, rettype); | ||||
| @@ -153,23 +154,41 @@ public class Utils { | |||||
| * @param sb the stringbuffer to return the java equivalent of the symbol | * @param sb the stringbuffer to return the java equivalent of the symbol | ||||
| * @return the index after the descriptor symbol | * @return the index after the descriptor symbol | ||||
| */ | */ | ||||
| public static int descriptor2java(String descriptor, int i, StringBuffer sb){ | |||||
| public static int descriptor2java(String descriptor, int i, StringBuffer sb) { | |||||
| // get the dimension | // get the dimension | ||||
| StringBuffer dim = new StringBuffer(); | StringBuffer dim = new StringBuffer(); | ||||
| for (;descriptor.charAt(i) == '['; i++){ | |||||
| for (; descriptor.charAt(i) == '['; i++) { | |||||
| dim.append("[]"); | dim.append("[]"); | ||||
| } | } | ||||
| // now get the type | // now get the type | ||||
| switch (descriptor.charAt(i)){ | |||||
| case 'B': sb.append("byte"); break; | |||||
| case 'C': sb.append("char"); break; | |||||
| case 'D': sb.append("double"); break; | |||||
| case 'F': sb.append("float"); break; | |||||
| case 'I': sb.append("int"); break; | |||||
| case 'J': sb.append("long"); break; | |||||
| case 'S': sb.append("short"); break; | |||||
| case 'Z': sb.append("boolean"); break; | |||||
| case 'V': sb.append("void"); break; | |||||
| switch (descriptor.charAt(i)) { | |||||
| case 'B': | |||||
| sb.append("byte"); | |||||
| break; | |||||
| case 'C': | |||||
| sb.append("char"); | |||||
| break; | |||||
| case 'D': | |||||
| sb.append("double"); | |||||
| break; | |||||
| case 'F': | |||||
| sb.append("float"); | |||||
| break; | |||||
| case 'I': | |||||
| sb.append("int"); | |||||
| break; | |||||
| case 'J': | |||||
| sb.append("long"); | |||||
| break; | |||||
| case 'S': | |||||
| sb.append("short"); | |||||
| break; | |||||
| case 'Z': | |||||
| sb.append("boolean"); | |||||
| break; | |||||
| case 'V': | |||||
| sb.append("void"); | |||||
| break; | |||||
| case 'L': | case 'L': | ||||
| // it is a class | // it is a class | ||||
| int pos = descriptor.indexOf(';', i + 1); | int pos = descriptor.indexOf(';', i + 1); | ||||
| @@ -196,6 +215,7 @@ public class Utils { | |||||
| public static boolean isAbstract(int access_flags) { | public static boolean isAbstract(int access_flags) { | ||||
| return (access_flags & ACC_ABSTRACT) != 0; | return (access_flags & ACC_ABSTRACT) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for public access | * check for public access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -203,6 +223,7 @@ public class Utils { | |||||
| public static boolean isPublic(int access_flags) { | public static boolean isPublic(int access_flags) { | ||||
| return (access_flags & ACC_PUBLIC) != 0; | return (access_flags & ACC_PUBLIC) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for a static access | * check for a static access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -210,6 +231,7 @@ public class Utils { | |||||
| public static boolean isStatic(int access_flags) { | public static boolean isStatic(int access_flags) { | ||||
| return (access_flags & ACC_STATIC) != 0; | return (access_flags & ACC_STATIC) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for native access | * check for native access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -217,6 +239,7 @@ public class Utils { | |||||
| public static boolean isNative(int access_flags) { | public static boolean isNative(int access_flags) { | ||||
| return (access_flags & ACC_NATIVE) != 0; | return (access_flags & ACC_NATIVE) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for class access | * check for class access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -224,6 +247,7 @@ public class Utils { | |||||
| public static boolean isClass(int access_flags) { | public static boolean isClass(int access_flags) { | ||||
| return !isInterface(access_flags); | return !isInterface(access_flags); | ||||
| } | } | ||||
| /** | /** | ||||
| * check for strict access | * check for strict access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -231,6 +255,7 @@ public class Utils { | |||||
| public static boolean isStrict(int access_flags) { | public static boolean isStrict(int access_flags) { | ||||
| return (access_flags & ACC_STRICT) != 0; | return (access_flags & ACC_STRICT) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for interface access | * check for interface access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -238,6 +263,7 @@ public class Utils { | |||||
| public static boolean isInterface(int access_flags) { | public static boolean isInterface(int access_flags) { | ||||
| return (access_flags & ACC_INTERFACE) != 0; | return (access_flags & ACC_INTERFACE) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for private access | * check for private access | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -245,6 +271,7 @@ public class Utils { | |||||
| public static boolean isPrivate(int access_flags) { | public static boolean isPrivate(int access_flags) { | ||||
| return (access_flags & ACC_PRIVATE) != 0; | return (access_flags & ACC_PRIVATE) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for transient flag | * check for transient flag | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -252,13 +279,15 @@ public class Utils { | |||||
| public static boolean isTransient(int access_flags) { | public static boolean isTransient(int access_flags) { | ||||
| return (access_flags & ACC_TRANSIENT) != 0; | return (access_flags & ACC_TRANSIENT) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for volatile flag | * check for volatile flag | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| */ | */ | ||||
| public static boolean isVolatile(int access_flags){ | |||||
| public static boolean isVolatile(int access_flags) { | |||||
| return (access_flags & ACC_VOLATILE) != 0; | return (access_flags & ACC_VOLATILE) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for super flag | * check for super flag | ||||
| * @param access_flags access flag | * @param access_flags access flag | ||||
| @@ -266,6 +295,7 @@ public class Utils { | |||||
| public static boolean isSuper(int access_flags) { | public static boolean isSuper(int access_flags) { | ||||
| return (access_flags & ACC_SUPER) != 0; | return (access_flags & ACC_SUPER) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for protected flag | * check for protected flag | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -273,6 +303,7 @@ public class Utils { | |||||
| public static boolean isProtected(int access_flags) { | public static boolean isProtected(int access_flags) { | ||||
| return (access_flags & ACC_PROTECTED) != 0; | return (access_flags & ACC_PROTECTED) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * chck for final flag | * chck for final flag | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -280,6 +311,7 @@ public class Utils { | |||||
| public static boolean isFinal(int access_flags) { | public static boolean isFinal(int access_flags) { | ||||
| return (access_flags & ACC_FINAL) != 0; | return (access_flags & ACC_FINAL) != 0; | ||||
| } | } | ||||
| /** | /** | ||||
| * check for synchronized flag | * check for synchronized flag | ||||
| * @param access_flags access flags | * @param access_flags access flags | ||||
| @@ -295,26 +327,26 @@ public class Utils { | |||||
| */ | */ | ||||
| public static String getMethodAccess(int access_flags) { | public static String getMethodAccess(int access_flags) { | ||||
| StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
| if(isPublic(access_flags)){ | |||||
| if (isPublic(access_flags)) { | |||||
| sb.append("public "); | sb.append("public "); | ||||
| } else if(isPrivate(access_flags)){ | |||||
| } else if (isPrivate(access_flags)) { | |||||
| sb.append("private "); | sb.append("private "); | ||||
| } else if(isProtected(access_flags)){ | |||||
| } else if (isProtected(access_flags)) { | |||||
| sb.append("protected "); | sb.append("protected "); | ||||
| } | } | ||||
| if(isFinal(access_flags)){ | |||||
| if (isFinal(access_flags)) { | |||||
| sb.append("final "); | sb.append("final "); | ||||
| } | } | ||||
| if(isStatic(access_flags)){ | |||||
| if (isStatic(access_flags)) { | |||||
| sb.append("static "); | sb.append("static "); | ||||
| } | } | ||||
| if(isSynchronized(access_flags)){ | |||||
| if (isSynchronized(access_flags)) { | |||||
| sb.append("synchronized "); | sb.append("synchronized "); | ||||
| } | } | ||||
| if(isNative(access_flags)){ | |||||
| if (isNative(access_flags)) { | |||||
| sb.append("native "); | sb.append("native "); | ||||
| } | } | ||||
| if(isAbstract(access_flags)){ | |||||
| if (isAbstract(access_flags)) { | |||||
| sb.append("abstract "); | sb.append("abstract "); | ||||
| } | } | ||||
| return sb.toString().trim(); | return sb.toString().trim(); | ||||
| @@ -327,23 +359,23 @@ public class Utils { | |||||
| */ | */ | ||||
| public static String getFieldAccess(int access_flags) { | public static String getFieldAccess(int access_flags) { | ||||
| StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
| if(isPublic(access_flags)){ | |||||
| if (isPublic(access_flags)) { | |||||
| sb.append("public "); | sb.append("public "); | ||||
| } else if(isPrivate(access_flags)){ | |||||
| } else if (isPrivate(access_flags)) { | |||||
| sb.append("private "); | sb.append("private "); | ||||
| } else if (isProtected(access_flags)){ | |||||
| } else if (isProtected(access_flags)) { | |||||
| sb.append("protected "); | sb.append("protected "); | ||||
| } | } | ||||
| if(isFinal(access_flags)){ | |||||
| if (isFinal(access_flags)) { | |||||
| sb.append("final "); | sb.append("final "); | ||||
| } | } | ||||
| if(isStatic(access_flags)){ | |||||
| if (isStatic(access_flags)) { | |||||
| sb.append("static "); | sb.append("static "); | ||||
| } | } | ||||
| if(isVolatile(access_flags)){ | |||||
| if (isVolatile(access_flags)) { | |||||
| sb.append("volatile "); | sb.append("volatile "); | ||||
| } | } | ||||
| if(isTransient(access_flags)){ | |||||
| if (isTransient(access_flags)) { | |||||
| sb.append("transient "); | sb.append("transient "); | ||||
| } | } | ||||
| return sb.toString().trim(); | return sb.toString().trim(); | ||||
| @@ -356,26 +388,26 @@ public class Utils { | |||||
| */ | */ | ||||
| public static String getClassAccess(int access_flags) { | public static String getClassAccess(int access_flags) { | ||||
| StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
| if(isPublic(access_flags)){ | |||||
| if (isPublic(access_flags)) { | |||||
| sb.append("public "); | sb.append("public "); | ||||
| } else if (isProtected(access_flags)){ | |||||
| } else if (isProtected(access_flags)) { | |||||
| sb.append("protected "); | sb.append("protected "); | ||||
| } else if (isPrivate(access_flags)){ | |||||
| } else if (isPrivate(access_flags)) { | |||||
| sb.append("private "); | sb.append("private "); | ||||
| } | } | ||||
| if(isFinal(access_flags)){ | |||||
| if (isFinal(access_flags)) { | |||||
| sb.append("final "); | sb.append("final "); | ||||
| } | } | ||||
| if(isSuper(access_flags)){ | |||||
| if (isSuper(access_flags)) { | |||||
| sb.append("/*super*/ "); | sb.append("/*super*/ "); | ||||
| } | } | ||||
| if(isInterface(access_flags)){ | |||||
| if (isInterface(access_flags)) { | |||||
| sb.append("interface "); | sb.append("interface "); | ||||
| } | } | ||||
| if(isAbstract(access_flags)){ | |||||
| if (isAbstract(access_flags)) { | |||||
| sb.append("abstract "); | sb.append("abstract "); | ||||
| } | } | ||||
| if(isClass(access_flags)){ | |||||
| if (isClass(access_flags)) { | |||||
| sb.append("class "); | sb.append("class "); | ||||
| } | } | ||||
| return sb.toString().trim(); | return sb.toString().trim(); | ||||