1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Added ability to read source if running as non plugin test

This commit is contained in:
Alena Laskavaia 2010-05-19 02:36:12 +00:00
parent 64a914802e
commit 5d3f18cb04

View file

@ -59,7 +59,7 @@ public class TestSourceReader {
/**
* Returns an array of StringBuffer objects for each comment section found preceding the named
* test in the source code.
* @param bundle the bundle containing the source
* @param bundle the bundle containing the source, if null can try to load using classpath (source folder has to be in the classpath for this to work)
* @param srcRoot the directory inside the bundle containing the packages
* @param clazz the name of the class containing the test
* @param testName the name of the test
@ -71,11 +71,16 @@ public class TestSourceReader {
public static StringBuffer[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException {
String fqn = clazz.getName().replace('.', '/');
fqn = fqn.indexOf("$")==-1 ? fqn : fqn.substring(0,fqn.indexOf("$"));
IPath filePath= new Path(srcRoot + '/' + fqn + ".java");
String classFile = fqn + ".java";
IPath filePath= new Path(srcRoot + '/' + classFile);
InputStream in;
try {
if (bundle != null)
in = FileLocator.openStream(bundle, filePath, false);
else {
in = clazz.getResourceAsStream('/'+classFile);
}
} catch(IOException e) {
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);