Skip to content

Commit 8b25315

Browse files
author
mgricken
committed
This commit fixes a grave error in our Ant build.xml file;
test failures were caught in a try-catch-finally construct, letting the build succeed even when unit tests failed. I also corrected the behavior of escaping in the command lines for external processes (use \), and I've defensively modified the code in ExecuteExternalDialog to not call DirectoryChooser.setSelectedFile so early, even though that appears to be a Swing bug to me. M src/edu/rice/cs/drjava/ui/ExecuteExternalDialog.java M src/edu/rice/cs/util/StringOps.java M src/edu/rice/cs/util/StringOpsTest.java M src/edu/rice/cs/util/BalancingStreamTokenizer.java M src/edu/rice/cs/util/BalancingStreamTokenizerTest.java M build.xml git-svn-id: file:///tmp/test-svn/trunk@4375 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 6b690d7 commit 8b25315

File tree

6 files changed

+707
-282
lines changed

6 files changed

+707
-282
lines changed

drjava/build.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@
417417
</if>
418418
</try>
419419

420+
<catch>
421+
<property name="${do-test-target}-failed" value="true"/>
422+
<fail if="${do-test-target}-failed" message="One or more unit tests failed."/>
423+
</catch>
420424
<finally>
421425
<move todir="testResults/@{iteration}">
422426
<fileset dir="${basedir}">
@@ -775,7 +779,10 @@
775779
<param name="test-formatter" value="xml" />
776780
</antcall>
777781
</try>
778-
<catch />
782+
<catch>
783+
<property name="do-test-15-failed" value="true"/>
784+
<fail if="do-test-15-failed" message="One or more unit tests failed."/>
785+
</catch>
779786
</trycatch>
780787
<move todir="benchmarkResults/local" file="testResults" />
781788
</target>
@@ -833,7 +840,10 @@
833840
</antcall>
834841
<ant dir="benchmarkSources" target="clean" />
835842
</try>
836-
<catch />
843+
<catch>
844+
<property name="do-test-failed" value="true"/>
845+
<fail if="do-test-failed" message="One or more unit tests failed."/>
846+
</catch>
837847
</trycatch>
838848
<exec executable="svn" dir="benchmarkSources" failonerror="yes">
839849
<arg value="revert" />
@@ -853,6 +863,10 @@
853863
<property name="test-repeat" value="1" />
854864
</ant>
855865
</try>
866+
<catch>
867+
<property name="do-test-failed" value="true"/>
868+
<fail if="do-test-failed" message="One or more unit tests failed."/>
869+
</catch>
856870
<finally>
857871
<move todir="${basedir}">
858872
<fileset dir="benchmarkSources">

