Skip to content

Commit 96704ae

Browse files
committed
Added ability to run the analysis manually
1 parent 12603e7 commit 96704ae

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/main/java/gr/gousiosg/javacg/stat/JCallGraph.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static void main(String[] args) {
7676
try {
7777
LOGGER.info("Starting java-cg!");
7878
switch(args[0]){
79+
case "manual-test": {
80+
manualMain(args);
81+
return;
82+
}
7983
case "git":{
8084
GitArguments arguments = new GitArguments(args);
8185
RepoTool rt = maybeObtainTool(arguments);
@@ -142,6 +146,55 @@ public static void main(String[] args) {
142146
}
143147

144148
LOGGER.info("java-cg is finished! Enjoy!");
149+
150+
}
151+
152+
public static void manualMain(String[] args) {
153+
154+
// First argument: the serialized file
155+
StaticCallgraph callgraph = null;
156+
try {
157+
File f = new File(args[1]);
158+
LOGGER.info("Deserializing file " + f.getAbsolutePath());
159+
callgraph = deserializeStaticCallGraph(new File(args[1]));
160+
} catch (IOException e) {
161+
LOGGER.error("Could not deserialize static call graph", e);
162+
} catch (ClassNotFoundException e) {
163+
LOGGER.error("This shouldn't happen, go fix your CLASSPATH", e);
164+
}
165+
166+
// Second argument: the jacoco.xml
167+
JacocoCoverage jacocoCoverage = null;
168+
try {
169+
File f = new File(args[2]);
170+
LOGGER.info("Reading JaCoCo coverage file " + f.getAbsolutePath());
171+
jacocoCoverage = new JacocoCoverage(f.getAbsolutePath());
172+
} catch (IOException | ParserConfigurationException | JAXBException | SAXException e) {
173+
LOGGER.error("Could not read JaCoCo coverage file", e);
174+
}
175+
176+
// Third argument: the entry point
177+
String entryPoint = args[3];
178+
179+
// Fourth argument: the output file
180+
String output = args[4];
181+
182+
if (callgraph == null || jacocoCoverage == null) {
183+
// Something went wrong, bail
184+
return;
185+
}
186+
187+
// Fifth argument, optional, is the depth
188+
Optional<Integer> depth = Optional.empty();
189+
if (args.length > 5)
190+
depth = Optional.of(Integer.parseInt(args[5]));
191+
192+
// This method changes the callgraph object
193+
Pruning.pruneOriginalGraph(callgraph, jacocoCoverage);
194+
195+
maybeInspectReachability(callgraph, depth, jacocoCoverage, args[3], args[4]);
196+
197+
// maybeWriteGraph(callgraph.graph, args[4]);
145198
}
146199

147200
private static void maybeWriteGraph(Graph<String, DefaultEdge> graph, String output) {

0 commit comments

Comments
 (0)