Skip to content

Commit

Permalink
Add support for .jar-files along with using the dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgHaj committed Jul 14, 2023
1 parent a15851f commit 80854bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion java/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.debricked</groupId>
<artifactId>SootWrapper</artifactId>
<version>5.0</version>
<version>5.1</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
18 changes: 15 additions & 3 deletions java/common/src/main/java/SootWrapper/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public static void main(String[] args) {

@Override
public Integer call() throws Exception {
checkExistsAndIsDir(userCodePaths);
checkExistsAndIsDir(libraryCodePaths);
checkExistsAndIsDir(userCodePaths, true);
checkExistsAndIsDir(libraryCodePaths, false);
BufferedWriter writer;
if (outputFile != null) {
if (outputFile.isDirectory()) {
Expand Down Expand Up @@ -85,13 +85,25 @@ public Integer call() throws Exception {
return exitCode;
}

private static void checkExistsAndIsDir(Iterable<? extends Path> paths) throws FileNotFoundException {
private static void checkExistsAndIsDir(Iterable<? extends Path> paths, boolean checkJar) throws FileNotFoundException {
for (Path p : paths) {
File f = p.toFile();
if (!f.exists()) {
throw new FileNotFoundException(String.format("Error: %s can't be found", p));
}
if (!f.isDirectory()) {
// Check for .jar file
if (checkJar) {
String fileName = f.getName();
int index = fileName.lastIndexOf('.');
if (index > 0) {
String extension = fileName.substring(index+1);
if (extension.equals("jar")) {
return;
}
}
}

throw new IllegalArgumentException(String.format("Error: %s is not a directory", p));
}
}
Expand Down
2 changes: 1 addition & 1 deletion java/common/src/test/java/SootWrapper/SootWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void testGetCallGraphSelf() {
"SootWrapper.Cli.main(String[])"
});
assertMethodIsCalledByMethods(calls, "java.io.File.exists()", new String[]{
"SootWrapper.Cli.checkExistsAndIsDir(Iterable)"
"SootWrapper.Cli.checkExistsAndIsDir(Iterable, boolean)"
});
assertMethodIsCalledByMethods(calls, "soot.G.reset()", new String[]{
"SootWrapper.SootWrapper.writeAnalysis(JSONWriter, Iterable, Iterable)"
Expand Down

0 comments on commit 80854bd

Please sign in to comment.