Skip to content

Commit dc60e01

Browse files
committed
hopefully fixes the test locator
1 parent 55c4e51 commit dc60e01

File tree

4 files changed

+64
-46
lines changed

4 files changed

+64
-46
lines changed

soot-infoflow-integration/test/soot/jimple/infoflow/integration/test/junit/river/BaseJUnitTests.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import soot.jimple.infoflow.sourcesSinks.definitions.ISourceSinkDefinition;
1717
import soot.jimple.infoflow.sourcesSinks.manager.BaseSourceSinkManager;
1818
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
19+
import soot.jimple.infoflow.test.base.AbstractJUnitTests;
1920
import soot.jimple.infoflow.test.junit.JUnitTests;
2021

2122
/**
@@ -111,13 +112,8 @@ protected SetupApplication initApplication(File apkFile) {
111112
*
112113
* @return The directory in which the FlowDroid main project is located
113114
*/
114-
public static File getIntegrationRoot() {
115-
File testRoot = new File(".");
116-
if (!new File(testRoot, "testAPKs").exists())
117-
testRoot = new File(testRoot, "soot-infoflow-integration");
118-
if (!new File(testRoot, "testAPKs").exists())
119-
throw new RuntimeException(String.format("Test root not found in %s", testRoot.getAbsolutePath()));
120-
return testRoot;
115+
public static File getIntegrationRoot() throws IOException {
116+
return AbstractJUnitTests.getInfoflowRoot(BaseJUnitTests.class, "soot-infoflow-integration");
121117
}
122118

123119
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import soot.jimple.infoflow.config.ConfigForTest;
2929
import soot.jimple.infoflow.results.InfoflowResults;
3030
import soot.jimple.infoflow.taintWrappers.EasyTaintWrapper;
31+
import soot.jimple.infoflow.test.base.AbstractJUnitTests;
3132

3233
/**
3334
* abstract super class of all test cases which handles initialization, keeps
@@ -58,7 +59,7 @@ public abstract class JUnitTests {
5859

5960
@BeforeClass
6061
public static void setUp() throws IOException {
61-
File f = new File(".");
62+
File f = AbstractJUnitTests.getInfoflowRoot(JUnitTests.class, "soot-infoflow-summaries");
6263
File testSrc1 = new File(f, "bin");
6364
File testSrc4 = new File(f, "testBin");
6465
File testSrc2 = new File(f, "build" + File.separator + "classes");

soot-infoflow/test/soot/jimple/infoflow/test/base/AbstractJUnitTests.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.io.File;
1717
import java.io.IOException;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
1921
import org.springframework.web.multipart.MultipartHttpServletRequest;
2022

2123
import jakarta.servlet.http.HttpServlet;
@@ -28,6 +30,8 @@
2830
*/
2931
public abstract class AbstractJUnitTests {
3032

33+
protected static final Logger logger = LoggerFactory.getLogger(AbstractJUnitTests.class);
34+
3135
/**
3236
* Appends the given path to the given {@link StringBuilder} if it exists
3337
*
@@ -89,4 +93,57 @@ protected static void addRtJarPath(StringBuilder libPathBuilder) throws IOExcept
8993
appendWithSeparator(libPathBuilder, new File(springJAR));
9094
}
9195

96+
/**
97+
* Gets the root of the current project from a reference class located in that
98+
* project
99+
*
100+
* @param referenceClass The reference class
101+
* @param moduleName The name of the FlowDroid module for which to get the
102+
* root folder
103+
* @return The root folder of the project
104+
* @throws IOException
105+
*/
106+
public static File getInfoflowRoot(Class<?> referenceClass, String moduleName) throws IOException {
107+
File classFile = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
108+
File f = classFile;
109+
if (f.exists()) {
110+
while (!f.getName().equals(moduleName) && f.getParentFile() != null)
111+
f = f.getParentFile();
112+
113+
// The project root must exist and must not be the file system root
114+
if (f.exists() && f.getParentFile() != null)
115+
return f;
116+
117+
logger.warn("Finding project root from class file {} failed", classFile);
118+
} else
119+
logger.warn("Class file {} does not exist", classFile);
120+
return getInfoflowRoot(moduleName);
121+
}
122+
123+
/**
124+
* Gets the root in which the FlowDroid main project is located
125+
*
126+
* @param moduleName The name of the FlowDroid module for which to get the root
127+
* folder
128+
* @return The directory in which the FlowDroid main project is located
129+
*/
130+
public static File getInfoflowRoot(String moduleName) throws IOException {
131+
File testRoot = new File(".").getCanonicalFile();
132+
133+
if (!new File(testRoot, "src").exists()) {
134+
// Try a subfolder
135+
File subFolder = new File(testRoot, moduleName);
136+
if (subFolder.exists())
137+
testRoot = subFolder;
138+
else {
139+
// Try a sibling folder
140+
testRoot = new File(testRoot.getParentFile(), moduleName);
141+
}
142+
}
143+
144+
if (!new File(testRoot, "src").exists())
145+
throw new RuntimeException(String.format("Test root not found in %s", testRoot.getAbsolutePath()));
146+
return testRoot;
147+
}
148+
92149
}

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,10 @@ public static void setUp() throws IOException {
7474
if (!fi.getCanonicalFile().equals(f.getCanonicalFile())) {
7575
addTestPathes(fi, appPathBuilder);
7676
}
77-
fi = new File(f, "../soot-infoflow-summaries");
78-
if (!fi.getCanonicalFile().equals(f.getCanonicalFile())) {
79-
addTestPathes(fi, appPathBuilder);
80-
}
8177
fi = new File("soot-infoflow");
8278
if (fi.exists()) {
8379
addTestPathes(fi, appPathBuilder);
8480
}
85-
fi = new File("soot-infoflow-summaries");
86-
if (fi.exists()) {
87-
addTestPathes(fi, appPathBuilder);
88-
}
8981
appPath = appPathBuilder.toString();
9082

9183
StringBuilder libPathBuilder = new StringBuilder();
@@ -210,20 +202,7 @@ protected void onlyForwards(IInfoflow infoflow, String message) {
210202
* @throws IOException
211203
*/
212204
public static File getInfoflowRoot(Class<?> referenceClass) throws IOException {
213-
File classFile = new File(referenceClass.getProtectionDomain().getCodeSource().getLocation().getPath());
214-
File f = classFile;
215-
if (f.exists()) {
216-
while (!f.getName().equals("soot-infoflow") && f.getParentFile() != null)
217-
f = f.getParentFile();
218-
219-
// The project root must exist and must not be the file system root
220-
if (f.exists() && f.getParentFile() != null)
221-
return f;
222-
223-
logger.warn("Finding project root from class file {} failed", classFile);
224-
} else
225-
logger.warn("Class file {} does not exist", classFile);
226-
return getInfoflowRoot();
205+
return getInfoflowRoot(referenceClass, "soot-infoflow");
227206
}
228207

229208
/**
@@ -232,22 +211,7 @@ public static File getInfoflowRoot(Class<?> referenceClass) throws IOException {
232211
* @return The directory in which the FlowDroid main project is located
233212
*/
234213
public static File getInfoflowRoot() throws IOException {
235-
File testRoot = new File(".").getCanonicalFile();
236-
237-
if (!new File(testRoot, "src").exists()) {
238-
// Try a subfolder
239-
File subFolder = new File(testRoot, "soot-infoflow");
240-
if (subFolder.exists())
241-
testRoot = subFolder;
242-
else {
243-
// Try a sibling folder
244-
testRoot = new File(testRoot.getParentFile(), "soot-infoflow");
245-
}
246-
}
247-
248-
if (!new File(testRoot, "src").exists())
249-
throw new RuntimeException(String.format("Test root not found in %s", testRoot.getAbsolutePath()));
250-
return testRoot;
214+
return getInfoflowRoot("soot-infoflow");
251215
}
252216

253217
}

0 commit comments

Comments
 (0)