Skip to content

Commit

Permalink
Merge pull request #57 from IBM/add-version-number-to-jar
Browse files Browse the repository at this point in the history
Add version number to jar
  • Loading branch information
rahlk authored Oct 21, 2024
2 parents a58e716 + ce253b2 commit 4a683f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ dependencies {

task fatJar(type: Jar) {
archiveBaseName = 'codeanalyzer'
archiveFileName = 'codeanalyzer.jar'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.0
version=1.0.1
26 changes: 18 additions & 8 deletions src/main/java/com/ibm/cldk/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class VersionProvider implements CommandLine.IVersionProvider {
public String[] getVersion() throws Exception {
String version = getClass().getPackage().getImplementationVersion();
return new String[]{ "codeanalyzer " + (version != null ? version : "unknown") };
return new String[]{ version != null ? version : "unknown" };
}
}
/**
Expand Down Expand Up @@ -99,12 +99,12 @@ public void run() {
Log.setVerbosity(verbose);
try {
analyze();
} catch (IOException | CallGraphBuilderCancelException | ClassHierarchyException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private static void analyze() throws IOException, ClassHierarchyException, CallGraphBuilderCancelException {
private static void analyze() throws Exception {

JsonObject combinedJsonObject = new JsonObject();
Map<String, JavaCompilationUnit> symbolTable;
Expand Down Expand Up @@ -159,6 +159,7 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
symbolTable = existingSymbolTable;
}
}

else {
// construct symbol table for project, write parse problems to file in output directory if specified
Pair<Map<String, JavaCompilationUnit>, Map<String, List<Problem>>> symbolTableExtractionResult =
Expand All @@ -176,16 +177,14 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
String sdgAsJSONString = SystemDependencyGraph.construct(input, dependencies, build);
JsonElement sdgAsJSONElement = gson.fromJson(sdgAsJSONString, JsonElement.class);
JsonObject sdgAsJSONObject = sdgAsJSONElement.getAsJsonObject();
JsonElement edges = sdgAsJSONObject.get("edges");

// We don't really need these fields, so we'll remove it.
sdgAsJSONObject.remove("nodes");
sdgAsJSONObject.remove("creator");
sdgAsJSONObject.remove("version");

// Remove the 'edges' element and move the list of edges up one level
JsonElement edges = sdgAsJSONObject.get("edges");
combinedJsonObject.add("system_dependency_graph", edges);

// Remove the 'edges' element and move the list of edges up one level
combinedJsonObject.add("system_dependency_graph", edges);
}
}
// Cleanup library dependencies directory
Expand All @@ -196,6 +195,17 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
JsonElement symbolTableJSON = gson.fromJson(symbolTableJSONString, JsonElement.class);
combinedJsonObject.add("symbol_table", symbolTableJSON);

// Add version number to the output JSON
try {
String[] versions = new VersionProvider().getVersion();
if (versions.length > 0) {
combinedJsonObject.addProperty("version", versions[0]);
} else {
combinedJsonObject.addProperty("version", "unknown");
}
} catch (Exception e) {
combinedJsonObject.addProperty("version", "error retrieving version");
}
String consolidatedJSONString = gson.toJson(combinedJsonObject);
emit(consolidatedJSONString);
}
Expand Down

0 comments on commit 4a683f5

Please sign in to comment.