1 19 20 package org.netbeans.modules.junit.output; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.regex.Matcher ; 25 import org.netbeans.modules.junit.output.Report.Trouble; 26 import static org.netbeans.modules.junit.output.RegexpUtils.NESTED_EXCEPTION_PREFIX; 27 import static org.netbeans.modules.junit.output.RegexpUtils.CALLSTACK_LINE_PREFIX; 28 import static org.netbeans.modules.junit.output.RegexpUtils.CALLSTACK_LINE_PREFIX_CATCH; 29 30 31 35 final class TroubleParser { 36 37 38 private static final boolean DONE = true; 39 40 private static final boolean WANT_MORE = false; 41 42 43 private final Trouble trouble; 44 45 private final RegexpUtils regexp; 46 47 48 private Trouble currTrouble; 49 50 private List <String > callstackBuffer; 51 52 54 TroubleParser(Trouble trouble, RegexpUtils regexp) { 55 this.trouble = trouble; 56 this.regexp = regexp; 57 58 currTrouble = trouble; 59 } 60 61 69 boolean processMessage(final String msg) { 70 Matcher matcher; 71 if (trouble.exceptionClsName == null) { 72 matcher = regexp.getTestcaseExceptionPattern().matcher(msg); 73 if (matcher.matches()) { 74 trouble.exceptionClsName = matcher.group(1); 75 String exceptionMsg = matcher.group(2); 76 if (exceptionMsg != null) { 77 trouble.message = exceptionMsg; 78 } 79 } 80 return WANT_MORE; } 83 84 String trimmed = RegexpUtils.specialTrim(msg); 85 if (trimmed.length() == 0) { 86 finishProcessing(); 87 return DONE; 88 } 89 90 if (msg.startsWith(NESTED_EXCEPTION_PREFIX)) { 91 if (callstackBuffer != null) { 92 matcher = regexp.getNestedExceptionPattern().matcher( 93 msg.substring(NESTED_EXCEPTION_PREFIX.length())); 94 if (matcher.matches()) { 95 fixateStackTrace(); 96 97 Trouble nestedTrouble = new Trouble(false); 98 nestedTrouble.exceptionClsName = matcher.group(1); 99 nestedTrouble.message = matcher.group(2); 100 101 currTrouble.nestedTrouble = nestedTrouble; 102 currTrouble = nestedTrouble; 103 return WANT_MORE; 104 } 105 } 106 } else { 107 if (trimmed.startsWith(CALLSTACK_LINE_PREFIX_CATCH)) { 108 trimmed = trimmed.substring(CALLSTACK_LINE_PREFIX_CATCH.length()); 109 } 110 if (trimmed.startsWith(CALLSTACK_LINE_PREFIX)) { 111 matcher = regexp.getCallstackLinePattern().matcher(msg); 112 if (matcher.matches()) { 113 if (callstackBuffer == null) { 114 callstackBuffer = new ArrayList <String >(8); 115 } 116 callstackBuffer.add( 117 trimmed.substring(CALLSTACK_LINE_PREFIX.length())); 118 return WANT_MORE; 119 } 120 } 121 } 122 if ((callstackBuffer == null) && (currTrouble.message != null)) { 123 currTrouble.message = currTrouble.message + '\n' + msg; 124 } 125 126 return WANT_MORE; 127 } 128 129 131 void finishProcessing() { 132 if (callstackBuffer != null) { 133 fixateStackTrace(); 134 } 135 } 136 137 139 private void fixateStackTrace() { 140 currTrouble.stackTrace = callstackBuffer.toArray( 141 new String [callstackBuffer.size()]); 142 callstackBuffer = null; 143 } 144 145 } 146 | Popular Tags |