Permalink
Browse files

Adding 'tasks' subcommand to get a list of task:version that a WDL uses

  • Loading branch information...
1 parent 0a2b656 commit f74183504bf3eaee2855d9aeb38762223aacbfe8 @scottfrazer scottfrazer committed with Scott Frazer May 22, 2014
View
@@ -18,7 +18,7 @@ $ mvn package
Which will create a file target/Wdl-${version}.jar as an executable JAR. To invoke the CLI:
```
-$ java -jar target/Wdl-0.0.4.jar examples/0.wdl ast
+$ java -jar target/Wdl-0.0.5.jar examples/0.wdl ast
```
Generating the parser code
@@ -57,7 +57,7 @@ Command-line Interface
The command line interface provides some common tools for analyzing and displaying WDL files Below are the actions that can be taken by running the executable JAR without any parameters:
```
-$ java -jar target/Wdl-0.0.4.jar
+$ java -jar target/Wdl-0.0.5.jar
Usage: <.wdl file> <tokens,astarsetree,entities,graph,format,format-ansi,format-html,replace>
Actions:
@@ -70,6 +70,7 @@ Actions:
format-ansi: reformat source code and colorize for the terminal
format-html: reformat source code and add HTML span tags
replace <task[:version]> <new task:version>: replace a task/version with a different task/version
+ tasks: return 1 line in the format <task:version> for each unique <task:version> pair
```
CLI Examples
@@ -102,7 +103,7 @@ composite_task test {
Get the abstract syntax tree:
```
-$ java -jar dist/Wdl-0.0.4.jar examples/7.wdl ast
+$ java -jar dist/Wdl-0.0.5.jar examples/7.wdl ast
(CompositeTask:
body=[
(Step:
@@ -225,7 +226,7 @@ $ java -jar dist/Wdl-0.0.4.jar examples/7.wdl ast
Get a view of the graph
```
-$ java -jar dist/Wdl-0.0.4.jar examples/7.wdl graph
+$ java -jar dist/Wdl-0.0.5.jar examples/7.wdl graph
VERTICIES
---------
[Step: name=s1]
View
@@ -9,7 +9,7 @@
<groupId>org.broadinstitute.compositetask</groupId>
<artifactId>Wdl</artifactId>
<packaging>jar</packaging>
- <version>0.0.4</version>
+ <version>0.0.5</version>
<name>Wdl</name>
<url>http://github.com/broadinstitute/wdl</url>
@@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
+import java.util.TreeSet;
import java.util.LinkedHashSet;
import java.util.HashMap;
import java.util.Iterator;
@@ -379,6 +380,10 @@ public boolean contains(CompositeTaskNode node) {
return replace(this.ast, from, from_version, to, to_version);
}
+ public Set<CompositeTaskSubTask> getAllSubTasks() {
+ return getAllSubTasks(this);
+ }
+
public int compareTo(CompositeTaskVertex other) {
return this.toString().compareTo(other.toString());
}
@@ -413,6 +418,19 @@ public String toString() {
return steps;
}
+ private Set<CompositeTaskSubTask> getAllSubTasks(CompositeTaskScope scope) {
+ Set<CompositeTaskSubTask> subTasks = new TreeSet<CompositeTaskSubTask>();
+ for ( CompositeTaskNode node : scope.getNodes() ) {
+ if ( node instanceof CompositeTaskStep ) {
+ CompositeTaskStep step = (CompositeTaskStep) node;
+ subTasks.add(step.getTask());
+ } else if ( node instanceof CompositeTaskScope ) {
+ subTasks.addAll(getAllSubTasks((CompositeTaskScope) node));
+ }
+ }
+ return subTasks;
+ }
+
private ParseTreeNode getParseTree(SourceCode source_code) throws SyntaxError {
CompositeTaskParser parser = new CompositeTaskParser(this.error_formatter);
Lexer lexer = new Lexer();
@@ -2,7 +2,7 @@
import java.util.Set;
-public class CompositeTaskSubTask {
+public class CompositeTaskSubTask implements Comparable<CompositeTaskSubTask> {
private String name;
private String version;
@@ -31,6 +31,14 @@ public boolean equals(CompositeTaskSubTask other) {
return false;
}
+ public int compareTo(CompositeTaskSubTask other) {
+ int nameCompare = this.getTaskName().compareTo(other.getTaskName());
+ int versionCompare = this.getVersion().compareTo(other.getVersion());
+ if (nameCompare != 0) return nameCompare;
+ else if (versionCompare != 0) return versionCompare;
+ else return 0;
+ }
+
public String toString() {
return "[Task: name="+this.name+", version="+this.version+"]";
}
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import org.broadinstitute.parser.Utility;
import org.broadinstitute.parser.Ast;
@@ -27,6 +28,7 @@ public static void usage() {
System.err.println(" format-ansi: reformat source code and colorize for the terminal");
System.err.println(" format-html: reformat source code and add HTML span tags");
System.err.println(" replace <task[:version]> <new task:version>: replace a task/version with a different task/version");
+ System.err.println(" tasks: return 1 line in the format <task:version> for each unique <task:version> pair");
System.exit(-1);
}
@@ -109,6 +111,11 @@ public static void main(String[] args) {
CompositeTaskSourceCodeFormatter formatter = new CompositeTaskSourceCodeFormatter();
String formatted = formatter.format(ctask);
System.out.println(formatted);
+ } else if ( args[1].equals("tasks") ) {
+ Set<CompositeTaskSubTask> subTasks = ctask.getAllSubTasks();
+ for ( CompositeTaskSubTask subTask : subTasks ) {
+ System.out.println(String.format("%s:%s", subTask.getTaskName(), subTask.getVersion()));
+ }
} else {
usage();
}

0 comments on commit f741835

Please sign in to comment.