Browse Source

Coding conventions

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274856 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
1f71acf427
33 changed files with 472 additions and 273 deletions
  1. +18
    -3
      src/main/org/apache/tools/ant/DemuxOutputStream.java
  2. +7
    -7
      src/main/org/apache/tools/ant/DirectoryScanner.java
  3. +4
    -4
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  4. +16
    -14
      src/main/org/apache/tools/ant/Main.java
  5. +2
    -2
      src/main/org/apache/tools/ant/PathTokenizer.java
  6. +2
    -1
      src/main/org/apache/tools/ant/Project.java
  7. +5
    -3
      src/main/org/apache/tools/ant/ProjectHelper.java
  8. +2
    -2
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  9. +5
    -5
      src/main/org/apache/tools/ant/Target.java
  10. +4
    -2
      src/main/org/apache/tools/ant/Task.java
  11. +14
    -7
      src/main/org/apache/tools/ant/TypeAdapter.java
  12. +4
    -5
      src/main/org/apache/tools/ant/UnknownElement.java
  13. +2
    -1
      src/main/org/apache/tools/ant/XmlLogger.java
  14. +2
    -2
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  15. +18
    -3
      src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java
  16. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
  17. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
  18. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java
  19. +167
    -87
      src/main/org/apache/tools/ant/taskdefs/optional/IContract.java
  20. +15
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/Javah.java
  21. +13
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java
  22. +35
    -22
      src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java
  23. +12
    -17
      src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
  24. +11
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
  25. +18
    -12
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  26. +19
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
  27. +8
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/Script.java
  28. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/StyleBook.java
  29. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  30. +32
    -27
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  31. +9
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java
  32. +10
    -10
      src/main/org/apache/tools/ant/types/optional/ScriptFilter.java
  33. +4
    -0
      src/main/org/apache/tools/ant/util/optional/WeakishReference12.java

+ 18
- 3
src/main/org/apache/tools/ant/DemuxOutputStream.java View File

@@ -92,6 +92,12 @@ public class DemuxOutputStream extends OutputStream {
/** Initial buffer size. */ /** Initial buffer size. */
private static final int INTIAL_SIZE = 132; private static final int INTIAL_SIZE = 132;


/** Carriage return */
private static final int CR = 0x0d;

/** Linefeed */
private static final int LF = 0x0a;

/** Mapping from thread to buffer (Thread to BufferInfo). */ /** Mapping from thread to buffer (Thread to BufferInfo). */
private Hashtable buffers = new Hashtable(); private Hashtable buffers = new Hashtable();


@@ -243,14 +249,23 @@ public class DemuxOutputStream extends OutputStream {
} }
} }


