Browse Source

fmt/refac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557021 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
3be2b26d81
4 changed files with 119 additions and 156 deletions
  1. +27
    -44
      src/main/org/apache/tools/ant/Diagnostics.java
  2. +41
    -48
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  3. +50
    -62
      src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
  4. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

+ 27
- 44
src/main/org/apache/tools/ant/Diagnostics.java View File

@@ -55,6 +55,7 @@ public final class Diagnostics {
* {@value} * {@value}
*/ */
private static final int BIG_DRIFT_LIMIT = 10000; private static final int BIG_DRIFT_LIMIT = 10000;

/** /**
* How big a test file to write. * How big a test file to write.
* {@value} * {@value}
@@ -64,15 +65,14 @@ public final class Diagnostics {
private static final int SECONDS_PER_MILLISECOND = 1000; private static final int SECONDS_PER_MILLISECOND = 1000;
private static final int SECONDS_PER_MINUTE = 60; private static final int SECONDS_PER_MINUTE = 60;
private static final int MINUTES_PER_HOUR = 60; private static final int MINUTES_PER_HOUR = 60;
private static final String TEST_CLASS
= "org.apache.tools.ant.taskdefs.optional.Test";
private static final String TEST_CLASS = "org.apache.tools.ant.taskdefs.optional.Test";


/** /**
* The error text when a security manager blocks access to a property. * The error text when a security manager blocks access to a property.
* {@value} * {@value}
*/ */
protected static final String ERROR_PROPERTY_ACCESS_BLOCKED protected static final String ERROR_PROPERTY_ACCESS_BLOCKED
= "Access to this property blocked by a security manager";
= "Access to this property blocked by a security manager";


/** utility class */ /** utility class */
private Diagnostics() { private Diagnostics() {
@@ -100,16 +100,14 @@ public final class Diagnostics {
*/ */
public static void validateVersion() throws BuildException { public static void validateVersion() throws BuildException {
try { try {
Class optional
= Class.forName(TEST_CLASS);
Class optional = Class.forName(TEST_CLASS);
String coreVersion = getImplementationVersion(Main.class); String coreVersion = getImplementationVersion(Main.class);
String optionalVersion = getImplementationVersion(optional); String optionalVersion = getImplementationVersion(optional);


if (coreVersion != null && !coreVersion.equals(optionalVersion)) { if (coreVersion != null && !coreVersion.equals(optionalVersion)) {
throw new BuildException("Invalid implementation version " throw new BuildException("Invalid implementation version "
+ "between Ant core and Ant optional tasks.\n"
+ " core : " + coreVersion + "\n"
+ " optional: " + optionalVersion);
+ "between Ant core and Ant optional tasks.\n" + " core : "
+ coreVersion + "\n" + " optional: " + optionalVersion);
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// ignore // ignore
@@ -144,7 +142,6 @@ public final class Diagnostics {
return name.endsWith(".jar"); return name.endsWith(".jar");
} }
}; };

File[] files = libDir.listFiles(filter); File[] files = libDir.listFiles(filter);
return files; return files;
} }
@@ -157,7 +154,6 @@ public final class Diagnostics {
doReport(System.out); doReport(System.out);
} }



/** /**
* Helper method to get the implementation version. * Helper method to get the implementation version.
* @param clazz the class to get the information from. * @param clazz the class to get the information from.
@@ -165,8 +161,7 @@ public final class Diagnostics {
* '?.?' for JDK 1.0 or 1.1. * '?.?' for JDK 1.0 or 1.1.
*/ */
private static String getImplementationVersion(Class clazz) { private static String getImplementationVersion(Class clazz) {
Package pkg = clazz.getPackage();
return pkg.getImplementationVersion();
return clazz.getPackage().getImplementationVersion();
} }


/** /**
@@ -178,7 +173,6 @@ public final class Diagnostics {
if (saxParser == null) { if (saxParser == null) {
return "Could not create an XML Parser"; return "Could not create an XML Parser";
} }

// check to what is in the classname // check to what is in the classname
String saxParserName = saxParser.getClass().getName(); String saxParserName = saxParser.getClass().getName();
return saxParserName; return saxParserName;
@@ -273,8 +267,7 @@ public final class Diagnostics {
Class optional = null; Class optional = null;
try { try {
optional = Class.forName(TEST_CLASS); optional = Class.forName(TEST_CLASS);
out.println("optional tasks : "
+ getImplementationVersion(optional));
out.println("optional tasks : " + getImplementationVersion(optional));
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
ignoreThrowable(e); ignoreThrowable(e);
out.println("optional tasks : not available"); out.println("optional tasks : not available");
@@ -331,8 +324,7 @@ public final class Diagnostics {
sysprops = System.getProperties(); sysprops = System.getProperties();
} catch (SecurityException e) { } catch (SecurityException e) {
ignoreThrowable(e); ignoreThrowable(e);
out.println("Access to System.getProperties() blocked "
+ "by a security manager");
out.println("Access to System.getProperties() blocked " + "by a security manager");
} }
for (Enumeration keys = sysprops.propertyNames(); for (Enumeration keys = sysprops.propertyNames();
keys.hasMoreElements();) { keys.hasMoreElements();) {
@@ -368,7 +360,7 @@ public final class Diagnostics {
p.initProperties(); p.initProperties();
out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_VERSION)); out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_VERSION));
out.println(MagicNames.ANT_JAVA_VERSION + ": " out.println(MagicNames.ANT_JAVA_VERSION + ": "
+ p.getProperty(MagicNames.ANT_JAVA_VERSION));
+ p.getProperty(MagicNames.ANT_JAVA_VERSION));
out.println(MagicNames.ANT_LIB + ": " + p.getProperty(MagicNames.ANT_LIB)); out.println(MagicNames.ANT_LIB + ": " + p.getProperty(MagicNames.ANT_LIB));
out.println(MagicNames.ANT_HOME + ": " + p.getProperty(MagicNames.ANT_HOME)); out.println(MagicNames.ANT_HOME + ": " + p.getProperty(MagicNames.ANT_HOME));
} }
@@ -407,8 +399,7 @@ public final class Diagnostics {
return; return;
} }
for (int i = 0; i < libs.length; i++) { for (int i = 0; i < libs.length; i++) {
out.println(libs[i].getName()
+ " (" + libs[i].length() + " bytes)");
out.println(libs[i].getName() + " (" + libs[i].length() + " bytes)");
} }
} }


@@ -421,8 +412,7 @@ public final class Diagnostics {
Throwable error = null; Throwable error = null;
try { try {
Class which = Class.forName("org.apache.env.Which"); Class which = Class.forName("org.apache.env.Which");
Method method
= which.getMethod("main", new Class[]{String[].class});
Method method = which.getMethod("main", new Class[] { String[].class });
method.invoke(null, new Object[]{new String[]{}}); method.invoke(null, new Object[]{new String[]{}});
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
out.println("Not available."); out.println("Not available.");
@@ -492,15 +482,12 @@ public final class Diagnostics {
String parserName = getXmlParserName(); String parserName = getXmlParserName();
String parserLocation = getXMLParserLocation(); String parserLocation = getXMLParserLocation();
printParserInfo(out, "XML Parser", parserName, parserLocation); printParserInfo(out, "XML Parser", parserName, parserLocation);
printParserInfo(out, "Namespace-aware parser",
getNamespaceParserName(),
printParserInfo(out, "Namespace-aware parser", getNamespaceParserName(),
getNamespaceParserLocation()); getNamespaceParserLocation());
} }


private static void printParserInfo(PrintStream out,
String parserType,
String parserName,
String parserLocation) {
private static void printParserInfo(PrintStream out, String parserType, String parserName,
String parserLocation) {
if (parserName == null) { if (parserName == null) {
parserName = "unknown"; parserName = "unknown";
} }
@@ -526,8 +513,7 @@ public final class Diagnostics {
out.println("Temp dir is " + tempdir); out.println("Temp dir is " + tempdir);
File tempDirectory = new File(tempdir); File tempDirectory = new File(tempdir);
if (!tempDirectory.exists()) { if (!tempDirectory.exists()) {
out.println("Warning, java.io.tmpdir directory does not exist: "
+ tempdir);
out.println("Warning, java.io.tmpdir directory does not exist: " + tempdir);
return; return;
} }
//create the file //create the file
@@ -554,8 +540,7 @@ public final class Diagnostics {
} }
} catch (IOException e) { } catch (IOException e) {
ignoreThrowable(e); ignoreThrowable(e);
out.println("Failed to create a temporary file in the temp dir "
+ tempdir);
out.println("Failed to create a temporary file in the temp dir " + tempdir);
out.println("File " + tempFile + " could not be created/written to"); out.println("File " + tempFile + " could not be created/written to");
} finally { } finally {
FileUtils.close(fileout); FileUtils.close(fileout);
@@ -573,16 +558,15 @@ public final class Diagnostics {
//calendar stuff. //calendar stuff.
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone(); TimeZone tz = cal.getTimeZone();
out.println("Timezone " + tz.getDisplayName()
+ " offset=" + tz.getOffset(cal.get(Calendar.ERA),
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.DAY_OF_WEEK),
((cal.get(Calendar.HOUR_OF_DAY) * MINUTES_PER_HOUR
+ cal.get(Calendar.MINUTE)) * SECONDS_PER_MINUTE
+ cal.get(Calendar.SECOND)) * SECONDS_PER_MILLISECOND
+ cal.get(Calendar.MILLISECOND)));
out.println("Timezone "
+ tz.getDisplayName()
+ " offset="
+ tz.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal
.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal
.get(Calendar.DAY_OF_WEEK), ((cal.get(Calendar.HOUR_OF_DAY)
* MINUTES_PER_HOUR + cal.get(Calendar.MINUTE))
* SECONDS_PER_MINUTE + cal.get(Calendar.SECOND))
* SECONDS_PER_MILLISECOND + cal.get(Calendar.MILLISECOND)));
} }


/** /**
@@ -629,8 +613,7 @@ public final class Diagnostics {
return; return;
} }
printProperty(out, ProxySetup.USE_SYSTEM_PROXIES); printProperty(out, ProxySetup.USE_SYSTEM_PROXIES);
final String proxyDiagClassname
= "org.apache.tools.ant.util.java15.ProxyDiagnostics";
final String proxyDiagClassname = "org.apache.tools.ant.util.java15.ProxyDiagnostics";
try { try {
Class proxyDiagClass = Class.forName(proxyDiagClassname); Class proxyDiagClass = Class.forName(proxyDiagClassname);
Object instance = proxyDiagClass.newInstance(); Object instance = proxyDiagClass.newInstance();


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

@@ -112,7 +112,6 @@ public class ProjectHelper2 extends ProjectHelper {
project.addReference(REFID_CONTEXT, context); project.addReference(REFID_CONTEXT, context);
project.addReference(REFID_TARGETS, context.getTargets()); project.addReference(REFID_TARGETS, context.getTargets());
} }

if (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);
@@ -171,9 +170,8 @@ public class ProjectHelper2 extends ProjectHelper {
// } else if (source instanceof InputSource ) { // } else if (source instanceof InputSource ) {
} else { } else {
throw new BuildException("Source " + source.getClass().getName() throw new BuildException("Source " + source.getClass().getName()
+ " not supported by this plugin");
+ " not supported by this plugin");
} }

InputStream inputStream = null; InputStream inputStream = null;
InputSource inputSource = null; InputSource inputSource = null;


@@ -196,8 +194,8 @@ public class ProjectHelper2 extends ProjectHelper {
if (uri != null) { if (uri != null) {
inputSource.setSystemId(uri); inputSource.setSystemId(uri);
} }
project.log("parsing buildfile " + buildFileName
+ " with URI = " + uri, Project.MSG_VERBOSE);
project.log("parsing buildfile " + buildFileName + " with URI = " + uri,
Project.MSG_VERBOSE);


DefaultHandler hb = handler; DefaultHandler hb = handler;


@@ -207,8 +205,8 @@ public class ProjectHelper2 extends ProjectHelper {
parser.setDTDHandler(hb); parser.setDTDHandler(hb);
parser.parse(inputSource); parser.parse(inputSource);
} catch (SAXParseException exc) { } catch (SAXParseException exc) {
Location location = new Location(exc.getSystemId(),
exc.getLineNumber(), exc.getColumnNumber());
Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc
.getColumnNumber());


Throwable t = exc.getException(); Throwable t = exc.getException();
if (t instanceof BuildException) { if (t instanceof BuildException) {
@@ -228,11 +226,11 @@ public class ProjectHelper2 extends ProjectHelper {
} catch (FileNotFoundException exc) { } catch (FileNotFoundException exc) {
throw new BuildException(exc); throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) { } catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file "
+ buildFileName + " is invalid.", exc);
throw new BuildException("Encoding of project file " + buildFileName + " is invalid.",
exc);
} catch (IOException exc) { } catch (IOException exc) {
throw new BuildException("Error reading project file "
+ buildFileName + ": " + exc.getMessage(), exc);
throw new BuildException("Error reading project file " + buildFileName + ": "
+ exc.getMessage(), exc);
} finally { } finally {
FileUtils.close(inputStream); FileUtils.close(inputStream);
} }
@@ -349,8 +347,8 @@ public class ProjectHelper2 extends ProjectHelper {
*/ */
public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs, public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs,
AntXMLContext context) throws SAXParseException { AntXMLContext context) throws SAXParseException {
throw new SAXParseException("Unexpected element \"" + qname
+ " \"", context.getLocator());
throw new SAXParseException("Unexpected element \"" + qname + " \"", context
.getLocator());
} }


/** /**
@@ -362,8 +360,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @param context the current context * @param context the current context
* @exception SAXParseException if an error occurs * @exception SAXParseException if an error occurs
*/ */
public void onEndChild(String uri, String tag, String qname,
AntXMLContext context) throws SAXParseException {
public void onEndChild(String uri, String tag, String qname, AntXMLContext context)
throws SAXParseException {
} }


/** /**
@@ -390,7 +388,7 @@ public class ProjectHelper2 extends ProjectHelper {
* case of error in an overridden version * case of error in an overridden version
*/ */
public void characters(char[] buf, int start, int count, AntXMLContext context) public void characters(char[] buf, int start, int count, AntXMLContext context)
throws SAXParseException {
throws SAXParseException {
String s = new String(buf, start, count).trim(); String s = new String(buf, start, count).trim();


if (s.length() > 0) { if (s.length() > 0) {
@@ -459,8 +457,8 @@ public class ProjectHelper2 extends ProjectHelper {
file = FILE_UTILS.resolveFile(context.getBuildFileParent(), path); file = FILE_UTILS.resolveFile(context.getBuildFileParent(), path);
context.getProject().log( context.getProject().log(
"Warning: '" + systemId + "' in " + context.getBuildFile() "Warning: '" + systemId + "' in " + context.getBuildFile()
+ " should be expressed simply as '" + path.replace('\\', '/')
+ "' for compliance with other XML tools", Project.MSG_WARN);
+ " should be expressed simply as '" + path.replace('\\', '/')
+ "' for compliance with other XML tools", Project.MSG_WARN);
} }
context.getProject().log("file=" + file, Project.MSG_DEBUG); context.getProject().log("file=" + file, Project.MSG_DEBUG);
try { try {
@@ -468,8 +466,8 @@ public class ProjectHelper2 extends ProjectHelper {
inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath())); inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath()));
return inputSource; return inputSource;
} catch (FileNotFoundException fne) { } catch (FileNotFoundException fne) {
context.getProject().log(file.getAbsolutePath()
+ " could not be found", Project.MSG_WARN);
context.getProject().log(file.getAbsolutePath() + " could not be found",
Project.MSG_WARN);
} }


} }
@@ -493,7 +491,7 @@ public class ProjectHelper2 extends ProjectHelper {
* <code>"project"</code> * <code>"project"</code>
*/ */
public void startElement(String uri, String tag, String qname, Attributes attrs) public void startElement(String uri, String tag, String qname, Attributes attrs)
throws SAXParseException {
throws SAXParseException {
AntHandler next = currentHandler.onStartChild(uri, tag, qname, attrs, context); AntHandler next = currentHandler.onStartChild(uri, tag, qname, attrs, context);
antHandlers.push(currentHandler); antHandlers.push(currentHandler);
currentHandler = next; currentHandler = next;
@@ -680,8 +678,8 @@ public class ProjectHelper2 extends ProjectHelper {
} }
} else { } else {
// XXX ignore attributes in a different NS ( maybe store them ? ) // XXX ignore attributes in a different NS ( maybe store them ? )
throw new SAXParseException("Unexpected attribute \""
+ attrs.getQName(i) + "\"", context.getLocator());
throw new SAXParseException("Unexpected attribute \"" + attrs.getQName(i)
+ "\"", context.getLocator());
} }
} }


