From 3849918afcc50b3f87292c7a9f3ef2bbb73fd4bc Mon Sep 17 00:00:00 2001 From: Nicolas Lalevee Date: Tue, 9 Nov 2010 11:35:56 +0000 Subject: [PATCH] If there is -d, debug mode, make the -p, project help, print the dependencies of the targets This will help debugging extension points git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1032931 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Main.java | 39 +++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index ec50d96e6..987bb3a0c 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -795,7 +795,8 @@ public class Main implements AntMain { if (projectHelp) { printDescription(project); - printTargets(project, msgOutputLevel > Project.MSG_INFO); + printTargets(project, msgOutputLevel > Project.MSG_INFO, + msgOutputLevel > Project.MSG_VERBOSE); return; } @@ -1080,7 +1081,8 @@ public class Main implements AntMain { * @param printSubTargets Whether or not subtarget names should also be * printed. */ - private static void printTargets(Project project, boolean printSubTargets) { + private static void printTargets(Project project, boolean printSubTargets, + boolean printDependencies) { // find the target with the longest name int maxLength = 0; Map ptargets = removeDuplicateTargets(project.getTargets()); @@ -1091,7 +1093,9 @@ public class Main implements AntMain { // on the presence of a description Vector topNames = new Vector(); Vector topDescriptions = new Vector(); + Vector/*>*/ topDependencies = new Vector(); Vector subNames = new Vector(); + Vector/*>*/ subDependencies = new Vector(); for (Iterator i = ptargets.values().iterator(); i.hasNext();) { currentTarget = (Target) i.next(); @@ -1104,6 +1108,9 @@ public class Main implements AntMain { if (targetDescription == null) { int pos = findTargetPosition(subNames, targetName); subNames.insertElementAt(targetName, pos); + if (printDependencies) { + subDependencies.insertElementAt(currentTarget.getDependencies(), pos); + } } else { int pos = findTargetPosition(topNames, targetName); topNames.insertElementAt(targetName, pos); @@ -1111,18 +1118,21 @@ public class Main implements AntMain { if (targetName.length() > maxLength) { maxLength = targetName.length(); } + if (printDependencies) { + topDependencies.insertElementAt(currentTarget.getDependencies(), pos); + } } } - printTargets(project, topNames, topDescriptions, "Main targets:", - maxLength); + printTargets(project, topNames, topDescriptions, topDependencies, + "Main targets:", maxLength); //if there were no main targets, we list all subtargets //as it means nothing has a description if (topNames.size() == 0) { printSubTargets = true; } if (printSubTargets) { - printTargets(project, subNames, null, "Other targets:", 0); + printTargets(project, subNames, null, subDependencies, "Other targets:", 0); } String defaultTarget = project.getDefaultTarget(); @@ -1165,6 +1175,9 @@ public class Main implements AntMain { * no descriptions are displayed. * If non-null, this should have * as many elements as names. + * @param topDependencies The list of dependencies for each target. + * The dependencies are listed as a non null + * enumeration of String. * @param heading The heading to display. * Should not be null. * @param maxlen The maximum length of the names of the targets. @@ -1173,7 +1186,8 @@ public class Main implements AntMain { * are shorter than this). */ private static void printTargets(Project project, Vector names, - Vector descriptions, String heading, + Vector descriptions, Vector dependencies, + String heading, int maxlen) { // now, start printing the targets and their descriptions String lSep = System.getProperty("line.separator"); @@ -1193,6 +1207,19 @@ public class Main implements AntMain { msg.append(descriptions.elementAt(i)); } msg.append(lSep); + if (!dependencies.isEmpty()) { + Enumeration deps = (Enumeration) dependencies.elementAt(i); + if (deps.hasMoreElements()) { + msg.append(" depends of: "); + while (deps.hasMoreElements()) { + msg.append(deps.nextElement()); + if (deps.hasMoreElements()) { + msg.append(", "); + } + } + msg.append(lSep); + } + } } project.log(msg.toString(), Project.MSG_WARN); }