mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Added ability to read source if running as non plugin test
This commit is contained in:
parent
64a914802e
commit
5d3f18cb04
1 changed files with 9 additions and 4 deletions
|
@ -59,7 +59,7 @@ public class TestSourceReader {
|
||||||
/**
|
/**
|
||||||
* Returns an array of StringBuffer objects for each comment section found preceding the named
|
* Returns an array of StringBuffer objects for each comment section found preceding the named
|
||||||
* test in the source code.
|
* 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 srcRoot the directory inside the bundle containing the packages
|
||||||
* @param clazz the name of the class containing the test
|
* @param clazz the name of the class containing the test
|
||||||
* @param testName the name of 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 {
|
public static StringBuffer[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException {
|
||||||
String fqn = clazz.getName().replace('.', '/');
|
String fqn = clazz.getName().replace('.', '/');
|
||||||
fqn = fqn.indexOf("$")==-1 ? fqn : fqn.substring(0,fqn.indexOf("$"));
|
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;
|
InputStream in;
|
||||||
try {
|
try {
|
||||||
|
if (bundle != null)
|
||||||
in = FileLocator.openStream(bundle, filePath, false);
|
in = FileLocator.openStream(bundle, filePath, false);
|
||||||
|
else {
|
||||||
|
in = clazz.getResourceAsStream('/'+classFile);
|
||||||
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
|
if(clazz.getSuperclass()!=null && !clazz.equals(TestCase.class)) {
|
||||||
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
||||||
|
|
Loading…
Add table
Reference in a new issue