@@ -692,16 +690,15 @@ public class ProjectHelper2 extends ProjectHelper {
File dupFile = new File(dup); File dupFile = new File(dup);
if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) { if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) {
project.log("Duplicated project name in import. Project " project.log("Duplicated project name in import. Project "
+ context.getCurrentProjectName() + " defined first in "
+ dup + " and again in " + context.getBuildFile(), Project.MSG_WARN);
+ context.getCurrentProjectName() + " defined first in " + dup
+ " and again in " + context.getBuildFile(), Project.MSG_WARN);
} }
} }

if (context.getBuildFile() != null && nameAttributeSet) { if (context.getBuildFile() != null && nameAttributeSet) {
project.setUserProperty(MagicNames.ANT_FILE + "."
+ context.getCurrentProjectName(), context.getBuildFile().toString());
project.setUserProperty(
MagicNames.ANT_FILE + "." + context.getCurrentProjectName(), context
.getBuildFile().toString());
} }

if (context.isIgnoringProjectTag()) { if (context.isIgnoringProjectTag()) {
// no further processing // no further processing
return; return;
@@ -718,12 +715,11 @@ public class ProjectHelper2 extends ProjectHelper {
if ((new File(baseDir)).isAbsolute()) { if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir); project.setBasedir(baseDir);
} else { } else {
project.setBaseDir(FILE_UTILS.resolveFile(
context.getBuildFileParent(), baseDir));
project.setBaseDir(FILE_UTILS.resolveFile(context.getBuildFileParent(),
baseDir));
} }
} }
} }

