@@ -103,12 +103,12 @@ public static void main(String[] args) {
103103 String propertyName = s .first .substring (s .first .lastIndexOf ("/" ) + 1 , s .first .length () - 4 );
104104 LOGGER .info (propertyName );
105105 rt .testProperty (propertyName );
106- JacocoCoverage jacocoCoverage = new JacocoCoverage (Optional . of ( s .first ) );
106+ JacocoCoverage jacocoCoverage = new JacocoCoverage (s .first );
107107 // 3. Prune the graph with coverage
108- Pruning .pruneOriginalGraph (callgraph , jacocoCoverage , arguments );
108+ Pruning .pruneOriginalGraph (callgraph , jacocoCoverage );
109109 // 4. Operate on the graph and write it to output
110- maybeWriteGraph (callgraph .graph , Optional . of ( propertyName ) );
111- maybeInspectReachability (callgraph , arguments , jacocoCoverage , Optional . of ( s .second ), Optional . of ( propertyName ) );
110+ maybeWriteGraph (callgraph .graph , JCallGraph . OUTPUT_DIRECTORY + propertyName );
111+ maybeInspectReachability (callgraph , arguments . maybeDepth () , jacocoCoverage , s .second , JCallGraph . OUTPUT_DIRECTORY + propertyName );
112112 maybeInspectAncestry (callgraph , arguments , jacocoCoverage , Optional .of (s .second ), Optional .of (propertyName ));
113113 rt .cleanTarget ();
114114 }
@@ -144,56 +144,38 @@ public static void main(String[] args) {
144144 LOGGER .info ("java-cg is finished! Enjoy!" );
145145 }
146146
147- private static void maybeWriteGraph (Graph <String , DefaultEdge > graph , Optional <String > output ) {
148- if (output .isPresent ()) {
149- Utilities .writeGraph (
150- graph , Utilities .defaultExporter (), output .map (JCallGraph ::asDot ));
151- }
147+ private static void maybeWriteGraph (Graph <String , DefaultEdge > graph , String output ) {
148+ Utilities .writeGraph (graph , Utilities .defaultExporter (), JCallGraph .asDot (output ));
152149 }
153150
154151 private static void maybeInspectReachability (
155- StaticCallgraph callgraph , TestArguments arguments , JacocoCoverage jacocoCoverage , Optional <String > entryPoint , Optional <String > outputFile ) {
156- if (entryPoint .isEmpty ()) {
157- return ;
158- }
152+ StaticCallgraph callgraph , Optional <Integer > depth , JacocoCoverage jacocoCoverage , String entryPoint , String outputFile ) {
159153
160154 /* Fetch reachability */
161155 Graph <ColoredNode , DefaultEdge > reachability =
162156 Reachability .compute (
163- callgraph .graph , entryPoint . get (), arguments . maybeDepth () );
157+ callgraph .graph , entryPoint , depth );
164158
165159 /* Apply coverage */
166160 jacocoCoverage .applyCoverage (reachability , callgraph .metadata );
167161
168- Pruning .pruneReachabilityGraph (reachability , callgraph .metadata , jacocoCoverage , arguments );
162+ Pruning .pruneReachabilityGraph (reachability , callgraph .metadata , jacocoCoverage );
169163
170164 /* Should we write the graph to a file? */
171- Optional <String > outputName =
172- outputFile .isPresent ()
173- ? Optional .of (outputFile .get () + DELIMITER + REACHABILITY )
174- : Optional .empty ();
165+ String outputName = outputFile + DELIMITER + REACHABILITY ;
175166
176167 /* Attach depth to name if present */
177- outputName =
178- outputName .map (
179- name -> {
180- if (arguments .maybeDepth ().isPresent ()) {
181- return name + DELIMITER + arguments .maybeDepth ().get ();
182- } else {
183- return name ;
184- }
185- });
168+ if (depth .isPresent ()) {
169+ outputName = outputName + DELIMITER + depth .get ();
170+ }
186171
187172 /* Store reachability in file? */
188- if (outputName .isPresent ()) {
189- Utilities .writeGraph (
190- reachability , Utilities .coloredExporter (), outputName .map (JCallGraph ::asDot ));
191- }
173+ Utilities .writeGraph (
174+ reachability , Utilities .coloredExporter (), JCallGraph .asDot (outputName ));
192175
193176 /* Analyze reachability coverage? */
194177 if (jacocoCoverage .hasCoverage ()) {
195- CoverageStatistics .analyze (
196- reachability , outputName .map (name -> asCsv (name + DELIMITER + COVERAGE )));
178+ CoverageStatistics .analyze ( reachability , Optional .of (asCsv (outputName + DELIMITER + COVERAGE )));
197179 }
198180 }
199181
@@ -217,7 +199,7 @@ private static void maybeInspectAncestry(
217199 + DELIMITER
218200 + arguments .maybeAncestry ().get ();
219201 Utilities .writeGraph (
220- ancestry , Utilities .coloredExporter (), Optional . of ( asDot (subgraphOutputName ) ));
202+ ancestry , Utilities .coloredExporter (), JCallGraph . OUTPUT_DIRECTORY + asDot (subgraphOutputName ));
221203 }
222204 }
223205
@@ -248,15 +230,16 @@ private static void maybeSerializeStaticCallGraph(StaticCallgraph callgraph, Bui
248230 // Throws: IOException when file cannot be read
249231 // Throws: ClassNotFoundException when object cannot be read properly
250232 private static StaticCallgraph deserializeStaticCallGraph (TestArguments arguments ) throws IOException , ClassNotFoundException {
251- File filename = new File (arguments .maybeBytecodeFile ().get ());
252- FileInputStream file = new FileInputStream ( filename );
253- ObjectInputStream ois = new ObjectInputStream ( file );
254- StaticCallgraph scg = ( StaticCallgraph ) ois . readObject ();
255- ois . close ();
256- file . close ();
257- return scg ;
233+ return deserializeStaticCallGraph ( new File (arguments .maybeBytecodeFile ().get () ));
234+ }
235+
236+ private static StaticCallgraph deserializeStaticCallGraph ( File f ) throws IOException , ClassNotFoundException {
237+ try ( ObjectInput ois = new ObjectInputStream ( new FileInputStream ( f ))) {
238+ return ( StaticCallgraph ) ois . readObject ();
239+ }
258240 }
259241
242+
260243 private static RepoTool maybeObtainTool (GitArguments arguments ) throws FileNotFoundException {
261244 Optional <RepoTool > rt = RepoTool .obtainTool (arguments .maybeGetConfig ().get ());
262245 if (rt .isPresent ())
0 commit comments