From 7d0968a529dd050edb94527487932469781eb562 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 4 Apr 2002 08:17:34 +0000 Subject: [PATCH] fix infinite loop bug in netrexxc, add a bunch of new attributes and allow all attributes to be set to default values by properties. PR: 7732 Submitted by: Patric Bechtel git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272194 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/netrexxc.html | 60 ++++- .../tools/ant/taskdefs/optional/NetRexxC.java | 240 ++++++++++++++++-- 2 files changed, 270 insertions(+), 30 deletions(-) diff --git a/docs/manual/OptionalTasks/netrexxc.html b/docs/manual/OptionalTasks/netrexxc.html index f28c18452..a1435ceee 100644 --- a/docs/manual/OptionalTasks/netrexxc.html +++ b/docs/manual/OptionalTasks/netrexxc.html @@ -15,17 +15,17 @@ source tree within the running (Ant) VM.

NetRexx source files to compile. Only NetRexx files that have no corresponding class file or where the class file is older than the java file will be compiled.

Files in the source tree are copied to the destination directory, -allowing support files to be located properly in the classpath. The source +allowing support files to be located properly in the classpath. The source files are copied because the NetRexx compiler cannot produce class files in a specific directory via parameters

The directory structure of the source tree should follow the package hierarchy.

It is possible to refine the set of files that are being compiled/copied. This can be done with the includes, includesfile, excludes, excludesfile and -defaultexcludes attributes. With the includes or includesfile attribute you -specify the files you want to have included by using patterns. The -exclude or excludesfile attribute is used to specify the files you want to have -excluded. This is also done with patterns. And finally with the +defaultexcludes attributes. With the includes or includesfile attribute you +specify the files you want to have included by using patterns. The +exclude or excludesfile attribute is used to specify the files you want to have +excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the @@ -35,6 +35,12 @@ supports all attributes of <fileset> (dir becomes srcdir) as well as the nested <include>, <exclude> and <patternset> elements.

+

All properties except classpath, srcdir and destDir are also available as properties in the form +ant.netrexxc.attributename, eg.
+<property name="ant.netrexxc.verbose" value="noverbose"/>
+or from the command line as
+ant -Dant.netrexxc.verbose=noverbose ... +

Parameters

@@ -63,7 +69,7 @@ supports all attributes of <fileset> + verbose format. Default is the compact format. @@ -191,8 +197,8 @@ supports all attributes of <fileset> @@ -210,8 +216,8 @@ supports all attributes of <fileset> - @@ -254,7 +260,39 @@ supports all attributes of <fileset> - + + + + + + + + + + + + + + + + + + + + + + + + + +
compact Whether error messages come out in compact or - verbose format No
strictargs Tells the NetRexx compiler that method calls always - need parentheses, even if no arguments are needed, e.g. - aStringVar.getBytes vs. + need parentheses, even if no arguments are needed, e.g. + aStringVar.getBytes vs. aStringVar.getBytes() No
strictimportWhether classes need to be imported explicitly using an - import statement. By default the NetRexx compiler will + Whether classes need to be imported explicitly using an + import statement. By default the NetRexx compiler will import certain packages automatically No
verbose Whether lots of warnings and error messages should be generatedYesNo
suppressMethodArgumentNotUsedTells whether we should filter out the + &Method argument not used& messages in strictargs mode.no
suppressPrivatePropertyNotUsedTells whether we should filter out the + &Private Property defined, but not used& messages in strictargs mode.no
suppressVariableNotUsedTells whether we should filter out the + &Variable set but not used& messages in strictargs mode. + Please be careful with this one, as you can hide errors behind it!no
suppressExceptionNotSignalledTells whether we should filter out the + &Exception is declared, but not signalled within the method& + messages in strictsignal mode.no
suppressDeprecationTells wether we should filter out any deprecation-messages + of the compiler out.no

Examples

diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java b/src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java index 1fa514d70..830830f84 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java @@ -70,6 +70,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.tools.ant.types.EnumeratedAttribute; /** * Task to compile NetRexx source files. This task can take the following @@ -101,6 +102,11 @@ import org.apache.tools.ant.taskdefs.MatchingTask; *
  • trace
  • *
  • utf8
  • *
  • verbose
  • + *
  • suppressMethodArgumentNotUsed
  • + *
  • suppressPrivatePropertyNotUsed
  • + *
  • suppressVariableNotUsed
  • + *
  • suppressExceptionNotSignalled
  • + *
  • suppressDeprecation
  • * * Of these arguments, the srcdir argument is required. * @@ -125,7 +131,7 @@ public class NetRexxC extends MatchingTask { private boolean binary; private String classpath; private boolean comments; - private boolean compact; + private boolean compact = true; // should be the default, as it integrates better in ant. private boolean compile = true; private boolean console; private boolean crossref; @@ -152,13 +158,24 @@ public class NetRexxC extends MatchingTask { private String trace = "trace2"; private boolean utf8; private String verbose = "verbose3"; + private boolean suppressMethodArgumentNotUsed = false; + private boolean suppressPrivatePropertyNotUsed = false; + private boolean suppressVariableNotUsed = false; + private boolean suppressExceptionNotSignalled = false; + private boolean suppressDeprecation = false; + + // constants for the messages to suppress by flags and their corresponding properties + static final String MSG_METHOD_ARGUMENT_NOT_USED = "Warning: Method argument is not used"; + static final String MSG_PRIVATE_PROPERTY_NOT_USED = "Warning: Private property is defined but not used"; + static final String MSG_VARIABLE_NOT_USED = "Warning: Variable is set but not used"; + static final String MSG_EXCEPTION_NOT_SIGNALLED = "is in SIGNALS list but is not signalled within the method"; + static final String MSG_DEPRECATION = "has been deprecated"; // other implementation variables private Vector compileList = new Vector(); private Hashtable filecopyList = new Hashtable(); private String oldClasspath = System.getProperty("java.class.path"); - /** * Set whether literals are treated as binary, rather than NetRexx types */ @@ -396,20 +413,19 @@ public class NetRexxC extends MatchingTask { this.time = time; } + public void setTrace(TraceAttr trace) { + this.trace = trace.getValue(); + } + /** * Turns on or off tracing and directs the resultant trace output * Valid values are: "trace", "trace1", "trace2" and "notrace". * "trace" and "trace2" */ public void setTrace(String trace) { - if (trace.equalsIgnoreCase("trace") - || trace.equalsIgnoreCase("trace1") - || trace.equalsIgnoreCase("trace2") - || trace.equalsIgnoreCase("notrace")) { - this.trace = trace; - } else { - throw new BuildException("Unknown trace value specified: '" + trace + "'"); - } + TraceAttr t = new TraceAttr(); + t.setValue(trace); + setTrace(t); } /** @@ -421,11 +437,174 @@ public class NetRexxC extends MatchingTask { this.utf8 = utf8; } + /** + * Whether lots of warnings and error messages should be generated + */ + public void setVerbose(VerboseAttr verbose) { + this.verbose = verbose.getValue(); + } + + /** * Whether lots of warnings and error messages should be generated */ public void setVerbose(String verbose) { - this.verbose = verbose; + VerboseAttr v = new VerboseAttr(); + v.setValue(verbose); + setVerbose(v); + } + + /** + * Whether the task should suppress the "Method argument is not used" + * in strictargs-Mode, which can not be suppressed by the compiler itself. + * The warning is logged as verbose message, though. + */ + public void setSuppressMethodArgumentNotUsed(boolean suppressMethodArgumentNotUsed) { + this.suppressMethodArgumentNotUsed = suppressMethodArgumentNotUsed; + } + + /** + * Whether the task should suppress the "Private property is defined but + * not used" in strictargs-Mode, which can be quite annoying while developing. + * The warning is logged as verbose message, though. + */ + public void setSuppressPrivatePropertyNotUsed(boolean suppressPrivatePropertyNotUsed) { + this.suppressPrivatePropertyNotUsed = suppressPrivatePropertyNotUsed; + } + + /** + * Whether the task should suppress the "Variable is set but not used" + * in strictargs-Mode. Be careful with this one! + * The warning is logged as verbose message, though. + */ + public void setSuppressVariableNotUsed(boolean suppressVariableNotUsed) { + this.suppressVariableNotUsed = suppressVariableNotUsed; + } + + /** + * Whether the task should suppress the "FooException is in SIGNALS list but + * is not signalled within the method", which is sometimes rather useless. + * The warning is logged as verbose message, though. + */ + public void setSuppressExceptionNotSignalled(boolean suppressExceptionNotSignalled) { + this.suppressExceptionNotSignalled = suppressExceptionNotSignalled; + } + + /** + * Whether the task should suppress the "FooException is in SIGNALS list but + * is not signalled within the method", which is sometimes rather useless. + * The warning is logged as verbose message, though. + */ + public void setSuppressDeprecation(boolean suppressDeprecation) { + this.suppressDeprecation = suppressDeprecation; + } + + /** + * init-Method sets defaults from Properties. That way, when ant is called with arguments + * like -Dant.netrexxc.verbose=verbose5 one can easily take control of all netrexxc-tasks. + */ + // Sorry for the formatting, but that way it's easier to keep in sync with the private properties (line by line). + public void init() { + String p; + if ((p=project.getProperty("ant.netrexxc.binary"))!=null) { + this.binary=Project.toBoolean(p); + } + // classpath makes no sense + if ((p=project.getProperty("ant.netrexxc.comments"))!=null) { + this.comments=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.compact"))!=null) { + this.compact=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.compile"))!=null) { + this.compile=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.console"))!=null) { + this.console=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.crossref"))!=null) { + this.crossref=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.decimal"))!=null) { + this.decimal=Project.toBoolean(p); + // destDir + } + if ((p=project.getProperty("ant.netrexxc.diag"))!=null) { + this.diag=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.explicit"))!=null) { + this.explicit=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.format"))!=null) { + this.format=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.java"))!=null) { + this.java=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.keep"))!=null) { + this.keep=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.logo"))!=null) { + this.logo=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.replace"))!=null) { + this.replace=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.savelog"))!=null) { + this.savelog=Project.toBoolean(p); + // srcDir + } + if ((p=project.getProperty("ant.netrexxc.sourcedir"))!=null) { + this.sourcedir=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictargs"))!=null) { + this.strictargs=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictassign"))!=null) { + this.strictassign=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictcase"))!=null) { + this.strictcase=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictimport"))!=null) { + this.strictimport=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictprops"))!=null) { + this.strictprops=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.strictsignal"))!=null) { + this.strictsignal=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.symbols"))!=null) { + this.symbols=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.time"))!=null) { + this.time=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.trace"))!=null) { + setTrace(p); + } + if ((p=project.getProperty("ant.netrexxc.utf8"))!=null) { + this.utf8=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.verbose"))!=null) { + setVerbose(p); + } + if ((p=project.getProperty("ant.netrexxc.suppressMethodArgumentNotUsed"))!=null) { + this.suppressMethodArgumentNotUsed=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.suppressPrivatePropertyNotUsed"))!=null) { + this.suppressPrivatePropertyNotUsed=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.suppressVariableNotUsed"))!=null) { + this.suppressVariableNotUsed=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.suppressExceptionNotSignalled"))!=null) { + this.suppressExceptionNotSignalled=Project.toBoolean(p); + } + if ((p=project.getProperty("ant.netrexxc.suppressDeprecation"))!=null) { + this.suppressDeprecation=Project.toBoolean(p); + } } /** @@ -571,24 +750,33 @@ public class NetRexxC extends MatchingTask { main(new Rexx(compileArgs), new PrintWriter(out)); String sdir=srcDir.getAbsolutePath(); String ddir=destDir.getAbsolutePath(); + boolean doReplace=!(sdir.equals(ddir)); int dlen=ddir.length(); String l; - StringBuffer lb; BufferedReader in=new BufferedReader(new StringReader(out.toString())); log("replacing destdir '"+ddir+"' through sourcedir '"+sdir+"'", Project.MSG_VERBOSE); while ((l=in.readLine())!=null) { - lb=new StringBuffer(l); int idx; - while ((idx=l.indexOf(ddir))!=-1) { // path is mentioned in the message - lb.replace(idx,idx+dlen,sdir); - l=lb.toString(); + while (doReplace && ((idx=l.indexOf(ddir))!=-1)) { // path is mentioned in the message + l=(new StringBuffer(l)).replace(idx,idx+dlen,sdir).toString(); } - if (l.indexOf("Error:")!=-1) { + // verbose level logging for suppressed messages + if (suppressMethodArgumentNotUsed && l.indexOf(MSG_METHOD_ARGUMENT_NOT_USED)!=-1) { + log(l, Project.MSG_VERBOSE); + } else if (suppressPrivatePropertyNotUsed && l.indexOf(MSG_PRIVATE_PROPERTY_NOT_USED)!=-1) { + log(l, Project.MSG_VERBOSE); + } else if (suppressVariableNotUsed && l.indexOf(MSG_VARIABLE_NOT_USED)!=-1) { + log(l, Project.MSG_VERBOSE); + } else if (suppressExceptionNotSignalled && l.indexOf(MSG_EXCEPTION_NOT_SIGNALLED)!=-1) { + log(l, Project.MSG_VERBOSE); + } else if (suppressDeprecation && l.indexOf(MSG_DEPRECATION)!=-1) { + log(l, Project.MSG_VERBOSE); + } else if (l.indexOf("Error:")!=-1) { // error level logging for compiler errors log(l, Project.MSG_ERR); - } else if (l.indexOf("Warning:")!=-1) { + } else if (l.indexOf("Warning:")!=-1) { // warning for all warning messages log(l, Project.MSG_WARN); } else { - log(l, Project.MSG_INFO); + log(l, Project.MSG_INFO); // info level for the rest. } } if (rc>1) { @@ -688,4 +876,18 @@ public class NetRexxC extends MatchingTask { } } + + public static class TraceAttr extends EnumeratedAttribute { + public String[] getValues() { + return new String[] {"trace", "trace1", "trace2", "notrace"}; + } + } + + public static class VerboseAttr extends EnumeratedAttribute { + public String[] getValues() { + return new String[] {"verbose", "verbose0", "verbose1", + "verbose2", "verbose3", "verbose4", + "verbose5", "noverbose"}; + } + } }