📄 project.java
字号:
addOrReplaceTarget(targetName, target); } /** * Add a target to the project, or replaces one with the same * name. * * @param target The target to be added or replaced in the project. * Must not be <code>null</code>. */ public void addOrReplaceTarget(Target target) { addOrReplaceTarget(target.getName(), target); } /** * Add a target to the project, or replaces one with the same * name. * * @param targetName The name to use for the target. * Must not be <code>null</code>. * @param target The target to be added or replaced in the project. * Must not be <code>null</code>. */ public void addOrReplaceTarget(String targetName, Target target) { String msg = " +Target: " + targetName; log(msg, MSG_DEBUG); target.setProject(this); targets.put(targetName, target); } /** * Return the hashtable of targets. The returned hashtable * is "live" and so should not be modified. * @return a map from name to target (String to Target). */ public Hashtable getTargets() { return targets; } /** * Create a new instance of a task, adding it to a list of * created tasks for later invalidation. This causes all tasks * to be remembered until the containing project is removed * @param taskType The name of the task to create an instance of. * Must not be <code>null</code>. * * @return an instance of the specified task, or <code>null</code> if * the task name is not recognised. * * @exception BuildException if the task name is recognised but task * creation fails. */ public Task createTask(String taskType) throws BuildException { return ComponentHelper.getComponentHelper(this).createTask(taskType); } /** * Create a new instance of a data type. * * @param typeName The name of the data type to create an instance of. * Must not be <code>null</code>. * * @return an instance of the specified data type, or <code>null</code> if * the data type name is not recognised. * * @exception BuildException if the data type name is recognised but * instance creation fails. */ public Object createDataType(String typeName) throws BuildException { return ComponentHelper.getComponentHelper(this).createDataType(typeName); } /** * Set the Executor instance for this Project. * @param e the Executor to use. */ public void setExecutor(Executor e) { addReference(MagicNames.ANT_EXECUTOR_REFERENCE, e); } /** * Get this Project's Executor (setting it if necessary). * @return an Executor instance. */ public Executor getExecutor() { Object o = getReference(MagicNames.ANT_EXECUTOR_REFERENCE); if (o == null) { String classname = getProperty(MagicNames.ANT_EXECUTOR_CLASSNAME); if (classname == null) { classname = DefaultExecutor.class.getName(); } log("Attempting to create object of type " + classname, MSG_DEBUG); try { o = Class.forName(classname, true, coreLoader).newInstance(); } catch (ClassNotFoundException seaEnEfEx) { //try the current classloader try { o = Class.forName(classname).newInstance(); } catch (Exception ex) { log(ex.toString(), MSG_ERR); } } catch (Exception ex) { log(ex.toString(), MSG_ERR); } if (o == null) { throw new BuildException( "Unable to obtain a Target Executor instance."); } setExecutor((Executor) o); } return (Executor) o; } /** * Execute the specified sequence of targets, and the targets * they depend on. * * @param names A vector of target name strings to execute. * Must not be <code>null</code>. * * @exception BuildException if the build failed. */ public void executeTargets(Vector names) throws BuildException { getExecutor().executeTargets(this, (String[]) (names.toArray(new String[names.size()]))); } /** * Demultiplex output so that each task receives the appropriate * messages. If the current thread is not currently executing a task, * the message is logged directly. * * @param output Message to handle. Should not be <code>null</code>. * @param isWarning Whether the text represents an warning (<code>true</code>) * or information (<code>false</code>). */ public void demuxOutput(String output, boolean isWarning) { Task task = getThreadTask(Thread.currentThread()); if (task == null) { log(output, isWarning ? MSG_WARN : MSG_INFO); } else { if (isWarning) { task.handleErrorOutput(output); } else { task.handleOutput(output); } } } /** * Read data from the default input stream. If no default has been * specified, System.in is used. * * @param buffer the buffer into which data is to be read. * @param offset the offset into the buffer at which data is stored. * @param length the amount of data to read. * * @return the number of bytes read. * * @exception IOException if the data cannot be read. * @since Ant 1.6 */ public int defaultInput(byte[] buffer, int offset, int length) throws IOException { if (defaultInputStream != null) { System.out.flush(); return defaultInputStream.read(buffer, offset, length); } else { throw new EOFException("No input provided for project"); } } /** * Demux an input request to the correct task. * * @param buffer the buffer into which data is to be read. * @param offset the offset into the buffer at which data is stored. * @param length the amount of data to read. * * @return the number of bytes read. * * @exception IOException if the data cannot be read. * @since Ant 1.6 */ public int demuxInput(byte[] buffer, int offset, int length) throws IOException { Task task = getThreadTask(Thread.currentThread()); if (task == null) { return defaultInput(buffer, offset, length); } else { return task.handleInput(buffer, offset, length); } } /** * Demultiplex flush operations so that each task receives the appropriate * messages. If the current thread is not currently executing a task, * the message is logged directly. * * @since Ant 1.5.2 * * @param output Message to handle. Should not be <code>null</code>. * @param isError Whether the text represents an error (<code>true</code>) * or information (<code>false</code>). */ public void demuxFlush(String output, boolean isError) { Task task = getThreadTask(Thread.currentThread()); if (task == null) { fireMessageLogged(this, output, isError ? MSG_ERR : MSG_INFO); } else { if (isError) { task.handleErrorFlush(output); } else { task.handleFlush(output); } } } /** * Execute the specified target and any targets it depends on. * * @param targetName The name of the target to execute. * Must not be <code>null</code>. * * @exception BuildException if the build failed. */ public void executeTarget(String targetName) throws BuildException { // sanity check ourselves, if we've been asked to build nothing // then we should complain if (targetName == null) { String msg = "No target specified"; throw new BuildException(msg); } // Sort and run the dependency tree. // Sorting checks if all the targets (and dependencies) // exist, and if there is any cycle in the dependency // graph. executeSortedTargets(topoSort(targetName, targets, false)); } /** * Execute a <code>Vector</code> of sorted targets. * @param sortedTargets the aforementioned <code>Vector</code>. * @throws BuildException on error. */ public void executeSortedTargets(Vector sortedTargets) throws BuildException { Set succeededTargets = new HashSet(); BuildException buildException = null; // first build exception for (Enumeration iter = sortedTargets.elements(); iter.hasMoreElements();) { Target curtarget = (Target) iter.nextElement(); boolean canExecute = true; for (Enumeration depIter = curtarget.getDependencies(); depIter.hasMoreElements();) { String dependencyName = ((String) depIter.nextElement()); if (!succeededTargets.contains(dependencyName)) { canExecute = false; log(curtarget, "Cannot execute '" + curtarget.getName() + "' - '" + dependencyName + "' failed or was not executed.", MSG_ERR); break; } } if (canExecute) { Throwable thrownException = null; try { curtarget.performTasks(); succeededTargets.add(curtarget.getName()); } catch (RuntimeException ex) { if (!(keepGoingMode)) { throw ex; // throw further } thrownException = ex; } catch (Throwable ex) { if (!(keepGoingMode)) { throw new BuildException(ex); } thrownException = ex; } if (thrownException != null) { if (thrownException instanceof BuildException) { log(curtarget, "Target '" + curtarget.getName() + "' failed with message '" + thrownException.getMessage() + "'.", MSG_ERR); // only the first build exception is reported if (buildException == null) { buildException = (BuildException) thrownException; } } else { log(curtarget, "Target '" + curtarget.getName() + "' failed with message '" + thrownException.getMessage() + "'.", MSG_ERR); thrownException.printStackTrace(System.err); if (buildException == null) { buildException = new BuildException(thrownException); } } } } } if (buildException != null) { throw buildException; } } /** * Return the canonical form of a filename. * <p> * If the specified file name is relative it is resolved * with respect to the given root directory. * * @param fileName The name of the file to resolve. * Must not be <code>null</code>. * * @param rootDir The directory respective to which relative file names * are resolved. May be <code>null</code>, in which case * the current directory is used. * * @return the resolved File. * * @deprecated since 1.4.x */ public File resolveFile(String fileName, File rootDir) { return FILE_UTILS.resolveFile(rootDir, fileName); } /** * Return the canonical form of a filename. * <p> * If the specified file name is relative it is resolved * with respect to the project's base directory. * * @param fileName The name of the file to resolve. * Must not be <code>null</code>. * * @return the resolved File. * */ public File resolveFile(String fileName) { return FILE_UTILS.resolveFile(baseDir, fileName); } /** * Translate a path into its native (platform specific) format. * <p> * This method uses PathTokenizer to separate the input path * into its components. This handles DOS style paths in a relatively
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -