Skip to content

Commit

Permalink
Some formatting, message and command name changes.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/easyant/tasks/trunk@1135994 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Siddhartha Purkayastha committed Jun 15, 2011
1 parent c89c57f commit 1bc8574
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -66,7 +72,8 @@ public void init(Map commands) {
} 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");
}
}

Expand All @@ -85,16 +92,20 @@ public void handleCommand(String command) {
if (selected != null) {
selected.execute(project, tokens);
} else {
project.log("'" + command + "' not a recognized command.");
printUsage();
}
}

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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -67,13 +67,15 @@ public List getAuditsForProperty(String key) {
return (List) propertyaudits.get(key);
}

public boolean commandSupported(String command) {
return "trace".equals(command);
}

public void execute(Project project, String[] params) {
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];
Expand All @@ -92,7 +94,9 @@ public void execute(Project project, String[] params) {
}

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.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down Expand Up @@ -53,7 +55,6 @@ public void execute(Project project, String[] params) {
}

public void printUsage(Project project) {
project.log("Incorrect Parameters");
project.log("Usage: inspect property some.property");
project.log(" inspect path path.id");
}
Expand Down
24 changes: 10 additions & 14 deletions command-line-debugger/src/main/org/apache/tools/ant/Locator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -33,10 +34,6 @@ public void execute(Project project, String[] params) {
// 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]);
Expand Down Expand Up @@ -69,7 +66,6 @@ public void execute(Project project, String[] params) {
}

public void printUsage(Project project) {
project.log("Incorrect Parameters");
project.log("Usage: locate property/path propertyname/pathname");
project.log("Usage: locate property some.property");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ public class DebuggerListener implements BuildListener, DebugSupport {

/**
* 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;

Expand Down Expand Up @@ -111,7 +117,8 @@ protected Map getDefaultCommandSupport() {
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;
Expand Down Expand Up @@ -165,41 +172,46 @@ public void taskStarted(BuildEvent event) {
* 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 (!"property".equals(params[1]) && !"target".equals(params[1])) {
if (params.length < 2) {
project.log("Incorrect Parameters");
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.");
}

}

0 comments on commit 1bc8574

Please sign in to comment.