From be6a549e7b4553190df865044d456aaac4842ff0 Mon Sep 17 00:00:00 2001 From: ebanks Date: Tue, 24 Nov 2009 02:34:48 +0000 Subject: [PATCH] Added the capability to allow expressions in an integration test command (i.e. -filter 'foo') by escaping them in the command. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2132 348d0f76-0448-11de-a6fe-93d51630548a --- .../org/broadinstitute/sting/utils/Utils.java | 8 +++++++ .../org/broadinstitute/sting/WalkerTest.java | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index 36fa44539..e41aa817d 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -541,6 +541,14 @@ public class Utils { return new Pair(max, index); } + public static String[] concatArrays(String[] A, String[] B) { + String[] C = new String[A.length + B.length]; + System.arraycopy(A, 0, C, 0, A.length); + System.arraycopy(B, 0, C, A.length, B.length); + return C; + } + + /** Returns indices of all occurrences of the specified symbol in the string */ public static int[] indexOfAll(String s, int ch) { int[] pos = new int[64]; diff --git a/java/test/org/broadinstitute/sting/WalkerTest.java b/java/test/org/broadinstitute/sting/WalkerTest.java index e508e4953..bc53720d9 100755 --- a/java/test/org/broadinstitute/sting/WalkerTest.java +++ b/java/test/org/broadinstitute/sting/WalkerTest.java @@ -126,13 +126,33 @@ public class WalkerTest extends BaseTest { System.out.println(String.format("Executing test %s with GATK arguments: %s", name, args)); CommandLineGATK instance = new CommandLineGATK(); - CommandLineExecutable.start(instance, args.split(" ")); + String[] command; + + // special case for ' and " so we can allow expressions + if ( args.indexOf('\'') != -1 ) + command = escapeExpressions(args, "'"); + else if ( args.indexOf('\"') != -1 ) + command = escapeExpressions(args, "\""); + else + command = args.split(" "); + + CommandLineExecutable.start(instance, command); if ( CommandLineExecutable.result != 0 ) { throw new RuntimeException("Error running the GATK with arguments: " + args); } return new Pair, List>(tmpFiles, assertMatchingMD5s(name, tmpFiles, spec.md5s)); + } + + private static String[] escapeExpressions(String args, String delimiter) { + String[] command = {}; + String[] split = args.split(delimiter); + for (int i = 0; i < split.length - 1; i+=2) { + command = Utils.concatArrays(command, split[i].trim().split(" ")); + command = Utils.concatArrays(command, new String[] { split[i+1] } ); + } + return Utils.concatArrays(command, split[split.length-1].trim().split(" ")); } @Test