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. | |||
* | |||
*/ | |||
package org.apache.tools.ant; | |||
import java.io.FileOutputStream; | |||
@@ -30,6 +29,7 @@ import java.util.Enumeration; | |||
import javax.xml.parsers.DocumentBuilder; | |||
import javax.xml.parsers.DocumentBuilderFactory; | |||
import org.apache.tools.ant.util.DOMElementWriter; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.StringUtils; | |||
import org.w3c.dom.Document; | |||
import org.w3c.dom.Element; | |||
@@ -73,36 +73,49 @@ public class XmlLogger implements BuildLogger { | |||
/** XML element name for a build. */ | |||
private static final String BUILD_TAG = "build"; | |||
/** XML element name for a target. */ | |||
private static final String TARGET_TAG = "target"; | |||
/** XML element name for a task. */ | |||
private static final String TASK_TAG = "task"; | |||
/** XML element name for a message. */ | |||
private static final String MESSAGE_TAG = "message"; | |||
/** XML attribute name for a name. */ | |||
private static final String NAME_ATTR = "name"; | |||
/** XML attribute name for a time. */ | |||
private static final String TIME_ATTR = "time"; | |||
/** XML attribute name for a message priority. */ | |||
private static final String PRIORITY_ATTR = "priority"; | |||
/** XML attribute name for a file location. */ | |||
private static final String LOCATION_ATTR = "location"; | |||
/** XML attribute name for an error description. */ | |||
private static final String ERROR_ATTR = "error"; | |||
/** XML element name for a stack trace. */ | |||
private static final String STACKTRACE_TAG = "stacktrace"; | |||
/** The complete log document for this build. */ | |||
private Document doc = builder.newDocument(); | |||
/** Mapping for when tasks started (Task to TimedElement). */ | |||
private Hashtable tasks = new Hashtable(); | |||
/** Mapping for when targets started (Task to TimedElement). */ | |||
private Hashtable targets = new Hashtable(); | |||
/** | |||
* Mapping of threads to stacks of elements | |||
* (Thread to Stack of TimedElement). | |||
*/ | |||
private Hashtable threadStacks = new Hashtable(); | |||
/** | |||
* When the build started. | |||
*/ | |||
@@ -149,12 +162,10 @@ public class XmlLogger implements BuildLogger { | |||
*/ | |||
public void buildFinished(BuildEvent event) { | |||
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) { | |||
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... | |||
// better have too much info than not enough. | |||
Throwable t = event.getException(); | |||
@@ -163,13 +174,11 @@ public class XmlLogger implements BuildLogger { | |||
stacktrace.appendChild(errText); | |||
buildElement.element.appendChild(stacktrace); | |||
} | |||
String outFilename = event.getProject().getProperty("XmlLogger.file"); | |||
if (outFilename == null) { | |||
outFilename = "log.xml"; | |||
} | |||
String xslUri | |||
= event.getProject().getProperty("ant.XmlLogger.stylesheet.uri"); | |||
String xslUri = event.getProject().getProperty("ant.XmlLogger.stylesheet.uri"); | |||
if (xslUri == null) { | |||
xslUri = "log.xsl"; | |||
} | |||
@@ -184,21 +193,14 @@ public class XmlLogger implements BuildLogger { | |||
out = new OutputStreamWriter(stream, "UTF8"); | |||
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | |||
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(); | |||
} catch (IOException exc) { | |||
throw new BuildException("Unable to write log file", exc); | |||
} finally { | |||
if (out != null) { | |||
try { | |||
out.close(); | |||
} catch (IOException e) { | |||
// ignore | |||
} | |||
} | |||
FileUtils.close(out); | |||
} | |||
buildElement = null; | |||
} | |||
@@ -249,20 +251,16 @@ public class XmlLogger implements BuildLogger { | |||
Target target = event.getTarget(); | |||
TimedElement targetElement = (TimedElement) targets.get(target); | |||
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; | |||
Stack threadStack = getStack(); | |||
if (!threadStack.empty()) { | |||
TimedElement poppedStack = (TimedElement) threadStack.pop(); | |||
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()) { | |||
parentElement = (TimedElement) threadStack.peek(); | |||
@@ -296,8 +294,7 @@ public class XmlLogger implements BuildLogger { | |||
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); | |||
getStack().push(taskElement); | |||
} | |||
@@ -312,36 +309,32 @@ public class XmlLogger implements BuildLogger { | |||
public void taskFinished(BuildEvent event) { | |||
Task task = event.getTask(); | |||
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); | |||
} | |||
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. | |||
* | |||
@@ -353,7 +346,6 @@ public class XmlLogger implements BuildLogger { | |||
if (element != null) { | |||
return element; | |||
} | |||
for (Enumeration e = tasks.keys(); e.hasMoreElements();) { | |||
Task key = (Task) e.nextElement(); | |||
if (key instanceof UnknownElement) { | |||
@@ -362,7 +354,6 @@ public class XmlLogger implements BuildLogger { | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
@@ -382,7 +373,7 @@ public class XmlLogger implements BuildLogger { | |||
Element messageElement = doc.createElement(MESSAGE_TAG); | |||
String name = "debug"; | |||
switch (event.getPriority()) { | |||
switch (priority) { | |||
case Project.MSG_ERR: | |||
name = "error"; | |||
break; | |||
@@ -419,19 +410,6 @@ public class XmlLogger implements BuildLogger { | |||
if (parentElement == null && target != null) { | |||
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) { | |||
parentElement.element.appendChild(messageElement); | |||
} else { | |||
@@ -15,7 +15,6 @@ | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
@@ -205,8 +204,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
*/ | |||
public void addMapper(Mapper mapper) { | |||
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; | |||
} | |||
@@ -229,8 +227,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
*/ | |||
public void addConfiguredStyle(Resources rc) { | |||
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()); | |||
} | |||
@@ -267,43 +265,34 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
log("Warning: the task name <style> is deprecated. Use <xslt> instead.", | |||
Project.MSG_WARN); | |||
} | |||
File savedBaseDir = baseDir; | |||
DirectoryScanner scanner; | |||
String[] list; | |||
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) { | |||
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()) { | |||
throw new BuildException( | |||
"input file " + inFile.toString() + " does not exist", getLocation()); | |||
throw new BuildException("input file " + inFile + " does not exist", getLocation()); | |||
} | |||
try { | |||
if (baseDir == null) { | |||
baseDir = getProject().resolveFile("."); | |||
} | |||
liaison = getLiaison(); | |||
// check if liaison wants to log errors using us as logger | |||
if (liaison instanceof XSLTLoggerAware) { | |||
((XSLTLoggerAware) liaison).setLogger(this); | |||
} | |||
log("Using " + liaison.getClass().toString(), Project.MSG_VERBOSE); | |||
if (xslFile != null) { | |||
@@ -317,8 +306,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
* the wrong version has been used. | |||
*/ | |||
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."); | |||
} | |||
} | |||
@@ -327,13 +315,11 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
fr.setFile(stylesheet); | |||
xslResource = fr; | |||
} | |||
// if we have an in file and out then process them | |||
if (inFile != null && outFile != null) { | |||
process(inFile, outFile, xslResource); | |||
return; | |||
} | |||
/* | |||
* if we get here, in and out have not been specified, we are | |||
* in batch processing mode. | |||
@@ -357,8 +343,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
for (int j = 0; j < dirs.length; ++j) { | |||
list = new File(baseDir, dirs[j]).list(); | |||
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 { | |||
if (classpath == null) { | |||
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. | |||
* @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 inF = null; | |||
@@ -633,11 +616,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
inF = new File(baseDir, xmlFile); | |||
if (inF.isDirectory()) { | |||
log("Skipping " + inF + " it is a directory.", | |||
Project.MSG_VERBOSE); | |||
log("Skipping " + inF + " it is a directory.", Project.MSG_VERBOSE); | |||
return; | |||
} | |||
FileNameMapper mapper = null; | |||
if (mapperElement != null) { | |||
mapper = mapperElement.getImplementation(); | |||
@@ -647,23 +628,18 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
String[] outFileName = mapper.mapFileName(xmlFile); | |||
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; | |||
} 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; | |||
} | |||
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); | |||
log("Processing " + inF + " to " + outF); | |||
configureLiaison(stylesheet); | |||
setLiaisonDynamicFileParameters(liaison, inF); | |||
liaison.transform(inF, outF); | |||
@@ -689,28 +665,22 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
* @param stylesheet the stylesheet to use. | |||
* @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 { | |||
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() | |||
|| styleSheetLastModified >= outFile.lastModified()) { | |||
|| styleSheetLastModified >= outFile.lastModified()) { | |||
ensureDirectoryFor(outFile); | |||
log("Processing " + inFile + " to " + outFile, | |||
Project.MSG_INFO); | |||
log("Processing " + inFile + " to " + outFile, Project.MSG_INFO); | |||
configureLiaison(stylesheet); | |||
setLiaisonDynamicFileParameters(liaison, inFile); | |||
liaison.transform(inFile, outFile); | |||
} 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) { | |||
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. | |||
* @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(); | |||
if (!directory.exists()) { | |||
if (!directory.mkdirs()) { | |||
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) { | |||
this.unlessProperty = unlessProperty; | |||
} | |||
/** | |||
* Ensures that the param passes the conditions placed | |||
* 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() { | |||
if (ifProperty != null && project.getProperty(ifProperty) == null) { | |||
return false; | |||
} else if (unlessProperty != null | |||
&& project.getProperty(unlessProperty) != null) { | |||
} | |||
if (unlessProperty != null && project.getProperty(unlessProperty) != null) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
} // Param | |||
/** | |||
* Create an instance of an output property to be configured. | |||
* @return the newly created output property. | |||
@@ -917,7 +885,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
return p; | |||
} | |||
/** | |||
* Specify how the result tree should be output as specified | |||
* 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); | |||
configureLiaison(fr); | |||
} | |||
/** | |||
* Loads the stylesheet and set xsl:param parameters. | |||
* | |||
@@ -1005,7 +973,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
if (liaison instanceof XSLTLiaison2) { | |||
((XSLTLiaison2) liaison).configure(this); | |||
} | |||
if (liaison instanceof XSLTLiaison3) { | |||
// If we are here we can set the stylesheet as a | |||
// resource | |||
@@ -1015,12 +982,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
// a resource, but we can set it as a file. So, | |||
// we make an attempt to get it as a file | |||
if (stylesheet instanceof FileResource) { | |||
liaison.setStylesheet( | |||
((FileResource) stylesheet).getFile()); | |||
liaison.setStylesheet(((FileResource) stylesheet).getFile()); | |||
} else { | |||
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();) { | |||
@@ -1030,8 +995,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
} | |||
} | |||
} 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); | |||
} | |||
} | |||
@@ -1046,10 +1010,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
* | |||
* @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) { | |||
liaison.addParam(fileNameParameter, inFile.getName()); | |||
} | |||
@@ -1058,10 +1019,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
File file = new File(fileName); | |||
// 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 | |||
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 | |||
* @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. | |||
if ("name".equalsIgnoreCase(name)) { | |||
this.name = value; | |||
@@ -1194,7 +1152,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||
} | |||
} | |||
} // -- class Attribute | |||
} // -- class Factory | |||
/** | |||
@@ -15,7 +15,6 @@ | |||
* limitations under the License. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
@@ -172,7 +171,6 @@ import org.xml.sax.EntityResolver; | |||
* | |||
* @ant.task name="xmlproperty" category="xml" | |||
*/ | |||
public class XmlProperty extends org.apache.tools.ant.Task { | |||
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 PATHID = "pathid"; | |||
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(); | |||
/** | |||
@@ -213,7 +212,6 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
xmlCatalog.setProject(getProject()); | |||
} | |||
/** | |||
* @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 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(); | |||
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 { | |||
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); | |||
} | |||
} | |||
} else { | |||
log("Unable to find property resource: " + r, | |||
Project.MSG_VERBOSE); | |||
log("Unable to find property resource: " + r, Project.MSG_VERBOSE); | |||
} | |||
} catch (SAXException sxe) { | |||
@@ -283,7 +275,6 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
x = sxe.getException(); | |||
} | |||
throw new BuildException("Failed to load " + src, x); | |||
} catch (ParserConfigurationException pce) { | |||
// Parser with specified options can't be built | |||
throw new BuildException(pce); | |||
@@ -294,9 +285,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
} | |||
/** 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. | |||
String nodePrefix = prefix; | |||
if (node.getNodeType() != Node.TEXT_NODE) { | |||
@@ -305,13 +294,11 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
} | |||
nodePrefix += node.getNodeName(); | |||
} | |||
// Pass the container to the processing of this node, | |||
Object nodeObject = processNode(node, nodePrefix, container); | |||
// now, iterate through children. | |||
if (node.hasChildNodes()) { | |||
NodeList nodeChildren = node.getChildNodes(); | |||
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 | |||
// processNode to its children -- in other word, each | |||
// 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? | |||
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. | |||
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); | |||
addProperty(prefix + attributeName, attributeValue, null); | |||
} else { | |||
String nodeName = attributeNode.getNodeName(); | |||
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 | |||
* 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)) { | |||
// ID has already been found above. | |||
continue; | |||
} else if (containingPath != null | |||
&& nodeName.equals(PATH)) { | |||
} | |||
if (containingPath != null && nodeName.equals(PATH)) { | |||
// A "path" attribute for a node within a Path object. | |||
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. | |||
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 | |||
// Path object. | |||
containingPath.setLocation(resolveFile(attributeValue)); | |||
} else if (nodeName.equals(PATHID)) { | |||
// A node identifying a new path | |||
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()); | |||
getProject().addReference(attributeValue, addedPath); | |||
} else { | |||
@@ -420,56 +399,52 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
} | |||
} | |||
} | |||
String nodeText = null; | |||
boolean emptyNode = false; | |||
boolean semanticEmptyOverride = false; | |||
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; | |||
} | |||
if (node.getNodeType() == Node.TEXT_NODE) { | |||
// For the text node, add a property. | |||
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(); | |||
if ("".equals(nodeText) && !semanticEmptyOverride) { | |||
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 = ""; | |||
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 = ""; | |||
emptyNode = true; | |||
} | |||
if (nodeText != null) { | |||
// 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; | |||
} | |||
if (nodeText.trim().length() != 0 || emptyNode) { | |||
addProperty(prefix, nodeText, id); | |||
} | |||
} | |||
// Return the Path we added or the ID of this node for | |||
// children to reference if needed. Path objects are | |||
// 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. | |||
if (attributeName.equals(REF_ID)) { | |||
return ""; | |||
} | |||
// Otherwise, return it appended unless property to hide it is set. | |||
} else if (!isSemanticAttribute(attributeName) | |||
|| includeSemanticAttribute) { | |||
if (!isSemanticAttribute(attributeName) || includeSemanticAttribute) { | |||
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)) { | |||
File f = resolveFile(nodeValue); | |||
return f.getPath(); | |||
} else if (attributeName.equals(REF_ID)) { | |||
} | |||
if (attributeName.equals(REF_ID)) { | |||
Object ref = getProject().getReference(nodeValue); | |||
if (ref != null) { | |||
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"); | |||
} | |||
if (src instanceof FileResource && !supportsNonFileResources()) { | |||
throw new BuildException("Only FileSystem resources are" | |||
+ " supported."); | |||
throw new BuildException("Only FileSystem resources are supported."); | |||
} | |||
this.src = src; | |||
} | |||
@@ -611,8 +582,8 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
*/ | |||
public void addConfigured(ResourceCollection a) { | |||
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()); | |||
} | |||
@@ -693,11 +664,7 @@ public class XmlProperty extends org.apache.tools.ant.Task { | |||
* @return the file attribute. | |||
*/ | |||
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 | |||
// overwrite 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. | |||
*/ | |||
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. | |||
* | |||
*/ | |||
package org.apache.tools.ant.taskdefs.compilers; | |||
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 | |||
* warning can be pretty annoying. | |||
*/ | |||
String warningsProperty = | |||
project.getProperty("build.compiler.warnings"); | |||
String warningsProperty = project.getProperty("build.compiler.warnings"); | |||
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)) { | |||
cmd.createArgument().setValue("-nowarn"); | |||
} | |||
@@ -174,8 +171,7 @@ public class Jikes extends DefaultCompilerAdapter { | |||
/** | |||
* 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)) { | |||
cmd.createArgument().setValue("+P"); | |||
} | |||
@@ -185,8 +181,7 @@ public class Jikes extends DefaultCompilerAdapter { | |||
* checking", see the jikes documentation for differences | |||
* between -depend and +F. | |||
*/ | |||
String fullDependProperty = | |||
project.getProperty("build.compiler.fulldepend"); | |||
String fullDependProperty = project.getProperty("build.compiler.fulldepend"); | |||
if (fullDependProperty != null | |||
&& Project.toBoolean(fullDependProperty)) { | |||
cmd.createArgument().setValue("+F"); | |||
@@ -198,14 +193,13 @@ public class Jikes extends DefaultCompilerAdapter { | |||
if (source.equals("1.1") || source.equals("1.2")) { | |||
// support for -source 1.1 and -source 1.2 has been | |||
// 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"); | |||
} else { | |||
cmd.createArgument().setValue(source); | |||
} | |||
} | |||
addCurrentCompilerArgs(cmd); | |||
int firstFileName = cmd.size(); | |||
@@ -215,12 +209,9 @@ public class Jikes extends DefaultCompilerAdapter { | |||
cmd.createArgument().setValue("-bootclasspath"); | |||
cmd.createArgument().setPath(boot); | |||
} | |||
logAndAddFilesToCompile(cmd); | |||
return | |||
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | |||
return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | |||
} | |||
} |