Skip to content

Commit ce253b2

Browse files
committed
Add version number to analysis.json
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 84b2533 commit ce253b2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
class VersionProvider implements CommandLine.IVersionProvider {
4343
public String[] getVersion() throws Exception {
4444
String version = getClass().getPackage().getImplementationVersion();
45-
return new String[]{ "codeanalyzer " + (version != null ? version : "unknown") };
45+
return new String[]{ version != null ? version : "unknown" };
4646
}
4747
}
4848
/**
@@ -99,12 +99,12 @@ public void run() {
9999
Log.setVerbosity(verbose);
100100
try {
101101
analyze();
102-
} catch (IOException | CallGraphBuilderCancelException | ClassHierarchyException e) {
102+
} catch (Exception e) {
103103
throw new RuntimeException(e);
104104
}
105105
}
106106

107-
private static void analyze() throws IOException, ClassHierarchyException, CallGraphBuilderCancelException {
107+
private static void analyze() throws Exception {
108108

109109
JsonObject combinedJsonObject = new JsonObject();
110110
Map<String, JavaCompilationUnit> symbolTable;
@@ -159,6 +159,7 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
159159
symbolTable = existingSymbolTable;
160160
}
161161
}
162+
162163
else {
163164
// construct symbol table for project, write parse problems to file in output directory if specified
164165
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult =
@@ -176,16 +177,14 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
176177
String sdgAsJSONString = SystemDependencyGraph.construct(input, dependencies, build);
177178
JsonElement sdgAsJSONElement = gson.fromJson(sdgAsJSONString, JsonElement.class);
178179
JsonObject sdgAsJSONObject = sdgAsJSONElement.getAsJsonObject();
180+
JsonElement edges = sdgAsJSONObject.get("edges");
179181

180182
// We don't really need these fields, so we'll remove it.
181183
sdgAsJSONObject.remove("nodes");
182184
sdgAsJSONObject.remove("creator");
183185
sdgAsJSONObject.remove("version");
184-
185-
// Remove the 'edges' element and move the list of edges up one level
186-
JsonElement edges = sdgAsJSONObject.get("edges");
187-
combinedJsonObject.add("system_dependency_graph", edges);
188-
186+
// Remove the 'edges' element and move the list of edges up one level
187+
combinedJsonObject.add("system_dependency_graph", edges);
189188
}
190189
}
191190
// Cleanup library dependencies directory
@@ -196,6 +195,17 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
196195
JsonElement symbolTableJSON = gson.fromJson(symbolTableJSONString, JsonElement.class);
197196
combinedJsonObject.add("symbol_table", symbolTableJSON);
198197

198+
// Add version number to the output JSON
199+
try {
200+
String[] versions = new VersionProvider().getVersion();
201+
if (versions.length > 0) {
202+
combinedJsonObject.addProperty("version", versions[0]);
203+
} else {
204+
combinedJsonObject.addProperty("version", "unknown");
205+
}
206+
} catch (Exception e) {
207+
combinedJsonObject.addProperty("version", "error retrieving version");
208+
}
199209
String consolidatedJSONString = gson.toJson(combinedJsonObject);
200210
emit(consolidatedJSONString);
201211
}

0 commit comments

Comments
 (0)