public void write(byte b[], int off, int len) throws IOException {
/**
* Write a block of characters to the output stream
*
* @param b the array containg the data
* @param off the offset into the array where data starts
* @param len the length of block
*
* @throws IOException if the data cannot be written into the stream.
*/
public void write(byte[] b, int off, int len) throws IOException {
// find the line breaks and pass other chars through in blocks // find the line breaks and pass other chars through in blocks
int offset = off; int offset = off;
int blockStartOffset = offset; int blockStartOffset = offset;
int remaining = len; int remaining = len;
BufferInfo bufferInfo = getBufferInfo(); BufferInfo bufferInfo = getBufferInfo();
while (remaining > 0) { while (remaining > 0) {
while (remaining > 0 && b[offset] != 0x0a && b[offset] != 0x0d) {
while (remaining > 0 && b[offset] != LF && b[offset] != CR) {
offset++; offset++;
remaining--; remaining--;
} }
@@ -259,7 +274,7 @@ public class DemuxOutputStream extends OutputStream {
if (blockLength > 0) { if (blockLength > 0) {
bufferInfo.buffer.write(b, blockStartOffset, blockLength); bufferInfo.buffer.write(b, blockStartOffset, blockLength);
} }
while (remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) {
while (remaining > 0 && (b[offset] == LF || b[offset] == CR)) {
write(b[offset]); write(b[offset]);
offset++; offset++;
remaining--; remaining--;


+ 7
- 7
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -655,7 +655,7 @@ public class DirectoryScanner
// put in the newroots vector the include patterns without // put in the newroots vector the include patterns without
// wildcard tokens // wildcard tokens
for (int icounter = 0; icounter < includes.length; icounter++) { for (int icounter = 0; icounter < includes.length; icounter++) {
String newpattern =
String newpattern =
SelectorUtils.rtrimWildcardTokens(includes[icounter]); SelectorUtils.rtrimWildcardTokens(includes[icounter]);
// check whether the candidate new pattern has a parent // check whether the candidate new pattern has a parent
boolean hasParent = false; boolean hasParent = false;
@@ -716,19 +716,19 @@ public class DirectoryScanner
} else { } else {
if (currentelement.length() > 0) { if (currentelement.length() > 0) {
if (currentelement.charAt(currentelement.length() if (currentelement.charAt(currentelement.length()
- 1)
- 1)
!= File.separatorChar) { != File.separatorChar) {
currentelement =
currentelement =
currentelement + File.separatorChar; currentelement + File.separatorChar;
} }
} }
scandir(myfile, currentelement, true); scandir(myfile, currentelement, true);
} }
} else { } else {
if (isCaseSensitive
if (isCaseSensitive
&& originalpattern.equals(currentelement)) { && originalpattern.equals(currentelement)) {
accountForIncludedFile(currentelement, myfile); accountForIncludedFile(currentelement, myfile);
} else if (!isCaseSensitive
} else if (!isCaseSensitive
&& originalpattern.equalsIgnoreCase(currentelement)) { && originalpattern.equalsIgnoreCase(currentelement)) {
accountForIncludedFile(currentelement, myfile); accountForIncludedFile(currentelement, myfile);
} }
@@ -1160,7 +1160,7 @@ public class DirectoryScanner
* @since Ant 1.6 * @since Ant 1.6
*/ */
private File findFileCaseInsensitive(File base, String path) { private File findFileCaseInsensitive(File base, String path) {
File f = findFileCaseInsensitive(base,
File f = findFileCaseInsensitive(base,
SelectorUtils.tokenizePath(path)); SelectorUtils.tokenizePath(path));
return f == null ? new File(base, path) : f; return f == null ? new File(base, path) : f;
} }
@@ -1211,7 +1211,7 @@ public class DirectoryScanner
* basedir? * basedir?
* @since Ant 1.6 * @since Ant 1.6
*/ */
private boolean isSymlink(File base, Vector pathElements) {
private boolean isSymlink(File base, Vector pathElements) {
if (pathElements.size() > 0) { if (pathElements.size() > 0) {
String current = (String) pathElements.remove(0); String current = (String) pathElements.remove(0);
try { try {


+ 4
- 4
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -502,8 +502,8 @@ public class IntrospectionHelper implements BuildListener {
return; return;
} else { } else {
// Not whitespace - fail // Not whitespace - fail
String msg = project.getElementName(element) +
" doesn't support nested text data.";
String msg = project.getElementName(element)
+ " doesn't support nested text data.";
throw new BuildException(msg); throw new BuildException(msg);
} }
} }
@@ -703,8 +703,8 @@ public class IntrospectionHelper implements BuildListener {
throws BuildException { throws BuildException {
Class at = (Class) attributeTypes.get(attributeName); Class at = (Class) attributeTypes.get(attributeName);
if (at == null) { if (at == null) {
String msg = "Class " + bean.getName() +
" doesn't support the \"" + attributeName + "\" attribute.";
String msg = "Class " + bean.getName()
+ " doesn't support the \"" + attributeName + "\" attribute.";
throw new BuildException(msg); throw new BuildException(msg);
} }
return at; return at;


+ 16
- 14
src/main/org/apache/tools/ant/Main.java View File

@@ -99,16 +99,16 @@ public class Main implements AntMain {
private static PrintStream err = System.err; private static PrintStream err = System.err;


/** The build targets. */ /** The build targets. */
private Vector targets = new Vector(5);
private Vector targets = new Vector();


/** Set of properties that can be used by tasks. */ /** Set of properties that can be used by tasks. */
private Properties definedProps = new Properties(); private Properties definedProps = new Properties();


/** Names of classes to add as listeners to project. */ /** Names of classes to add as listeners to project. */
private Vector listeners = new Vector(5);
private Vector listeners = new Vector(1);


/** File names of property files to load on startup. */ /** File names of property files to load on startup. */
private Vector propertyFiles = new Vector(5);
private Vector propertyFiles = new Vector(1);


/** Indicates whether this build is to support interactive input */ /** Indicates whether this build is to support interactive input */
private boolean allowInput = true; private boolean allowInput = true;
@@ -334,8 +334,8 @@ public class Main implements AntMain {
+ "permissions."; + "permissions.";
throw new BuildException(msg); throw new BuildException(msg);
} catch (ArrayIndexOutOfBoundsException aioobe) { } catch (ArrayIndexOutOfBoundsException aioobe) {
String msg = "You must specify a log file when " +
"using the -log argument";
String msg = "You must specify a log file when "
+ "using the -log argument";
throw new BuildException(msg); throw new BuildException(msg);
} }
} else if (arg.equals("-buildfile") || arg.equals("-file") } else if (arg.equals("-buildfile") || arg.equals("-file")
@@ -344,8 +344,8 @@ public class Main implements AntMain {
buildFile = new File(args[i + 1].replace('/', File.separatorChar)); buildFile = new File(args[i + 1].replace('/', File.separatorChar));
i++; i++;
} catch (ArrayIndexOutOfBoundsException aioobe) { } catch (ArrayIndexOutOfBoundsException aioobe) {
String msg = "You must specify a buildfile when " +
"using the -buildfile argument";
String msg = "You must specify a buildfile when "
+ "using the -buildfile argument";
throw new BuildException(msg); throw new BuildException(msg);
} }
} else if (arg.equals("-listener")) { } else if (arg.equals("-listener")) {
@@ -353,8 +353,8 @@ public class Main implements AntMain {
listeners.addElement(args[i + 1]); listeners.addElement(args[i + 1]);
i++; i++;
} catch (ArrayIndexOutOfBoundsException aioobe) { } catch (ArrayIndexOutOfBoundsException aioobe) {
String msg = "You must specify a classname when " +
"using the -listener argument";
String msg = "You must specify a classname when "
+ "using the -listener argument";
throw new BuildException(msg); throw new BuildException(msg);
} }
} else if (arg.startsWith("-D")) { } else if (arg.startsWith("-D")) {
@@ -421,8 +421,8 @@ public class Main implements AntMain {
propertyFiles.addElement(args[i + 1]); propertyFiles.addElement(args[i + 1]);
i++; i++;
} catch (ArrayIndexOutOfBoundsException aioobe) { } catch (ArrayIndexOutOfBoundsException aioobe) {
String msg = "You must specify a property filename when " +
"using the -propertyfile argument";
String msg = "You must specify a property filename when "
+ "using the -propertyfile argument";
throw new BuildException(msg); throw new BuildException(msg);
} }
} else if (arg.equals("-k") || arg.equals("-keep-going")) { } else if (arg.equals("-k") || arg.equals("-keep-going")) {
@@ -483,6 +483,7 @@ public class Main implements AntMain {
try { try {
fis.close(); fis.close();
} catch (IOException e) { } catch (IOException e) {
// ignore
} }
} }
} }
@@ -502,7 +503,8 @@ public class Main implements AntMain {
} }


if (logTo != null) { if (logTo != null) {
out = err = logTo;
out = logTo;
err = logTo;
System.setOut(out); System.setOut(out);
System.setErr(out); System.setErr(out);
} }
@@ -605,8 +607,8 @@ public class Main implements AntMain {
// use a system manager that prevents from System.exit() // use a system manager that prevents from System.exit()
// only in JDK > 1.1 // only in JDK > 1.1
SecurityManager oldsm = null; SecurityManager oldsm = null;
if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0) &&
!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0)
&& !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
oldsm = System.getSecurityManager(); oldsm = System.getSecurityManager();


//SecurityManager can not be installed here for backwards //SecurityManager can not be installed here for backwards


+ 2
- 2
src/main/org/apache/tools/ant/PathTokenizer.java View File

@@ -176,8 +176,8 @@ public class PathTokenizer {
// make sure we aren't going to get the path separator next // make sure we aren't going to get the path separator next
if (!nextToken.equals(File.pathSeparator)) { if (!nextToken.equals(File.pathSeparator)) {
if (nextToken.equals(":")) { if (nextToken.equals(":")) {
if (!token.startsWith("/") && !token.startsWith("\\")
&& !token.startsWith(".")
if (!token.startsWith("/") && !token.startsWith("\\")
&& !token.startsWith(".")
&& !token.startsWith("..")) { && !token.startsWith("..")) {
// it indeed is a drive spec, get the next bit // it indeed is a drive spec, get the next bit
String oneMore = tokenizer.nextToken().trim(); String oneMore = tokenizer.nextToken().trim();


+ 2
- 1
src/main/org/apache/tools/ant/Project.java View File

@@ -2029,7 +2029,8 @@ public class Project {
// Should move to a separate public class - and have API to add // Should move to a separate public class - and have API to add
// listeners, etc. // listeners, etc.
private static class AntRefTable extends Hashtable { private static class AntRefTable extends Hashtable {
Project project;
private Project project;

public AntRefTable(Project project) { public AntRefTable(Project project) {
super(); super();
this.project = project; this.project = project;


+ 5
- 3
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -132,7 +132,7 @@ public class ProjectHelper {
// Since the tree is composed of UE and RC - it can be reused ! // Since the tree is composed of UE and RC - it can be reused !
// protected Hashtable processedFiles=new Hashtable(); // protected Hashtable processedFiles=new Hashtable();


protected Vector importStack = new Vector();
private Vector importStack = new Vector();


// Temporary - until we figure a better API // Temporary - until we figure a better API
/** EXPERIMENTAL WILL_CHANGE /** EXPERIMENTAL WILL_CHANGE
@@ -146,6 +146,8 @@ public class ProjectHelper {
* Import stack. * Import stack.
* Used to keep track of imported files. Error reporting should * Used to keep track of imported files. Error reporting should
* display the import path. * display the import path.
*
* @return the stack of import source objects.
*/ */
public Vector getImportStack() { public Vector getImportStack() {
return importStack; return importStack;
@@ -229,8 +231,8 @@ public class ProjectHelper {
String helperClassName = rd.readLine(); String helperClassName = rd.readLine();
rd.close(); rd.close();


if (helperClassName != null &&
!"".equals(helperClassName)) {
if (helperClassName != null
&& !"".equals(helperClassName)) {


helper = newHelper(helperClassName); helper = newHelper(helperClassName);
} }


+ 2
- 2
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -349,8 +349,8 @@ public class RuntimeConfigurable implements Serializable {
} }


// Configure the object // Configure the object
Object target = (wrappedObject instanceof TypeAdapter) ?
((TypeAdapter) wrappedObject).getProxy() : wrappedObject;
Object target = (wrappedObject instanceof TypeAdapter)
? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject;


//PropertyHelper ph=PropertyHelper.getPropertyHelper(p); //PropertyHelper ph=PropertyHelper.getPropertyHelper(p);
IntrospectionHelper ih = IntrospectionHelper ih =


+ 5
- 5
src/main/org/apache/tools/ant/Target.java View File

@@ -77,12 +77,12 @@ public class Target implements TaskContainer {
/** The "unless" condition to test on execution. */ /** The "unless" condition to test on execution. */
private String unlessCondition = ""; private String unlessCondition = "";
/** List of targets this target is dependent on. */ /** List of targets this target is dependent on. */
private List/*<String>*/ dependencies = null;
private List dependencies = null;
/** Children of this target (tasks and data types). */ /** Children of this target (tasks and data types). */
private List/*<Task|RuntimeConfigurable>*/ children = new ArrayList(5);
private List children = new ArrayList();
/** Position in task list */ /** Position in task list */
private int taskPosition = 0; private int taskPosition = 0;
/** Project this target belongs to. */ /** Project this target belongs to. */
private Project project; private Project project;
/** Description of this target, if any. */ /** Description of this target, if any. */
@@ -180,7 +180,7 @@ public class Target implements TaskContainer {
public void startImportedTasks() { public void startImportedTasks() {
importedTasks = new ArrayList(); importedTasks = new ArrayList();
} }
/** /**
* Adds a task to this target. * Adds a task to this target.
* *
@@ -228,7 +228,7 @@ public class Target implements TaskContainer {
} }
} }


return (Task[])tasks.toArray(new Task[tasks.size()]);
return (Task[]) tasks.toArray(new Task[tasks.size()]);
} }


/** /**


+ 4
- 2
src/main/org/apache/tools/ant/Task.java View File

@@ -204,7 +204,8 @@ public abstract class Task extends ProjectComponent {
* *
* @exception BuildException if someting goes wrong with the build * @exception BuildException if someting goes wrong with the build
*/ */
public void init() throws BuildException {}
public void init() throws BuildException {
}


/** /**
* Called by the project to let the task do its work. This method may be * Called by the project to let the task do its work. This method may be
@@ -215,7 +216,8 @@ public abstract class Task extends ProjectComponent {
* *
* @exception BuildException if something goes wrong with the build * @exception BuildException if something goes wrong with the build
*/ */
public void execute() throws BuildException {}
public void execute() throws BuildException {
}


/** /**
* Returns the file/location where this task was defined. * Returns the file/location where this task was defined.


+ 14
- 7
src/main/org/apache/tools/ant/TypeAdapter.java View File

@@ -60,17 +60,21 @@ package org.apache.tools.ant;
* @author costin@dnt.ro * @author costin@dnt.ro
* @author peter reilly * @author peter reilly
*/ */
public interface TypeAdapter {
public interface TypeAdapter {


/** /**
* Sets the project * Sets the project
*
* @param p the project instance.
*/ */
public void setProject(Project p);
void setProject(Project p);


/** /**
* Gets the project * Gets the project
*
* @return the project instance.
*/ */
public Project getProject();
Project getProject();


/** /**
* Sets the proxy object, whose methods are going to be * Sets the proxy object, whose methods are going to be
@@ -81,17 +85,20 @@ public interface TypeAdapter {
* *
* @param o The target object. Must not be <code>null</code>. * @param o The target object. Must not be <code>null</code>.
*/ */
public void setProxy(Object o);
void setProxy(Object o);


/** /**
* Returns the proxy object. * Returns the proxy object.
* *
* @return the target proxy object * @return the target proxy object
*/ */
public Object getProxy();
Object getProxy();


/** /**
* Check if the proxy class matchs the criteria
* Check if the proxy class is compatible with this adapter - i.e.
* the adapter will be able to adapt instances of the give class.
*
* @patam proxyClass the class to be checked.
*/ */
public void checkProxyClass(Class proxyClass);
void checkProxyClass(Class proxyClass);
} }

+ 4
- 5
src/main/org/apache/tools/ant/UnknownElement.java View File

@@ -439,8 +439,9 @@ public class UnknownElement extends Task {
*/ */
public String getTaskName() { public String getTaskName() {
//return elementName; //return elementName;
return realThing == null || !(realThing instanceof Task) ?
super.getTaskName() : ((Task) realThing).getTaskName();
return realThing == null
|| !(realThing instanceof Task) ? super.getTaskName()
: ((Task) realThing).getTaskName();
} }


/** /**
@@ -481,6 +482,4 @@ public class UnknownElement extends Task {
} }
return false; return false;
} }


}// UnknownElement
}

+ 2
- 1
src/main/org/apache/tools/ant/XmlLogger.java View File

@@ -92,7 +92,7 @@ public class XmlLogger implements BuildLogger {
private PrintStream outStream; private PrintStream outStream;


/** DocumentBuilder to use when creating the document to start with. */ /** DocumentBuilder to use when creating the document to start with. */
private static final DocumentBuilder builder = getDocumentBuilder();
private static DocumentBuilder builder = getDocumentBuilder();


/** /**
* Returns a default DocumentBuilder instance or throws an * Returns a default DocumentBuilder instance or throws an
@@ -230,6 +230,7 @@ public class XmlLogger implements BuildLogger {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
// ignore
} }
} }
} }


+ 2
- 2
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -104,7 +104,7 @@ public class ProjectHelper2 extends ProjectHelper {


public void parse(Project project, Object source) public void parse(Project project, Object source)
throws BuildException { throws BuildException {
this.getImportStack().addElement(source);
getImportStack().addElement(source);
//System.out.println("Adding " + source); //System.out.println("Adding " + source);
AntXMLContext context = null; AntXMLContext context = null;
context = (AntXMLContext) project.getReference("ant.parsing.context"); context = (AntXMLContext) project.getReference("ant.parsing.context");
@@ -116,7 +116,7 @@ public class ProjectHelper2 extends ProjectHelper {
project.addReference("ant.targets", context.getTargets()); project.addReference("ant.targets", context.getTargets());
} }


if (this.getImportStack().size() > 1) {
if (getImportStack().size() > 1) {
// we are in an imported file. // we are in an imported file.
context.setIgnoreProjectTag(true); context.setIgnoreProjectTag(true);
context.getCurrentTarget().startImportedTasks(); context.getCurrentTarget().startImportedTasks();


+ 18
- 3
src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java View File

@@ -76,6 +76,12 @@ public class LogOutputStream extends OutputStream {
/** Initial buffer size. */ /** Initial buffer size. */
private static final int INTIAL_SIZE = 132; private static final int INTIAL_SIZE = 132;


/** Carriage return */
private static final int CR = 0x0d;

/** Linefeed */
private static final int LF = 0x0a;

private ByteArrayOutputStream buffer private ByteArrayOutputStream buffer
= new ByteArrayOutputStream(INTIAL_SIZE); = new ByteArrayOutputStream(INTIAL_SIZE);
private boolean skip = false; private boolean skip = false;
@@ -162,13 +168,22 @@ public class LogOutputStream extends OutputStream {
return level; return level;
} }


public void write(byte b[], int off, int len) throws IOException {
/**
* Write a block of characters to the output stream
*
* @param b the array containg the data
* @param off the offset into the array where data starts
* @param len the length of block
*
* @throws IOException if the data cannot be written into the stream.
*/
public void write(byte[] b, int off, int len) throws IOException {
// find the line breaks and pass other chars through in blocks // find the line breaks and pass other chars through in blocks
int offset = off; int offset = off;
int blockStartOffset = offset; int blockStartOffset = offset;
int remaining = len; int remaining = len;
while (remaining > 0) { while (remaining > 0) {
while (remaining > 0 && b[offset] != 0x0a && b[offset] != 0x0d) {
while (remaining > 0 && b[offset] != LF && b[offset] != CR) {
offset++; offset++;
remaining--; remaining--;
} }
@@ -177,7 +192,7 @@ public class LogOutputStream extends OutputStream {
if (blockLength > 0) { if (blockLength > 0) {
buffer.write(b, blockStartOffset, blockLength); buffer.write(b, blockStartOffset, blockLength);
} }
while (remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) {
while (remaining > 0 && (b[offset] == LF || b[offset] == CR)) {
write(b[offset]); write(b[offset]);
offset++; offset++;
remaining--; remaining--;


+ 2
- 0
src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java View File

@@ -298,6 +298,7 @@ public class ANTLR extends Task {


public void execute() throws BuildException { public void execute() throws BuildException {
validateAttributes(); validateAttributes();

//TODO: use ANTLR to parse the grammar file to do this. //TODO: use ANTLR to parse the grammar file to do this.
File generatedFile = getGeneratedFile(); File generatedFile = getGeneratedFile();
boolean targetIsOutOfDate = boolean targetIsOutOfDate =
@@ -437,6 +438,7 @@ public class ANTLR extends Task {
/** /**
* Whether the antlr version is 2.7.2 (or higher). * Whether the antlr version is 2.7.2 (or higher).
* *
* @return true if the version of Antlr present is 2.7.2 or later.
* @since Ant 1.6 * @since Ant 1.6
*/ */
protected boolean is272() { protected boolean is272() {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -177,8 +177,8 @@ public class Cab extends MatchingTask {
boolean upToDate = true; boolean upToDate = true;
for (int i = 0; i < files.size() && upToDate; i++) { for (int i = 0; i < files.size() && upToDate; i++) {
String file = files.elementAt(i).toString(); String file = files.elementAt(i).toString();
if (fileUtils.resolveFile(baseDir, file).lastModified() >
cabFile.lastModified()) {
if (fileUtils.resolveFile(baseDir, file).lastModified()
> cabFile.lastModified()) {
upToDate = false; upToDate = false;
} }
} }


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java View File

@@ -296,7 +296,9 @@ public class EchoProperties extends Task {
if (null != in) { if (null != in) {
in.close(); in.close();
} }
} catch (IOException ioe) {}
} catch (IOException ioe) {
//ignore
}
} }
} }


@@ -347,6 +349,7 @@ public class EchoProperties extends Task {
try { try {
os.close(); os.close();
} catch (IOException e) { } catch (IOException e) {
//ignore
} }
} }
} }
@@ -390,7 +393,7 @@ public class EchoProperties extends Task {
String name; String name;
Enumeration e = props.propertyNames(); Enumeration e = props.propertyNames();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
name = (String)e.nextElement();
name = (String) e.nextElement();
Element propElement = doc.createElement(PROPERTY); Element propElement = doc.createElement(PROPERTY);
propElement.setAttribute(ATTR_NAME, name); propElement.setAttribute(ATTR_NAME, name);
propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); propElement.setAttribute(ATTR_VALUE, props.getProperty(name));


+ 167
- 87
src/main/org/apache/tools/ant/taskdefs/optional/IContract.java View File

@@ -53,8 +53,6 @@
*/ */
package org.apache.tools.ant.taskdefs.optional; package org.apache.tools.ant.taskdefs.optional;




import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -84,7 +82,8 @@ import org.apache.tools.ant.types.Reference;
* iControl generates a control file that you can refer to * iControl generates a control file that you can refer to
* from this task using the controlfile attribute. * from this task using the controlfile attribute.
* iContract is at * iContract is at
* <a href="http://www.reliable-systems.com/tools/">http://www.reliable-systems.com/tools/</a>
* <a href="http://www.reliable-systems.com/tools/">
* http://www.reliable-systems.com/tools/</a>
* <p/> * <p/>
* Thanks to Rainer Schmitz for enhancements and comments. * Thanks to Rainer Schmitz for enhancements and comments.
* *
@@ -104,55 +103,63 @@ import org.apache.tools.ant.types.Reference;
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">instrumentdir</td> * <td valign="top">instrumentdir</td>
* <td valign="top">Indicates where the instrumented source files should go.</td>
* <td valign="top">Indicates where the instrumented source
* files should go.</td>
* <td valign="top" align="center">Yes</td> * <td valign="top" align="center">Yes</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">repositorydir</td> * <td valign="top">repositorydir</td>
* <td valign="top">Indicates where the repository source files should go.</td>
* <td valign="top">Indicates where the repository source
* files should go.</td>
* <td valign="top" align="center">Yes</td> * <td valign="top" align="center">Yes</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">builddir</td> * <td valign="top">builddir</td>
* <td valign="top">Indicates where the compiled instrumented classes should go.
* Defaults to the value of instrumentdir.
* <td valign="top">Indicates where the compiled instrumented
* classes should go. Defaults to the value of
* instrumentdir.
* </p> * </p>
* <em>NOTE:</em> Don't use the same directory for compiled instrumented classes
* and uninstrumented classes. It will break the dependency checking. (Classes will
* not be reinstrumented if you change them).</td>
* <em>NOTE:</em> Don't use the same directory for compiled
* instrumented classes and uninstrumented classes. It will break the
* dependency checking. (Classes will not be reinstrumented if you
* change them).</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">repbuilddir</td> * <td valign="top">repbuilddir</td>
* <td valign="top">Indicates where the compiled repository classes should go.
* Defaults to the value of repositorydir.</td>
* <td valign="top">Indicates where the compiled repository classes
* should go. Defaults to the value of repositorydir.</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">pre</td> * <td valign="top">pre</td>
* <td valign="top">Indicates whether or not to instrument for preconditions.
* Defaults to <code>true</code> unless controlfile is specified, in which case it
* defaults to <code>false</code>.</td>
* <td valign="top">Indicates whether or not to instrument for
* preconditions. Defaults to <code>true</code> unless
* controlfile is specified, in which case it defaults
* to <code>false</code>.</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">post</td> * <td valign="top">post</td>
* <td valign="top">Indicates whether or not to instrument for postconditions.
* Defaults to <code>true</code> unless controlfile is specified, in which case it
* defaults to <code>false</code>.</td>
* <td valign="top">Indicates whether or not to instrument for
* postconditions. Defaults to <code>true</code> unless
* controlfile is specified, in which case it defaults
* to <code>false</code>.</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">invariant</td> * <td valign="top">invariant</td>
* <td valign="top">Indicates whether or not to instrument for invariants. * <td valign="top">Indicates whether or not to instrument for invariants.
* Defaults to <code>true</code> unless controlfile is specified, in which case it
* defaults to <code>false</code>.</td>
* Defaults to <code>true</code> unless controlfile is
* specified, in which case it defaults to
* <code>false</code>.</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">failthrowable</td> * <td valign="top">failthrowable</td>
* <td valign="top">The full name of the Throwable (Exception) that should be
* thrown when an assertion is violated. Defaults to <code>java.lang.Error</code></td>
* <td valign="top">The full name of the Throwable (Exception) that
* should be thrown when an assertion is violated.
* Defaults to <code>java.lang.Error</code></td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* <tr> * <tr>
@@ -180,22 +187,28 @@ import org.apache.tools.ant.types.Reference;
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">controlfile</td> * <td valign="top">controlfile</td>
* <td valign="top">The name of the control file to pass to iContract. Consider using iControl to generate the file.
* Default is not to pass a file. </td>
* <td valign="top" align="center">Only if <code>updateicontrol=true</code></td>
* <td valign="top">The name of the control file to pass to iContract.
* Consider using iControl to generate the file.
* Default is not to pass a file. </td>
* <td valign="top" align="center">
* Only if <code>updateicontrol=true</code></td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">classdir</td> * <td valign="top">classdir</td>
* <td valign="top">Indicates where compiled (unistrumented) classes are located.
* This is required in order to properly update the icontrol.properties file, not
* for instrumentation.</td>
* <td valign="top" align="center">Only if <code>updateicontrol=true</code></td>
* <td valign="top">Indicates where compiled (unistrumented) classes are
* located. This is required in order to properly update
* the icontrol.properties file, not for instrumentation.
* </td>
* <td valign="top" align="center">Only if
* <code>updateicontrol=true</code></td>
* </tr> * </tr>
* <tr> * <tr>
* <td valign="top">targets</td> * <td valign="top">targets</td>
* <td valign="top">Name of the file that will be generated by this task, which lists all the
* classes that iContract will instrument. If specified, the file will not be deleted after execution.
* If not specified, a file will still be created, but it will be deleted after execution.</td>
* <td valign="top">Name of the file that will be generated by this task,
* which lists all the classes that iContract will
* instrument. If specified, the file will not be deleted
* after execution. If not specified, a file will still
* be created, but it will be deleted after execution.</td>
* <td valign="top" align="center">No</td> * <td valign="top" align="center">No</td>
* </tr> * </tr>
* </table> * </table>
@@ -228,8 +241,9 @@ import org.apache.tools.ant.types.Reference;
*/ */
public class IContract extends MatchingTask { public class IContract extends MatchingTask {


private static final String ICONTROL_PROPERTIES_HEADER =
" You might want to set classRoot to point to your normal compilation class root directory.";
private static final String ICONTROL_PROPERTIES_HEADER
= "You might want to set classRoot to point to your normal "
+ "compilation class root directory.";


/** compiler to use for instrumenation */ /** compiler to use for instrumenation */
private String icCompiler = "javac"; private String icCompiler = "javac";
@@ -288,8 +302,12 @@ public class IContract extends MatchingTask {
private boolean invariant = true; private boolean invariant = true;
private boolean invariantModified = false; private boolean invariantModified = false;


/** Indicates whether or not to instrument all files regardless of timestamp */
// can't be explicitly set, is set if control file exists and is newer than any source file
/**
* Indicates whether or not to instrument all files regardless of timestamp
*
* Can't be explicitly set, is set if control file exists and is newer
* than any source file
*/
private boolean instrumentall = false; private boolean instrumentall = false;


/** /**
@@ -534,13 +552,14 @@ public class IContract extends MatchingTask {
} }




// We want to be notified if iContract jar is missing. This makes life easier for the user
// who didn't understand that iContract is a separate library (duh!)
// We want to be notified if iContract jar is missing.
// This makes life easier for the user who didn't understand
// that iContract is a separate library (duh!)
getProject().addBuildListener(new IContractPresenceDetector()); getProject().addBuildListener(new IContractPresenceDetector());


// Prepare the directories for iContract. iContract will make them if they
// don't exist, but for some reason I don't know, it will complain about the REP files
// afterwards
// Prepare the directories for iContract. iContract will make
// them if they don't exist, but for some reason I don't know,
// it will complain about the REP files afterwards
Mkdir mkdir = (Mkdir) getProject().createTask("mkdir"); Mkdir mkdir = (Mkdir) getProject().createTask("mkdir");


mkdir.setDir(instrumentDir); mkdir.setDir(instrumentDir);
@@ -553,42 +572,60 @@ public class IContract extends MatchingTask {
// Set the classpath that is needed for regular Javac compilation // Set the classpath that is needed for regular Javac compilation
Path baseClasspath = createClasspath(); Path baseClasspath = createClasspath();


// Might need to add the core classes if we're not using Sun's Javac (like Jikes)
// Might need to add the core classes if we're not using
// Sun's Javac (like Jikes)
String compiler = getProject().getProperty("build.compiler"); String compiler = getProject().getProperty("build.compiler");
ClasspathHelper classpathHelper = new ClasspathHelper(compiler); ClasspathHelper classpathHelper = new ClasspathHelper(compiler);


classpathHelper.modify(baseClasspath); classpathHelper.modify(baseClasspath);


// Create the classpath required to compile the sourcefiles BEFORE instrumentation
// Create the classpath required to compile the sourcefiles
// BEFORE instrumentation
Path beforeInstrumentationClasspath = ((Path) baseClasspath.clone()); Path beforeInstrumentationClasspath = ((Path) baseClasspath.clone());


beforeInstrumentationClasspath.append(new Path(getProject(), beforeInstrumentationClasspath.append(new Path(getProject(),
srcDir.getAbsolutePath())); srcDir.getAbsolutePath()));


// Create the classpath required to compile the sourcefiles AFTER instrumentation
// Create the classpath required to compile the sourcefiles
// AFTER instrumentation
Path afterInstrumentationClasspath = ((Path) baseClasspath.clone()); Path afterInstrumentationClasspath = ((Path) baseClasspath.clone());


afterInstrumentationClasspath.append(new Path(getProject(), instrumentDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(), repositoryDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(), srcDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(), buildDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(),
instrumentDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(),
repositoryDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(),
srcDir.getAbsolutePath()));
afterInstrumentationClasspath.append(new Path(getProject(),
buildDir.getAbsolutePath()));


// Create the classpath required to automatically compile the repository files
// Create the classpath required to automatically compile the
// repository files
Path repositoryClasspath = ((Path) baseClasspath.clone()); Path repositoryClasspath = ((Path) baseClasspath.clone());


repositoryClasspath.append(new Path(getProject(), instrumentDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(), srcDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(), repositoryDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(), buildDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(),
instrumentDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(),
srcDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(),
repositoryDir.getAbsolutePath()));
repositoryClasspath.append(new Path(getProject(),
buildDir.getAbsolutePath()));


// Create the classpath required for iContract itself // Create the classpath required for iContract itself
Path iContractClasspath = ((Path) baseClasspath.clone()); Path iContractClasspath = ((Path) baseClasspath.clone());


iContractClasspath.append(new Path(getProject(), System.getProperty("java.home") + File.separator + ".." + File.separator + "lib" + File.separator + "tools.jar"));
iContractClasspath.append(new Path(getProject(), srcDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(), repositoryDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(), instrumentDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(), buildDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(),
System.getProperty("java.home") + File.separator + ".."
+ File.separator + "lib" + File.separator + "tools.jar"));
iContractClasspath.append(new Path(getProject(),
srcDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(),
repositoryDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(),
instrumentDir.getAbsolutePath()));
iContractClasspath.append(new Path(getProject(),
buildDir.getAbsolutePath()));


// Create a forked java process // Create a forked java process
Java iContract = (Java) getProject().createTask("java"); Java iContract = (Java) getProject().createTask("java");
@@ -603,18 +640,36 @@ public class IContract extends MatchingTask {


args.append(directiveString()); args.append(directiveString());
args.append("-v").append(verbosity).append(" "); args.append("-v").append(verbosity).append(" ");
args.append("-b").append("\"").append(icCompiler).append(" -classpath ").append(beforeInstrumentationClasspath).append("\" ");
args.append("-c").append("\"").append(icCompiler).append(" -classpath ").append(afterInstrumentationClasspath).append(" -d ").append(buildDir).append("\" ");
args.append("-n").append("\"").append(icCompiler).append(" -classpath ").append(repositoryClasspath).append("\" ");

args.append("-b").append("\"").append(icCompiler);
args.append(" -classpath ").append(beforeInstrumentationClasspath);
args.append("\" ");

args.append("-c").append("\"").append(icCompiler);
args.append(" -classpath ").append(afterInstrumentationClasspath);
args.append(" -d ").append(buildDir).append("\" ");

args.append("-n").append("\"").append(icCompiler);
args.append(" -classpath ").append(repositoryClasspath);
args.append("\" ");

args.append("-d").append(failThrowable).append(" "); args.append("-d").append(failThrowable).append(" ");
args.append("-o").append(instrumentDir).append(File.separator).append("@p").append(File.separator).append("@f.@e ");
args.append("-k").append(repositoryDir).append(File.separator).append("@p ");

args.append("-o").append(instrumentDir).append(File.separator);
args.append("@p").append(File.separator).append("@f.@e ");

args.append("-k").append(repositoryDir).append(File.separator);
args.append("@p ");

args.append(quiet ? "-q " : ""); args.append(quiet ? "-q " : "");
args.append(instrumentall ? "-a " : "");// reinstrument everything if controlFile exists and is newer than any class
// reinstrument everything if controlFile exists and is newer
// than any class
args.append(instrumentall ? "-a " : "");
args.append("@").append(targets.getAbsolutePath()); args.append("@").append(targets.getAbsolutePath());
iContract.createArg().setLine(args.toString()); iContract.createArg().setLine(args.toString());


//System.out.println( "JAVA -classpath " + iContractClasspath + " com.reliablesystems.iContract.Tool " + args.toString() );
//System.out.println( "JAVA -classpath " + iContractClasspath
// + " com.reliablesystems.iContract.Tool " + args.toString() );


// update iControlProperties if it's set. // update iControlProperties if it's set.
if (updateIcontrol) { if (updateIcontrol) {
@@ -624,17 +679,24 @@ public class IContract extends MatchingTask {
// to read existing propertiesfile // to read existing propertiesfile
iControlProps.load(new FileInputStream("icontrol.properties")); iControlProps.load(new FileInputStream("icontrol.properties"));
} catch (IOException e) { } catch (IOException e) {
log("File icontrol.properties not found. That's ok. Writing a default one.");
log("File icontrol.properties not found. That's ok. "
+ "Writing a default one.");
} }
iControlProps.setProperty("sourceRoot", srcDir.getAbsolutePath());
iControlProps.setProperty("classRoot", classDir.getAbsolutePath());
iControlProps.setProperty("classpath", afterInstrumentationClasspath.toString());
iControlProps.setProperty("controlFile", controlFile.getAbsolutePath());
iControlProps.setProperty("targetsFile", targets.getAbsolutePath());
iControlProps.setProperty("sourceRoot",
srcDir.getAbsolutePath());
iControlProps.setProperty("classRoot",
classDir.getAbsolutePath());
iControlProps.setProperty("classpath",
afterInstrumentationClasspath.toString());
iControlProps.setProperty("controlFile",
controlFile.getAbsolutePath());
iControlProps.setProperty("targetsFile",
targets.getAbsolutePath());


try { try {
// to read existing propertiesfile // to read existing propertiesfile
iControlProps.store(new FileOutputStream("icontrol.properties"), ICONTROL_PROPERTIES_HEADER);
iControlProps.store(new FileOutputStream("icontrol.properties"),
ICONTROL_PROPERTIES_HEADER);
log("Updated icontrol.properties"); log("Updated icontrol.properties");
} catch (IOException e) { } catch (IOException e) {
log("Couldn't write icontrol.properties."); log("Couldn't write icontrol.properties.");
@@ -646,11 +708,14 @@ public class IContract extends MatchingTask {


if (result != 0) { if (result != 0) {
if (iContractMissing) { if (iContractMissing) {
log("iContract can't be found on your classpath. Your classpath is:");
log("iContract can't be found on your classpath. "
+ "Your classpath is:");
log(classpath.toString()); log(classpath.toString());
log("If you don't have the iContract jar, go get it at http://www.reliable-systems.com/tools/");
log("If you don't have the iContract jar, go get it at "
+ "http://www.reliable-systems.com/tools/");
} }
throw new BuildException("iContract instrumentation failed. Code=" + result);
throw new BuildException("iContract instrumentation failed. "
+ "Code = " + result);
} }
} else { } else {
// not dirty // not dirty
@@ -662,22 +727,28 @@ public class IContract extends MatchingTask {
/** Checks that the required attributes are set. */ /** Checks that the required attributes are set. */
private void preconditions() throws BuildException { private void preconditions() throws BuildException {
if (srcDir == null) { if (srcDir == null) {
throw new BuildException("srcdir attribute must be set!", getLocation());
throw new BuildException("srcdir attribute must be set!",
getLocation());
} }
if (!srcDir.exists()) { if (!srcDir.exists()) {
throw new BuildException("srcdir \"" + srcDir.getPath() + "\" does not exist!", getLocation());
throw new BuildException("srcdir \"" + srcDir.getPath()
+ "\" does not exist!", getLocation());
} }
if (instrumentDir == null) { if (instrumentDir == null) {
throw new BuildException("instrumentdir attribute must be set!", getLocation());
throw new BuildException("instrumentdir attribute must be set!",
getLocation());
} }
if (repositoryDir == null) { if (repositoryDir == null) {
throw new BuildException("repositorydir attribute must be set!", getLocation());
throw new BuildException("repositorydir attribute must be set!",
getLocation());
} }
if (updateIcontrol && classDir == null) { if (updateIcontrol && classDir == null) {
throw new BuildException("classdir attribute must be specified when updateicontrol=true!", getLocation());
throw new BuildException("classdir attribute must be specified "
+ "when updateicontrol=true!", getLocation());
} }
if (updateIcontrol && controlFile == null) { if (updateIcontrol && controlFile == null) {
throw new BuildException("controlfile attribute must be specified when updateicontrol=true!", getLocation());
throw new BuildException("controlfile attribute must be specified "
+ "when updateicontrol=true!", getLocation());
} }
} }


@@ -706,10 +777,12 @@ public class IContract extends MatchingTask {
try { try {
if (targets == null) { if (targets == null) {
targets = new File("targets"); targets = new File("targets");
log("Warning: targets file not specified. generating file: " + targets.getName());
log("Warning: targets file not specified. generating file: "
+ targets.getName());
writeTargets = true; writeTargets = true;
} else if (!targets.exists()) { } else if (!targets.exists()) {
log("Specified targets file doesn't exist. generating file: " + targets.getName());
log("Specified targets file doesn't exist. generating file: "
+ targets.getName());
writeTargets = true; writeTargets = true;
} }
if (writeTargets) { if (writeTargets) {
@@ -733,7 +806,9 @@ public class IContract extends MatchingTask {
} }


if (!classFile.exists() || srcFile.lastModified() > classFile.lastModified()) { if (!classFile.exists() || srcFile.lastModified() > classFile.lastModified()) {
//log( "Found a file newer than the instrumentDir class file: " + srcFile.getPath() + " newer than " + classFile.getPath() + ". Running iContract again..." );
//log( "Found a file newer than the instrumentDir class file: "
// + srcFile.getPath() + " newer than " + classFile.getPath()
// + ". Running iContract again..." );
dirty = true; dirty = true;
} }
} }
@@ -761,7 +836,10 @@ public class IContract extends MatchingTask {
if (files[i].endsWith(".class")) { if (files[i].endsWith(".class")) {
if (controlFileTime > srcFile.lastModified()) { if (controlFileTime > srcFile.lastModified()) {
if (!dirty) { if (!dirty) {
log("Control file " + controlFile.getAbsolutePath() + " has been updated. Instrumenting all files...");
log("Control file "
+ controlFile.getAbsolutePath()
+ " has been updated. "
+ "Instrumenting all files...");
} }
dirty = true; dirty = true;
instrumentall = true; instrumentall = true;
@@ -771,7 +849,8 @@ public class IContract extends MatchingTask {
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
throw new BuildException("Got an interesting exception:" + t.getMessage());
throw new BuildException("Got an interesting exception:"
+ t.getMessage());
} }
} }


@@ -876,7 +955,8 @@ public class IContract extends MatchingTask {


// make it public // make it public
public void modify(Path path) { public void modify(Path path) {
// depending on what compiler to use, set the includeJavaRuntime flag
// depending on what compiler to use, set the
// includeJavaRuntime flag
if ("jikes".equals(compiler)) { if ("jikes".equals(compiler)) {
icCompiler = compiler; icCompiler = compiler;
includeJavaRuntime = true; includeJavaRuntime = true;


+ 15
- 9
src/main/org/apache/tools/ant/taskdefs/optional/Javah.java View File

@@ -275,25 +275,31 @@ public class Javah extends Task {
} }


/** /**
* Executes the task.
* Execute the task
*
* @throws BuildException is there is a problem in the task execution.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
// first off, make sure that we've got a srcdir // first off, make sure that we've got a srcdir


if ((cls == null) && (classes.size() == 0)) { if ((cls == null) && (classes.size() == 0)) {
throw new BuildException("class attribute must be set!", getLocation());
throw new BuildException("class attribute must be set!",
getLocation());
} }


if ((cls != null) && (classes.size() > 0)) { if ((cls != null) && (classes.size() > 0)) {
throw new BuildException("set class attribute or class element, not both.", getLocation());
throw new BuildException("set class attribute or class element, "
+ "not both.", getLocation());
} }


if (destDir != null) { if (destDir != null) {
if (!destDir.isDirectory()) { if (!destDir.isDirectory()) {
throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", getLocation());
throw new BuildException("destination directory \"" + destDir
+ "\" does not exist or is not a directory", getLocation());
} }
if (outputFile != null) { if (outputFile != null) {
throw new BuildException("destdir and outputFile are mutually exclusive", getLocation());
throw new BuildException("destdir and outputFile are mutually "
+ "exclusive", getLocation());
} }
} }


@@ -305,8 +311,8 @@ public class Javah extends Task {


String compiler = getProject().getProperty("build.compiler"); String compiler = getProject().getProperty("build.compiler");
if (compiler == null) { if (compiler == null) {
if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) &&
!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)
&& !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
compiler = "modern"; compiler = "modern";
} else { } else {
compiler = "classic"; compiler = "classic";
@@ -357,9 +363,9 @@ public class Javah extends Task {
Object javahMain = constructor.newInstance(new Object[] {cmd.getArguments()}); Object javahMain = constructor.newInstance(new Object[] {cmd.getArguments()});


// find the run method // find the run method
Method runMethod = javahMainClass.getMethod("run",new Class[0]);
Method runMethod = javahMainClass.getMethod("run", new Class[0]);


runMethod.invoke(javahMain,new Object[0]);
runMethod.invoke(javahMain, new Object[0]);
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof BuildException) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;


+ 13
- 2
src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java View File

@@ -135,6 +135,10 @@ public class Native2Ascii extends MatchingTask {


/** /**
* Defines the FileNameMapper to use (nested mapper element). * Defines the FileNameMapper to use (nested mapper element).
*
* @return the mapper to use for file name translations.
*
* @throws BuildException if more than one mapper is defined.
*/ */
public Mapper createMapper() throws BuildException { public Mapper createMapper() throws BuildException {
if (mapper != null) { if (mapper != null) {
@@ -145,6 +149,11 @@ public class Native2Ascii extends MatchingTask {
return mapper; return mapper;
} }


/**
* Execute the task
*
* @throws BuildException is there is a problem in the task execution.
*/
public void execute() throws BuildException { public void execute() throws BuildException {


DirectoryScanner scanner = null; // Scanner to find our inputs DirectoryScanner scanner = null; // Scanner to find our inputs
@@ -252,8 +261,10 @@ public class Native2Ascii extends MatchingTask {


private class ExtMapper implements FileNameMapper { private class ExtMapper implements FileNameMapper {


public void setFrom(String s) {}
public void setTo(String s) {}
public void setFrom(String s) {
}
public void setTo(String s) {
}


public String[] mapFileName(String fileName) { public String[] mapFileName(String fileName) {
int lastDot = fileName.lastIndexOf('.'); int lastDot = fileName.lastIndexOf('.');


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

@@ -163,10 +163,14 @@ public class NetRexxC extends MatchingTask {
private boolean suppressDeprecation = false; private boolean suppressDeprecation = false;


// constants for the messages to suppress by flags and their corresponding properties // 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_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"; static final String MSG_DEPRECATION = "has been deprecated";


// other implementation variables // other implementation variables
@@ -290,7 +294,7 @@ public class NetRexxC extends MatchingTask {
* false. * false.
*/ */
public void setJava(boolean java) { public void setJava(boolean java) {
log( "The attribute java is currently unused.", Project.MSG_WARN );
log("The attribute java is currently unused.", Project.MSG_WARN);
} }




@@ -527,7 +531,6 @@ public class NetRexxC extends MatchingTask {
* with arguments like -Dant.netrexxc.verbose=verbose5 one can easily take * with arguments like -Dant.netrexxc.verbose=verbose5 one can easily take
* control of all netrexxc-tasks. * 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() { public void init() {
String p; String p;


@@ -736,7 +739,7 @@ public class NetRexxC extends MatchingTask {
j++; j++;
} }
// create a single array of arguments for the compiler // create a single array of arguments for the compiler
String compileArgs[] = new String[compileOptionsArray.length + fileListArray.length];
String[] compileArgs = new String[compileOptionsArray.length + fileListArray.length];


for (int i = 0; i < compileOptionsArray.length; i++) { for (int i = 0; i < compileOptionsArray.length; i++) {
compileArgs[i] = compileOptionsArray[i]; compileArgs[i] = compileOptionsArray[i];
@@ -782,38 +785,48 @@ public class NetRexxC extends MatchingTask {
String l; String l;
BufferedReader in = new BufferedReader(new StringReader(out.toString())); BufferedReader in = new BufferedReader(new StringReader(out.toString()));


log("replacing destdir '" + ddir + "' through sourcedir '" + sdir + "'", Project.MSG_VERBOSE);
log("replacing destdir '" + ddir + "' through sourcedir '"
+ sdir + "'", Project.MSG_VERBOSE);
while ((l = in.readLine()) != null) { while ((l = in.readLine()) != null) {
int idx; int idx;


while (doReplace && ((idx = l.indexOf(ddir)) != -1)) {// path is mentioned in the message
while (doReplace && ((idx = l.indexOf(ddir)) != -1)) {
// path is mentioned in the message
l = (new StringBuffer(l)).replace(idx, idx + dlen, sdir).toString(); l = (new StringBuffer(l)).replace(idx, idx + dlen, sdir).toString();
} }
// verbose level logging for suppressed messages // verbose level logging for suppressed messages
if (suppressMethodArgumentNotUsed && l.indexOf(MSG_METHOD_ARGUMENT_NOT_USED) != -1) {
if (suppressMethodArgumentNotUsed
&& l.indexOf(MSG_METHOD_ARGUMENT_NOT_USED) != -1) {
log(l, Project.MSG_VERBOSE); log(l, Project.MSG_VERBOSE);
} else if (suppressPrivatePropertyNotUsed && l.indexOf(MSG_PRIVATE_PROPERTY_NOT_USED) != -1) {
} else if (suppressPrivatePropertyNotUsed
&& l.indexOf(MSG_PRIVATE_PROPERTY_NOT_USED) != -1) {
log(l, Project.MSG_VERBOSE); log(l, Project.MSG_VERBOSE);
} else if (suppressVariableNotUsed && l.indexOf(MSG_VARIABLE_NOT_USED) != -1) {
} else if (suppressVariableNotUsed
&& l.indexOf(MSG_VARIABLE_NOT_USED) != -1) {
log(l, Project.MSG_VERBOSE); log(l, Project.MSG_VERBOSE);
} else if (suppressExceptionNotSignalled && l.indexOf(MSG_EXCEPTION_NOT_SIGNALLED) != -1) {
} else if (suppressExceptionNotSignalled
&& l.indexOf(MSG_EXCEPTION_NOT_SIGNALLED) != -1) {
log(l, Project.MSG_VERBOSE); log(l, Project.MSG_VERBOSE);
} else if (suppressDeprecation && l.indexOf(MSG_DEPRECATION) != -1) {
} else if (suppressDeprecation
&& l.indexOf(MSG_DEPRECATION) != -1) {
log(l, Project.MSG_VERBOSE); log(l, Project.MSG_VERBOSE);
} else if (l.indexOf("Error:") != -1) {// error level logging for compiler errors
} else if (l.indexOf("Error:") != -1) {
// error level logging for compiler errors
log(l, Project.MSG_ERR); log(l, Project.MSG_ERR);
} else if (l.indexOf("Warning:") != -1) {// warning for all warning messages
} else if (l.indexOf("Warning:") != -1) {
// warning for all warning messages
log(l, Project.MSG_WARN); log(l, Project.MSG_WARN);
} else { } else {
log(l, Project.MSG_INFO);// info level for the rest.
log(l, Project.MSG_INFO); // info level for the rest.
} }
} }
if (rc > 1) { if (rc > 1) {
throw new BuildException("Compile failed, messages should have been provided.");
throw new BuildException("Compile failed, messages should "
+ "have been provided.");
} }
} catch (IOException ioe) { } catch (IOException ioe) {
throw new BuildException("Unexpected IOException while playing with Strings",
ioe);
throw new BuildException("Unexpected IOException while "
+ "playing with Strings", ioe);
} finally { } finally {
// need to reset java.class.path property // need to reset java.class.path property
// since the NetRexx compiler has no option for the classpath // since the NetRexx compiler has no option for the classpath
@@ -902,8 +915,8 @@ public class NetRexxC extends MatchingTask {
target.append(File.pathSeparator); target.append(File.pathSeparator);
target.append(f.getAbsolutePath()); target.append(f.getAbsolutePath());
} else { } else {
log("Dropping from classpath: " +
f.getAbsolutePath(), Project.MSG_VERBOSE);
log("Dropping from classpath: "
+ f.getAbsolutePath(), Project.MSG_VERBOSE);
} }
} }




+ 12
- 17
src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java View File

@@ -98,7 +98,8 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
*The &lt;propertyfile&gt; task must have:<br> *The &lt;propertyfile&gt; task must have:<br>
* <ul><li>file</li></ul> * <ul><li>file</li></ul>
*Other parameters are:<br> *Other parameters are:<br>
* <ul><li>comment, key, operation, type and value (the final four being eliminated shortly)</li></ul>
* <ul><li>comment, key, operation, type and value (the final four being
* eliminated shortly)</li></ul>
* *
*The &lt;entry&gt; task must have:<br> *The &lt;entry&gt; task must have:<br>
* <ul><li>key</li></ul> * <ul><li>key</li></ul>
@@ -253,7 +254,9 @@ public class PropertyFile extends Task {
if (bos != null) { if (bos != null) {
try { try {
bos.close(); bos.close();
} catch (IOException ioex) {}
} catch (IOException ioex) {
// ignore
}
} }
} }
} }
@@ -506,8 +509,8 @@ public class PropertyFile extends Task {
* fields * fields
*/ */
private void checkParameters() throws BuildException { private void checkParameters() throws BuildException {
if (type == Type.STRING_TYPE &&
operation == Operation.DECREMENT_OPER) {
if (type == Type.STRING_TYPE
&& operation == Operation.DECREMENT_OPER) {
throw new BuildException("- is not suported for string " throw new BuildException("- is not suported for string "
+ "properties (key:" + key + ")"); + "properties (key:" + key + ")");
} }
@@ -518,8 +521,7 @@ public class PropertyFile extends Task {
if (key == null) { if (key == null) {
throw new BuildException("key is mandatory"); throw new BuildException("key is mandatory");
} }
if (type == Type.STRING_TYPE &&
pattern != null) {
if (type == Type.STRING_TYPE && pattern != null) {
throw new BuildException("pattern is not suported for string " throw new BuildException("pattern is not suported for string "
+ "properties (key:" + key + ")"); + "properties (key:" + key + ")");
} }
@@ -631,16 +633,9 @@ public class PropertyFile extends Task {
private static final String MONTH = "month"; private static final String MONTH = "month";
private static final String YEAR = "year"; private static final String YEAR = "year";


private static final String[] units = {
MILLISECOND,
SECOND,
MINUTE,
HOUR,
DAY,
WEEK,
MONTH,
YEAR
};
private static final String[] UNITS
= {MILLISECOND, SECOND, MINUTE, HOUR,
DAY, WEEK, MONTH, YEAR };


private Hashtable calendarFields = new Hashtable(); private Hashtable calendarFields = new Hashtable();


@@ -663,7 +658,7 @@ public class PropertyFile extends Task {
} }


public String[] getValues() { public String[] getValues() {
return units;
return UNITS;
} }
} }
} }

+ 11
- 1
src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java View File

@@ -98,7 +98,9 @@ public class RenameExtensions extends MatchingTask {


/** /**
* The string that files must end in to be renamed * The string that files must end in to be renamed
**/
*
* @param from the extension of files being renamed.
*/
public void setFromExtension(String from) { public void setFromExtension(String from) {
fromExtension = from; fromExtension = from;
} }
@@ -106,6 +108,8 @@ public class RenameExtensions extends MatchingTask {
/** /**
* The string that renamed files will end with on * The string that renamed files will end with on
* completion * completion
*
* @param to the extension of the renamed files.
*/ */
public void setToExtension(String to) { public void setToExtension(String to) {
toExtension = to; toExtension = to;
@@ -114,6 +118,8 @@ public class RenameExtensions extends MatchingTask {
/** /**
* store replace attribute - this determines whether the target file * store replace attribute - this determines whether the target file
* should be overwritten if present * should be overwritten if present
*
* @param replace if true overwrite any target files that exist.
*/ */
public void setReplace(boolean replace) { public void setReplace(boolean replace) {
this.replace = replace; this.replace = replace;
@@ -121,6 +127,8 @@ public class RenameExtensions extends MatchingTask {


/** /**
* Set the source dir to find the files to be renamed. * Set the source dir to find the files to be renamed.
*
* @param srcDir the source directory.
*/ */
public void setSrcDir(File srcDir) { public void setSrcDir(File srcDir) {
this.srcDir = srcDir; this.srcDir = srcDir;
@@ -128,6 +136,8 @@ public class RenameExtensions extends MatchingTask {


/** /**
* Executes the task. * Executes the task.
*
* @throws BuildException is there is a problem in the task execution.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {




+ 18
- 12
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -220,9 +220,11 @@ public class ReplaceRegExp extends Task {
* <li>g : Global replacement. Replace all occurences found * <li>g : Global replacement. Replace all occurences found
* <li>i : Case Insensitive. Do not consider case in the match * <li>i : Case Insensitive. Do not consider case in the match
* <li>m : Multiline. Treat the string as multiple lines of input, * <li>m : Multiline. Treat the string as multiple lines of input,
* using "^" and "$" as the start or end of any line, respectively, rather than start or end of string.
* using "^" and "$" as the start or end of any line, respectively,
* rather than start or end of string.
* <li> s : Singleline. Treat the string as a single line of input, using * <li> s : Singleline. Treat the string as a single line of input, using
* "." to match any character, including a newline, which normally, it would not match.
* "." to match any character, including a newline, which normally,
* it would not match.
*</ul> *</ul>
*/ */
public void setFlags(String flags) { public void setFlags(String flags) {
@@ -334,13 +336,11 @@ public class ReplaceRegExp extends Task {


boolean changes = false; boolean changes = false;


log("Replacing pattern '" + regex.getPattern(getProject()) +
"' with '" + subs.getExpression(getProject()) +
"' in '" + f.getPath() + "'" +
(byline ? " by line" : "") +
(flags.length() > 0 ? " with flags: '" + flags + "'" : "") +
".",
Project.MSG_VERBOSE);
log("Replacing pattern '" + regex.getPattern(getProject())
+ "' with '" + subs.getExpression(getProject())
+ "' in '" + f.getPath() + "'" + (byline ? " by line" : "")
+ (flags.length() > 0 ? " with flags: '" + flags + "'" : "")
+ ".", Project.MSG_VERBOSE);


if (byline) { if (byline) {
StringBuffer linebuf = new StringBuffer(); StringBuffer linebuf = new StringBuffer();
@@ -450,6 +450,7 @@ public class ReplaceRegExp extends Task {
r.close(); r.close();
} }
} catch (Exception e) { } catch (Exception e) {
// ignore any secondary exceptions
} }


try { try {
@@ -457,6 +458,7 @@ public class ReplaceRegExp extends Task {
w.close(); w.close();
} }
} catch (Exception e) { } catch (Exception e) {
// ignore any secondary exceptions
} }
if (temp != null) { if (temp != null) {
temp.delete(); temp.delete();
@@ -465,8 +467,12 @@ public class ReplaceRegExp extends Task {
} }




public void execute()
throws BuildException {
/**
* Execute the task
*
* @throws BuildException is there is a problem in the task execution.
*/
public void execute() throws BuildException {
if (regex == null) { if (regex == null) {
throw new BuildException("No expression to match."); throw new BuildException("No expression to match.");
} }
@@ -516,7 +522,7 @@ public class ReplaceRegExp extends Task {
FileSet fs = (FileSet) (filesets.elementAt(i)); FileSet fs = (FileSet) (filesets.elementAt(i));
DirectoryScanner ds = fs.getDirectoryScanner(getProject()); DirectoryScanner ds = fs.getDirectoryScanner(getProject());


String files[] = ds.getIncludedFiles();
String[] files = ds.getIncludedFiles();


for (int j = 0; j < files.length; j++) { for (int j = 0; j < files.length; j++) {
File f = new File(fs.getDir(getProject()), files[j]); File f = new File(fs.getDir(getProject()), files[j]);


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

@@ -126,6 +126,11 @@ public class Rpm extends Task {
*/ */
private File error; private File error;


/**
* Execute the task
*
* @throws BuildException is there is a problem in the task execution.
*/
public void execute() throws BuildException { public void execute() throws BuildException {


Commandline toExecute = new Commandline(); Commandline toExecute = new Commandline();
@@ -161,7 +166,9 @@ public class Rpm extends Task {
} else { } else {
if (output != null) { if (output != null) {
try { try {
outputstream = new PrintStream(new BufferedOutputStream(new FileOutputStream(output)));
BufferedOutputStream bos
= new BufferedOutputStream(new FileOutputStream(output));
outputstream = new PrintStream(bos);
} catch (IOException e) { } catch (IOException e) {
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} }
@@ -170,7 +177,9 @@ public class Rpm extends Task {
} }
if (error != null) { if (error != null) {
try { try {
errorstream = new PrintStream(new BufferedOutputStream(new FileOutputStream(error)));
BufferedOutputStream bos
= new BufferedOutputStream(new FileOutputStream(error));
errorstream = new PrintStream(bos);
} catch (IOException e) { } catch (IOException e) {
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} }
@@ -198,12 +207,16 @@ public class Rpm extends Task {
if (output != null) { if (output != null) {
try { try {
outputstream.close(); outputstream.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore any secondary error
}
} }
if (error != null) { if (error != null) {
try { try {
errorstream.close(); errorstream.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore any secondary error
}
} }
} }
} }
@@ -213,6 +226,8 @@ public class Rpm extends Task {
* subdirectories, SPECS, SOURCES, BUILD, SRPMS ; optional. * subdirectories, SPECS, SOURCES, BUILD, SRPMS ; optional.
* If this isn't specified, * If this isn't specified,
* the <tt>baseDir</tt> value is used * the <tt>baseDir</tt> value is used
*
* @param td the directory containing the normal RPM directories.
*/ */
public void setTopDir(File td) { public void setTopDir(File td) {
this.topDir = td; this.topDir = td;


+ 8
- 8
src/main/org/apache/tools/ant/taskdefs/optional/Script.java View File

@@ -81,8 +81,8 @@ public class Script extends Task {
for (Enumeration e = dictionary.keys(); e.hasMoreElements();) { for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement(); String key = (String) e.nextElement();


boolean isValid = key.length() > 0 &&
Character.isJavaIdentifierStart(key.charAt(0));
boolean isValid = key.length() > 0
&& Character.isJavaIdentifierStart(key.charAt(0));


for (int i = 1; isValid && i < key.length(); i++) { for (int i = 1; isValid && i < key.length(); i++) {
isValid = Character.isJavaIdentifierPart(key.charAt(i)); isValid = Character.isJavaIdentifierPart(key.charAt(i));
@@ -112,7 +112,7 @@ public class Script extends Task {


BSFManager manager = new BSFManager (); BSFManager manager = new BSFManager ();


for (Enumeration e = beans.keys() ; e.hasMoreElements() ;) {
for (Enumeration e = beans.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement(); String key = (String) e.nextElement();
Object value = beans.get(key); Object value = beans.get(key);
manager.declareBean(key, value, value.getClass()); manager.declareBean(key, value, value.getClass());
@@ -137,7 +137,7 @@ public class Script extends Task {
/** /**
* Defines the language (required). * Defines the language (required).
* *
* @param msg Sets the value for the script variable.
* @param language the scripting language name for the script.
*/ */
public void setLanguage(String language) { public void setLanguage(String language) {
this.language = language; this.language = language;
@@ -146,7 +146,7 @@ public class Script extends Task {
/** /**
* Load the script from an external file ; optional. * Load the script from an external file ; optional.
* *
* @param msg Sets the value for the script variable.
* @param fileName the name of the file containing the script source.
*/ */
public void setSrc(String fileName) { public void setSrc(String fileName) {
File file = new File(fileName); File file = new File(fileName);
@@ -155,7 +155,7 @@ public class Script extends Task {
} }


int count = (int) file.length(); int count = (int) file.length();
byte data[] = new byte[count];
byte[] data = new byte[count];


try { try {
FileInputStream inStream = new FileInputStream(file); FileInputStream inStream = new FileInputStream(file);
@@ -169,9 +169,9 @@ public class Script extends Task {
} }


/** /**
* The script text.
* Set the script text.
* *
* @param msg Sets the value for the script variable.
* @param text a component of the script text to be added.
*/ */
public void addText(String text) { public void addText(String text) {
this.script += text; this.script += text;


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/optional/StyleBook.java View File

@@ -70,8 +70,7 @@ import org.apache.tools.ant.taskdefs.Java;
* @author <a href="mailto:marcus.boerger@post.rwth-aachen.de">Marcus * @author <a href="mailto:marcus.boerger@post.rwth-aachen.de">Marcus
* B&ouml;rger</a> * B&ouml;rger</a>
*/ */
public class StyleBook
extends Java {
public class StyleBook extends Java {
protected File m_targetDirectory; protected File m_targetDirectory;
protected File m_skinDirectory; protected File m_skinDirectory;
protected String m_loaderConfig; protected String m_loaderConfig;


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -209,8 +209,8 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware
reader.setEntityResolver(entityResolver); reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is)); src = new SAXSource(reader, new InputSource(is));
} else { } else {
throw new IllegalStateException("xcatalog specified, but " +
"parser doesn't support SAX");
throw new IllegalStateException("xcatalog specified, but "
+ "parser doesn't support SAX");
} }
} else { } else {
src = new StreamSource(is); src = new StreamSource(is);
@@ -305,8 +305,8 @@ public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware


// specific attributes for the transformer // specific attributes for the transformer
for (int i = 0; i < attributes.size(); i++) { for (int i = 0; i < attributes.size(); i++) {
final Object[] pair = (Object[])attributes.elementAt(i);
tfactory.setAttribute((String)pair[0], pair[1]);
final Object[] pair = (Object[]) attributes.elementAt(i);
tfactory.setAttribute((String) pair[0], pair[1]);
} }


if (uriResolver != null) { if (uriResolver != null) {


+ 32
- 27
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -87,8 +87,10 @@ import org.xml.sax.helpers.ParserAdapter;
* Checks XML files are valid (or only well formed). The * Checks XML files are valid (or only well formed). The
* task uses the SAX2 parser implementation provided by JAXP by default * task uses the SAX2 parser implementation provided by JAXP by default
* (probably the one that is used by Ant itself), but one can specify any * (probably the one that is used by Ant itself), but one can specify any
* SAX1/2 parser if needed
* @author Raphael Pierquin <a href="mailto:raphael.pierquin@agisphere.com">raphael.pierquin@agisphere.com</a>
* SAX1/2 parser if needed.
*
* @author Raphael Pierquin <a href="mailto:raphael.pierquin@agisphere.com">
* raphael.pierquin@agisphere.com</a>
* @author Nick Pellow <a href="mailto:nick@svana.org">nick@svana.org</a> * @author Nick Pellow <a href="mailto:nick@svana.org">nick@svana.org</a>
*/ */
public class XMLValidateTask extends Task { public class XMLValidateTask extends Task {
@@ -98,7 +100,7 @@ public class XMLValidateTask extends Task {
*/ */
private static FileUtils fu = FileUtils.newFileUtils(); private static FileUtils fu = FileUtils.newFileUtils();


protected static String INIT_FAILED_MSG =
protected static final String INIT_FAILED_MSG =
"Could not start xml validation: "; "Could not start xml validation: ";


// ant task properties // ant task properties
@@ -108,8 +110,10 @@ public class XMLValidateTask extends Task {
protected boolean lenient = false; protected boolean lenient = false;
protected String readerClassName = null; protected String readerClassName = null;


protected File file = null; // file to be validated
protected Vector filesets = new Vector(); // sets of file to be validated
/** file to be validated */
protected File file = null;
/** sets of file to be validated */
protected Vector filesets = new Vector();
protected Path classpath; protected Path classpath;




@@ -137,7 +141,6 @@ public class XMLValidateTask extends Task {
* parser yields an error. * parser yields an error.
*/ */
public void setFailOnError(boolean fail) { public void setFailOnError(boolean fail) {

failOnError = fail; failOnError = fail;
} }


@@ -147,35 +150,35 @@ public class XMLValidateTask extends Task {
* If set to <code>true</true> (default), log a warn message for each SAX warn event. * If set to <code>true</true> (default), log a warn message for each SAX warn event.
*/ */
public void setWarn(boolean bool) { public void setWarn(boolean bool) {

warn = bool; warn = bool;
} }


/** /**
* Specify whether the parser should be validating. Default is <code>true</code>.
* Specify whether the parser should be validating. Default
* is <code>true</code>.
* <p> * <p>
* If set to false, the validation will fail only if the parsed document is not well formed XML.
* If set to false, the validation will fail only if the parsed document
* is not well formed XML.
* <p> * <p>
* this option is ignored if the specified class with {@link #setClassName(String)} is not a SAX2
* XMLReader.
* this option is ignored if the specified class
* with {@link #setClassName(String)} is not a SAX2 XMLReader.
*/ */
public void setLenient(boolean bool) { public void setLenient(boolean bool) {

lenient = bool; lenient = bool;
} }


/** /**
* Specify the class name of the SAX parser to be used. (optional) * Specify the class name of the SAX parser to be used. (optional)
* @param className should be an implementation of SAX2 <code>org.xml.sax.XMLReader</code>
* or SAX2 <code>org.xml.sax.Parser</code>.
* <p> if className is an implementation of <code>org.xml.sax.Parser</code>, {@link #setLenient(boolean)},
* @param className should be an implementation of SAX2
* <code>org.xml.sax.XMLReader</code> or SAX2 <code>org.xml.sax.Parser</code>.
* <p> if className is an implementation of
* <code>org.xml.sax.Parser</code>, {@link #setLenient(boolean)},
* will be ignored. * will be ignored.
* <p> if not set, the default will be used. * <p> if not set, the default will be used.
* @see org.xml.sax.XMLReader * @see org.xml.sax.XMLReader
* @see org.xml.sax.Parser * @see org.xml.sax.Parser
*/ */
public void setClassName(String className) { public void setClassName(String className) {

readerClassName = className; readerClassName = className;
} }


@@ -184,7 +187,6 @@ public class XMLValidateTask extends Task {
* Specify the classpath to be searched to load the parser (optional) * Specify the classpath to be searched to load the parser (optional)
*/ */
public void setClasspath(Path classpath) { public void setClasspath(Path classpath) {

if (this.classpath == null) { if (this.classpath == null) {
this.classpath = classpath; this.classpath = classpath;
} else { } else {
@@ -268,7 +270,8 @@ public class XMLValidateTask extends Task {


int fileProcessed = 0; int fileProcessed = 0;
if (file == null && (filesets.size() == 0)) { if (file == null && (filesets.size() == 0)) {
throw new BuildException("Specify at least one source - a file or a fileset.");
throw new BuildException("Specify at least one source - "
+ "a file or a fileset.");
} }


initValidator(); initValidator();
@@ -293,7 +296,7 @@ public class XMLValidateTask extends Task {
DirectoryScanner ds = fs.getDirectoryScanner(getProject()); DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] files = ds.getIncludedFiles(); String[] files = ds.getIncludedFiles();


for (int j = 0; j < files.length ; j++) {
for (int j = 0; j < files.length; j++) {
File srcFile = new File(fs.getDir(getProject()), files[j]); File srcFile = new File(fs.getDir(getProject()), files[j]);
doValidate(srcFile); doValidate(srcFile);
fileProcessed++; fileProcessed++;
@@ -352,8 +355,8 @@ public class XMLValidateTask extends Task {
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
} else { } else {
throw new BuildException(INIT_FAILED_MSG throw new BuildException(INIT_FAILED_MSG
+ reader.getClass().getName()
+ " implements nor SAX1 Parser nor SAX2 XMLReader.");
+ reader.getClass().getName()
+ " implements nor SAX1 Parser nor SAX2 XMLReader.");
} }
} }


@@ -420,7 +423,8 @@ public class XMLValidateTask extends Task {


if (errorHandler.getFailure()) { if (errorHandler.getFailure()) {
if (failOnError) { if (failOnError) {
throw new BuildException(afile + " is not a valid XML document.");
throw new BuildException(afile
+ " is not a valid XML document.");
} else { } else {
log(afile + " is not a valid XML document", Project.MSG_ERR); log(afile + " is not a valid XML document", Project.MSG_ERR);
} }
@@ -480,11 +484,12 @@ public class XMLValidateTask extends Task {
try { try {
int line = e.getLineNumber(); int line = e.getLineNumber();
int col = e.getColumnNumber(); int col = e.getColumnNumber();
return new URL(sysID).getFile() +
(line == -1 ? "" : (":" + line +
(col == -1 ? "" : (":" + col)))) +
": " + e.getMessage();
return new URL(sysID).getFile()
+ (line == -1 ? "" : (":" + line
+ (col == -1 ? "" : (":" + col))))
+ ": " + e.getMessage();
} catch (MalformedURLException mfue) { } catch (MalformedURLException mfue) {
// ignore and just return exception message
} }
} }
return e.getMessage(); return e.getMessage();
@@ -499,7 +504,7 @@ public class XMLValidateTask extends Task {
public class Attribute { public class Attribute {
/** The name of the attribute to set. /** The name of the attribute to set.
* *
* Valid attributes <a href=http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">include.</a>
* Valid attributes <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">include.</a>
*/ */
private String attributeName = null; private String attributeName = null;




+ 9
- 3
src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java View File

@@ -108,17 +108,23 @@ public class XalanLiaison implements XSLTLiaison {
if (xslStream != null) { if (xslStream != null) {
xslStream.close(); xslStream.close();
} }
} catch (IOException ignored) {}
} catch (IOException ignored) {
//ignore
}
try { try {
if (fis != null) { if (fis != null) {
fis.close(); fis.close();
} }
} catch (IOException ignored) {}
} catch (IOException ignored) {
//ignore
}
try { try {
if (fos != null) { if (fos != null) {
fos.close(); fos.close();
} }
} catch (IOException ignored) {}
} catch (IOException ignored) {
//ignore
}
} }
} }




+ 10
- 10
src/main/org/apache/tools/ant/types/optional/ScriptFilter.java View File

@@ -72,6 +72,8 @@ import org.apache.tools.ant.BuildException;
* to a script. * to a script.
* The script is meant to use get self.token and * The script is meant to use get self.token and
* set self.token in the reply. * set self.token in the reply.
*
* @author Not Specified.
*/ */
public class ScriptFilter extends TokenFilter.ChainableReaderFilter { public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
/** The language - attribute of element */ /** The language - attribute of element */
@@ -90,7 +92,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
/** /**
* Defines the language (required). * Defines the language (required).
* *
* @param msg Sets the value for the script variable.
* @param language the scripting language name for the script.
*/ */
public void setLanguage(String language) { public void setLanguage(String language) {
this.language = language; this.language = language;
@@ -105,8 +107,8 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
for (Enumeration e = dictionary.keys(); e.hasMoreElements();) { for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement(); String key = (String) e.nextElement();


boolean isValid = key.length() > 0 &&
Character.isJavaIdentifierStart(key.charAt(0));
boolean isValid = key.length() > 0
&& Character.isJavaIdentifierStart(key.charAt(0));


for (int i = 1; isValid && i < key.length(); i++) { for (int i = 1; isValid && i < key.length(); i++) {
isValid = Character.isJavaIdentifierPart(key.charAt(i)); isValid = Character.isJavaIdentifierPart(key.charAt(i));
@@ -116,8 +118,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
if (isValid) { if (isValid) {
beans.put(key, dictionary.get(key)); beans.put(key, dictionary.get(key));
} }
}
catch (Throwable t) {
} catch (Throwable t) {
throw new BuildException(t); throw new BuildException(t);
//System.err.println("What the helll"); //System.err.println("What the helll");
} }
@@ -203,8 +204,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
try { try {
manager.exec(language, "<ANT>", 0, 0, script); manager.exec(language, "<ANT>", 0, 0, script);
return getToken(); return getToken();
}
catch (BSFException be) {
} catch (BSFException be) {
Throwable t = be; Throwable t = be;
Throwable te = be.getTargetException(); Throwable te = be.getTargetException();
if (te != null) { if (te != null) {
@@ -220,7 +220,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
/** /**
* Load the script from an external file ; optional. * Load the script from an external file ; optional.
* *
* @param msg Sets the value for the script variable.
* @param fileName the name of the file containing the script source.
*/ */
public void setSrc(String fileName) { public void setSrc(String fileName) {
File file = new File(fileName); File file = new File(fileName);
@@ -229,7 +229,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
} }


int count = (int) file.length(); int count = (int) file.length();
byte data[] = new byte[count];
byte[] data = new byte[count];


try { try {
FileInputStream inStream = new FileInputStream(file); FileInputStream inStream = new FileInputStream(file);
@@ -245,7 +245,7 @@ public class ScriptFilter extends TokenFilter.ChainableReaderFilter {
/** /**
* The script text. * The script text.
* *
* @param msg Sets the value for the script variable.
* @param text a component of the script text to be added.
*/ */
public void addText(String text) { public void addText(String text) {
this.script += text; this.script += text;


+ 4
- 0
src/main/org/apache/tools/ant/util/optional/WeakishReference12.java View File

@@ -61,6 +61,8 @@ import java.lang.ref.WeakReference;
/** /**
* This is a reference that really is is Weak, as it uses the * This is a reference that really is is Weak, as it uses the
* appropriate java.lang.ref class. * appropriate java.lang.ref class.
*
* @author Not Specified.
*/ */
public class WeakishReference12 extends WeakishReference { public class WeakishReference12 extends WeakishReference {


@@ -78,6 +80,8 @@ public class WeakishReference12 extends WeakishReference {


/** /**
* Returns this reference object's referent. * Returns this reference object's referent.
*
* @return referent.
*/ */
public Object get() { public Object get() {
return weakref.get(); return weakref.get();


Loading…
Cancel
Save