project.addTarget("", context.getImplicitTarget()); project.addTarget("", context.getImplicitTarget());
context.setCurrentTarget(context.getImplicitTarget()); context.setCurrentTarget(context.getImplicitTarget());
} }
@@ -816,8 +812,8 @@ public class ProjectHelper2 extends ProjectHelper {
} else if (key.equals("description")) { } else if (key.equals("description")) {
target.setDescription(value); target.setDescription(value);
} else { } else {
throw new SAXParseException("Unexpected attribute \""
+ key + "\"", context.getLocator());
throw new SAXParseException("Unexpected attribute \"" + key + "\"", context
.getLocator());
} }
} }


@@ -830,26 +826,23 @@ public class ProjectHelper2 extends ProjectHelper {
if (context.getCurrentTargets().get(name) != null) { if (context.getCurrentTargets().get(name) != null) {
throw new BuildException("Duplicate target '" + name + "'", target.getLocation()); throw new BuildException("Duplicate target '" + name + "'", target.getLocation());
} }

Hashtable projectTargets = project.getTargets(); Hashtable projectTargets = project.getTargets();
boolean usedTarget = false; boolean usedTarget = false;
// If the name has not already been defined define it // If the name has not already been defined define it
if (projectTargets.containsKey(name)) { if (projectTargets.containsKey(name)) {
project.log("Already defined in main or a previous import, ignore "
+ name, Project.MSG_VERBOSE);
project.log("Already defined in main or a previous import, ignore " + name,
Project.MSG_VERBOSE);
} else { } else {
target.setName(name); target.setName(name);
context.getCurrentTargets().put(name, target); context.getCurrentTargets().put(name, target);
project.addOrReplaceTarget(name, target); project.addOrReplaceTarget(name, target);
usedTarget = true; usedTarget = true;
} }

if (depends.length() > 0) { if (depends.length() > 0) {
target.setDepends(depends); target.setDepends(depends);
} }

if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null
&& context.getCurrentProjectName().length() != 0) {
&& context.getCurrentProjectName().length() != 0) {
// In an impored file (and not completely // In an impored file (and not completely
// ignoring the project tag) // ignoring the project tag)
String newName = context.getCurrentProjectName() + "." + name; String newName = context.getCurrentProjectName() + "." + name;
@@ -940,8 +933,8 @@ public class ProjectHelper2 extends ProjectHelper {
task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag)); task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));
task.setTaskName(qname); task.setTaskName(qname);