drjava/src/edu/rice/cs/drjava/ui/ExecuteExternalDialog.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public ExecuteExternalDialog(MainFrame mf) {
297297
/** Build the dialog. */
298298
private void initComponents() {
299299
_dirChooser = new DirectoryChooser(this);
300-
_dirChooser.setSelectedFile(new File(System.getProperty("user.dir")));
301300
_dirChooser.setDialogTitle("Select Work Directory");
302301
_dirChooser.setApproveButtonText("Select");
303302

@@ -639,7 +638,7 @@ public void update(DocumentEvent e) {
639638
public void removeUpdate(DocumentEvent e) { update(e); }
640639
};
641640
_commandWorkDirLine.getDocument().addDocumentListener(_workDirDocumentListener);
642-
_commandWorkDirLine.setText("${user.dir}");
641+
_commandWorkDirLine.setText("${drjava.working.dir}");
643642
_workDirDocumentListener.changedUpdate(null);
644643

645644
DrJava.getConfig().addOptionListener(DEFINITIONS_COMMENT_COLOR, new OptionListener<Color>() {
@@ -1006,7 +1005,7 @@ public void update(DocumentEvent e) {
10061005
public void removeUpdate(DocumentEvent e) { update(e); }
10071006
};
10081007
_javaCommandWorkDirLine.getDocument().addDocumentListener(_javaWorkDirDocumentListener);
1009-
_javaCommandWorkDirLine.setText("${user.dir}");
1008+
_javaCommandWorkDirLine.setText("${drjava.working.dir}");
10101009
_javaWorkDirDocumentListener.changedUpdate(null);
10111010

10121011
DrJava.getConfig().addOptionListener(DEFINITIONS_COMMENT_COLOR, new OptionListener<Color>() {
@@ -1081,7 +1080,7 @@ public void run() {
10811080
StyledDocument doc = (StyledDocument)pane.getDocument();
10821081
doc.removeDocumentListener(dl);
10831082
String str = pane.getText();
1084-
BalancingStreamTokenizer tok = new BalancingStreamTokenizer(new StringReader(str));
1083+
BalancingStreamTokenizer tok = new BalancingStreamTokenizer(new StringReader(str), '\\');
10851084
tok.wordRange(0,255);
10861085
tok.addQuotes("${", "}");
10871086

@@ -1090,7 +1089,7 @@ public void run() {
10901089
String next = null;
10911090
try {
10921091
while((next=tok.getNextToken())!=null) {
1093-
if (next.startsWith("${")) {
1092+
if ((tok.token()==BalancingStreamTokenizer.Token.QUOTED) && (next.startsWith("${"))) {
10941093
if (next.endsWith("}")) {
10951094
String key;
10961095
String attrList = "";
@@ -1115,34 +1114,36 @@ public void run() {
11151114
if (attrList.length()>0) {
11161115
int subpos = pos + 2 + key.length() + 1;
11171116
int added = 0;
1118-
BalancingStreamTokenizer atok = new BalancingStreamTokenizer(new StringReader(attrList));
1117+
BalancingStreamTokenizer atok = new BalancingStreamTokenizer(new StringReader(attrList), '\\');
11191118
atok.wordRange(0,255);
11201119
atok.addQuotes("\"", "\"");
11211120
atok.addKeyword(";");
11221121
atok.addKeyword("=");
11231122
// LOG.log("\tProcessing AttrList");
11241123
String n = null;
11251124
while((n=atok.getNextToken())!=null) {
1126-
if ((n==null) || n.trim().equals(";") || n.trim().equals("=") || n.trim().startsWith("\"")) {
1125+
if ((n==null) || (atok.token()!=BalancingStreamTokenizer.Token.NORMAL) ||
1126+
n.trim().equals(";") || n.trim().equals("=") || n.trim().startsWith("\"")) {
11271127
doc.setCharacterAttributes(subpos,pos+next.length(),error,true);
11281128
break;
11291129
}
11301130
added += n.length();
11311131
String name = n.trim();
11321132
n = atok.getNextToken();
1133-
if ((n==null) || (!n.trim().equals("="))) {
1133+
if ((n==null) || (atok.token()!=BalancingStreamTokenizer.Token.KEYWORD) || (!n.trim().equals("="))) {
11341134
doc.setCharacterAttributes(subpos,pos+next.length(),error,true);
11351135
break;
11361136
}
11371137
added += n.length();
11381138
n = atok.getNextToken();
1139-
if ((n==null) || (!n.trim().startsWith("\""))) {
1139+
if ((n==null) || (atok.token()!=BalancingStreamTokenizer.Token.QUOTED) || (!n.trim().startsWith("\""))) {
11401140
doc.setCharacterAttributes(subpos,pos+next.length(),error,true);
11411141
break;
11421142
}
11431143
added += n.length();
11441144
n = atok.getNextToken();
1145-
if ((n!=null) && (!n.trim().equals(";"))) {
1145+
if (((n!=null) && ((atok.token()!=BalancingStreamTokenizer.Token.KEYWORD) || (!n.equals(";")))) ||
1146+
((n==null) && (atok.token()!=BalancingStreamTokenizer.Token.END))) {
11461147
doc.setCharacterAttributes(subpos,pos+next.length(),error,true);
11471148
break;
11481149
}
@@ -1188,7 +1189,7 @@ private void _cancel() {
11881189
if (_cm!=null) { _cm.set(); }
11891190
}
11901191

1191-
public static edu.rice.cs.util.Log LOG = new edu.rice.cs.util.Log("process.txt", false);
1192+
// public static edu.rice.cs.util.Log LOG = new edu.rice.cs.util.Log("process.txt", false);
11921193

11931194
/** Run a command and return an external process panel. */
11941195
public ExternalProcessPanel runCommand(String name, String cmdline, String workdir) {

drjava/src/edu/rice/cs/util/BalancingStreamTokenizer.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public State(State o) {
114114
/** The current character is the escape character. */
115115
protected boolean _isEscape = false;
116116

117+
/** Kind of tokens to be returned. */
118+
public enum Token { NONE, NORMAL, QUOTED, KEYWORD, END };
119+
120+
public volatile Token _token = Token.NONE;
121+
117122
/**
118123
* Create a new balancing stream tokenizer.
119124
* @param r reader to tokenize
@@ -229,6 +234,9 @@ protected void popState() {
229234
setState(_stateStack.pop());
230235
}
231236

237+
/** Returns the type of the current token. */
238+
public Token token() { return _token; }
239+
232240
/**
233241
* Specify a range characters as word characters.
234242
* @param lo the character beginning the word character range, inclusive
@@ -483,6 +491,7 @@ public String getNextToken() throws IOException {
483491
}
484492
else {
485493
if (buf.length()>0) {
494+
_token = Token.NORMAL;
486495
return buf.toString();
487496
}
488497
}
@@ -511,6 +520,7 @@ public String apply(String in) {
511520
for(int i=temp.length()-1; i>=0; --i) {
512521
pushToken(temp.charAt(i));
513522
}
523+
_token = Token.NORMAL;
514524
return buf.toString();
515525
}
516526
String begin = temp;
@@ -570,6 +580,7 @@ else if (_stateStack.peek().quotes.contains(s)) {
570580

571581
// restore the old state
572582
popState();
583+
_token = Token.QUOTED;
573584
return quoteBuf.toString();
574585
}
575586
}
@@ -594,8 +605,10 @@ public String apply(String in) {
594605
for(int i=temp.length()-1; i>=0; --i) {
595606
pushToken(temp.charAt(i));
596607
}
608+
_token = Token.NORMAL;
597609
return buf.toString();
598610
}
611+
_token = Token.KEYWORD;
599612
return unescape(temp);
600613
}
601614
}
@@ -607,6 +620,60 @@ public String apply(String in) {
607620
buf.append(String.valueOf(_escape));
608621
_isEscape = _wasEscape = false;
609622
}
623+
else {
624+
// there was an escape
625+
// see if whitespace or escape is coming up
626+
// System.err.println("There was an escape");
627+
int cnext = nextToken();
628+
if ((cnext!=(int)_escape) && (!_state.whitespace.contains(cnext))) {
629+
// System.err.println("But it's not an escape or whitespace");
630+
// see if a quote might be coming up
631+
String temp = findMatch(cnext, _state.quotes, new Lambda<String,String>() {
632+
public String apply(String in) {
633+
// push the tokens back
634+
for(int i=in.length()-1; i>0; --i) {
635+
pushToken(in.charAt(i));
636+
}
637+
return null;
638+
}
639+
});
640+
if (temp!=null) {
641+
// push the tokens back
642+
for(int i=temp.length()-1; i>0; --i) {
643+
pushToken(temp.charAt(i));
644+
}
645+
// System.err.println("It looks like a quote");
646+
}
647+
else {
648+
// System.err.println("But it's not a quote");
649+
// it wasn't a quote, see if it could be a keyword
650+
temp = findMatch(cnext, _state.keywords, new Lambda<String,String>() {
651+
public String apply(String in) {
652+
// push the tokens back
653+
for(int i=in.length()-1; i>0; --i) {
654+
pushToken(in.charAt(i));
655+
}
656+
return null;
657+
}
658+
});
659+
if (temp!=null) {
660+
// push the tokens back
661+
for(int i=temp.length()-1; i>0; --i) {
662+
pushToken(temp.charAt(i));
663+
}
664+
// System.err.println("It looks like a keyword");
665+
}
666+
else {
667+
// System.err.println("But it's not a keyword ==> lone escape");
668+
// neither a quote nor a keyword coming up
669+
// lone escape
670+
buf.append(String.valueOf(_escape));
671+
_isEscape = _wasEscape = false;
672+
}
673+
}
674+
}
675+
pushToken(cnext);
676+
}
610677
}
611678
else {
612679
buf.append(String.valueOf((char)c));
@@ -621,9 +688,11 @@ public String apply(String in) {
621688
}
622689
// end of stream, return remaining buffer as last token
623690
if (buf.length()>0) {
691+
_token = Token.NORMAL;
624692
return buf.toString();
625693
}
626694
// or return null to represent the end of the stream
695+
_token = Token.END;
627696
return null;
628697
}
629698

0 commit comments

Comments
 (0)