Browse Source

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 <bechtel@ipcon.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272194 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
7d0968a529
2 changed files with 270 additions and 30 deletions
  1. +49
    -11
      docs/manual/OptionalTasks/netrexxc.html
  2. +221
    -19
      src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java

+ 49
- 11
docs/manual/OptionalTasks/netrexxc.html View File

@@ -15,17 +15,17 @@ source tree within the running (Ant) VM.</p>
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.</p>
<p>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</p>
<p>The directory structure of the source tree should follow the package
hierarchy.</p>
<p>It is possible to refine the set of files that are being compiled/copied.
This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and
<i>defaultexcludes</i> attributes. With the <i>includes</i> or <i>includesfile</i> attribute you
specify the files you want to have included by using patterns. The
<i>exclude</i> or <i>excludesfile</i> attribute is used to specify the files you want to have
excluded. This is also done with patterns. And finally with the
<i>defaultexcludes</i> attributes. With the <i>includes</i> or <i>includesfile</i> attribute you
specify the files you want to have included by using patterns. The
<i>exclude</i> or <i>excludesfile</i> attribute is used to specify the files you want to have
excluded. This is also done with patterns. And finally with the
<i>defaultexcludes</i> attribute, you can specify whether you
want to use default exclusions or not. See the section on <a
href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
@@ -35,6 +35,12 @@ supports all attributes of <code>&lt;fileset&gt;</code>
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
<code>&lt;patternset&gt;</code> elements.</p>
<p>All properties except classpath, srcdir and destDir are also available as properties in the form
<code>ant.netrexxc.<i>attributename</i></code>, eg.<br>
<code>&lt;property name="ant.netrexxc.verbose" value="noverbose"/&gt;</code><br>
or from the command line as<br>
<code>ant -Dant.netrexxc.verbose=noverbose ...</code>
</p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
@@ -63,7 +69,7 @@ supports all attributes of <code>&lt;fileset&gt;</code>
<tr>
<td valign="top">compact</td>
<td valign="top">Whether error messages come out in compact or
verbose format</td>
verbose format. Default is the compact format.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
@@ -191,8 +197,8 @@ supports all attributes of <code>&lt;fileset&gt;</code>
<tr>
<td valign="top">strictargs</td>
<td valign="top">Tells the NetRexx compiler that method calls always
need parentheses, even if no arguments are needed, e.g.
<code>aStringVar.getBytes</code> vs.
need parentheses, even if no arguments are needed, e.g.
<code>aStringVar.getBytes</code> vs.
<code>aStringVar.getBytes()</code></td>
<td valign="top" align="center">No</td>
</tr>
@@ -210,8 +216,8 @@ supports all attributes of <code>&lt;fileset&gt;</code>
</tr>
<tr>
<td valign="top">strictimport</td>
<td valign="top">Whether classes need to be imported explicitly using an
<code>import</code> statement. By default the NetRexx compiler will
<td valign="top">Whether classes need to be imported explicitly using an
<code>import</code> statement. By default the NetRexx compiler will
import certain packages automatically</td>
<td valign="top" align="center">No</td>
</tr>
@@ -254,7 +260,39 @@ supports all attributes of <code>&lt;fileset&gt;</code>
<td valign="top">verbose</td>
<td valign="top">Whether lots of warnings and error messages should
be generated</td>
<td valign="top" align="center">Yes</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">suppressMethodArgumentNotUsed</td>
<td valign="top">Tells whether we should filter out the
&amp;Method argument not used&amp; messages in strictargs mode.</td>
<td valign="top" align="center">no</td>
</tr>
<tr>
<td valign="top">suppressPrivatePropertyNotUsed</td>
<td valign="top">Tells whether we should filter out the
&amp;Private Property defined, but not used&amp; messages in strictargs mode.</td>
<td valign="top" align="center">no</td>
</tr>
<tr>
<td valign="top">suppressVariableNotUsed</td>
<td valign="top">Tells whether we should filter out the
&amp;Variable set but not used&amp; messages in strictargs mode.
Please be careful with this one, as you can hide errors behind it!</td>
<td valign="top" align="center">no</td>
</tr>
<tr>
<td valign="top">suppressExceptionNotSignalled</td>
<td valign="top">Tells whether we should filter out the
&amp;Exception is declared, but not signalled within the method&amp;
messages in strictsignal mode.</td>
<td valign="top" align="center">no</td>
</tr>
<tr>
<td valign="top">suppressDeprecation</td>
<td valign="top">Tells wether we should filter out any deprecation-messages
of the compiler out.</td>
<td valign="top" align="center">no</td>
</tr>
</table>
<h3>Examples</h3>


+ 221
- 19
src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java View File

@@ -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;
* <li>trace</li>
* <li>utf8</li>
* <li>verbose</li>
* <li>suppressMethodArgumentNotUsed</li>
* <li>suppressPrivatePropertyNotUsed</li>
* <li>suppressVariableNotUsed</li>
* <li>suppressExceptionNotSignalled</li>
* <li>suppressDeprecation</li>
* </ul>
* Of these arguments, the <b>srcdir</b> 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"};
}
}
}

Loading…
Cancel
Save