/** * sets the build file to which the XML context belongs * @param buildFile Ant build file * @throws MalformedURLException if parent URL cannot be constructed * @since Ant 1.8.0 */ public void setBuildFile(URL buildFile) throws MalformedURLException { this.buildFileURL = buildFile; this.buildFileParentURL = new URL(buildFile, "."); if (implicitTarget.getLocation() == null) { implicitTarget.setLocation(new Location(buildFile.toString())); } }
private Resource getFileAttributeResource() { // Paths are relative to the build file they're imported from, // *not* the current directory (same as entity includes). if (file != null) { if (isExistingAbsoluteFile(file)) { return new FileResource(FILE_UTILS.normalize(file)); } File buildFile = new File(getLocation().getFileName()).getAbsoluteFile(); if (buildFile.exists()) { File buildFileParent = new File(buildFile.getParent()); File importedFile = FILE_UTILS.resolveFile(buildFileParent, file); return new FileResource(importedFile); } // maybe this import tasks is inside an imported URL? try { URL buildFileURL = new URL(getLocation().getFileName()); URL importedFile = new URL(buildFileURL, file); return new URLResource(importedFile); } catch (MalformedURLException ex) { log(ex.toString(), Project.MSG_VERBOSE); } throw new BuildException("failed to resolve %s relative to %s", file, getLocation().getFileName()); } return null; }
/** * Equality operation. * @param other the object to compare to. * @return true if the other object contains the same information * as this object. * @since Ant 1.6.3 */ @Override public boolean equals(Object other) { return this == other || other != null && other.getClass() == getClass() && toString().equals(other.toString()); }
public MessageBean setLocation(final Location location) { final MessageBean ret = new MessageBean(this); ret.srcFile = toURI(location.getFileName()); ret.srcLine = location.getLineNumber(); ret.srcColumn = location.getColumnNumber(); return ret; }
@Override public void init() throws BuildException { // Append N-1 empty lines, to match Gosu line numbers with build.xml. Location loc = getLocation(); if (loc != null) { for (int i = 0; i < getLocation().getLineNumber() - 1; i++) { _expression.append('\n'); } } }
|| buildException.getLocation().getFileName() == null ) File antFile = new File( buildException.getLocation().getFileName() ); if ( !antFile.exists() ) while ( ( line = reader.readLine() ) != null ) if ( reader.getLineNumber() == buildException.getLocation().getLineNumber() ) return "around Ant part ..." + line.trim() + "... @ " + buildException.getLocation().getLineNumber() + ":" + buildException.getLocation().getColumnNumber() + " in " + antFile.getAbsolutePath();
length = node.getLength(); } else { line = location.getLineNumber(); if (line == 0) { AntProjectNode projectNode = getProjectNode();
/** * sets the build file to which the XML context belongs * @param buildFile ant build file */ public void setBuildFile(File buildFile) { this.buildFile = buildFile; if (buildFile != null) { this.buildFileParent = new File(buildFile.getParent()); implicitTarget.setLocation(new Location(buildFile.getAbsolutePath())); try { setBuildFile(FileUtils.getFileUtils().getFileURL(buildFile)); } catch (MalformedURLException ex) { throw new BuildException(ex); } } else { this.buildFileParent = null; } }
if (getLocation() == null || getLocation().getFileName() == null) { throw new BuildException("Unable to get location of import task");
/** * Returns the location of the error and the error message. * * @return the location of the error and the error message */ public String toString() { return location.toString() + getMessage(); }
private Target onStartTarget(final Attributes attrs, String tagName, String ns) { final Target target = new Target(); target.setProject(project); target.setLocation(new Location(antXmlContext.getLocator())); try { antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext); final Target newTarget = getProject().getTargets().get(attrs.getValue("name")); // execute dependencies (if any) final Vector<Target> targets = new Vector<Target>(); for (final Enumeration<String> deps = newTarget.getDependencies(); deps.hasMoreElements();) { final String targetName = deps.nextElement(); targets.add(project.getTargets().get(targetName)); } getProject().executeSortedTargets(targets); antXmlContext.setCurrentTarget(newTarget); return newTarget; } catch (final SAXParseException e) { log.log(Level.SEVERE, "Caught: " + e, e); } return null; }
private void importResource(ProjectHelper helper, Resource importedResource) { getProject().log("Importing file " + importedResource + " from " + getLocation().getFileName(), Project.MSG_VERBOSE); + getLocation().getFileName(); if (optional) { getProject().log(message, Project.MSG_VERBOSE);
/** * Fired when a task starts building, this pushes a timed element * for the task onto the stack of elements for the current thread, * remembering the current time and the name of the task. * * @param event An event with any relevant extra information. * Will not be <code>null</code>. */ @Override public void taskStarted(BuildEvent event) { TimedElement taskElement = new TimedElement(); taskElement.startTime = System.currentTimeMillis(); taskElement.element = doc.createElement(TASK_TAG); Task task = event.getTask(); String name = event.getTask().getTaskName(); if (name == null) { name = ""; } taskElement.element.setAttribute(NAME_ATTR, name); taskElement.element.setAttribute(LOCATION_ATTR, event.getTask().getLocation().toString()); tasks.put(task, taskElement); getStack().push(taskElement); }
private Target onDefineTarget(final Attributes attrs, String tagName, String ns) { final Target target = new Target(); target.setProject(project); target.setLocation(new Location(antXmlContext.getLocator())); try { antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext); final Target newTarget = getProject().getTargets().get(attrs.getValue("name")); antXmlContext.setCurrentTarget(newTarget); definingTarget = newTarget; return newTarget; } catch (final SAXParseException e) { log.log(Level.SEVERE, "Caught: " + e, e); } return null; }
@Override public String getFilePath() { return getLocation().getFileName(); } };
/** * Add location to build exception. * @param ex the build exception, if the build exception * does not include * @param newLocation the location of the calling task (may be null) * @return a new build exception based in the build exception with * location set to newLocation. If the original exception * did not have a location, just return the build exception */ public static BuildException addLocationToBuildException( BuildException ex, Location newLocation) { if (ex.getLocation() == null || ex.getMessage() == null) { return ex; } String errorMessage = String.format("The following error occurred while executing this line:%n%s%s", ex.getLocation().toString(), ex.getMessage()); if (ex instanceof ExitStatusException) { int exitStatus = ((ExitStatusException) ex).getStatus(); if (newLocation == null) { return new ExitStatusException(errorMessage, exitStatus); } return new ExitStatusException(errorMessage, exitStatus, newLocation); } if (newLocation == null) { return new BuildException(errorMessage, ex); } return new BuildException(errorMessage, ex, newLocation); }
parser.parse(inputSource); } catch (SAXParseException exc) { Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc .getColumnNumber());
/** * Try to build a script name for the script of the groovy task to have an helpful value in stack traces in case of exception * @return the name to use when compiling the script */ private String computeScriptName() { if (srcFile != null) { return srcFile.getAbsolutePath(); } else { String name = PREFIX; if (getLocation().getFileName().length() > 0) name += getLocation().getFileName().replaceAll("[^\\w_\\.]", "_"); else name += SUFFIX; return name; } }
public String getUri() { Location loc = getLocation(); return loc == null ? null : loc.toString(); }
parser.parse(inputSource); } catch (SAXParseException exc) { Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc .getColumnNumber());