Location location = new Location(context.getLocator().getSystemId(),
context.getLocator().getLineNumber(), context.getLocator().getColumnNumber());
Location location = new Location(context.getLocator().getSystemId(), context
.getLocator().getLineNumber(), context.getLocator().getColumnNumber());
task.setLocation(location); task.setLocation(location);
task.setOwningTarget(context.getCurrentTarget()); task.setOwningTarget(context.getCurrentTarget());


@@ -971,19 +964,19 @@ public class ProjectHelper2 extends ProjectHelper {
// an ant-type is a component name which can // an ant-type is a component name which can
// be namespaced, need to extract the name // be namespaced, need to extract the name
// and convert from qualified name to uri/name // and convert from qualified name to uri/name
if (ANT_TYPE.equals(name) || (ANT_CORE_URI.equals(attrUri)
&& ANT_TYPE.equals(attrs.getLocalName(i)))) {
if (ANT_TYPE.equals(name)
|| (ANT_CORE_URI.equals(attrUri) && ANT_TYPE.equals(attrs.getLocalName(i)))) {
name = ANT_TYPE; name = ANT_TYPE;
int index = value.indexOf(":"); int index = value.indexOf(":");
if (index >= 0) { if (index >= 0) {
String prefix = value.substring(0, index); String prefix = value.substring(0, index);
String mappedUri = context.getPrefixMapping(prefix); String mappedUri = context.getPrefixMapping(prefix);
if (mappedUri == null) { if (mappedUri == null) {
throw new BuildException(
"Unable to find XML NS prefix \"" + prefix + "\"");
throw new BuildException("Unable to find XML NS prefix \"" + prefix
+ "\"");
} }
value = ProjectHelper.genComponentName(
mappedUri, value.substring(index + 1));
value = ProjectHelper.genComponentName(mappedUri, value
.substring(index + 1));
} }
} }
wrapper.setAttribute(name, value); wrapper.setAttribute(name, value);


+ 50
- 62
src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java View File

@@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */

package org.apache.tools.ant.helper; package org.apache.tools.ant.helper;


import java.io.File; import java.io.File;
@@ -65,18 +64,22 @@ public class ProjectHelperImpl extends ProjectHelper {


/** The project to configure. */ /** The project to configure. */
private Project project; private Project project;

/** The configuration file to parse. */ /** The configuration file to parse. */
private File buildFile; private File buildFile;

/** /**
* Parent directory of the build file. Used for resolving entities * Parent directory of the build file. Used for resolving entities
* and setting the project's base directory. * and setting the project's base directory.
*/ */
private File buildFileParent; private File buildFileParent;

/** /**
* Locator for the configuration file parser. * Locator for the configuration file parser.
* Used for giving locations of errors etc. * Used for giving locations of errors etc.
*/ */
private Locator locator; private Locator locator;

/** /**
* Target that all other targets will depend upon implicitly. * Target that all other targets will depend upon implicitly.
* *
@@ -119,14 +122,11 @@ public class ProjectHelperImpl extends ProjectHelper {
} catch (BuildException e) { } catch (BuildException e) {
parser = new XMLReaderAdapter(JAXPUtils.getXMLReader()); parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
} }


String uri = FILE_UTILS.toURI(bFile.getAbsolutePath()); String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
inputStream = new FileInputStream(bFile); inputStream = new FileInputStream(bFile);
inputSource = new InputSource(inputStream); inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri); inputSource.setSystemId(uri);
project.log("parsing buildfile " + bFile + " with URI = "
+ uri, Project.MSG_VERBOSE);
project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE);
HandlerBase hb = new RootHandler(this); HandlerBase hb = new RootHandler(this);
parser.setDocumentHandler(hb); parser.setDocumentHandler(hb);
parser.setEntityResolver(hb); parser.setEntityResolver(hb);
@@ -134,9 +134,8 @@ public class ProjectHelperImpl extends ProjectHelper {
parser.setDTDHandler(hb); parser.setDTDHandler(hb);
parser.parse(inputSource); parser.parse(inputSource);
} catch (SAXParseException exc) { } catch (SAXParseException exc) {
Location location =
new Location(exc.getSystemId(), exc.getLineNumber(),
exc.getColumnNumber());
Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc
.getColumnNumber());


Throwable t = exc.getException(); Throwable t = exc.getException();
if (t instanceof BuildException) { if (t instanceof BuildException) {
@@ -146,7 +145,6 @@ public class ProjectHelperImpl extends ProjectHelper {
} }
throw be; throw be;
} }

throw new BuildException(exc.getMessage(), t, location); throw new BuildException(exc.getMessage(), t, location);
} catch (SAXException exc) { } catch (SAXException exc) {
Throwable t = exc.getException(); Throwable t = exc.getException();
@@ -157,11 +155,9 @@ public class ProjectHelperImpl extends ProjectHelper {
} catch (FileNotFoundException exc) { } catch (FileNotFoundException exc) {
throw new BuildException(exc); throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) { } catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file is invalid.",
exc);
throw new BuildException("Encoding of project file is invalid.", exc);
} catch (IOException exc) { } catch (IOException exc) {
throw new BuildException("Error reading project file: "
+ exc.getMessage(), exc);
throw new BuildException("Error reading project file: " + exc.getMessage(), exc);
} finally { } finally {
FileUtils.close(inputStream); FileUtils.close(inputStream);
} }
@@ -290,8 +286,7 @@ public class ProjectHelperImpl extends ProjectHelper {
* @param systemId The system identifier provided in the XML * @param systemId The system identifier provided in the XML
* document. Will not be <code>null</code>. * document. Will not be <code>null</code>.
*/ */
public InputSource resolveEntity(String publicId,
String systemId) {
public InputSource resolveEntity(String publicId, String systemId) {


helperImpl.project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE); helperImpl.project.log("resolving systemId: " + systemId, Project.MSG_VERBOSE);


@@ -301,11 +296,9 @@ public class ProjectHelperImpl extends ProjectHelper {
File file = new File(path); File file = new File(path);
if (!file.isAbsolute()) { if (!file.isAbsolute()) {
file = FILE_UTILS.resolveFile(helperImpl.buildFileParent, path); file = FILE_UTILS.resolveFile(helperImpl.buildFileParent, path);
helperImpl.project.log(
"Warning: '" + systemId + "' in " + helperImpl.buildFile
helperImpl.project.log("Warning: '" + systemId + "' in " + helperImpl.buildFile
+ " should be expressed simply as '" + path.replace('\\', '/') + " should be expressed simply as '" + path.replace('\\', '/')
+ "' for compliance with other XML tools",
Project.MSG_WARN);
+ "' for compliance with other XML tools", Project.MSG_WARN);
} }
try { try {
InputSource inputSource = new InputSource(new FileInputStream(file)); InputSource inputSource = new InputSource(new FileInputStream(file));
@@ -313,7 +306,7 @@ public class ProjectHelperImpl extends ProjectHelper {
return inputSource; return inputSource;
} catch (FileNotFoundException fne) { } catch (FileNotFoundException fne) {
helperImpl.project.log(file.getAbsolutePath() + " could not be found", helperImpl.project.log(file.getAbsolutePath() + " could not be found",
Project.MSG_WARN);
Project.MSG_WARN);
} }
} }
// use default if not file or file not found // use default if not file or file not found
@@ -336,8 +329,8 @@ public class ProjectHelperImpl extends ProjectHelper {
if (tag.equals("project")) { if (tag.equals("project")) {
new ProjectHandler(helperImpl, this).init(tag, attrs); new ProjectHandler(helperImpl, this).init(tag, attrs);
} else { } else {
throw new SAXParseException("Config file is not of expected "
+ "XML type", helperImpl.locator);
throw new SAXParseException("Config file is not of expected " + "XML type",
helperImpl.locator);
} }
} }


@@ -403,8 +396,8 @@ public class ProjectHelperImpl extends ProjectHelper {
} else if (key.equals("basedir")) { } else if (key.equals("basedir")) {
baseDir = value; baseDir = value;
} else { } else {
throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"",
helperImpl.locator);
throw new SAXParseException(
"Unexpected attribute \"" + attrs.getName(i) + "\"", helperImpl.locator);
} }
} }


