/** * Topologically sort a set of targets. Equivalent to calling * <code>topoSort(new String[] {root}, targets, returnAll)</code>. * * @param root The name of the root target. The sort is created in such * a way that the sequence of Targets up to the root * target is the minimum possible such sequence. * Must not be <code>null</code>. * @param targetTable A Hashtable mapping names to Targets. * Must not be <code>null</code>. * @param returnAll <code>boolean</code> indicating whether to return all * targets, or the execution sequence only. * @return a Vector of Target objects in sorted order. * @exception BuildException if there is a cyclic dependency among the * targets, or if a named target does not exist. * @since Ant 1.6.3 */ public final Vector<Target> topoSort(final String root, final Hashtable<String, Target> targetTable, final boolean returnAll) throws BuildException { return topoSort(new String[] {root}, targetTable, returnAll); }
/** * Topologically sort a set of targets. Equivalent to calling * <code>topoSort(new String[] {root}, targets, true)</code>. * * @param root The name of the root target. The sort is created in such * a way that the sequence of Targets up to the root * target is the minimum possible such sequence. * Must not be <code>null</code>. * @param targetTable A Hashtable mapping names to Targets. * Must not be <code>null</code>. * @return a Vector of ALL Target objects in sorted order. * @exception BuildException if there is a cyclic dependency among the * targets, or if a named target does not exist. */ public final Vector<Target> topoSort(final String root, final Hashtable<String, Target> targetTable) throws BuildException { return topoSort(new String[] {root}, targetTable, true); }
/** * 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(final String targetName) throws BuildException { // sanity check ourselves, if we've been asked to build nothing // then we should complain if (targetName == null) { final 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)); }
/** * Does this target depend on the named target? * @param other the other named target. * @return true if the target does depend on the named target * @since Ant 1.6 */ public boolean dependsOn(String other) { Project p = getProject(); Hashtable<String, Target> t = p == null ? null : p.getTargets(); return p != null && p.topoSort(getName(), t, false).contains(t.get(other)); }
/** {@inheritDoc}. */ public void executeTargets(Project project, String[] targetNames) throws BuildException { project.executeSortedTargets( project.topoSort(targetNames, project.getTargets(), false)); }
/** * method assumes sendor has checked whether to report problems */ private void checkCircularDependencies(IAntElement node) { Target target = ((AntTargetNode) node).getTarget(); String name = target.getName(); if (name == null) { return; } try { target.getProject().topoSort(name, target.getProject().getTargets()); } catch (BuildException be) { // possible circular dependency String message = be.getMessage(); if (message.startsWith("Circular")) { //$NON-NLS-1$ //we do our own checking for missing dependencies IProblem problem = createProblem(message, node.getProjectNode().getOffset(), node.getProjectNode().getSelectionLength(), AntModelProblem.SEVERITY_ERROR); acceptProblem(problem); markHierarchy(node.getProjectNode(), AntModelProblem.SEVERITY_ERROR, message); } } }