Some formatting, message and command name changes.
git-svn-id: https://svn.apache.org/repos/asf/incubator/easyant/tasks/trunk@1135994 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/command-line-debugger/src/main/org/apache/ant/debugger/DebugCommandSet.java b/command-line-debugger/src/main/org/apache/ant/debugger/DebugCommandSet.java
index aa648be..f4e9bb5 100644
--- a/command-line-debugger/src/main/org/apache/ant/debugger/DebugCommandSet.java
+++ b/command-line-debugger/src/main/org/apache/ant/debugger/DebugCommandSet.java
@@ -4,13 +4,19 @@
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
/**
- * Handles all debug support functionality.
+ * Handles all debug support functionality. This is initialized by the
+ * {@link #init(Map)} method which accepts a set of {@link DebugSupport}
+ * instances. Additionally, it reads and initializes a set of commands from
+ * debug-support.properties for further support. New commands may be added by
+ * making entries in the said file.
*/
public class DebugCommandSet {
@@ -66,7 +72,8 @@
} catch (IOException ioe) {
// if the resource could not be located, then initialize with what
// is known
- throw new RuntimeException(ioe);
+ throw new BuildException(
+ "Could not locate debug-support.properties");
}
}
@@ -85,6 +92,7 @@
if (selected != null) {
selected.execute(project, tokens);
} else {
+ project.log("'" + command + "' not a recognized command.");
printUsage();
}
}
@@ -92,9 +100,12 @@
protected void printUsage() {
// log all help stuff here
project
- .log("You may use one of the following commands: locate, inspect, return");
- project
- .log("Type the command followed by /? for more information. Eg. inspect /?");
+ .log("Use one of the following commands. Type the command followed by /? for further help on the command.");
+ Iterator it = commandSupport.keySet().iterator();
+ while (it.hasNext()) {
+ String command = (String) it.next();
+ project.log(" - " + command);
+ }
}
}
diff --git a/command-line-debugger/src/main/org/apache/ant/debugger/DebugSupport.java b/command-line-debugger/src/main/org/apache/ant/debugger/DebugSupport.java
index 1e26146..dbfdfd5 100644
--- a/command-line-debugger/src/main/org/apache/ant/debugger/DebugSupport.java
+++ b/command-line-debugger/src/main/org/apache/ant/debugger/DebugSupport.java
@@ -3,19 +3,11 @@
import org.apache.tools.ant.Project;
/**
- * An interface for supporting debug commands.
+ * An interface for supporting debug commands. All debug commands MUST implement this interface.
*/
public interface DebugSupport {
/**
- * Check if this command is supported.
- *
- * @param command
- * @return
- */
- public boolean commandSupported(String command);
-
- /**
* Main execution body of the class. Pass all command parameters.
*
* @param project
diff --git a/command-line-debugger/src/main/org/apache/ant/debugger/DefaultAuditor.java b/command-line-debugger/src/main/org/apache/ant/debugger/DefaultAuditor.java
index 0438a33..3ced454 100644
--- a/command-line-debugger/src/main/org/apache/ant/debugger/DefaultAuditor.java
+++ b/command-line-debugger/src/main/org/apache/ant/debugger/DefaultAuditor.java
@@ -14,9 +14,9 @@
* acts as a Debug command permitting the recorded audits to be available on
* user commands.
* <p />
- * Optionally, this class allows a {@link DebugPrompt} instance to attach itself to
- * this auditor, so that if change to a certain property is attempted, then the
- * debugger may be chosen to be transferred the control to.
+ * Optionally, this class allows a {@link DebugPrompt} instance to attach itself
+ * to this auditor, so that if change to a certain property is attempted, then
+ * the debugger may be chosen to be transferred the control to.
*/
public class DefaultAuditor implements Auditor, DebugSupport {
@@ -67,13 +67,15 @@
return (List) propertyaudits.get(key);
}
- public boolean commandSupported(String command) {
- return "trace".equals(command);
- }
-
public void execute(Project project, String[] params) {
- if (params.length != 2) {
+ if (params.length > 1 && "/?".equals(params[1])) {
printUsage(project);
+ return;
+ }
+ if (params.length != 2) {
+ project.log("Incorrect Parameters");
+ printUsage(project);
+ return;
}
String property = params[1];
@@ -92,7 +94,9 @@
}
public void printUsage(Project project) {
- project.log("Some HelpFul Message here");
+ project.log("Usage: trace some.property");
+ project
+ .log("The above command will return all modification attempts on the specified property.");
}
}
diff --git a/command-line-debugger/src/main/org/apache/ant/debugger/Inspector.java b/command-line-debugger/src/main/org/apache/ant/debugger/Inspector.java
index 319ec1e..638b905 100644
--- a/command-line-debugger/src/main/org/apache/ant/debugger/Inspector.java
+++ b/command-line-debugger/src/main/org/apache/ant/debugger/Inspector.java
@@ -7,17 +7,19 @@
import org.apache.tools.ant.util.StringUtils;
/**
- * Inspects the current value of a property, path or some reference.
+ * Inspects the current value of a property or path.
*/
public class Inspector implements DebugSupport {
- public boolean commandSupported(String command) {
- return "inspect".equalsIgnoreCase(command);
- }
-
public void execute(Project project, String[] params) {
- if (params.length < 3 || "/?".equals(params[1])) {
+ if (params.length > 1 && "/?".equals(params[1])) {
printUsage(project);
+ return;
+ }
+ if (params.length < 3) {
+ project.log("Incorrect Parameters");
+ printUsage(project);
+ return;
}
if ("property".equalsIgnoreCase(params[1])) {
@@ -53,7 +55,6 @@
}
public void printUsage(Project project) {
- project.log("Incorrect Parameters");
project.log("Usage: inspect property some.property");
project.log(" inspect path path.id");
}
diff --git a/command-line-debugger/src/main/org/apache/tools/ant/Locator.java b/command-line-debugger/src/main/org/apache/tools/ant/Locator.java
index 98202e7..b2f74ab 100644
--- a/command-line-debugger/src/main/org/apache/tools/ant/Locator.java
+++ b/command-line-debugger/src/main/org/apache/tools/ant/Locator.java
@@ -6,23 +6,24 @@
import org.apache.ant.debugger.DebugSupport;
import org.apache.ant.debugger.DebugUtils;
-
import org.apache.tools.ant.taskdefs.Property;
-import org.apache.tools.ant.types.Path;
/**
- * Locates properties / paths in static build sources
+ * Locates properties in static build sources.
+ *
+ * TODO: See how this can be augmented to support other Tasks.
*/
public class Locator implements DebugSupport {
- public boolean commandSupported(String command) {
- return "locate".equalsIgnoreCase(command);
- }
-
public void execute(Project project, String[] params) {
// the command syntax is 'locate property some.property'
// or 'locate path some.path
- if (params.length != 3 || "/?".equals(params[1])) {
+ if (params.length > 1 && "/?".equals(params[1])) {
+ printUsage(project);
+ return;
+ }
+ if (params.length != 3) {
+ project.log("Incorrect Parameters");
printUsage(project);
return;
}
@@ -33,10 +34,6 @@
// locate and publish the property
matches = DebugUtils.searchTask(Property.class, project);
key = "name";
- } else if ("path".equalsIgnoreCase(params[1])) {
- // locate and publish the path
- matches = DebugUtils.searchTask(Path.class, project);
- key = "id";
} else {
// see if any other component may be supported
project.log("Unexpected component: " + params[1]);
@@ -69,7 +66,6 @@
}
public void printUsage(Project project) {
- project.log("Incorrect Parameters");
- project.log("Usage: locate property/path propertyname/pathname");
+ project.log("Usage: locate property some.property");
}
}
\ No newline at end of file
diff --git a/command-line-debugger/src/main/org/apache/tools/ant/listener/DebuggerListener.java b/command-line-debugger/src/main/org/apache/tools/ant/listener/DebuggerListener.java
index 4d92a82..c7ff754 100644
--- a/command-line-debugger/src/main/org/apache/tools/ant/listener/DebuggerListener.java
+++ b/command-line-debugger/src/main/org/apache/tools/ant/listener/DebuggerListener.java
@@ -51,12 +51,18 @@
/**
* Contains the current target being executed.
+ *
+ * TODO: This is not being used now but there is a possibility for its use.
*/
protected Target currentTarget = null;
/**
* An Auditor instance that keeps track of all changes to properties
* identified by the user.
+ *
+ *
+ * TODO: The auditor instance itself should be pluggable, I think to allow
+ * different PropertyHelpers to be used.
*/
protected Auditor auditor = null;
@@ -111,7 +117,8 @@
if (auditor instanceof DebugSupport) {
Map defaults = new HashMap();
defaults.put("trace", auditor);
- defaults.put("add", this);
+ defaults.put("break", this);
+ defaults.put("watch", this);
return defaults;
}
return null;
@@ -165,41 +172,46 @@
* target/property break points at runtime.
*/
- /**
- * The current listener as a {@link DebugSupport} command only supports add
- * new breakpoints.
+ /*
+ * TODO INFO command is yet to be implemented. The idea is to output a list
+ * of all target break points and properties being monitored with their
+ * statuses (Pending / Done etc).
*/
- public boolean commandSupported(String command) {
- return "add".equals(command);
- }
-
public void execute(Project project, String[] params) {
- if (params.length < 3) {
+ if (params.length > 1 && "/?".equals(params[1])) {
+ printUsage(project);
+ return;
+ }
+ if (params.length < 2) {
+ project.log("Incorrect Parameters");
printUsage(project);
return;
}
- if (!"property".equals(params[1]) && !"target".equals(params[1])) {
- printUsage(project);
- return;
- }
-
- boolean isproperty = "property".equals(params[1]);
- for (int i = 2; i < params.length; i++) {
- if (isproperty) {
- // add as a property to be audited
- auditor.addPropertyForAudits(params[i], project);
- project.log("Added BreakPoint at Property: " + params[2]);
- } else {
+ String command = params[0];
+ if ("break".equalsIgnoreCase(command)) {
+ for (int i = 1; i < params.length; i++) {
debugtargets.add(params[i]);
- project.log("Added BreakPoint at Target: " + params[2]);
+ project.log("Added BreakPoint at Target: " + params[i]);
}
+ } else if ("watch".equalsIgnoreCase(command)) {
+ /*
+ * watch points for properties
+ */
+ for (int i = 1; i < params.length; i++) {
+ auditor.addPropertyForAudits(params[i], project);
+ project.log("Added BreakPoint at Property: " + params[i]);
+ }
+ } else if ("info".equalsIgnoreCase(command)) {
+ // TODO show all break points and watch points here
}
}
public void printUsage(Project project) {
+ project.log("Usage: break property some.property.1 some.property.2");
+ project.log(" break target some.target.1 some.target.2");
project
- .log("Some Helpful Message to add debug/property break points at runtime.");
+ .log("The above command will add all properties/targets as breakpoints.");
}
}