in testsuite/jflex-testsuite-maven-plugin/src/main/java/jflex/maven/plugin/testsuite/ExecUtils.java [119:187]
public static TestResult execClass(
String theClass,
String path,
List<String> files,
List<File> additionalJars,
String outputFileEncoding,
List<String> cmdline)
throws UnsupportedEncodingException {
String[] cmd = toArray(cmdline, files);
Class<?> c;
Method main;
Class<?>[] sig = {String[].class};
// System.out.println("exec class "+theClass);
// System.out.println("cmdline "+cmdline+"\nfiles: "+files);
CustomClassLoader l = new CustomClassLoader(path);
// Locate the shaded jar in the lib directory
// TODO(regisd) Alternatively, we could load JFlex and its dependency graph.
try {
for (File jar : additionalJars) {
// We are in $basedir/testsuite/testcases
l.addPath(jar);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
try {
c = l.loadClass(theClass, true);
} catch (ClassNotFoundException e) {
System.out.println("no such class: " + e);
return null;
}
try {
main = c.getMethod("main", sig);
} catch (NoSuchMethodException e) {
System.out.println("no main: " + e);
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
boolean success = true;
// System.out.println("loaded class "+theClass);
PrintStream stdOut = System.out;
System.setOut(new PrintStream(out, true));
try {
Object[] params = {cmd};
main.invoke(null, params);
System.setOut(stdOut);
} catch (IllegalAccessException e) {
System.setOut(stdOut);
System.out.println("main not public :" + e + main);
return null;
} catch (InvocationTargetException e) {
System.setOut(stdOut);
System.out.println("test subject threw exception :" + e);
success = false;
}
// System.out.println("finished exec class "+theClass);
return new TestResult(out.toString(outputFileEncoding), success);
}