42
42
class VersionProvider implements CommandLine .IVersionProvider {
43
43
public String [] getVersion () throws Exception {
44
44
String version = getClass ().getPackage ().getImplementationVersion ();
45
- return new String []{ "codeanalyzer " + ( version != null ? version : "unknown" ) };
45
+ return new String []{ version != null ? version : "unknown" };
46
46
}
47
47
}
48
48
/**
@@ -99,12 +99,12 @@ public void run() {
99
99
Log .setVerbosity (verbose );
100
100
try {
101
101
analyze ();
102
- } catch (IOException | CallGraphBuilderCancelException | ClassHierarchyException e ) {
102
+ } catch (Exception e ) {
103
103
throw new RuntimeException (e );
104
104
}
105
105
}
106
106
107
- private static void analyze () throws IOException , ClassHierarchyException , CallGraphBuilderCancelException {
107
+ private static void analyze () throws Exception {
108
108
109
109
JsonObject combinedJsonObject = new JsonObject ();
110
110
Map <String , JavaCompilationUnit > symbolTable ;
@@ -159,6 +159,7 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
159
159
symbolTable = existingSymbolTable ;
160
160
}
161
161
}
162
+
162
163
else {
163
164
// construct symbol table for project, write parse problems to file in output directory if specified
164
165
Pair <Map <String , JavaCompilationUnit >, Map <String , List <Problem >>> symbolTableExtractionResult =
@@ -176,16 +177,14 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
176
177
String sdgAsJSONString = SystemDependencyGraph .construct (input , dependencies , build );
177
178
JsonElement sdgAsJSONElement = gson .fromJson (sdgAsJSONString , JsonElement .class );
178
179
JsonObject sdgAsJSONObject = sdgAsJSONElement .getAsJsonObject ();
180
+ JsonElement edges = sdgAsJSONObject .get ("edges" );
179
181
180
182
// We don't really need these fields, so we'll remove it.
181
183
sdgAsJSONObject .remove ("nodes" );
182
184
sdgAsJSONObject .remove ("creator" );
183
185
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 );
189
188
}
190
189
}
191
190
// Cleanup library dependencies directory
@@ -196,6 +195,17 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
196
195
JsonElement symbolTableJSON = gson .fromJson (symbolTableJSONString , JsonElement .class );
197
196
combinedJsonObject .add ("symbol_table" , symbolTableJSON );
198
197
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
+ }
199
209
String consolidatedJSONString = gson .toJson (combinedJsonObject );
200
210
emit (consolidatedJSONString );
201
211
}
0 commit comments