Skip to content

Commit 78d704e

Browse files
authored
Merge pull request #22 from IBM/create-directory
fix the folder creation bug
2 parents 76488fb + bea2134 commit 78d704e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,18 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
117117
SymbolTable.extractAll(Paths.get(input));
118118

119119
symbolTable = symbolTableExtractionResult.getLeft();
120-
/*
121-
* if (output != null) {
122-
* Path outputPath = Paths.get(output);
123-
* if (!Files.exists(outputPath)) {
124-
* Files.createDirectories(outputPath);
125-
* }
126-
* gson.toJson(symbolTableExtractionResult.getRight(), new FileWriter(new File(outputPath.toString(), "parse_errors.json")));
120+
121+
if (output != null) {
122+
Path outputPath = Paths.get(output);
123+
if (!Files.exists(outputPath)) {
124+
Files.createDirectories(outputPath);
125+
}
126+
String parseError = gson.toJson(symbolTableExtractionResult.getRight());
127+
emit(parseError, "parse_errors.json");
128+
/* gson.toJson(symbolTableExtractionResult.getRight(), new FileWriter(new File(outputPath.toString(), "parse_errors.json")));
127129
* }
128130
**/
131+
}
129132

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

157160
String consolidatedJSONString = gson.toJson(combinedJsonObject);
158-
emit(consolidatedJSONString);
161+
emit(consolidatedJSONString, "analysis.json");
159162
}
160163

161-
private static void emit(String consolidatedJSONString) throws IOException {
164+
private static void emit(String consolidatedJSONString, String filename) throws IOException {
162165
if (output == null) {
163166
System.out.println(consolidatedJSONString);
164167
} else {
165168
// If output is not null, export to a file
166-
File file = new File(output, "analysis.json");
169+
File file = new File(output, filename);
167170
try (FileWriter fileWriter = new FileWriter(file)) {
168171
fileWriter.write(consolidatedJSONString);
169172
Log.done("Analysis output saved at " + output);

0 commit comments

Comments
 (0)