|
@@ -1,11 +1,13 @@
|
|
|
package com.moekr.moocoder.logic.api;
|
|
package com.moekr.moocoder.logic.api;
|
|
|
|
|
|
|
|
|
|
+import com.ibm.wala.classLoader.IClass;
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
import com.ibm.wala.classLoader.Language;
|
|
import com.ibm.wala.classLoader.Language;
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
|
|
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
|
|
|
|
|
+import com.ibm.wala.ipa.cha.ClassHierarchy;
|
|
|
import com.ibm.wala.util.collections.Pair;
|
|
import com.ibm.wala.util.collections.Pair;
|
|
|
import com.ibm.wala.util.graph.traverse.DFS;
|
|
import com.ibm.wala.util.graph.traverse.DFS;
|
|
|
import com.moekr.moocoder.util.FileUtil;
|
|
import com.moekr.moocoder.util.FileUtil;
|
|
@@ -106,6 +108,46 @@ public class WalaController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ public List<String> getAllJavaClasses(String srcDir) {
|
|
|
|
|
+ String filterPath = getClass().getResource(FILTER).getFile();
|
|
|
|
|
+ File f = new File(srcDir);
|
|
|
|
|
+ Wala wala = new Wala(filterPath, f.getPath());
|
|
|
|
|
+ ClassHierarchy cha = wala.getCha();
|
|
|
|
|
+
|
|
|
|
|
+ List<String> ret = new ArrayList<>();
|
|
|
|
|
+ for (IClass iClass: cha) {
|
|
|
|
|
+ if(wala.getScope().isApplicationLoader(iClass.getClassLoader())) {
|
|
|
|
|
+ String className = iClass.getName().getClassName().toString();
|
|
|
|
|
+ if (className.contains("$")){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret.add(className);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ret;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<String> getAllJavaPackages(String srcDir) {
|
|
|
|
|
+ String filterPath = getClass().getResource(FILTER).getFile();
|
|
|
|
|
+ File f = new File(srcDir);
|
|
|
|
|
+ Wala wala = new Wala(filterPath, f.getPath());
|
|
|
|
|
+ ClassHierarchy cha = wala.getCha();
|
|
|
|
|
+
|
|
|
|
|
+ Set<String> ret = new HashSet<>();
|
|
|
|
|
+ for (IClass iClass: cha) {
|
|
|
|
|
+ if(wala.getScope().isApplicationLoader(iClass.getClassLoader())) {
|
|
|
|
|
+ String className = iClass.getName().getClassName().toString();
|
|
|
|
|
+ if (className.contains("$")){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ ret.add(iClass.getName().getPackage().toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new ArrayList<>(ret);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
private void makeGraph(AnalysisScope scope, List<CallGraph> cgs, String path) throws IOException {
|
|
private void makeGraph(AnalysisScope scope, List<CallGraph> cgs, String path) throws IOException {
|
|
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))){
|
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))){
|
|
|
Set<String> strs = new HashSet<>();
|
|
Set<String> strs = new HashSet<>();
|