@@ -433,8 +426,8 @@ public class ProjectHelperImpl extends ProjectHelper {
if ((new File(baseDir)).isAbsolute()) { if ((new File(baseDir)).isAbsolute()) {
helperImpl.project.setBasedir(baseDir); helperImpl.project.setBasedir(baseDir);
} else { } else {
File resolvedBaseDir = FILE_UTILS.resolveFile(
helperImpl.buildFileParent, baseDir);
File resolvedBaseDir = FILE_UTILS.resolveFile(helperImpl.buildFileParent,
baseDir);
helperImpl.project.setBaseDir(resolvedBaseDir); helperImpl.project.setBaseDir(resolvedBaseDir);
} }
} }
@@ -462,8 +455,7 @@ public class ProjectHelperImpl extends ProjectHelper {
if (name.equals("target")) { if (name.equals("target")) {
handleTarget(name, attrs); handleTarget(name, attrs);
} else { } else {
handleElement(helperImpl, this, helperImpl.implicitTarget,
name, attrs);
handleElement(helperImpl, this, helperImpl.implicitTarget, name, attrs);
} }
} }


@@ -482,7 +474,6 @@ public class ProjectHelperImpl extends ProjectHelper {
private void handleTarget(String tag, AttributeList attrs) throws SAXParseException { private void handleTarget(String tag, AttributeList attrs) throws SAXParseException {
new TargetHandler(helperImpl, this).init(tag, attrs); new TargetHandler(helperImpl, this).init(tag, attrs);
} }

} }


