git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557005 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -15,7 +15,6 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| * | * | ||||
| */ | */ | ||||
| package org.apache.tools.ant; | package org.apache.tools.ant; | ||||
| import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
| @@ -30,6 +29,7 @@ import java.util.Enumeration; | |||||
| import javax.xml.parsers.DocumentBuilder; | import javax.xml.parsers.DocumentBuilder; | ||||
| import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
| import org.apache.tools.ant.util.DOMElementWriter; | import org.apache.tools.ant.util.DOMElementWriter; | ||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| import org.apache.tools.ant.util.StringUtils; | import org.apache.tools.ant.util.StringUtils; | ||||
| import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
| import org.w3c.dom.Element; | import org.w3c.dom.Element; | ||||
| @@ -73,36 +73,49 @@ public class XmlLogger implements BuildLogger { | |||||
| /** XML element name for a build. */ | /** XML element name for a build. */ | ||||
| private static final String BUILD_TAG = "build"; | private static final String BUILD_TAG = "build"; | ||||
| /** XML element name for a target. */ | /** XML element name for a target. */ | ||||
| private static final String TARGET_TAG = "target"; | private static final String TARGET_TAG = "target"; | ||||
| /** XML element name for a task. */ | /** XML element name for a task. */ | ||||
| private static final String TASK_TAG = "task"; | private static final String TASK_TAG = "task"; | ||||
| /** XML element name for a message. */ | /** XML element name for a message. */ | ||||
| private static final String MESSAGE_TAG = "message"; | private static final String MESSAGE_TAG = "message"; | ||||
| /** XML attribute name for a name. */ | /** XML attribute name for a name. */ | ||||
| private static final String NAME_ATTR = "name"; | private static final String NAME_ATTR = "name"; | ||||
| /** XML attribute name for a time. */ | /** XML attribute name for a time. */ | ||||
| private static final String TIME_ATTR = "time"; | private static final String TIME_ATTR = "time"; | ||||
| /** XML attribute name for a message priority. */ | /** XML attribute name for a message priority. */ | ||||
| private static final String PRIORITY_ATTR = "priority"; | private static final String PRIORITY_ATTR = "priority"; | ||||
| /** XML attribute name for a file location. */ | /** XML attribute name for a file location. */ | ||||
| private static final String LOCATION_ATTR = "location"; | private static final String LOCATION_ATTR = "location"; | ||||
| /** XML attribute name for an error description. */ | /** XML attribute name for an error description. */ | ||||
| private static final String ERROR_ATTR = "error"; | private static final String ERROR_ATTR = "error"; | ||||
| /** XML element name for a stack trace. */ | /** XML element name for a stack trace. */ | ||||
| private static final String STACKTRACE_TAG = "stacktrace"; | private static final String STACKTRACE_TAG = "stacktrace"; | ||||
| /** The complete log document for this build. */ | /** The complete log document for this build. */ | ||||
| private Document doc = builder.newDocument(); | private Document doc = builder.newDocument(); | ||||
| /** Mapping for when tasks started (Task to TimedElement). */ | /** Mapping for when tasks started (Task to TimedElement). */ | ||||
| private Hashtable tasks = new Hashtable(); | private Hashtable tasks = new Hashtable(); | ||||
| /** Mapping for when targets started (Task to TimedElement). */ | /** Mapping for when targets started (Task to TimedElement). */ | ||||
| private Hashtable targets = new Hashtable(); | private Hashtable targets = new Hashtable(); | ||||
| /** | /** | ||||
| * Mapping of threads to stacks of elements | * Mapping of threads to stacks of elements | ||||
| * (Thread to Stack of TimedElement). | * (Thread to Stack of TimedElement). | ||||
| */ | */ | ||||
| private Hashtable threadStacks = new Hashtable(); | private Hashtable threadStacks = new Hashtable(); | ||||
| /** | /** | ||||
| * When the build started. | * When the build started. | ||||
| */ | */ | ||||
| @@ -149,12 +162,10 @@ public class XmlLogger implements BuildLogger { | |||||
| */ | */ | ||||
| public void buildFinished(BuildEvent event) { | public void buildFinished(BuildEvent event) { | ||||
| long totalTime = System.currentTimeMillis() - buildElement.startTime; | long totalTime = System.currentTimeMillis() - buildElement.startTime; | ||||
| buildElement.element.setAttribute(TIME_ATTR, | |||||
| DefaultLogger.formatTime(totalTime)); | |||||
| buildElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime)); | |||||
| if (event.getException() != null) { | if (event.getException() != null) { | ||||
| buildElement.element.setAttribute(ERROR_ATTR, | |||||
| event.getException().toString()); | |||||
| buildElement.element.setAttribute(ERROR_ATTR, event.getException().toString()); | |||||
| // print the stacktrace in the build file it is always useful... | // print the stacktrace in the build file it is always useful... | ||||
| // better have too much info than not enough. | // better have too much info than not enough. | ||||
| Throwable t = event.getException(); | Throwable t = event.getException(); | ||||
| @@ -163,13 +174,11 @@ public class XmlLogger implements BuildLogger { | |||||
| stacktrace.appendChild(errText); | stacktrace.appendChild(errText); | ||||
| buildElement.element.appendChild(stacktrace); | buildElement.element.appendChild(stacktrace); | ||||
| } | } | ||||
| String outFilename = event.getProject().getProperty("XmlLogger.file"); | String outFilename = event.getProject().getProperty("XmlLogger.file"); | ||||
| if (outFilename == null) { | if (outFilename == null) { | ||||
| outFilename = "log.xml"; | outFilename = "log.xml"; | ||||
| } | } | ||||
| String xslUri | |||||
| = event.getProject().getProperty("ant.XmlLogger.stylesheet.uri"); | |||||
| String xslUri = event.getProject().getProperty("ant.XmlLogger.stylesheet.uri"); | |||||
| if (xslUri == null) { | if (xslUri == null) { | ||||
| xslUri = "log.xsl"; | xslUri = "log.xsl"; | ||||
| } | } | ||||
| @@ -184,21 +193,14 @@ public class XmlLogger implements BuildLogger { | |||||
| out = new OutputStreamWriter(stream, "UTF8"); | out = new OutputStreamWriter(stream, "UTF8"); | ||||
| out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | ||||
| if (xslUri.length() > 0) { | if (xslUri.length() > 0) { | ||||
| out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" | |||||
| + xslUri + "\"?>\n\n"); | |||||
| out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri + "\"?>\n\n"); | |||||
| } | } | ||||
| (new DOMElementWriter()).write(buildElement.element, out, 0, "\t"); | |||||
| new DOMElementWriter().write(buildElement.element, out, 0, "\t"); | |||||
| out.flush(); | out.flush(); | ||||
| } catch (IOException exc) { | } catch (IOException exc) { | ||||
| throw new BuildException("Unable to write log file", exc); | throw new BuildException("Unable to write log file", exc); | ||||
| } finally { | } finally { | ||||
| if (out != null) { | |||||
| try { | |||||
| out.close(); | |||||
| } catch (IOException e) { | |||||
| // ignore | |||||
| } | |||||
| } | |||||
| FileUtils.close(out); | |||||
| } | } | ||||
| buildElement = null; | buildElement = null; | ||||
| } | } | ||||
| @@ -249,20 +251,16 @@ public class XmlLogger implements BuildLogger { | |||||
| Target target = event.getTarget(); | Target target = event.getTarget(); | ||||
| TimedElement targetElement = (TimedElement) targets.get(target); | TimedElement targetElement = (TimedElement) targets.get(target); | ||||
| if (targetElement != null) { | if (targetElement != null) { | ||||
| long totalTime | |||||
| = System.currentTimeMillis() - targetElement.startTime; | |||||
| targetElement.element.setAttribute(TIME_ATTR, | |||||
| DefaultLogger.formatTime(totalTime)); | |||||
| long totalTime = System.currentTimeMillis() - targetElement.startTime; | |||||
| targetElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime)); | |||||
| TimedElement parentElement = null; | TimedElement parentElement = null; | ||||
| Stack threadStack = getStack(); | Stack threadStack = getStack(); | ||||
| if (!threadStack.empty()) { | if (!threadStack.empty()) { | ||||
| TimedElement poppedStack = (TimedElement) threadStack.pop(); | TimedElement poppedStack = (TimedElement) threadStack.pop(); | ||||
| if (poppedStack != targetElement) { | if (poppedStack != targetElement) { | ||||
| throw new RuntimeException("Mismatch - popped element = " | |||||
| + poppedStack | |||||
| + " finished target element = " | |||||
| + targetElement); | |||||
| throw new RuntimeException("Mismatch - popped element = " + poppedStack | |||||
| + " finished target element = " + targetElement); | |||||
| } | } | ||||
| if (!threadStack.empty()) { | if (!threadStack.empty()) { | ||||
| parentElement = (TimedElement) threadStack.peek(); | parentElement = (TimedElement) threadStack.peek(); | ||||
| @@ -296,8 +294,7 @@ public class XmlLogger implements BuildLogger { | |||||
| name = ""; | name = ""; | ||||
| } | } | ||||
| taskElement.element.setAttribute(NAME_ATTR, name); | taskElement.element.setAttribute(NAME_ATTR, name); | ||||
| taskElement.element.setAttribute(LOCATION_ATTR, | |||||
| event.getTask().getLocation().toString()); | |||||
| taskElement.element.setAttribute(LOCATION_ATTR, event.getTask().getLocation().toString()); | |||||
| tasks.put(task, taskElement); | tasks.put(task, taskElement); | ||||
| getStack().push(taskElement); | getStack().push(taskElement); | ||||
| } | } | ||||
| @@ -312,36 +309,32 @@ public class XmlLogger implements BuildLogger { | |||||
| public void taskFinished(BuildEvent event) { | public void taskFinished(BuildEvent event) { | ||||
| Task task = event.getTask(); | Task task = event.getTask(); | ||||
| TimedElement taskElement = (TimedElement) tasks.get(task); | TimedElement taskElement = (TimedElement) tasks.get(task); | ||||
| if (taskElement != null) { | |||||
| long totalTime = System.currentTimeMillis() - taskElement.startTime; | |||||
| taskElement.element.setAttribute(TIME_ATTR, | |||||
| DefaultLogger.formatTime(totalTime)); | |||||
| Target target = task.getOwningTarget(); | |||||
| TimedElement targetElement = null; | |||||
| if (target != null) { | |||||
| targetElement = (TimedElement) targets.get(target); | |||||
| } | |||||
| if (targetElement == null) { | |||||
| buildElement.element.appendChild(taskElement.element); | |||||
| } else { | |||||
| targetElement.element.appendChild(taskElement.element); | |||||
| } | |||||
| Stack threadStack = getStack(); | |||||
| if (!threadStack.empty()) { | |||||
| TimedElement poppedStack = (TimedElement) threadStack.pop(); | |||||
| if (poppedStack != taskElement) { | |||||
| throw new RuntimeException("Mismatch - popped element = " | |||||
| + poppedStack + " finished task element = " | |||||
| + taskElement); | |||||
| } | |||||
| } | |||||
| tasks.remove(task); | |||||
| } else { | |||||
| if (taskElement == null) { | |||||
| throw new RuntimeException("Unknown task " + task + " not in " + tasks); | throw new RuntimeException("Unknown task " + task + " not in " + tasks); | ||||
| } | } | ||||
| long totalTime = System.currentTimeMillis() - taskElement.startTime; | |||||
| taskElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime)); | |||||
| Target target = task.getOwningTarget(); | |||||
| TimedElement targetElement = null; | |||||
| if (target != null) { | |||||
| targetElement = (TimedElement) targets.get(target); | |||||
| } | |||||
| if (targetElement == null) { | |||||
| buildElement.element.appendChild(taskElement.element); | |||||
| } else { | |||||
| targetElement.element.appendChild(taskElement.element); | |||||
| } | |||||
| Stack threadStack = getStack(); | |||||
| if (!threadStack.empty()) { | |||||
| TimedElement poppedStack = (TimedElement) threadStack.pop(); | |||||
| if (poppedStack != taskElement) { | |||||
| throw new RuntimeException("Mismatch - popped element = " + poppedStack | |||||
| + " finished task element = " + taskElement); | |||||
| } | |||||
| } | |||||
| tasks.remove(task); | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the TimedElement associated with a task. | * Get the TimedElement associated with a task. | ||||
| * | * | ||||
| @@ -353,7 +346,6 @@ public class XmlLogger implements BuildLogger { | |||||
| if (element != null) { | if (element != null) { | ||||
| return element; | return element; | ||||
| } | } | ||||
| for (Enumeration e = tasks.keys(); e.hasMoreElements();) { | for (Enumeration e = tasks.keys(); e.hasMoreElements();) { | ||||
| Task key = (Task) e.nextElement(); | Task key = (Task) e.nextElement(); | ||||
| if (key instanceof UnknownElement) { | if (key instanceof UnknownElement) { | ||||
| @@ -362,7 +354,6 @@ public class XmlLogger implements BuildLogger { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| @@ -382,7 +373,7 @@ public class XmlLogger implements BuildLogger { | |||||
| Element messageElement = doc.createElement(MESSAGE_TAG); | Element messageElement = doc.createElement(MESSAGE_TAG); | ||||
| String name = "debug"; | String name = "debug"; | ||||
| switch (event.getPriority()) { | |||||
| switch (priority) { | |||||
| case Project.MSG_ERR: | case Project.MSG_ERR: | ||||
| name = "error"; | name = "error"; | ||||
| break; | break; | ||||
| @@ -419,19 +410,6 @@ public class XmlLogger implements BuildLogger { | |||||
| if (parentElement == null && target != null) { | if (parentElement == null && target != null) { | ||||
| parentElement = (TimedElement) targets.get(target); | parentElement = (TimedElement) targets.get(target); | ||||
| } | } | ||||
| /* | |||||
| if (parentElement == null) { | |||||
| Stack threadStack | |||||
| = (Stack) threadStacks.get(Thread.currentThread()); | |||||
| if (threadStack != null) { | |||||
| if (!threadStack.empty()) { | |||||
| parentElement = (TimedElement) threadStack.peek(); | |||||
| } | |||||
| } | |||||
| } | |||||
| */ | |||||
| if (parentElement != null) { | if (parentElement != null) { | ||||
| parentElement.element.appendChild(messageElement); | parentElement.element.appendChild(messageElement); | ||||
| } else { | } else { | ||||
| @@ -15,7 +15,6 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| * | * | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import java.io.File; | import java.io.File; | ||||
| @@ -205,8 +204,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| */ | */ | ||||
| public void addMapper(Mapper mapper) { | public void addMapper(Mapper mapper) { | ||||
| if (mapperElement != null) { | if (mapperElement != null) { | ||||
| throw new BuildException("Cannot define more than one mapper", | |||||
| getLocation()); | |||||
| throw new BuildException("Cannot define more than one mapper", getLocation()); | |||||
| } | } | ||||
| mapperElement = mapper; | mapperElement = mapper; | ||||
| } | } | ||||
| @@ -229,8 +227,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| */ | */ | ||||
| public void addConfiguredStyle(Resources rc) { | public void addConfiguredStyle(Resources rc) { | ||||
| if (rc.size() != 1) { | if (rc.size() != 1) { | ||||
| throw new BuildException("The style element must be specified" | |||||
| + " with exactly one nested resource."); | |||||
| throw new BuildException( | |||||
| "The style element must be specified with exactly one nested resource."); | |||||
| } | } | ||||
| setXslResource((Resource) rc.iterator().next()); | setXslResource((Resource) rc.iterator().next()); | ||||
| } | } | ||||
| @@ -267,43 +265,34 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| log("Warning: the task name <style> is deprecated. Use <xslt> instead.", | log("Warning: the task name <style> is deprecated. Use <xslt> instead.", | ||||
| Project.MSG_WARN); | Project.MSG_WARN); | ||||
| } | } | ||||
| File savedBaseDir = baseDir; | File savedBaseDir = baseDir; | ||||
| DirectoryScanner scanner; | DirectoryScanner scanner; | ||||
| String[] list; | String[] list; | ||||
| String[] dirs; | String[] dirs; | ||||
| if (xslResource == null && xslFile == null) { | |||||
| throw new BuildException("specify the " | |||||
| + "stylesheet either as a filename in style " | |||||
| + "attribute or as a nested resource", getLocation()); | |||||
| String baseMessage = | |||||
| "specify the stylesheet either as a filename in style attribute or as a nested resource"; | |||||
| if (xslResource == null && xslFile == null) { | |||||
| throw new BuildException(baseMessage, getLocation()); | |||||
| } | } | ||||
| if (xslResource != null && xslFile != null) { | if (xslResource != null && xslFile != null) { | ||||
| throw new BuildException("specify the " | |||||
| + "stylesheet either as a filename in style " | |||||
| + "attribute or as a nested resource but not " | |||||
| + "as both", getLocation()); | |||||
| throw new BuildException(baseMessage + " but not as both", getLocation()); | |||||
| } | } | ||||
| if (inFile != null && !inFile.exists()) { | if (inFile != null && !inFile.exists()) { | ||||
| throw new BuildException( | |||||
| "input file " + inFile.toString() + " does not exist", getLocation()); | |||||
| throw new BuildException("input file " + inFile + " does not exist", getLocation()); | |||||
| } | } | ||||
| try { | try { | ||||
| if (baseDir == null) { | if (baseDir == null) { | ||||
| baseDir = getProject().resolveFile("."); | baseDir = getProject().resolveFile("."); | ||||
| } | } | ||||
| liaison = getLiaison(); | liaison = getLiaison(); | ||||
| // check if liaison wants to log errors using us as logger | // check if liaison wants to log errors using us as logger | ||||
| if (liaison instanceof XSLTLoggerAware) { | if (liaison instanceof XSLTLoggerAware) { | ||||
| ((XSLTLoggerAware) liaison).setLogger(this); | ((XSLTLoggerAware) liaison).setLogger(this); | ||||
| } | } | ||||
| log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE); | log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE); | ||||
| if (xslFile != null) { | if (xslFile != null) { | ||||
| @@ -317,8 +306,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * the wrong version has been used. | * the wrong version has been used. | ||||
| */ | */ | ||||
| if (stylesheet.exists()) { | if (stylesheet.exists()) { | ||||
| log("DEPRECATED - the 'style' attribute should be relative " | |||||
| + "to the project's"); | |||||
| log("DEPRECATED - the 'style' attribute should be relative to the project's"); | |||||
| log(" basedir, not the tasks's basedir."); | log(" basedir, not the tasks's basedir."); | ||||
| } | } | ||||
| } | } | ||||
| @@ -327,13 +315,11 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| fr.setFile(stylesheet); | fr.setFile(stylesheet); | ||||
| xslResource = fr; | xslResource = fr; | ||||
| } | } | ||||
| // if we have an in file and out then process them | // if we have an in file and out then process them | ||||
| if (inFile != null && outFile != null) { | if (inFile != null && outFile != null) { | ||||
| process(inFile, outFile, xslResource); | process(inFile, outFile, xslResource); | ||||
| return; | return; | ||||
| } | } | ||||
| /* | /* | ||||
| * if we get here, in and out have not been specified, we are | * if we get here, in and out have not been specified, we are | ||||
| * in batch processing mode. | * in batch processing mode. | ||||
| @@ -357,8 +343,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| for (int j = 0; j < dirs.length; ++j) { | for (int j = 0; j < dirs.length; ++j) { | ||||
| list = new File(baseDir, dirs[j]).list(); | list = new File(baseDir, dirs[j]).list(); | ||||
| for (int i = 0; i < list.length; ++i) { | for (int i = 0; i < list.length; ++i) { | ||||
| process(baseDir, dirs[j] + File.separator + list[i], | |||||
| destDir, xslResource); | |||||
| process(baseDir, dirs[j] + File.separator + list[i], destDir, | |||||
| xslResource); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -546,12 +532,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| private Class loadClass(String classname) throws Exception { | private Class loadClass(String classname) throws Exception { | ||||
| if (classpath == null) { | if (classpath == null) { | ||||
| return Class.forName(classname); | return Class.forName(classname); | ||||
| } else { | |||||
| loader = getProject().createClassLoader(classpath); | |||||
| loader.setThreadContextLoader(); | |||||
| Class c = Class.forName(classname, true, loader); | |||||
| return c; | |||||
| } | } | ||||
| loader = getProject().createClassLoader(classpath); | |||||
| loader.setThreadContextLoader(); | |||||
| return Class.forName(classname, true, loader); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -621,9 +605,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * @param stylesheet the stylesheet to use. | * @param stylesheet the stylesheet to use. | ||||
| * @exception BuildException if the processing fails. | * @exception BuildException if the processing fails. | ||||
| */ | */ | ||||
| private void process(File baseDir, String xmlFile, File destDir, | |||||
| Resource stylesheet) | |||||
| throws BuildException { | |||||
| private void process(File baseDir, String xmlFile, File destDir, Resource stylesheet) | |||||
| throws BuildException { | |||||
| File outF = null; | File outF = null; | ||||
| File inF = null; | File inF = null; | ||||
| @@ -633,11 +616,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| inF = new File(baseDir, xmlFile); | inF = new File(baseDir, xmlFile); | ||||
| if (inF.isDirectory()) { | if (inF.isDirectory()) { | ||||
| log("Skipping " + inF + " it is a directory.", | |||||
| Project.MSG_VERBOSE); | |||||
| log("Skipping " + inF + " it is a directory.", Project.MSG_VERBOSE); | |||||
| return; | return; | ||||
| } | } | ||||
| FileNameMapper mapper = null; | FileNameMapper mapper = null; | ||||
| if (mapperElement != null) { | if (mapperElement != null) { | ||||
| mapper = mapperElement.getImplementation(); | mapper = mapperElement.getImplementation(); | ||||
| @@ -647,23 +628,18 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| String[] outFileName = mapper.mapFileName(xmlFile); | String[] outFileName = mapper.mapFileName(xmlFile); | ||||
| if (outFileName == null || outFileName.length == 0) { | if (outFileName == null || outFileName.length == 0) { | ||||
| log("Skipping " + inFile + " it cannot get mapped to output.", | |||||
| Project.MSG_VERBOSE); | |||||
| log("Skipping " + inFile + " it cannot get mapped to output.", Project.MSG_VERBOSE); | |||||
| return; | return; | ||||
| } else if (outFileName == null || outFileName.length > 1) { | } else if (outFileName == null || outFileName.length > 1) { | ||||
| log("Skipping " + inFile + " its mapping is ambiguos.", | |||||
| Project.MSG_VERBOSE); | |||||
| log("Skipping " + inFile + " its mapping is ambiguos.", Project.MSG_VERBOSE); | |||||
| return; | return; | ||||
| } | } | ||||
| outF = new File(destDir, outFileName[0]); | outF = new File(destDir, outFileName[0]); | ||||
| if (force | |||||
| || inF.lastModified() > outF.lastModified() | |||||
| || styleSheetLastModified > outF.lastModified()) { | |||||
| if (force || inF.lastModified() > outF.lastModified() | |||||
| || styleSheetLastModified > outF.lastModified()) { | |||||
| ensureDirectoryFor(outF); | ensureDirectoryFor(outF); | ||||
| log("Processing " + inF + " to " + outF); | log("Processing " + inF + " to " + outF); | ||||
| configureLiaison(stylesheet); | configureLiaison(stylesheet); | ||||
| setLiaisonDynamicFileParameters(liaison, inF); | setLiaisonDynamicFileParameters(liaison, inF); | ||||
| liaison.transform(inF, outF); | liaison.transform(inF, outF); | ||||
| @@ -689,28 +665,22 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * @param stylesheet the stylesheet to use. | * @param stylesheet the stylesheet to use. | ||||
| * @exception BuildException if the processing fails. | * @exception BuildException if the processing fails. | ||||
| */ | */ | ||||
| private void process(File inFile, File outFile, Resource stylesheet) | |||||
| throws BuildException { | |||||
| private void process(File inFile, File outFile, Resource stylesheet) throws BuildException { | |||||
| try { | try { | ||||
| long styleSheetLastModified = stylesheet.getLastModified(); | long styleSheetLastModified = stylesheet.getLastModified(); | ||||
| log("In file " + inFile + " time: " + inFile.lastModified(), | |||||
| Project.MSG_DEBUG); | |||||
| log("Out file " + outFile + " time: " + outFile.lastModified(), | |||||
| Project.MSG_DEBUG); | |||||
| log("Style file " + xslFile + " time: " + styleSheetLastModified, | |||||
| Project.MSG_DEBUG); | |||||
| log("In file " + inFile + " time: " + inFile.lastModified(), Project.MSG_DEBUG); | |||||
| log("Out file " + outFile + " time: " + outFile.lastModified(), Project.MSG_DEBUG); | |||||
| log("Style file " + xslFile + " time: " + styleSheetLastModified, Project.MSG_DEBUG); | |||||
| if (force || inFile.lastModified() >= outFile.lastModified() | if (force || inFile.lastModified() >= outFile.lastModified() | ||||
| || styleSheetLastModified >= outFile.lastModified()) { | |||||
| || styleSheetLastModified >= outFile.lastModified()) { | |||||
| ensureDirectoryFor(outFile); | ensureDirectoryFor(outFile); | ||||
| log("Processing " + inFile + " to " + outFile, | |||||
| Project.MSG_INFO); | |||||
| log("Processing " + inFile + " to " + outFile, Project.MSG_INFO); | |||||
| configureLiaison(stylesheet); | configureLiaison(stylesheet); | ||||
| setLiaisonDynamicFileParameters(liaison, inFile); | setLiaisonDynamicFileParameters(liaison, inFile); | ||||
| liaison.transform(inFile, outFile); | liaison.transform(inFile, outFile); | ||||
| } else { | } else { | ||||
| log("Skipping input file " + inFile | |||||
| + " because it is older than output file " + outFile | |||||
| + " and so is the stylesheet " + stylesheet, Project.MSG_DEBUG); | |||||
| log("Skipping input file " + inFile + " because it is older than output file " | |||||
| + outFile + " and so is the stylesheet " + stylesheet, Project.MSG_DEBUG); | |||||
| } | } | ||||
| } catch (Exception ex) { | } catch (Exception ex) { | ||||
| log("Failed to process " + inFile, Project.MSG_INFO); | log("Failed to process " + inFile, Project.MSG_INFO); | ||||
| @@ -727,13 +697,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * @param targetFile the file for which the directories are required. | * @param targetFile the file for which the directories are required. | ||||
| * @exception BuildException if the directories cannot be created. | * @exception BuildException if the directories cannot be created. | ||||
| */ | */ | ||||
| private void ensureDirectoryFor(File targetFile) | |||||
| throws BuildException { | |||||
| private void ensureDirectoryFor(File targetFile) throws BuildException { | |||||
| File directory = targetFile.getParentFile(); | File directory = targetFile.getParentFile(); | ||||
| if (!directory.exists()) { | if (!directory.exists()) { | ||||
| if (!directory.mkdirs()) { | if (!directory.mkdirs()) { | ||||
| throw new BuildException("Unable to create directory: " | throw new BuildException("Unable to create directory: " | ||||
| + directory.getAbsolutePath()); | |||||
| + directory.getAbsolutePath()); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -888,6 +857,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| public void setUnless(String unlessProperty) { | public void setUnless(String unlessProperty) { | ||||
| this.unlessProperty = unlessProperty; | this.unlessProperty = unlessProperty; | ||||
| } | } | ||||
| /** | /** | ||||
| * Ensures that the param passes the conditions placed | * Ensures that the param passes the conditions placed | ||||
| * on it with <code>if</code> and <code>unless</code> properties. | * on it with <code>if</code> and <code>unless</code> properties. | ||||
| @@ -896,16 +866,14 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| public boolean shouldUse() { | public boolean shouldUse() { | ||||
| if (ifProperty != null && project.getProperty(ifProperty) == null) { | if (ifProperty != null && project.getProperty(ifProperty) == null) { | ||||
| return false; | return false; | ||||
| } else if (unlessProperty != null | |||||
| && project.getProperty(unlessProperty) != null) { | |||||
| } | |||||
| if (unlessProperty != null && project.getProperty(unlessProperty) != null) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } // Param | } // Param | ||||
| /** | /** | ||||
| * Create an instance of an output property to be configured. | * Create an instance of an output property to be configured. | ||||
| * @return the newly created output property. | * @return the newly created output property. | ||||
| @@ -917,7 +885,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| return p; | return p; | ||||
| } | } | ||||
| /** | /** | ||||
| * Specify how the result tree should be output as specified | * Specify how the result tree should be output as specified | ||||
| * in the <a href="http://www.w3.org/TR/xslt#output"> | * in the <a href="http://www.w3.org/TR/xslt#output"> | ||||
| @@ -985,6 +952,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| fr.setFile(stylesheet); | fr.setFile(stylesheet); | ||||
| configureLiaison(fr); | configureLiaison(fr); | ||||
| } | } | ||||
| /** | /** | ||||
| * Loads the stylesheet and set xsl:param parameters. | * Loads the stylesheet and set xsl:param parameters. | ||||
| * | * | ||||
| @@ -1005,7 +973,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| if (liaison instanceof XSLTLiaison2) { | if (liaison instanceof XSLTLiaison2) { | ||||
| ((XSLTLiaison2) liaison).configure(this); | ((XSLTLiaison2) liaison).configure(this); | ||||
| } | } | ||||
| if (liaison instanceof XSLTLiaison3) { | if (liaison instanceof XSLTLiaison3) { | ||||
| // If we are here we can set the stylesheet as a | // If we are here we can set the stylesheet as a | ||||
| // resource | // resource | ||||
| @@ -1015,12 +982,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| // a resource, but we can set it as a file. So, | // a resource, but we can set it as a file. So, | ||||
| // we make an attempt to get it as a file | // we make an attempt to get it as a file | ||||
| if (stylesheet instanceof FileResource) { | if (stylesheet instanceof FileResource) { | ||||
| liaison.setStylesheet( | |||||
| ((FileResource) stylesheet).getFile()); | |||||
| liaison.setStylesheet(((FileResource) stylesheet).getFile()); | |||||
| } else { | } else { | ||||
| throw new BuildException(liaison.getClass().toString() | throw new BuildException(liaison.getClass().toString() | ||||
| + " accepts the stylesheet only as a file", | |||||
| getLocation()); | |||||
| + " accepts the stylesheet only as a file", getLocation()); | |||||
| } | } | ||||
| } | } | ||||
| for (Enumeration e = params.elements(); e.hasMoreElements();) { | for (Enumeration e = params.elements(); e.hasMoreElements();) { | ||||
| @@ -1030,8 +995,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| } | } | ||||
| } | } | ||||
| } catch (Exception ex) { | } catch (Exception ex) { | ||||
| log("Failed to transform using stylesheet " + stylesheet, | |||||
| Project.MSG_INFO); | |||||
| log("Failed to transform using stylesheet " + stylesheet, Project.MSG_INFO); | |||||
| throw new BuildException(ex); | throw new BuildException(ex); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1046,10 +1010,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * | * | ||||
| * @since Ant 1.7 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| private void setLiaisonDynamicFileParameters( | |||||
| XSLTLiaison liaison, | |||||
| File inFile | |||||
| ) throws Exception { | |||||
| private void setLiaisonDynamicFileParameters(XSLTLiaison liaison, File inFile) throws Exception { | |||||
| if (fileNameParameter != null) { | if (fileNameParameter != null) { | ||||
| liaison.addParam(fileNameParameter, inFile.getName()); | liaison.addParam(fileNameParameter, inFile.getName()); | ||||
| } | } | ||||
| @@ -1058,10 +1019,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| File file = new File(fileName); | File file = new File(fileName); | ||||
| // Give always a slash as file separator, so the stylesheet could be sure about that | // Give always a slash as file separator, so the stylesheet could be sure about that | ||||
| // Use '.' so a dir+"/"+name would not result in an absolute path | // Use '.' so a dir+"/"+name would not result in an absolute path | ||||
| liaison.addParam( | |||||
| fileDirParameter, | |||||
| (file.getParent() != null) | |||||
| ? file.getParent().replace('\\', '/') : "."); | |||||
| liaison.addParam(fileDirParameter, file.getParent() != null ? file.getParent().replace( | |||||
| '\\', '/') : "."); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1170,8 +1129,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| * @param value the value of the attribute | * @param value the value of the attribute | ||||
| * @throws BuildException on error | * @throws BuildException on error | ||||
| */ | */ | ||||
| public void setDynamicAttribute(String name, String value) | |||||
| throws BuildException { | |||||
| public void setDynamicAttribute(String name, String value) throws BuildException { | |||||
| // only 'name' and 'value' exist. | // only 'name' and 'value' exist. | ||||
| if ("name".equalsIgnoreCase(name)) { | if ("name".equalsIgnoreCase(name)) { | ||||
| this.name = value; | this.name = value; | ||||
| @@ -1194,7 +1152,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
| } | } | ||||
| } | } | ||||
| } // -- class Attribute | } // -- class Attribute | ||||
| } // -- class Factory | } // -- class Factory | ||||
| /** | /** | ||||
| @@ -15,7 +15,6 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| * | * | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import java.io.File; | import java.io.File; | ||||
| @@ -172,7 +171,6 @@ import org.xml.sax.EntityResolver; | |||||
| * | * | ||||
| * @ant.task name="xmlproperty" category="xml" | * @ant.task name="xmlproperty" category="xml" | ||||
| */ | */ | ||||
| public class XmlProperty extends org.apache.tools.ant.Task { | public class XmlProperty extends org.apache.tools.ant.Task { | ||||
| private Resource src; | private Resource src; | ||||
| @@ -193,8 +191,9 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| private static final String PATH = "path"; | private static final String PATH = "path"; | ||||
| private static final String PATHID = "pathid"; | private static final String PATHID = "pathid"; | ||||
| private static final String[] ATTRIBUTES = new String[] { | private static final String[] ATTRIBUTES = new String[] { | ||||
| ID, REF_ID, LOCATION, VALUE, PATH, PATHID | |||||
| ID, REF_ID, LOCATION, VALUE, PATH, PATHID | |||||
| }; | }; | ||||
| private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
| /** | /** | ||||
| @@ -213,7 +212,6 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| xmlCatalog.setProject(getProject()); | xmlCatalog.setProject(getProject()); | ||||
| } | } | ||||
| /** | /** | ||||
| * @return the xmlCatalog as the entityresolver. | * @return the xmlCatalog as the entityresolver. | ||||
| */ | */ | ||||
| @@ -227,16 +225,12 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| * @todo validate the source file is valid before opening, print a better error message | * @todo validate the source file is valid before opening, print a better error message | ||||
| * @todo add a verbose level log message listing the name of the file being loaded | * @todo add a verbose level log message listing the name of the file being loaded | ||||
| */ | */ | ||||
| public void execute() | |||||
| throws BuildException { | |||||
| public void execute() throws BuildException { | |||||
| Resource r = getResource(); | Resource r = getResource(); | ||||
| if (r == null) { | if (r == null) { | ||||
| String msg = "XmlProperty task requires a source resource"; | |||||
| throw new BuildException(msg); | |||||
| throw new BuildException("XmlProperty task requires a source resource"); | |||||
| } | } | ||||
| try { | try { | ||||
| log("Loading " + src, Project.MSG_VERBOSE); | log("Loading " + src, Project.MSG_VERBOSE); | ||||
| @@ -270,10 +264,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| addNodeRecursively(topChildren.item(i), prefix, null); | addNodeRecursively(topChildren.item(i), prefix, null); | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| log("Unable to find property resource: " + r, | |||||
| Project.MSG_VERBOSE); | |||||
| log("Unable to find property resource: " + r, Project.MSG_VERBOSE); | |||||
| } | } | ||||
| } catch (SAXException sxe) { | } catch (SAXException sxe) { | ||||
| @@ -283,7 +275,6 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| x = sxe.getException(); | x = sxe.getException(); | ||||
| } | } | ||||
| throw new BuildException("Failed to load " + src, x); | throw new BuildException("Failed to load " + src, x); | ||||
| } catch (ParserConfigurationException pce) { | } catch (ParserConfigurationException pce) { | ||||
| // Parser with specified options can't be built | // Parser with specified options can't be built | ||||
| throw new BuildException(pce); | throw new BuildException(pce); | ||||
| @@ -294,9 +285,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| } | } | ||||
| /** Iterate through all nodes in the tree. */ | /** Iterate through all nodes in the tree. */ | ||||
| private void addNodeRecursively(Node node, String prefix, | |||||
| Object container) { | |||||
| private void addNodeRecursively(Node node, String prefix, Object container) { | |||||
| // Set the prefix for this node to include its tag name. | // Set the prefix for this node to include its tag name. | ||||
| String nodePrefix = prefix; | String nodePrefix = prefix; | ||||
| if (node.getNodeType() != Node.TEXT_NODE) { | if (node.getNodeType() != Node.TEXT_NODE) { | ||||
| @@ -305,13 +294,11 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| } | } | ||||
| nodePrefix += node.getNodeName(); | nodePrefix += node.getNodeName(); | ||||
| } | } | ||||
| // Pass the container to the processing of this node, | // Pass the container to the processing of this node, | ||||
| Object nodeObject = processNode(node, nodePrefix, container); | Object nodeObject = processNode(node, nodePrefix, container); | ||||
| // now, iterate through children. | // now, iterate through children. | ||||
| if (node.hasChildNodes()) { | if (node.hasChildNodes()) { | ||||
| NodeList nodeChildren = node.getChildNodes(); | NodeList nodeChildren = node.getChildNodes(); | ||||
| int numChildren = nodeChildren.getLength(); | int numChildren = nodeChildren.getLength(); | ||||
| @@ -319,8 +306,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| // For each child, pass the object added by | // For each child, pass the object added by | ||||
| // processNode to its children -- in other word, each | // processNode to its children -- in other word, each | ||||
| // object can pass information along to its children. | // object can pass information along to its children. | ||||
| addNodeRecursively(nodeChildren.item(i), nodePrefix, | |||||
| nodeObject); | |||||
| addNodeRecursively(nodeChildren.item(i), nodePrefix, nodeObject); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -361,8 +347,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| // Is there an id attribute? | // Is there an id attribute? | ||||
| Node idNode = nodeAttributes.getNamedItem(ID); | Node idNode = nodeAttributes.getNamedItem(ID); | ||||
| id = (semanticAttributes && idNode != null | |||||
| ? idNode.getNodeValue() : null); | |||||
| id = semanticAttributes && idNode != null ? idNode.getNodeValue() : null; | |||||
| // Now, iterate through the attributes adding them. | // Now, iterate through the attributes adding them. | ||||
| for (int i = 0; i < nodeAttributes.getLength(); i++) { | for (int i = 0; i < nodeAttributes.getLength(); i++) { | ||||
| @@ -374,13 +359,11 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| String attributeValue = getAttributeValue(attributeNode); | String attributeValue = getAttributeValue(attributeNode); | ||||
| addProperty(prefix + attributeName, attributeValue, null); | addProperty(prefix + attributeName, attributeValue, null); | ||||
| } else { | } else { | ||||
| String nodeName = attributeNode.getNodeName(); | String nodeName = attributeNode.getNodeName(); | ||||
| String attributeValue = getAttributeValue(attributeNode); | String attributeValue = getAttributeValue(attributeNode); | ||||
| Path containingPath = (container != null | |||||
| && container instanceof Path ? (Path) container : null); | |||||
| Path containingPath = container != null && container instanceof Path ? (Path) container | |||||
| : null; | |||||
| /* | /* | ||||
| * The main conditional logic -- if the attribute | * The main conditional logic -- if the attribute | ||||
| * is somehow "special" (i.e., it has known | * is somehow "special" (i.e., it has known | ||||
| @@ -390,26 +373,22 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| if (nodeName.equals(ID)) { | if (nodeName.equals(ID)) { | ||||
| // ID has already been found above. | // ID has already been found above. | ||||
| continue; | continue; | ||||
| } else if (containingPath != null | |||||
| && nodeName.equals(PATH)) { | |||||
| } | |||||
| if (containingPath != null && nodeName.equals(PATH)) { | |||||
| // A "path" attribute for a node within a Path object. | // A "path" attribute for a node within a Path object. | ||||
| containingPath.setPath(attributeValue); | containingPath.setPath(attributeValue); | ||||
| } else if (container instanceof Path | |||||
| && nodeName.equals(REF_ID)) { | |||||
| } else if (container instanceof Path && nodeName.equals(REF_ID)) { | |||||
| // A "refid" attribute for a node within a Path object. | // A "refid" attribute for a node within a Path object. | ||||
| containingPath.setPath(attributeValue); | containingPath.setPath(attributeValue); | ||||
| } else if (container instanceof Path | |||||
| && nodeName.equals(LOCATION)) { | |||||
| } else if (container instanceof Path && nodeName.equals(LOCATION)) { | |||||
| // A "location" attribute for a node within a | // A "location" attribute for a node within a | ||||
| // Path object. | // Path object. | ||||
| containingPath.setLocation(resolveFile(attributeValue)); | containingPath.setLocation(resolveFile(attributeValue)); | ||||
| } else if (nodeName.equals(PATHID)) { | } else if (nodeName.equals(PATHID)) { | ||||
| // A node identifying a new path | // A node identifying a new path | ||||
| if (container != null) { | if (container != null) { | ||||
| throw new BuildException("XmlProperty does not " | |||||
| + "support nested paths"); | |||||
| throw new BuildException("XmlProperty does not support nested paths"); | |||||
| } | } | ||||
| addedPath = new Path(getProject()); | addedPath = new Path(getProject()); | ||||
| getProject().addReference(attributeValue, addedPath); | getProject().addReference(attributeValue, addedPath); | ||||
| } else { | } else { | ||||
| @@ -420,56 +399,52 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| String nodeText = null; | String nodeText = null; | ||||
| boolean emptyNode = false; | boolean emptyNode = false; | ||||
| boolean semanticEmptyOverride = false; | boolean semanticEmptyOverride = false; | ||||
| if (node.getNodeType() == Node.ELEMENT_NODE | if (node.getNodeType() == Node.ELEMENT_NODE | ||||
| && semanticAttributes | |||||
| && node.hasAttributes() | |||||
| && (node.getAttributes().getNamedItem(VALUE) != null | |||||
| || node.getAttributes().getNamedItem(LOCATION) != null | |||||
| || node.getAttributes().getNamedItem(REF_ID) != null | |||||
| || node.getAttributes().getNamedItem(PATH) != null | |||||
| || node.getAttributes().getNamedItem(PATHID) != null)) { | |||||
| && semanticAttributes | |||||
| && node.hasAttributes() | |||||
| && (node.getAttributes().getNamedItem(VALUE) != null | |||||
| || node.getAttributes().getNamedItem(LOCATION) != null | |||||
| || node.getAttributes().getNamedItem(REF_ID) != null | |||||
| || node.getAttributes().getNamedItem(PATH) != null || node.getAttributes() | |||||
| .getNamedItem(PATHID) != null)) { | |||||
| semanticEmptyOverride = true; | semanticEmptyOverride = true; | ||||
| } | } | ||||
| if (node.getNodeType() == Node.TEXT_NODE) { | if (node.getNodeType() == Node.TEXT_NODE) { | ||||
| // For the text node, add a property. | // For the text node, add a property. | ||||
| nodeText = getAttributeValue(node); | nodeText = getAttributeValue(node); | ||||
| } else if ((node.getNodeType() == Node.ELEMENT_NODE) | |||||
| && (node.getChildNodes().getLength() == 1) | |||||
| && (node.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE)) { | |||||
| } else if (node.getNodeType() == Node.ELEMENT_NODE | |||||
| && node.getChildNodes().getLength() == 1 | |||||
| && node.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE) { | |||||
| nodeText = node.getFirstChild().getNodeValue(); | nodeText = node.getFirstChild().getNodeValue(); | ||||
| if ("".equals(nodeText) && !semanticEmptyOverride) { | if ("".equals(nodeText) && !semanticEmptyOverride) { | ||||
| emptyNode = true; | emptyNode = true; | ||||
| } | } | ||||
| } else if ((node.getNodeType() == Node.ELEMENT_NODE) | |||||
| && (node.getChildNodes().getLength() == 0) | |||||
| && !semanticEmptyOverride) { | |||||
| } else if (node.getNodeType() == Node.ELEMENT_NODE | |||||
| && node.getChildNodes().getLength() == 0 | |||||
| && !semanticEmptyOverride) { | |||||
| nodeText = ""; | nodeText = ""; | ||||
| emptyNode = true; | emptyNode = true; | ||||
| } else if ((node.getNodeType() == Node.ELEMENT_NODE) | |||||
| && (node.getChildNodes().getLength() == 1) | |||||
| && (node.getFirstChild().getNodeType() == Node.TEXT_NODE) | |||||
| && ("".equals(node.getFirstChild().getNodeValue())) | |||||
| && !semanticEmptyOverride) { | |||||
| } else if (node.getNodeType() == Node.ELEMENT_NODE | |||||
| && node.getChildNodes().getLength() == 1 | |||||
| && node.getFirstChild().getNodeType() == Node.TEXT_NODE | |||||
| && "".equals(node.getFirstChild().getNodeValue()) | |||||
| && !semanticEmptyOverride) { | |||||
| nodeText = ""; | nodeText = ""; | ||||
| emptyNode = true; | emptyNode = true; | ||||
| } | } | ||||
| if (nodeText != null) { | if (nodeText != null) { | ||||
| // If the containing object was a String, then use it as the ID. | // If the containing object was a String, then use it as the ID. | ||||
| if (semanticAttributes && id == null | |||||
| && container instanceof String) { | |||||
| if (semanticAttributes && id == null && container instanceof String) { | |||||
| id = (String) container; | id = (String) container; | ||||
| } | } | ||||
| if (nodeText.trim().length() != 0 || emptyNode) { | if (nodeText.trim().length() != 0 || emptyNode) { | ||||
| addProperty(prefix, nodeText, id); | addProperty(prefix, nodeText, id); | ||||
| } | } | ||||
| } | } | ||||
| // Return the Path we added or the ID of this node for | // Return the Path we added or the ID of this node for | ||||
| // children to reference if needed. Path objects are | // children to reference if needed. Path objects are | ||||
| // definitely used by child path elements, and ID may be used | // definitely used by child path elements, and ID may be used | ||||
| @@ -526,18 +501,14 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| // attribute name. | // attribute name. | ||||
| if (attributeName.equals(REF_ID)) { | if (attributeName.equals(REF_ID)) { | ||||
| return ""; | return ""; | ||||
| } | |||||
| // Otherwise, return it appended unless property to hide it is set. | // Otherwise, return it appended unless property to hide it is set. | ||||
| } else if (!isSemanticAttribute(attributeName) | |||||
| || includeSemanticAttribute) { | |||||
| if (!isSemanticAttribute(attributeName) || includeSemanticAttribute) { | |||||
| return "." + attributeName; | return "." + attributeName; | ||||
| } else { | |||||
| return ""; | |||||
| } | } | ||||
| } else if (collapseAttributes) { | |||||
| return "." + attributeName; | |||||
| } else { | |||||
| return "(" + attributeName + ")"; | |||||
| return ""; | |||||
| } | } | ||||
| return collapseAttributes ? "." + attributeName : "(" + attributeName + ")"; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -572,7 +543,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| if (attributeName.equals(LOCATION)) { | if (attributeName.equals(LOCATION)) { | ||||
| File f = resolveFile(nodeValue); | File f = resolveFile(nodeValue); | ||||
| return f.getPath(); | return f.getPath(); | ||||
| } else if (attributeName.equals(REF_ID)) { | |||||
| } | |||||
| if (attributeName.equals(REF_ID)) { | |||||
| Object ref = getProject().getReference(nodeValue); | Object ref = getProject().getReference(nodeValue); | ||||
| if (ref != null) { | if (ref != null) { | ||||
| return ref.toString(); | return ref.toString(); | ||||
| @@ -599,8 +571,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| throw new BuildException("the source can't be a directory"); | throw new BuildException("the source can't be a directory"); | ||||
| } | } | ||||
| if (src instanceof FileResource && !supportsNonFileResources()) { | if (src instanceof FileResource && !supportsNonFileResources()) { | ||||
| throw new BuildException("Only FileSystem resources are" | |||||
| + " supported."); | |||||
| throw new BuildException("Only FileSystem resources are supported."); | |||||
| } | } | ||||
| this.src = src; | this.src = src; | ||||
| } | } | ||||
| @@ -611,8 +582,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| */ | */ | ||||
| public void addConfigured(ResourceCollection a) { | public void addConfigured(ResourceCollection a) { | ||||
| if (a.size() != 1) { | if (a.size() != 1) { | ||||
| throw new BuildException("only single argument resource collections" | |||||
| + " are supported as archives"); | |||||
| throw new BuildException( | |||||
| "only single argument resource collections are supported as archives"); | |||||
| } | } | ||||
| setSrcResource((Resource) a.iterator().next()); | setSrcResource((Resource) a.iterator().next()); | ||||
| } | } | ||||
| @@ -693,11 +664,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| * @return the file attribute. | * @return the file attribute. | ||||
| */ | */ | ||||
| protected File getFile () { | protected File getFile () { | ||||
| if (src instanceof FileResource) { | |||||
| return ((FileResource) src).getFile(); | |||||
| } else { | |||||
| return null; | |||||
| } | |||||
| return src instanceof FileResource ? ((FileResource) src).getFile() : null; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -707,11 +674,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| // delegate this way around to support subclasses that | // delegate this way around to support subclasses that | ||||
| // overwrite getFile | // overwrite getFile | ||||
| File f = getFile(); | File f = getFile(); | ||||
| if (f != null) { | |||||
| return new FileResource(f); | |||||
| } else { | |||||
| return src; | |||||
| } | |||||
| return f == null ? src : src instanceof FileResource | |||||
| && ((FileResource) src).getFile().equals(f) ? src : new FileResource(f); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -768,10 +732,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||||
| * rootDirectory has been set. | * rootDirectory has been set. | ||||
| */ | */ | ||||
| private File resolveFile(String fileName) { | private File resolveFile(String fileName) { | ||||
| if (rootDirectory == null) { | |||||
| return FILE_UTILS.resolveFile(getProject().getBaseDir(), fileName); | |||||
| } | |||||
| return FILE_UTILS.resolveFile(rootDirectory, fileName); | |||||
| return FILE_UTILS.resolveFile(rootDirectory == null ? getProject().getBaseDir() | |||||
| : rootDirectory, fileName); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -15,7 +15,6 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| * | * | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.compilers; | package org.apache.tools.ant.taskdefs.compilers; | ||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| @@ -156,13 +155,11 @@ public class Jikes extends DefaultCompilerAdapter { | |||||
| * that don't exist. As this is often the case, these | * that don't exist. As this is often the case, these | ||||
| * warning can be pretty annoying. | * warning can be pretty annoying. | ||||
| */ | */ | ||||
| String warningsProperty = | |||||
| project.getProperty("build.compiler.warnings"); | |||||
| String warningsProperty = project.getProperty("build.compiler.warnings"); | |||||
| if (warningsProperty != null) { | if (warningsProperty != null) { | ||||
| attributes.log("!! the build.compiler.warnings property is " | |||||
| + "deprecated. !!", Project.MSG_WARN); | |||||
| attributes.log("!! Use the nowarn attribute instead. !!", | |||||
| Project.MSG_WARN); | |||||
| attributes.log("!! the build.compiler.warnings property is " + "deprecated. !!", | |||||
| Project.MSG_WARN); | |||||
| attributes.log("!! Use the nowarn attribute instead. !!", Project.MSG_WARN); | |||||
| if (!Project.toBoolean(warningsProperty)) { | if (!Project.toBoolean(warningsProperty)) { | ||||
| cmd.createArgument().setValue("-nowarn"); | cmd.createArgument().setValue("-nowarn"); | ||||
| } | } | ||||
| @@ -174,8 +171,7 @@ public class Jikes extends DefaultCompilerAdapter { | |||||
| /** | /** | ||||
| * Jikes can issue pedantic warnings. | * Jikes can issue pedantic warnings. | ||||
| */ | */ | ||||
| String pedanticProperty = | |||||
| project.getProperty("build.compiler.pedantic"); | |||||
| String pedanticProperty = project.getProperty("build.compiler.pedantic"); | |||||
| if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) { | if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) { | ||||
| cmd.createArgument().setValue("+P"); | cmd.createArgument().setValue("+P"); | ||||
| } | } | ||||
| @@ -185,8 +181,7 @@ public class Jikes extends DefaultCompilerAdapter { | |||||
| * checking", see the jikes documentation for differences | * checking", see the jikes documentation for differences | ||||
| * between -depend and +F. | * between -depend and +F. | ||||
| */ | */ | ||||
| String fullDependProperty = | |||||
| project.getProperty("build.compiler.fulldepend"); | |||||
| String fullDependProperty = project.getProperty("build.compiler.fulldepend"); | |||||
| if (fullDependProperty != null | if (fullDependProperty != null | ||||
| && Project.toBoolean(fullDependProperty)) { | && Project.toBoolean(fullDependProperty)) { | ||||
| cmd.createArgument().setValue("+F"); | cmd.createArgument().setValue("+F"); | ||||
| @@ -198,14 +193,13 @@ public class Jikes extends DefaultCompilerAdapter { | |||||
| if (source.equals("1.1") || source.equals("1.2")) { | if (source.equals("1.1") || source.equals("1.2")) { | ||||
| // support for -source 1.1 and -source 1.2 has been | // support for -source 1.1 and -source 1.2 has been | ||||
| // added with JDK 1.4.2, Jikes doesn't like it | // added with JDK 1.4.2, Jikes doesn't like it | ||||
| attributes.log("Jikes doesn't support '-source " | |||||
| + source + "', will use '-source 1.3' instead"); | |||||
| attributes.log("Jikes doesn't support '-source " + source | |||||
| + "', will use '-source 1.3' instead"); | |||||
| cmd.createArgument().setValue("1.3"); | cmd.createArgument().setValue("1.3"); | ||||
| } else { | } else { | ||||
| cmd.createArgument().setValue(source); | cmd.createArgument().setValue(source); | ||||
| } | } | ||||
| } | } | ||||
| addCurrentCompilerArgs(cmd); | addCurrentCompilerArgs(cmd); | ||||
| int firstFileName = cmd.size(); | int firstFileName = cmd.size(); | ||||
| @@ -215,12 +209,9 @@ public class Jikes extends DefaultCompilerAdapter { | |||||
| cmd.createArgument().setValue("-bootclasspath"); | cmd.createArgument().setValue("-bootclasspath"); | ||||
| cmd.createArgument().setPath(boot); | cmd.createArgument().setPath(boot); | ||||
| } | } | ||||
| logAndAddFilesToCompile(cmd); | logAndAddFilesToCompile(cmd); | ||||
| return | |||||
| executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | |||||
| return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | |||||
| } | } | ||||
| } | } | ||||