Skip to content

Commit ddcdada

Browse files
committed
improved the code to find the test root
1 parent 989a6c9 commit ddcdada

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

soot-infoflow-integration/test/soot/jimple/infoflow/collections/test/junit/FlowDroidTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void resetSootAndStream() throws IOException {
6868
}
6969

7070
public static void commonSetup() throws IOException {
71-
File rootDir = getIntegrationRoot();
71+
File rootDir = getIntegrationRoot(FlowDroidTests.class);
7272
File testSrc = new File(new File(rootDir, "build"), "testclasses");
7373
if (!testSrc.exists()) {
7474
Assert.fail("Test aborted - none of the test sources are available");
@@ -191,6 +191,24 @@ protected boolean containsStmtString(InfoflowResults res, String substr) {
191191
return false;
192192
}
193193

194+
/**
195+
* Gets the root of the current project from a reference class located in that
196+
* project
197+
*
198+
* @param referenceClass The reference class
199+
* @return The root folder of the project
200+
* @throws IOException
201+
*/
202+
public static File getIntegrationRoot(Class<?> referenceClass) throws IOException {
203+
File f = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
204+
if (f.exists()) {
205+
while (!f.getName().equals("soot-infoflow-integration") && f.getParentFile() != null)
206+
f = f.getParentFile();
207+
return f;
208+
}
209+
return getIntegrationRoot();
210+
}
211+
194212
/**
195213
* Gets the root in which the FlowDroid main project is located
196214
*

soot-infoflow/test/soot/jimple/infoflow/test/junit/JUnitTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public abstract class JUnitTests extends AbstractJUnitTests {
6262

6363
@BeforeClass
6464
public static void setUp() throws IOException {
65-
File f = getInfoflowRoot();
65+
File f = getInfoflowRoot(JUnitTests.class);
6666
StringBuilder appPathBuilder = new StringBuilder();
6767
addTestPathes(f, appPathBuilder);
6868

@@ -197,6 +197,24 @@ protected void onlyForwards(IInfoflow infoflow, String message) {
197197
Assume.assumeTrue("Test is only applicable on forwards analysis: " + message, infoflow instanceof Infoflow);
198198
}
199199

200+
/**
201+
* Gets the root of the current project from a reference class located in that
202+
* project
203+
*
204+
* @param referenceClass The reference class
205+
* @return The root folder of the project
206+
* @throws IOException
207+
*/
208+
public static File getInfoflowRoot(Class<?> referenceClass) throws IOException {
209+
File f = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
210+
if (f.exists()) {
211+
while (!f.getName().equals("soot-infoflow") && f.getParentFile() != null)
212+
f = f.getParentFile();
213+
return f;
214+
}
215+
return getInfoflowRoot();
216+
}
217+
200218
/**
201219
* Gets the root in which the FlowDroid main project is located
202220
*

0 commit comments

Comments
 (0)