53 lines
1.4 KiB
Java
53 lines
1.4 KiB
Java
|
package ch.usi.inf.sp.callgraph;
|
||
|
|
||
|
import ch.usi.inf.sp.framework.ArchiveScanner;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Invoke like this...
|
||
|
* <p>
|
||
|
* java App test-input/pacman-src.jar
|
||
|
* <p>
|
||
|
* to produce ....
|
||
|
* Afterwards, go to the test-output folder, and call...
|
||
|
* <p>
|
||
|
* dot -Tpdf -ograph.pdf graph.dot
|
||
|
* <p>
|
||
|
* ...to produce a file graph.pdf of the call graph.
|
||
|
*
|
||
|
* MAKE SURE YOU MANUALLY VERIFY FOR EACH METHOD THAT
|
||
|
* THE CALL GRAPH IT'S ACTUALLY CORRECT.
|
||
|
*/
|
||
|
public final class App {
|
||
|
|
||
|
public static void main(final String[] args) throws IOException {
|
||
|
for (final String arg : args) {
|
||
|
System.out.println(arg);
|
||
|
}
|
||
|
final ArchiveScanner scanner = new ArchiveScanner();
|
||
|
|
||
|
// phase 1: build inheritance hierarchy
|
||
|
final ClassHierarchyBuilder classHierarchyBuilder = new ClassHierarchyBuilder();
|
||
|
scanner.addAnalyzer(classHierarchyBuilder);
|
||
|
for (int i=0; i<args.length; i++) {
|
||
|
scanner.scan(args[i]);
|
||
|
}
|
||
|
scanner.removeAnalyzer(classHierarchyBuilder);
|
||
|
|
||
|
// phase 2: add call sites and edges
|
||
|
final CallGraphBuilder callGraphBuilder = new CallGraphBuilder(classHierarchyBuilder.getClassHierarchy());
|
||
|
scanner.addAnalyzer(callGraphBuilder);
|
||
|
for (int i=0; i<args.length; i++) {
|
||
|
scanner.scan(args[i]);
|
||
|
}
|
||
|
|
||
|
// dump info about the call graph
|
||
|
new File("test-output").mkdirs(); // create output directory
|
||
|
new CallGraphRenderer().dumpDot(classHierarchyBuilder.getClassHierarchy(), "test-output/graph.dot");
|
||
|
|
||
|
}
|
||
|
}
|