git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274441 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,20 +1,20 @@ | |||||
<project default="checkstyle" name="CheckAnt"> | <project default="checkstyle" name="CheckAnt"> | ||||
<property name="java.dir" value="src/main"/> | <property name="java.dir" value="src/main"/> | ||||
<property name="tocheck" value="**/*.java"/> | |||||
<property name="tocheck" value="**/*.java"/> | |||||
<property name="javadoc.scope" value="public"/> | <property name="javadoc.scope" value="public"/> | ||||
<target name="checkstyle"> | <target name="checkstyle"> | ||||
<taskdef name="checkstyle" | <taskdef name="checkstyle" | ||||
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/> | classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/> | ||||
<checkstyle> | |||||
<property key="checkstyle.header.file" file="src/etc/RequiredHeader.txt"/> | |||||
<property key="checkstyle.header.ignoreline" value="4"/> | |||||
<property key="checkstyle.javadoc.scope" value="${javadoc.scope}"/> | |||||
<checkstyle headerFile="src/etc/RequiredHeader.txt" | |||||
headerIgnoreLine="4" | |||||
allowProtected="true" | |||||
javadocScope="${javadoc.scope}"> | |||||
<fileset dir="${java.dir}"> | <fileset dir="${java.dir}"> | ||||
<include name="${tocheck}"/> | <include name="${tocheck}"/> | ||||
</fileset> | </fileset> | ||||
</checkstyle> | </checkstyle> | ||||
</target> | </target> | ||||
</project> | </project> | ||||
@@ -436,8 +436,7 @@ public class IntrospectionHelper implements BuildListener { | |||||
DynamicConfigurator dc = (DynamicConfigurator) element; | DynamicConfigurator dc = (DynamicConfigurator) element; | ||||
dc.setDynamicAttribute(attributeName, value); | dc.setDynamicAttribute(attributeName, value); | ||||
return; | return; | ||||
} | |||||
else { | |||||
} else { | |||||
String msg = getElementName(p, element) + | String msg = getElementName(p, element) + | ||||
" doesn't support the \"" + attributeName + | " doesn't support the \"" + attributeName + | ||||
"\" attribute."; | "\" attribute."; | ||||
@@ -903,8 +903,7 @@ public class Project { | |||||
&& oldLoader instanceof AntClassLoader | && oldLoader instanceof AntClassLoader | ||||
&& newLoader instanceof AntClassLoader | && newLoader instanceof AntClassLoader | ||||
&& ((AntClassLoader) oldLoader).getClasspath() | && ((AntClassLoader) oldLoader).getClasspath() | ||||
.equals(((AntClassLoader) newLoader).getClasspath()) | |||||
) { | |||||
.equals(((AntClassLoader) newLoader).getClasspath())) { | |||||
// same classname loaded from the same | // same classname loaded from the same | ||||
// classpath components | // classpath components | ||||
logLevel = MSG_VERBOSE; | logLevel = MSG_VERBOSE; | ||||
@@ -2071,7 +2070,7 @@ public class Project { | |||||
int priority) { | int priority) { | ||||
event.setMessage(message, priority); | event.setMessage(message, priority); | ||||
Vector listeners = getBuildListeners(); | Vector listeners = getBuildListeners(); | ||||
synchronized(this) { | |||||
synchronized (this) { | |||||
if (loggingMessage) { | if (loggingMessage) { | ||||
throw new BuildException("Listener attempted to access " | throw new BuildException("Listener attempted to access " | ||||
+ (priority == MSG_ERR ? "System.err" : "System.out") | + (priority == MSG_ERR ? "System.err" : "System.out") | ||||
@@ -2171,7 +2170,7 @@ 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; | ||||
@@ -2212,9 +2211,9 @@ public class Project { | |||||
} | } | ||||
private static class AntTaskTable extends LazyHashtable { | private static class AntTaskTable extends LazyHashtable { | ||||
Project project; | |||||
Properties props; | |||||
boolean tasks = false; | |||||
private Project project; | |||||
private Properties props; | |||||
private boolean tasks = false; | |||||
public AntTaskTable(Project p, boolean tasks) { | public AntTaskTable(Project p, boolean tasks) { | ||||
this.project = p; | this.project = p; | ||||
@@ -2226,46 +2225,57 @@ public class Project { | |||||
} | } | ||||
protected void initAll() { | protected void initAll() { | ||||
if (initAllDone ) return; | |||||
if (initAllDone) { | |||||
return; | |||||
} | |||||
project.log("InitAll", Project.MSG_DEBUG); | project.log("InitAll", Project.MSG_DEBUG); | ||||
if (props==null ) return; | |||||
if (props == null) { | |||||
return; | |||||
} | |||||
Enumeration enum = props.propertyNames(); | Enumeration enum = props.propertyNames(); | ||||
while (enum.hasMoreElements()) { | while (enum.hasMoreElements()) { | ||||
String key = (String) enum.nextElement(); | String key = (String) enum.nextElement(); | ||||
Class taskClass=getTask( key ); | |||||
if (taskClass!=null ) { | |||||
Class taskClass = getTask(key); | |||||
if (taskClass != null) { | |||||
// This will call a get() and a put() | // This will call a get() and a put() | ||||
if (tasks ) | |||||
if (tasks) { | |||||
project.addTaskDefinition(key, taskClass); | project.addTaskDefinition(key, taskClass); | ||||
else | |||||
project.addDataTypeDefinition(key, taskClass ); | |||||
} else { | |||||
project.addDataTypeDefinition(key, taskClass); | |||||
} | |||||
} | } | ||||
} | } | ||||
initAllDone=true; | |||||
initAllDone = true; | |||||
} | } | ||||
protected Class getTask(String key) { | protected Class getTask(String key) { | ||||
if (props==null ) return null; // for tasks loaded before init() | |||||
String value=props.getProperty(key); | |||||
if (value==null) { | |||||
//project.log( "No class name for " + key, Project.MSG_VERBOSE ); | |||||
if (props == null) { | |||||
return null; // for tasks loaded before init() | |||||
} | |||||
String value = props.getProperty(key); | |||||
if (value == null) { | |||||
//project.log( "No class name for " + key, Project.MSG_VERBOSE); | |||||
return null; | return null; | ||||
} | } | ||||
try { | try { | ||||
Class taskClass=null; | |||||
Class taskClass = null; | |||||
if (project.getCoreLoader() != null && | if (project.getCoreLoader() != null && | ||||
!("only".equals(project.getProperty("build.sysclasspath")))) { | !("only".equals(project.getProperty("build.sysclasspath")))) { | ||||
try { | try { | ||||
taskClass=project.getCoreLoader().loadClass(value); | |||||
if (taskClass != null ) return taskClass; | |||||
} catch( Exception ex ) { | |||||
taskClass = project.getCoreLoader().loadClass(value); | |||||
if (taskClass != null) { | |||||
return taskClass; | |||||
} | |||||
} catch (Exception ex) { | |||||
// ignore | |||||
} | } | ||||
} | } | ||||
taskClass = Class.forName(value); | taskClass = Class.forName(value); | ||||
return taskClass; | return taskClass; | ||||
} catch (NoClassDefFoundError ncdfe) { | } catch (NoClassDefFoundError ncdfe) { | ||||
project.log("Could not load a dependent class (" | project.log("Could not load a dependent class (" | ||||
+ ncdfe.getMessage() + ") for task " + key, Project.MSG_DEBUG); | |||||
+ ncdfe.getMessage() + ") for task " | |||||
+ key, Project.MSG_DEBUG); | |||||
} catch (ClassNotFoundException cnfe) { | } catch (ClassNotFoundException cnfe) { | ||||
project.log("Could not load class (" + value | project.log("Could not load class (" + value | ||||
+ ") for task " + key, Project.MSG_DEBUG); | + ") for task " + key, Project.MSG_DEBUG); | ||||
@@ -2274,20 +2284,25 @@ public class Project { | |||||
} | } | ||||
// Hashtable implementation | // Hashtable implementation | ||||
public Object get( Object key ) { | |||||
Object orig=super.get( key ); | |||||
if (orig!= null ) return orig; | |||||
if (! (key instanceof String) ) return null; | |||||
project.log("Get task " + key, Project.MSG_DEBUG ); | |||||
Object taskClass=getTask( (String) key); | |||||
if (taskClass != null) | |||||
super.put( key, taskClass ); | |||||
public Object get(Object key) { | |||||
Object orig = super.get(key); | |||||
if (orig != null) { | |||||
return orig; | |||||
} | |||||
if (!(key instanceof String)) { | |||||
return null; | |||||
} | |||||
project.log("Get task " + key, Project.MSG_DEBUG); | |||||
Object taskClass = getTask((String) key); | |||||
if (taskClass != null) { | |||||
super.put(key, taskClass); | |||||
} | |||||
return taskClass; | return taskClass; | ||||
} | } | ||||
public boolean containsKey(Object key) { | public boolean containsKey(Object key) { | ||||
return get(key) != null; | return get(key) != null; | ||||
} | } | ||||
} | } | ||||
} | } |
@@ -133,6 +133,12 @@ public class RuntimeConfigurable implements Serializable { | |||||
proxyConfigured = false; | proxyConfigured = false; | ||||
} | } | ||||
/** | |||||
* Get the object for which this RuntimeConfigurable holds the configuration | |||||
* information | |||||
* | |||||
* @return the object whose configure is held by this instance. | |||||
*/ | |||||
public Object getProxy() { | public Object getProxy() { | ||||
return wrappedObject; | return wrappedObject; | ||||
} | } | ||||
@@ -151,6 +157,12 @@ public class RuntimeConfigurable implements Serializable { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Set an attribute to a given value | |||||
* | |||||
* @param name the name of the attribute. | |||||
* @param value the attribute's value. | |||||
*/ | |||||
public void setAttribute(String name, String value) { | public void setAttribute(String name, String value) { | ||||
attributeNames.addElement(name); | attributeNames.addElement(name); | ||||
attributeMap.put(name, value); | attributeMap.put(name, value); | ||||
@@ -357,6 +369,8 @@ public class RuntimeConfigurable implements Serializable { | |||||
/** | /** | ||||
* Reconfigure the element, even if it has already been configured. | * Reconfigure the element, even if it has already been configured. | ||||
* | |||||
* @param p the project instance for this configuration. | |||||
*/ | */ | ||||
public void reconfigure(Project p) { | public void reconfigure(Project p) { | ||||
proxyConfigured = false; | proxyConfigured = false; | ||||
@@ -143,7 +143,8 @@ public abstract class BaseFilterReader | |||||
* @exception IllegalArgumentException If <code>n</code> is negative. | * @exception IllegalArgumentException If <code>n</code> is negative. | ||||
* @exception IOException If an I/O error occurs | * @exception IOException If an I/O error occurs | ||||
*/ | */ | ||||
public final long skip(final long n) throws IOException { | |||||
public final long skip(final long n) | |||||
throws IOException, IllegalArgumentException { | |||||
if (n < 0L) { | if (n < 0L) { | ||||
throw new IllegalArgumentException("skip value is negative"); | throw new IllegalArgumentException("skip value is negative"); | ||||
} | } | ||||
@@ -66,8 +66,9 @@ import org.apache.tools.ant.types.Parameter; | |||||
* | * | ||||
* Or: | * Or: | ||||
* | * | ||||
* <pre><filterreader classname="org.apache.tools.ant.filters.EscapeUnicode"/> | |||||
* </pre> | |||||
* <pre><filterreader | |||||
classname="org.apache.tools.ant.filters.EscapeUnicode"/> | |||||
* </pre> | |||||
* | * | ||||
* @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a> | * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a> | ||||
* @since Ant 1.6 | * @since Ant 1.6 | ||||
@@ -107,7 +108,7 @@ public class EscapeUnicode | |||||
* @return the next character in the resulting stream, or -1 | * @return the next character in the resulting stream, or -1 | ||||
* if the end of the resulting stream has been reached | * if the end of the resulting stream has been reached | ||||
* | * | ||||
* @exception java.io.IOException if the underlying stream throws | |||||
* @exception IOException if the underlying stream throws | |||||
* an IOException during reading | * an IOException during reading | ||||
*/ | */ | ||||
public final int read() throws IOException { | public final int read() throws IOException { | ||||
@@ -116,7 +117,7 @@ public class EscapeUnicode | |||||
setInitialized(true); | setInitialized(true); | ||||
} | } | ||||
int ch= - 1; | |||||
int ch = -1; | |||||
if (unicodeBuf.length() == 0) { | if (unicodeBuf.length() == 0) { | ||||
ch = in.read(); | ch = in.read(); | ||||
if (ch != -1) { | if (ch != -1) { | ||||
@@ -130,7 +131,7 @@ public class EscapeUnicode | |||||
- s.length() + i, | - s.length() + i, | ||||
s.charAt(i)); | s.charAt(i)); | ||||
} | } | ||||
ch='\\'; | |||||
ch = '\\'; | |||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
@@ -73,7 +73,8 @@ import org.apache.tools.ant.types.Parameter; | |||||
* | * | ||||
* Or: | * Or: | ||||
* | * | ||||
* <pre><filterreader classname="org.apache.tools.ant.filters.StripLineComments"> | |||||
* <pre><filterreader | |||||
* classname="org.apache.tools.ant.filters.StripLineComments"> | |||||
* <param type="comment" value="#"/> | * <param type="comment" value="#"/> | ||||
* <param type="comment" value="--"/> | * <param type="comment" value="--"/> | ||||
* <param type="comment" value="REM "/> | * <param type="comment" value="REM "/> | ||||
@@ -161,7 +161,8 @@ public final class ChainReaderHelper { | |||||
Object o = finalFilters.elementAt(i); | Object o = finalFilters.elementAt(i); | ||||
if (o instanceof AntFilterReader) { | if (o instanceof AntFilterReader) { | ||||
final AntFilterReader filter = (AntFilterReader) finalFilters.elementAt(i); | |||||
final AntFilterReader filter | |||||
= (AntFilterReader) finalFilters.elementAt(i); | |||||
final String className = filter.getClassName(); | final String className = filter.getClassName(); | ||||
final Path classpath = filter.getClasspath(); | final Path classpath = filter.getClasspath(); | ||||
final Project project = filter.getProject(); | final Project project = filter.getProject(); | ||||
@@ -135,7 +135,8 @@ public class ProjectHelperImpl extends ProjectHelper { | |||||
*/ | */ | ||||
public void parse(Project project, Object source) throws BuildException { | public void parse(Project project, Object source) throws BuildException { | ||||
if (!(source instanceof File)) { | if (!(source instanceof File)) { | ||||
throw new BuildException("Only File source supported by default plugin"); | |||||
throw new BuildException("Only File source supported by " | |||||
+ "default plugin"); | |||||
} | } | ||||
File buildFile = (File) source; | File buildFile = (File) source; | ||||
FileInputStream inputStream = null; | FileInputStream inputStream = null; | ||||
@@ -92,19 +92,19 @@ public class Parallel extends Task | |||||
private final Object semaphore = new Object(); | private final Object semaphore = new Object(); | ||||
/** Total number of threads to run */ | /** Total number of threads to run */ | ||||
int numThreads = 0; | |||||
private int numThreads = 0; | |||||
/** Total number of threads per processor to run. */ | /** Total number of threads per processor to run. */ | ||||
int numThreadsPerProcessor = 0; | |||||
private int numThreadsPerProcessor = 0; | |||||
/** Interval (in ms) to poll for finished threads. */ | /** Interval (in ms) to poll for finished threads. */ | ||||
int pollInterval = 1000; // default is once a second | |||||
private int pollInterval = 1000; // default is once a second | |||||
/** | /** | ||||
* Add a nested task to execute in parallel. | * Add a nested task to execute in parallel. | ||||
* @param nestedTask Nested task to be executed in parallel | * @param nestedTask Nested task to be executed in parallel | ||||
*/ | */ | ||||
public void addTask(Task nestedTask) throws BuildException { | |||||
public void addTask(Task nestedTask) { | |||||
nestedTasks.addElement(nestedTask); | nestedTasks.addElement(nestedTask); | ||||
} | } | ||||
@@ -128,7 +128,8 @@ public class Parallel extends Task | |||||
* simultaneously. If there are less tasks than threads then all will be | * simultaneously. If there are less tasks than threads then all will be | ||||
* executed at once, if there are more then only <code>threadCount</code> | * executed at once, if there are more then only <code>threadCount</code> | ||||
* tasks will be executed at one time. If <code>threadsPerProcessor</code> | * tasks will be executed at one time. If <code>threadsPerProcessor</code> | ||||
* is set and the JVM is at least a 1.4 VM then this value is ignormed.; optional | |||||
* is set and the JVM is at least a 1.4 VM then this value is | |||||
* ignored.; optional | |||||
* | * | ||||
* @param numThreads total number of therads. | * @param numThreads total number of therads. | ||||
* | * | ||||
@@ -147,6 +148,11 @@ public class Parallel extends Task | |||||
this.pollInterval = pollInterval; | this.pollInterval = pollInterval; | ||||
} | } | ||||
/** | |||||
* Execute the parallel tasks | |||||
* | |||||
* @exception BuildException if any of the threads failed. | |||||
*/ | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
updateThreadCounts(); | updateThreadCounts(); | ||||
if (numThreads == 0) { | if (numThreads == 0) { | ||||
@@ -155,6 +161,9 @@ public class Parallel extends Task | |||||
spinThreads(); | spinThreads(); | ||||
} | } | ||||
/** | |||||
* Determine the number of threads based on the number of processors | |||||
*/ | |||||
private void updateThreadCounts() { | private void updateThreadCounts() { | ||||
if (numThreadsPerProcessor != 0) { | if (numThreadsPerProcessor != 0) { | ||||
int numProcessors = getNumProcessors(); | int numProcessors = getNumProcessors(); | ||||
@@ -165,7 +174,9 @@ public class Parallel extends Task | |||||
} | } | ||||
/** | /** | ||||
* Spin up threadCount threads. | |||||
* Spin up required threads with a maximum number active at any given time. | |||||
* | |||||
* @exception BuildException if any of the threads failed. | |||||
*/ | */ | ||||
private void spinThreads() throws BuildException { | private void spinThreads() throws BuildException { | ||||
final int numTasks = nestedTasks.size(); | final int numTasks = nestedTasks.size(); | ||||
@@ -189,12 +200,13 @@ public class Parallel extends Task | |||||
// now run them in limited numbers... | // now run them in limited numbers... | ||||
outer: | outer: | ||||
while (threadNumber < numTasks) { | while (threadNumber < numTasks) { | ||||
synchronized(semaphore) { | |||||
synchronized (semaphore) { | |||||
for (int i = 0; i < maxRunning; i++) { | for (int i = 0; i < maxRunning; i++) { | ||||
if (running[i] == null || !running[i].isAlive()) { | if (running[i] == null || !running[i].isAlive()) { | ||||
running[i] = threads[threadNumber++]; | running[i] = threads[threadNumber++]; | ||||
running[i].start(); | running[i].start(); | ||||
// countinue on outer while loop in case we used our last thread | |||||
// countinue on outer while loop in case we | |||||
// used our last thread | |||||
continue outer; | continue outer; | ||||
} | } | ||||
} | } | ||||
@@ -252,7 +264,12 @@ public class Parallel extends Task | |||||
firstLocation); | firstLocation); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Determine the number of processors. Only effective on later VMs | |||||
* | |||||
* @return the number of processors available or 0 if not determinable. | |||||
*/ | |||||
private int getNumProcessors() { | private int getNumProcessors() { | ||||
try { | try { | ||||
Class[] paramTypes = {}; | Class[] paramTypes = {}; | ||||