/** /**
@@ -534,9 +525,8 @@ public class ProjectHelperImpl extends ProjectHelper {
if (key.equals("name")) { if (key.equals("name")) {
name = value; name = value;
if (name.equals("")) { if (name.equals("")) {
throw new BuildException("name attribute must not"
+ " be empty",
new Location(helperImpl.locator));
throw new BuildException("name attribute must not" + " be empty",
new Location(helperImpl.locator));
} }
} else if (key.equals("depends")) { } else if (key.equals("depends")) {
depends = value; depends = value;
@@ -549,14 +539,14 @@ public class ProjectHelperImpl extends ProjectHelper {
} else if (key.equals("description")) { } else if (key.equals("description")) {
description = value; description = value;
} else { } else {
throw new SAXParseException("Unexpected attribute \""
+ key + "\"", helperImpl.locator);
throw new SAXParseException("Unexpected attribute \"" + key + "\"",
helperImpl.locator);
} }
} }


if (name == null) { if (name == null) {
throw new SAXParseException("target element appears without a name attribute", throw new SAXParseException("target element appears without a name attribute",
helperImpl.locator);
helperImpl.locator);
} }


target = new Target(); target = new Target();
@@ -605,20 +595,14 @@ public class ProjectHelperImpl extends ProjectHelper {
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
private static void handleElement(ProjectHelperImpl helperImpl,
DocumentHandler parent,
Target target, String elementName,
AttributeList attrs)
throws SAXParseException {
private static void handleElement(ProjectHelperImpl helperImpl, DocumentHandler parent,
Target target, String elementName, AttributeList attrs) throws SAXParseException {
if (elementName.equals("description")) { if (elementName.equals("description")) {
new DescriptionHandler(helperImpl, parent); new DescriptionHandler(helperImpl, parent);
} else if (helperImpl.project.getDataTypeDefinitions()
.get(elementName) != null) {
new DataTypeHandler(helperImpl, parent, target)
.init(elementName, attrs);
} else if (helperImpl.project.getDataTypeDefinitions().get(elementName) != null) {
new DataTypeHandler(helperImpl, parent, target).init(elementName, attrs);
} else { } else {
new TaskHandler(helperImpl, parent, target, null, target)
.init(elementName, attrs);
new TaskHandler(helperImpl, parent, target, null, target).init(elementName, attrs);
} }
} }


@@ -665,20 +649,24 @@ public class ProjectHelperImpl extends ProjectHelper {
static class TaskHandler extends AbstractHandler { static class TaskHandler extends AbstractHandler {
/** Containing target, if any. */ /** Containing target, if any. */
private Target target; private Target target;

