-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMavenClassHierarchy.java
More file actions
49 lines (35 loc) · 1.63 KB
/
MavenClassHierarchy.java
File metadata and controls
49 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package graphcode;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import com.ibm.wala.core.java11.Java9AnalysisScopeReader;
import com.ibm.wala.core.util.config.AnalysisScopeReader;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.io.FileUtil;
public class MavenClassHierarchy {
public static void main(String... args) throws IOException, ClassHierarchyException, InterruptedException {
AnalysisScope scope = toAnalysisScope(args[0], args[1], args[2]);
IClassHierarchy cha = ClassHierarchyFactory.make(scope);
System.err.println(cha);
}
public static AnalysisScope toAnalysisScope(String group, String artifact, String version) throws IOException, InterruptedException {
URL p2s = MavenClassHierarchy.class.getResource("pomToScope.sh");
String script = p2s.getFile();
ProcessBuilder pb = new ProcessBuilder(new String[]{"bash", "-l", script, group, artifact, version});
Process p = pb.start();
p.waitFor();
String scopeContents = new String(FileUtil.readBytes(p.getInputStream()));
String errorContents = new String(FileUtil.readBytes(p.getErrorStream()));
assert errorContents.isEmpty();
AnalysisScopeReader reader = new Java9AnalysisScopeReader() {
};
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
for(String line : scopeContents.split("\n")) {
reader.processScopeDefLine(scope, MavenClassHierarchy.class.getClassLoader(), line);
}
return scope;
}
}