Skip to content

Commit

Permalink
Merge pull request #22 from IBM/create-directory
Browse files Browse the repository at this point in the history
fix the folder creation bug
  • Loading branch information
rangeetpan authored May 24, 2024
2 parents 76488fb + bea2134 commit 78d704e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/java/com/ibm/northstar/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,18 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
SymbolTable.extractAll(Paths.get(input));

symbolTable = symbolTableExtractionResult.getLeft();
/*
* if (output != null) {
* Path outputPath = Paths.get(output);
* if (!Files.exists(outputPath)) {
* Files.createDirectories(outputPath);
* }
* gson.toJson(symbolTableExtractionResult.getRight(), new FileWriter(new File(outputPath.toString(), "parse_errors.json")));

if (output != null) {
Path outputPath = Paths.get(output);
if (!Files.exists(outputPath)) {
Files.createDirectories(outputPath);
}
String parseError = gson.toJson(symbolTableExtractionResult.getRight());
emit(parseError, "parse_errors.json");
/* gson.toJson(symbolTableExtractionResult.getRight(), new FileWriter(new File(outputPath.toString(), "parse_errors.json")));
* }
**/
}

if (analysisLevel > 1) {
// Save SDG, and Call graph as JSON
Expand Down Expand Up @@ -155,15 +158,15 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
combinedJsonObject.add("symbol_table", symbolTableJSON);

String consolidatedJSONString = gson.toJson(combinedJsonObject);
emit(consolidatedJSONString);
emit(consolidatedJSONString, "analysis.json");
}

private static void emit(String consolidatedJSONString) throws IOException {
private static void emit(String consolidatedJSONString, String filename) throws IOException {
if (output == null) {
System.out.println(consolidatedJSONString);
} else {
// If output is not null, export to a file
File file = new File(output, "analysis.json");
File file = new File(output, filename);
try (FileWriter fileWriter = new FileWriter(file)) {
fileWriter.write(consolidatedJSONString);
Log.done("Analysis output saved at " + output);
Expand Down

0 comments on commit 78d704e

Please sign in to comment.