/** /**
* Container for the task, if any. If target is * Container for the task, if any. If target is
* non-<code>null</code>, this must be too. * non-<code>null</code>, this must be too.
*/ */
private TaskContainer container; private TaskContainer container;

/** /**
* Task created by this handler. * Task created by this handler.
*/ */
private Task task; private Task task;

/** /**
* Wrapper for the parent element, if any. The wrapper for this * Wrapper for the parent element, if any. The wrapper for this
* element will be added to this wrapper as a child. * element will be added to this wrapper as a child.
*/ */
private RuntimeConfigurable parentWrapper; private RuntimeConfigurable parentWrapper;

/** /**
* Wrapper for this element which takes care of actually configuring * Wrapper for this element which takes care of actually configuring
* the element, if this element is contained within a target. * the element, if this element is contained within a target.
@@ -735,14 +723,12 @@ public class ProjectHelperImpl extends ProjectHelper {
// swallow here, will be thrown again in // swallow here, will be thrown again in
// UnknownElement.maybeConfigure if the problem persists. // UnknownElement.maybeConfigure if the problem persists.
} }

if (task == null) { if (task == null) {
task = new UnknownElement(tag); task = new UnknownElement(tag);
task.setProject(helperImpl.project); task.setProject(helperImpl.project);
//XXX task.setTaskType(tag); //XXX task.setTaskType(tag);
task.setTaskName(tag); task.setTaskName(tag);
} }

task.setLocation(new Location(helperImpl.locator)); task.setLocation(new Location(helperImpl.locator));
helperImpl.configureId(task, attrs); helperImpl.configureId(task, attrs);


@@ -784,11 +770,10 @@ public class ProjectHelperImpl extends ProjectHelper {
public void startElement(String name, AttributeList attrs) throws SAXParseException { public void startElement(String name, AttributeList attrs) throws SAXParseException {
if (task instanceof TaskContainer) { if (task instanceof TaskContainer) {
// task can contain other tasks - no other nested elements possible // task can contain other tasks - no other nested elements possible
new TaskHandler(helperImpl, this, (TaskContainer) task,
wrapper, target).init(name, attrs);
new TaskHandler(helperImpl, this, (TaskContainer) task, wrapper, target).init(name,
attrs);
} else { } else {
new NestedElementHandler(helperImpl, this, task,
wrapper, target).init(name, attrs);
new NestedElementHandler(helperImpl, this, task, wrapper, target).init(name, attrs);
} }
} }
} }
@@ -799,13 +784,16 @@ public class ProjectHelperImpl extends ProjectHelper {
static class NestedElementHandler extends AbstractHandler { static class NestedElementHandler extends AbstractHandler {
/** Parent object (task/data type/etc). */ /** Parent object (task/data type/etc). */
private Object parent; private Object parent;

