publicstaticclass LaunchOptions { publicfinal String debuggeeClass; publicfinal List<String> debuggeeOptions = new LinkedList<>(); public String sourceFilename; public String vmOptions = null;
public LaunchOptions(String debuggeeClass) { this.debuggeeClass = debuggeeClass;
} public LaunchOptions addDebuggeeOption(String option) {
debuggeeOptions.add(option); returnthis;
} public LaunchOptions addDebuggeeOptions(String[] options) {
debuggeeOptions.addAll(Arrays.asList(options)); returnthis;
} public LaunchOptions setSourceFilename(String name) {
sourceFilename = name; returnthis;
} public LaunchOptions addVMOptions(String vmOptions) { this.vmOptions = vmOptions; returnthis;
}
}
public JdbTest(LaunchOptions launchOptions) { this.launchOptions = launchOptions;
} public JdbTest(String debuggeeClass) { this(new LaunchOptions(debuggeeClass));
}
// sourceFilename is used by setBreakpoints and redefineClass public JdbTest(String debuggeeClass, String sourceFilename) { this(new LaunchOptions(debuggeeClass).setSourceFilename(sourceFilename));
}
// Parses the specified source file for "@{id} breakpoint" tags and returns // list of the line numbers containing the tag. // Example: // System.out.println("BP is here"); // @1 breakpoint publicstatic List<Integer> parseBreakpoints(String filePath, int id) { final String pattern = "@" + id + " breakpoint"; int lineNum = 1;
List<Integer> result = new LinkedList<>(); try { for (String line: Files.readAllLines(Paths.get(filePath))) { if (line.contains(pattern)) {
result.add(lineNum);
}
lineNum++;
}
} catch (IOException ex) { thrownew RuntimeException("failed to parse " + filePath, ex);
} return result;
}
// sets breakpoints to the lines parsed by {@code parseBreakpoints} // returns number of the breakpoints set. publicstaticint setBreakpoints(Jdb jdb, String debuggeeClass, String sourcePath, int id) {
List<Integer> bps = parseBreakpoints(sourcePath, id); for (int bp : bps) {
String reply = jdb.command(JdbCommand.stopAt(debuggeeClass, bp)).stream()
.collect(Collectors.joining("\n")); if (reply.contains("Unable to set")) { thrownew RuntimeException("jdb failed to set breakpoint at " + debuggeeClass + ":" + bp);
}
} return bps.size();
}
// sets breakpoints to the lines parsed by {@code parseBreakpoints} // from the file from test source directory. // returns number of the breakpoints set. protectedint setBreakpointsFromTestSource(String debuggeeFileName, int id) { return setBreakpoints(jdb, launchOptions.debuggeeClass,
getTestSourcePath(debuggeeFileName), id);
}
// sets breakpoints in the class {@code launchOptions.debuggeeClass} // to the lines parsed by {@code parseBreakpoints} // from the file from test source directory specified by {@code launchOptions.sourceFilename}. // returns number of the breakpoints set. protectedint setBreakpoints(int id) {
verifySourceFilename(); return setBreakpointsFromTestSource(launchOptions.sourceFilename, id);
}
// transforms class with the specified id (see {@code ClassTransformer}), // executes "redefine" jdb command for {@code launchOptions.debuggeeClass} // and updates source path by using "use" jdb command. // returns reply for the commands. protected List<String> redefineClass(int id, String... compilerOptions) {
verifySourceFilename();
String transformedClassFile = ClassTransformer.fromTestSource(launchOptions.sourceFilename)
.transform(id, launchOptions.debuggeeClass, compilerOptions);
List<String> reply = jdb.command(JdbCommand.redefine(launchOptions.debuggeeClass, transformedClassFile));
reply.addAll(jdb.command(JdbCommand.use(Paths.get(transformedClassFile).getParent().toString()))); return reply;
}
// gets full test source path for the given test filename publicstatic String getTestSourcePath(String fileName) { return Paths.get(System.getProperty("test.src")).resolve(fileName).toString();
}
// verifies that sourceFilename is specified in ctor privatevoid verifySourceFilename() { if (launchOptions.sourceFilename == null) { thrownew RuntimeException("launchOptions.sourceFilename must be specified.");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.