git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557021 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -55,6 +55,7 @@ public final class Diagnostics { | |||
| * {@value} | |||
| */ | |||
| private static final int BIG_DRIFT_LIMIT = 10000; | |||
| /** | |||
| * How big a test file to write. | |||
| * {@value} | |||
| @@ -64,15 +65,14 @@ public final class Diagnostics { | |||
| private static final int SECONDS_PER_MILLISECOND = 1000; | |||
| private static final int SECONDS_PER_MINUTE = 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. | |||
| * {@value} | |||
| */ | |||
| 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 */ | |||
| private Diagnostics() { | |||
| @@ -100,16 +100,14 @@ public final class Diagnostics { | |||
| */ | |||
| public static void validateVersion() throws BuildException { | |||
| try { | |||
| Class optional | |||
| = Class.forName(TEST_CLASS); | |||
| Class optional = Class.forName(TEST_CLASS); | |||
| String coreVersion = getImplementationVersion(Main.class); | |||
| String optionalVersion = getImplementationVersion(optional); | |||
| if (coreVersion != null && !coreVersion.equals(optionalVersion)) { | |||
| 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) { | |||
| // ignore | |||
| @@ -144,7 +142,6 @@ public final class Diagnostics { | |||
| return name.endsWith(".jar"); | |||
| } | |||
| }; | |||
| File[] files = libDir.listFiles(filter); | |||
| return files; | |||
| } | |||
| @@ -157,7 +154,6 @@ public final class Diagnostics { | |||
| doReport(System.out); | |||
| } | |||
| /** | |||
| * Helper method to get the implementation version. | |||
| * @param clazz the class to get the information from. | |||
| @@ -165,8 +161,7 @@ public final class Diagnostics { | |||
| * '?.?' for JDK 1.0 or 1.1. | |||
| */ | |||
| 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) { | |||
| return "Could not create an XML Parser"; | |||
| } | |||
| // check to what is in the classname | |||
| String saxParserName = saxParser.getClass().getName(); | |||
| return saxParserName; | |||
| @@ -273,8 +267,7 @@ public final class Diagnostics { | |||
| Class optional = null; | |||
| try { | |||
| optional = Class.forName(TEST_CLASS); | |||
| out.println("optional tasks : " | |||
| + getImplementationVersion(optional)); | |||
| out.println("optional tasks : " + getImplementationVersion(optional)); | |||
| } catch (ClassNotFoundException e) { | |||
| ignoreThrowable(e); | |||
| out.println("optional tasks : not available"); | |||
| @@ -331,8 +324,7 @@ public final class Diagnostics { | |||
| sysprops = System.getProperties(); | |||
| } catch (SecurityException 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(); | |||
| keys.hasMoreElements();) { | |||
| @@ -368,7 +360,7 @@ public final class Diagnostics { | |||
| p.initProperties(); | |||
| out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_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_HOME + ": " + p.getProperty(MagicNames.ANT_HOME)); | |||
| } | |||
| @@ -407,8 +399,7 @@ public final class Diagnostics { | |||
| return; | |||
| } | |||
| 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; | |||
| try { | |||
| 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[]{}}); | |||
| } catch (ClassNotFoundException e) { | |||
| out.println("Not available."); | |||
| @@ -492,15 +482,12 @@ public final class Diagnostics { | |||
| String parserName = getXmlParserName(); | |||
| String parserLocation = getXMLParserLocation(); | |||
| printParserInfo(out, "XML Parser", parserName, parserLocation); | |||
| printParserInfo(out, "Namespace-aware parser", | |||
| getNamespaceParserName(), | |||
| printParserInfo(out, "Namespace-aware parser", getNamespaceParserName(), | |||
| 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) { | |||
| parserName = "unknown"; | |||
| } | |||
| @@ -526,8 +513,7 @@ public final class Diagnostics { | |||
| out.println("Temp dir is " + tempdir); | |||
| File tempDirectory = new File(tempdir); | |||
| 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; | |||
| } | |||
| //create the file | |||
| @@ -554,8 +540,7 @@ public final class Diagnostics { | |||
| } | |||
| } catch (IOException 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"); | |||
| } finally { | |||
| FileUtils.close(fileout); | |||
| @@ -573,16 +558,15 @@ public final class Diagnostics { | |||
| //calendar stuff. | |||
| Calendar cal = Calendar.getInstance(); | |||
| 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; | |||
| } | |||
| 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 { | |||
| Class proxyDiagClass = Class.forName(proxyDiagClassname); | |||
| Object instance = proxyDiagClass.newInstance(); | |||
| @@ -112,7 +112,6 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| project.addReference(REFID_CONTEXT, context); | |||
| project.addReference(REFID_TARGETS, context.getTargets()); | |||
| } | |||
| if (getImportStack().size() > 1) { | |||
| // we are in an imported file. | |||
| context.setIgnoreProjectTag(true); | |||
| @@ -171,9 +170,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| // } else if (source instanceof InputSource ) { | |||
| } else { | |||
| throw new BuildException("Source " + source.getClass().getName() | |||
| + " not supported by this plugin"); | |||
| + " not supported by this plugin"); | |||
| } | |||
| InputStream inputStream = null; | |||
| InputSource inputSource = null; | |||
| @@ -196,8 +194,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| if (uri != null) { | |||
| 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; | |||
| @@ -207,8 +205,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| parser.setDTDHandler(hb); | |||
| parser.parse(inputSource); | |||
| } 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(); | |||
| if (t instanceof BuildException) { | |||
| @@ -228,11 +226,11 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| } catch (FileNotFoundException exc) { | |||
| throw new BuildException(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) { | |||
| throw new BuildException("Error reading project file " | |||
| + buildFileName + ": " + exc.getMessage(), exc); | |||
| throw new BuildException("Error reading project file " + buildFileName + ": " | |||
| + exc.getMessage(), exc); | |||
| } finally { | |||
| FileUtils.close(inputStream); | |||
| } | |||
| @@ -349,8 +347,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| */ | |||
| public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs, | |||
| 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 | |||
| * @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 | |||
| */ | |||
| public void characters(char[] buf, int start, int count, AntXMLContext context) | |||
| throws SAXParseException { | |||
| throws SAXParseException { | |||
| String s = new String(buf, start, count).trim(); | |||
| if (s.length() > 0) { | |||
| @@ -459,8 +457,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| file = FILE_UTILS.resolveFile(context.getBuildFileParent(), path); | |||
| context.getProject().log( | |||
| "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); | |||
| try { | |||
| @@ -468,8 +466,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath())); | |||
| return inputSource; | |||
| } 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> | |||
| */ | |||
| public void startElement(String uri, String tag, String qname, Attributes attrs) | |||
| throws SAXParseException { | |||
| throws SAXParseException { | |||
| AntHandler next = currentHandler.onStartChild(uri, tag, qname, attrs, context); | |||
| antHandlers.push(currentHandler); | |||
| currentHandler = next; | |||
| @@ -680,8 +678,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| } | |||
| } else { | |||
| // 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); | |||
| if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) { | |||
| 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) { | |||
| project.setUserProperty(MagicNames.ANT_FILE + "." | |||
| + context.getCurrentProjectName(), context.getBuildFile().toString()); | |||
| project.setUserProperty( | |||
| MagicNames.ANT_FILE + "." + context.getCurrentProjectName(), context | |||
| .getBuildFile().toString()); | |||
| } | |||
| if (context.isIgnoringProjectTag()) { | |||
| // no further processing | |||
| return; | |||
| @@ -718,12 +715,11 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| if ((new File(baseDir)).isAbsolute()) { | |||
| project.setBasedir(baseDir); | |||
| } else { | |||
| project.setBaseDir(FILE_UTILS.resolveFile( | |||
| context.getBuildFileParent(), baseDir)); | |||
| project.setBaseDir(FILE_UTILS.resolveFile(context.getBuildFileParent(), | |||
| baseDir)); | |||
| } | |||
| } | |||
| } | |||
| project.addTarget("", context.getImplicitTarget()); | |||
| context.setCurrentTarget(context.getImplicitTarget()); | |||
| } | |||
| @@ -816,8 +812,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| } else if (key.equals("description")) { | |||
| target.setDescription(value); | |||
| } 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) { | |||
| throw new BuildException("Duplicate target '" + name + "'", target.getLocation()); | |||
| } | |||
| Hashtable projectTargets = project.getTargets(); | |||
| boolean usedTarget = false; | |||
| // If the name has not already been defined define it | |||
| 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 { | |||
| target.setName(name); | |||
| context.getCurrentTargets().put(name, target); | |||
| project.addOrReplaceTarget(name, target); | |||
| usedTarget = true; | |||
| } | |||
| if (depends.length() > 0) { | |||
| target.setDepends(depends); | |||
| } | |||
| if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null | |||
| && context.getCurrentProjectName().length() != 0) { | |||
| && context.getCurrentProjectName().length() != 0) { | |||
| // In an impored file (and not completely | |||
| // ignoring the project tag) | |||
| String newName = context.getCurrentProjectName() + "." + name; | |||
| @@ -940,8 +933,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag)); | |||
| 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.setOwningTarget(context.getCurrentTarget()); | |||
| @@ -971,19 +964,19 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| // an ant-type is a component name which can | |||
| // be namespaced, need to extract the 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; | |||
| int index = value.indexOf(":"); | |||
| if (index >= 0) { | |||
| String prefix = value.substring(0, index); | |||
| String mappedUri = context.getPrefixMapping(prefix); | |||
| 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); | |||
| @@ -15,7 +15,6 @@ | |||
| * limitations under the License. | |||
| * | |||
| */ | |||
| package org.apache.tools.ant.helper; | |||
| import java.io.File; | |||
| @@ -65,18 +64,22 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| /** The project to configure. */ | |||
| private Project project; | |||
| /** The configuration file to parse. */ | |||
| private File buildFile; | |||
| /** | |||
| * Parent directory of the build file. Used for resolving entities | |||
| * and setting the project's base directory. | |||
| */ | |||
| private File buildFileParent; | |||
| /** | |||
| * Locator for the configuration file parser. | |||
| * Used for giving locations of errors etc. | |||
| */ | |||
| private Locator locator; | |||
| /** | |||
| * Target that all other targets will depend upon implicitly. | |||
| * | |||
| @@ -119,14 +122,11 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| } catch (BuildException e) { | |||
| parser = new XMLReaderAdapter(JAXPUtils.getXMLReader()); | |||
| } | |||
| String uri = FILE_UTILS.toURI(bFile.getAbsolutePath()); | |||
| inputStream = new FileInputStream(bFile); | |||
| inputSource = new InputSource(inputStream); | |||
| 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); | |||
| parser.setDocumentHandler(hb); | |||
| parser.setEntityResolver(hb); | |||
| @@ -134,9 +134,8 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| parser.setDTDHandler(hb); | |||
| parser.parse(inputSource); | |||
| } 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(); | |||
| if (t instanceof BuildException) { | |||
| @@ -146,7 +145,6 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| } | |||
| throw be; | |||
| } | |||
| throw new BuildException(exc.getMessage(), t, location); | |||
| } catch (SAXException exc) { | |||
| Throwable t = exc.getException(); | |||
| @@ -157,11 +155,9 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| } catch (FileNotFoundException exc) { | |||
| throw new BuildException(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) { | |||
| throw new BuildException("Error reading project file: " | |||
| + exc.getMessage(), exc); | |||
| throw new BuildException("Error reading project file: " + exc.getMessage(), exc); | |||
| } finally { | |||
| FileUtils.close(inputStream); | |||
| } | |||
| @@ -290,8 +286,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| * @param systemId The system identifier provided in the XML | |||
| * 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); | |||
| @@ -301,11 +296,9 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| File file = new File(path); | |||
| if (!file.isAbsolute()) { | |||
| 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('\\', '/') | |||
| + "' for compliance with other XML tools", | |||
| Project.MSG_WARN); | |||
| + "' for compliance with other XML tools", Project.MSG_WARN); | |||
| } | |||
| try { | |||
| InputSource inputSource = new InputSource(new FileInputStream(file)); | |||
| @@ -313,7 +306,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| return inputSource; | |||
| } catch (FileNotFoundException fne) { | |||
| helperImpl.project.log(file.getAbsolutePath() + " could not be found", | |||
| Project.MSG_WARN); | |||
| Project.MSG_WARN); | |||
| } | |||
| } | |||
| // use default if not file or file not found | |||
| @@ -336,8 +329,8 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| if (tag.equals("project")) { | |||
| new ProjectHandler(helperImpl, this).init(tag, attrs); | |||
| } 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")) { | |||
| baseDir = value; | |||
| } 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()) { | |||
| helperImpl.project.setBasedir(baseDir); | |||
| } else { | |||
| File resolvedBaseDir = FILE_UTILS.resolveFile( | |||
| helperImpl.buildFileParent, baseDir); | |||
| File resolvedBaseDir = FILE_UTILS.resolveFile(helperImpl.buildFileParent, | |||
| baseDir); | |||
| helperImpl.project.setBaseDir(resolvedBaseDir); | |||
| } | |||
| } | |||
| @@ -462,8 +455,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| if (name.equals("target")) { | |||
| handleTarget(name, attrs); | |||
| } 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 { | |||
| new TargetHandler(helperImpl, this).init(tag, attrs); | |||
| } | |||
| } | |||
| /** | |||
| @@ -534,9 +525,8 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| if (key.equals("name")) { | |||
| name = value; | |||
| 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")) { | |||
| depends = value; | |||
| @@ -549,14 +539,14 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| } else if (key.equals("description")) { | |||
| description = value; | |||
| } else { | |||
| throw new SAXParseException("Unexpected attribute \"" | |||
| + key + "\"", helperImpl.locator); | |||
| throw new SAXParseException("Unexpected attribute \"" + key + "\"", | |||
| helperImpl.locator); | |||
| } | |||
| } | |||
| if (name == null) { | |||
| throw new SAXParseException("target element appears without a name attribute", | |||
| helperImpl.locator); | |||
| helperImpl.locator); | |||
| } | |||
| target = new Target(); | |||
| @@ -605,20 +595,14 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| * | |||
| * @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")) { | |||
| 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 { | |||
| 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 { | |||
| /** Containing target, if any. */ | |||
| private Target target; | |||
| /** | |||
| * Container for the task, if any. If target is | |||
| * non-<code>null</code>, this must be too. | |||
| */ | |||
| private TaskContainer container; | |||
| /** | |||
| * Task created by this handler. | |||
| */ | |||
| private Task task; | |||
| /** | |||
| * Wrapper for the parent element, if any. The wrapper for this | |||
| * element will be added to this wrapper as a child. | |||
| */ | |||
| private RuntimeConfigurable parentWrapper; | |||
| /** | |||
| * Wrapper for this element which takes care of actually configuring | |||
| * 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 | |||
| // UnknownElement.maybeConfigure if the problem persists. | |||
| } | |||
| if (task == null) { | |||
| task = new UnknownElement(tag); | |||
| task.setProject(helperImpl.project); | |||
| //XXX task.setTaskType(tag); | |||
| task.setTaskName(tag); | |||
| } | |||
| task.setLocation(new Location(helperImpl.locator)); | |||
| helperImpl.configureId(task, attrs); | |||
| @@ -784,11 +770,10 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| public void startElement(String name, AttributeList attrs) throws SAXParseException { | |||
| if (task instanceof TaskContainer) { | |||
| // 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 { | |||
| 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 { | |||
| /** Parent object (task/data type/etc). */ | |||
| private Object parent; | |||
| /** The nested element itself. */ | |||
| private Object child; | |||
| /** | |||
| * Wrapper for the parent element, if any. The wrapper for this | |||
| * element will be added to this wrapper as a child. | |||
| */ | |||
| private RuntimeConfigurable parentWrapper; | |||
| /** | |||
| * Wrapper for this element which takes care of actually configuring | |||
| * the element, if a parent wrapper is provided. | |||
| @@ -813,6 +801,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| * @see ProjectHelper#configure(Object,AttributeList,Project) | |||
| */ | |||
| private RuntimeConfigurable childWrapper = null; | |||
| /** Target this element is part of, if any. */ | |||
| private Target target; | |||
| @@ -866,8 +855,7 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| */ | |||
| public void init(String propType, AttributeList attrs) throws SAXParseException { | |||
| Class parentClass = parent.getClass(); | |||
| IntrospectionHelper ih = | |||
| IntrospectionHelper.getHelper(helperImpl.project, parentClass); | |||
| IntrospectionHelper ih = IntrospectionHelper.getHelper(helperImpl.project, parentClass); | |||
| try { | |||
| String elementName = propType.toLowerCase(Locale.US); | |||
| @@ -879,7 +867,6 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| } else { | |||
| child = ih.createElement(helperImpl.project, parent, elementName); | |||
| } | |||
| helperImpl.configureId(child, attrs); | |||
| childWrapper = new RuntimeConfigurable(child, propType); | |||
| @@ -919,11 +906,11 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| if (child instanceof TaskContainer) { | |||
| // taskcontainer nested element can contain other tasks - no other | |||
| // 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 { | |||
| 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 { | |||
| /** Parent target, if any. */ | |||
| private Target target; | |||
| /** The element being configured. */ | |||
| private Object element; | |||
| /** Wrapper for this element, if it's part of a target. */ | |||
| private RuntimeConfigurable wrapper = null; | |||
| @@ -949,8 +938,8 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| * @param target The parent target of this element. | |||
| * 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); | |||
| this.target = target; | |||
| } | |||
| @@ -977,7 +966,6 @@ public class ProjectHelperImpl extends ProjectHelper { | |||
| if (element == null) { | |||
| throw new BuildException("Unknown data type " + propType); | |||
| } | |||
| wrapper = new RuntimeConfigurable(element, propType); | |||
| wrapper.setAttributes(attrs); | |||
| target.addDataType(wrapper); | |||
| @@ -15,7 +15,6 @@ | |||
| * limitations under the License. | |||
| * | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.condition; | |||
| import org.apache.tools.ant.BuildException; | |||
| @@ -41,7 +40,7 @@ public class AntVersion extends Task implements Condition { | |||
| if (propertyname == null) { | |||
| 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 (eval()) { | |||
| getProject().setNewProperty(propertyname, getVersion().toString()); | |||