Skip to content

Commit ae8f815

Browse files
authored
Merge pull request #19 from IBM/analysis-json-out-reformatted
Analysis json out reformatted
2 parents 3ec824a + 6d296b4 commit ae8f815

File tree

4 files changed

+9
-50
lines changed

4 files changed

+9
-50
lines changed

output.json

Whitespace-only changes.

src/main/java/com/ibm/northstar/CodeAnalyzer.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* The type Code analyzer.
4242
*/
43-
@Command(name = "codeanalyzer", mixinStandardHelpOptions = true, sortOptions = false, version = "codeanalyzer v1.1", description = "Convert java binary (*.jar, *.ear, *.war) into a comprehensive system dependency graph.")
43+
@Command(name = "codeanalyzer", mixinStandardHelpOptions = true, sortOptions = false, version = "codeanalyzer v1.1", description = "Convert java binary into a comprehensive system dependency graph.")
4444
public class CodeAnalyzer implements Runnable {
4545

4646
@Option(names = {"-i", "--input"}, description = "Path to the project root directory.")
@@ -58,7 +58,7 @@ public class CodeAnalyzer implements Runnable {
5858
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
5959
private static boolean noBuild = false;
6060

61-
@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for full analysis including the system depenedency graph). Default: 1")
61+
@Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1")
6262
private static int analysisLevel = 1;
6363

6464
@Option(names = {"-d", "--dependencies"}, description = "Path to the application 3rd party dependencies that may be helpful in analyzing the application.")
@@ -158,15 +158,7 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
158158

159159
private static void emit(String consolidatedJSONString) throws IOException {
160160
if (output == null) {
161-
byte[] bytes = consolidatedJSONString.getBytes(StandardCharsets.UTF_8);
162-
// Create the GZIPOutputStream, using System.out
163-
GZIPOutputStream gzipOS = new GZIPOutputStream(System.out);
164-
// Write the byte array to the GZIPOutputStream
165-
gzipOS.write(bytes);
166-
// Flush the GZIPOutputStream
167-
gzipOS.flush();
168-
// Close the GZIPOutputStream
169-
gzipOS.close();
161+
System.out.println(consolidatedJSONString);
170162
} else {
171163
// If output is not null, export to a file
172164
File file = new File(output, "analysis.json");

src/main/java/com/ibm/northstar/SystemDependencyGraph.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
2424
import com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory;
2525
import com.ibm.wala.classLoader.CallSiteReference;
26-
import com.ibm.wala.classLoader.IClass;
27-
import com.ibm.wala.classLoader.IMethod;
2826
import com.ibm.wala.ipa.callgraph.*;
2927
import com.ibm.wala.ipa.callgraph.AnalysisOptions.ReflectionOptions;
3028
import com.ibm.wala.ipa.callgraph.impl.Util;
@@ -37,7 +35,6 @@
3735
import com.ibm.wala.ipa.slicer.SDG;
3836
import com.ibm.wala.ipa.slicer.Slicer;
3937
import com.ibm.wala.ipa.slicer.Statement;
40-
import com.ibm.wala.ssa.IR;
4138
import com.ibm.wala.types.ClassLoaderReference;
4239
import com.ibm.wala.util.collections.HashMapFactory;
4340
import com.ibm.wala.util.graph.Graph;
@@ -79,7 +76,6 @@ private static JSONExporter<Pair<String, Callable>, AbstractGraphEdge> getGraphE
7976
return gson.toJson(vertex);
8077
}
8178
);
82-
// exporter.setVertexAttributeProvider(v -> v.getRight().getAttributes());
8379
exporter.setEdgeAttributeProvider(AbstractGraphEdge::getAttributes);
8480
return exporter;
8581
}
@@ -155,41 +151,6 @@ private static org.jgrapht.Graph<Pair<String, Callable>, AbstractGraphEdge> buil
155151
}
156152
}
157153
}));
158-
159-
callGraph.getEntrypointNodes()
160-
.forEach(p -> {
161-
// Get call statements that may execute in a given method
162-
Iterator<CallSiteReference> outGoingCalls = p.iterateCallSites();
163-
outGoingCalls.forEachRemaining(n -> {
164-
callGraph.getPossibleTargets(p, n).stream()
165-
.filter(o -> AnalysisUtils.isApplicationClass(o.getMethod().getDeclaringClass()))
166-
.forEach(o -> {
167-
168-
// Add the source nodes to the graph as vertices
169-
Pair<String, Callable> source = Optional.ofNullable(getCallableFromSymbolTable(p.getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(p.getMethod()));
170-
graph.addVertex(source);
171-
172-
// Add the target nodes to the graph as vertices
173-
Pair<String, Callable> target = Optional.ofNullable(getCallableFromSymbolTable(o.getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(o.getMethod()));
174-
graph.addVertex(target);
175-
176-
if (!source.equals(target) && source.getRight() != null && target.getRight() != null) {
177-
178-
// Get the edge between the source and the target
179-
AbstractGraphEdge cgEdge = graph.getEdge(source, target);
180-
181-
if (cgEdge == null) {
182-
graph.addEdge(source, target, new CallEdge());
183-
}
184-
// If edge exists, then increment the weight
185-
else {
186-
cgEdge.incrementWeight();
187-
}
188-
}
189-
});
190-
});
191-
});
192-
193154
return graph;
194155
}
195156

src/main/java/com/ibm/northstar/utils/ScopeUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public static AnalysisScope createScope(String projectPath, String applicationDe
6767
addDefaultExclusions(scope);
6868

6969
Log.info("Loading Java SE standard libs.");
70+
71+
if (System.getenv("JAVA_HOME") == null) {
72+
Log.error("JAVA_HOME is not set.");
73+
throw new RuntimeException("JAVA_HOME is not set.");
74+
}
75+
7076
String[] stdlibs = Files.walk(Paths.get(System.getenv("JAVA_HOME"), "jmods"))
7177
.filter(path -> path.toString().endsWith(".jmod"))
7278
.map(path -> path.toAbsolutePath().toString())

0 commit comments

Comments
 (0)