/** The nested element itself. */ /** The nested element itself. */
private Object child; private Object child;

/** /**
* Wrapper for the parent element, if any. The wrapper for this * Wrapper for the parent element, if any. The wrapper for this
* element will be added to this wrapper as a child. * element will be added to this wrapper as a child.
*/ */
private RuntimeConfigurable parentWrapper; private RuntimeConfigurable parentWrapper;

/** /**
* Wrapper for this element which takes care of actually configuring * Wrapper for this element which takes care of actually configuring
* the element, if a parent wrapper is provided. * the element, if a parent wrapper is provided.
@@ -813,6 +801,7 @@ public class ProjectHelperImpl extends ProjectHelper {
* @see ProjectHelper#configure(Object,AttributeList,Project) * @see ProjectHelper#configure(Object,AttributeList,Project)
*/ */
private RuntimeConfigurable childWrapper = null; private RuntimeConfigurable childWrapper = null;

/** Target this element is part of, if any. */ /** Target this element is part of, if any. */
private Target target; private Target target;


@@ -866,8 +855,7 @@ public class ProjectHelperImpl extends ProjectHelper {
*/ */
public void init(String propType, AttributeList attrs) throws SAXParseException { public void init(String propType, AttributeList attrs) throws SAXParseException {
Class parentClass = parent.getClass(); Class parentClass = parent.getClass();
IntrospectionHelper ih =
IntrospectionHelper.getHelper(helperImpl.project, parentClass);
IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass);


try { try {
String elementName = propType.toLowerCase(Locale.US); String elementName = propType.toLowerCase(Locale.US);
@@ -879,7 +867,6 @@ public class ProjectHelperImpl extends ProjectHelper {
} else { } else {
child = ih.createElement(helperImpl.project, parent, elementName); child = ih.createElement(helperImpl.project, parent, elementName);
} }

helperImpl.configureId(child, attrs); helperImpl.configureId(child, attrs);


childWrapper = new RuntimeConfigurable(child, propType); childWrapper = new RuntimeConfigurable(child, propType);
@@ -919,11 +906,11 @@ public class ProjectHelperImpl extends ProjectHelper {
if (child instanceof TaskContainer) { if (child instanceof TaskContainer) {
// taskcontainer nested element can contain other tasks - no other // taskcontainer nested element can contain other tasks - no other
// nested elements possible // nested elements possible
new TaskHandler(helperImpl, this, (TaskContainer) child,
childWrapper, target).init(name, attrs);
new TaskHandler(helperImpl, this, (TaskContainer) child, childWrapper, target)
.init(name, attrs);
} else { } else {
new NestedElementHandler(helperImpl, this, child,
childWrapper, target).init(name, attrs);
new NestedElementHandler(helperImpl, this, child, childWrapper, target).init(name,
attrs);
} }
} }
} }
@@ -934,8 +921,10 @@ public class ProjectHelperImpl extends ProjectHelper {
static class DataTypeHandler extends AbstractHandler { static class DataTypeHandler extends AbstractHandler {
/** Parent target, if any. */ /** Parent target, if any. */
private Target target; private Target target;

/** The element being configured. */ /** The element being configured. */
private Object element; private Object element;

/** Wrapper for this element, if it's part of a target. */ /** Wrapper for this element, if it's part of a target. */
private RuntimeConfigurable wrapper = null; private RuntimeConfigurable wrapper = null;


@@ -949,8 +938,8 @@ public class ProjectHelperImpl extends ProjectHelper {
* @param target The parent target of this element. * @param target The parent target of this element.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*/ */
public DataTypeHandler(ProjectHelperImpl helperImpl,
DocumentHandler parentHandler, Target target) {
public DataTypeHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler,
Target target) {
super(helperImpl, parentHandler); super(helperImpl, parentHandler);
this.target = target; this.target = target;
} }
@@ -977,7 +966,6 @@ public class ProjectHelperImpl extends ProjectHelper {
if (element == null) { if (element == null) {
throw new BuildException("Unknown data type " + propType); throw new BuildException("Unknown data type " + propType);
} }

wrapper = new RuntimeConfigurable(element, propType); wrapper = new RuntimeConfigurable(element, propType);
wrapper.setAttributes(attrs); wrapper.setAttributes(attrs);
target.addDataType(wrapper); target.addDataType(wrapper);


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

@@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */

package org.apache.tools.ant.taskdefs.condition; package org.apache.tools.ant.taskdefs.condition;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -41,7 +40,7 @@ public class AntVersion extends Task implements Condition {
if (propertyname == null) { if (propertyname == null) {
throw new BuildException("'property' must be set."); throw new BuildException("'property' must be set.");
} }
if (atLeast!=null || exactly!=null) {
if (atLeast != null || exactly != null) {
// If condition values are set, evaluate the condition // If condition values are set, evaluate the condition
if (eval()) { if (eval()) {
getProject().setNewProperty(propertyname, getVersion().toString()); getProject().setNewProperty(propertyname, getVersion().toString());


Loading…
Cancel
Save