Skip to content

Commit

Permalink
Regex for new trace format #144
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasPohl committed Jul 23, 2022
1 parent ec1468c commit 97c4d1f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ public class TraceFileReader {

private Pattern pattern;

private static final String PATTERN_REGEX = ".{1,1000} at \\('(.{0,100})', '(\\w{1,5})\\.\\w{1,5}'\\).{0,1000}";

private static final String PATTERN_REGEX = ".{1,1000}''?([^']{1,1000})''? at \\('?(.{0,100})'?, '?(\\w{1,5})\\.\\w{1,5}'?\\).{0,1000}";
//Contains the executionData per module
private HashMap<String, ModuleExecutionData> moduleCache = new HashMap<>();

public TraceFileReader(File traceFile) {

pattern = Pattern.compile(PATTERN_REGEX);
this.traceFile = traceFile;
}
Expand Down Expand Up @@ -146,19 +144,15 @@ public String inputStreamToString(InputStream is) throws IOException {
private void readLine(String line) {
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
String function = matcher.group(1).trim();
String relativeLine = matcher.group(2).trim();
int statementBegin = line.indexOf("''") + 2;
int statementEnd = line.lastIndexOf("''", line.indexOf(" at "));
if (statementEnd > statementBegin) {
String statement = line.substring(statementBegin, statementEnd)
.trim();
String schemaAndModuleName = "";
if (function.contains(".")) {
schemaAndModuleName = function.substring(0, function.lastIndexOf('.')).trim();
}
addExecution(function, relativeLine, statement, schemaAndModuleName);
String function = matcher.group(2).trim();
String relativeLine = matcher.group(3).trim();

String statement = matcher.group(1);
String schemaAndModuleName = "";
if (function.contains(".")) {
schemaAndModuleName = function.substring(0, function.lastIndexOf('.')).trim();
}
addExecution(function, relativeLine, statement, schemaAndModuleName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,15 @@ public void visitModuleExecution(ModuleExecutionData data) {
});
assertThat(trace).isNotNull();
}
@Test
void readerTestNewFormat() {


TraceFileReader reader = new TraceFileReader(
new File("src/test/resources/codecoverage/newFormat.txt")).readTrace(testVisitor);
assertEquals(1, reader.getModuleCount());
assertNotNull(reader.getModuleExecutionData("org.abhi.TransformXMLToJSON_Compute"));
assertEquals(1, reader.getModuleExecutionData("org.abhi.TransformXMLToJSON_Compute").size());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-01-13 13:53:51.022424 498100 UserTrace BIP2540I: Node '': Finished evaluating expression 'CARDINALITY(InputRoot.*:*[])' at (org.abhi.TransformXMLToJSON_Compute.CopyMessageHeaders, 4.11). The result was '2'.

0 comments on commit 97c4d1f

Please sign in to comment.