Skip to content

Commit 9aec5ff

Browse files
committed
Ensure the output directory is created only after clean is performed in the project lifecycle
Signed-off-by: Rahul Krishna <[email protected]>
1 parent d7fe0b9 commit 9aec5ff

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,6 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
115115

116116
symbolTable = symbolTableExtractionResult.getLeft();
117117

118-
if (output != null) {
119-
Path outputPath = Paths.get(output);
120-
if (!Files.exists(outputPath)) {
121-
Files.createDirectories(outputPath);
122-
}
123-
// Make parse error as a list/csv
124-
// String parseError = gson.toJson(symbolTableExtractionResult.getRight());
125-
// emit(parseError, "parse_errors.json");
126-
/* gson.toJson(symbolTableExtractionResult.getRight(), new FileWriter(new File(outputPath.toString(), "parse_errors.json")));
127-
* }
128-
**/
129-
}
130-
131118
if (analysisLevel > 1) {
132119
// Save SDG, and Call graph as JSON
133120
// If noBuild is not true, and build is also not provided, we will use "auto" as the build command
@@ -156,15 +143,19 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
156143
combinedJsonObject.add("symbol_table", symbolTableJSON);
157144

158145
String consolidatedJSONString = gson.toJson(combinedJsonObject);
159-
emit(consolidatedJSONString, "analysis.json");
146+
emit(consolidatedJSONString);
160147
}
161148

162-
private static void emit(String consolidatedJSONString, String filename) throws IOException {
149+
private static void emit(String consolidatedJSONString) throws IOException {
163150
if (output == null) {
164151
System.out.println(consolidatedJSONString);
165152
} else {
153+
Path outputPath = Paths.get(output);
154+
if (!Files.exists(outputPath)) {
155+
Files.createDirectories(outputPath);
156+
}
166157
// If output is not null, export to a file
167-
File file = new File(output, filename);
158+
File file = new File(output, "analysis.json");
168159
try (FileWriter fileWriter = new FileWriter(file)) {
169160
fileWriter.write(consolidatedJSONString);
170161
Log.done("Analysis output saved at " + output);

src/main/java/com/ibm/northstar/utils/BuildProject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static boolean mavenBuild(String projectPath) {
7373
return false;
7474
}
7575
String[] mavenCommand = {
76-
MAVEN_CMD, "package", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip",
76+
MAVEN_CMD, "clean", "package", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip",
7777
"-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip",
7878
"-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true",
7979
"-Drat.skip=true", "-Dspotless.check.skip=true" };
@@ -84,7 +84,7 @@ private static boolean mavenBuild(String projectPath) {
8484
public static boolean gradleBuild(String projectPath) {
8585
// Adjust Gradle command as needed
8686
String gradleWrapper = projectPath + File.separator + GRADLE_CMD;
87-
String[] gradleCommand = { gradleWrapper, "compileJava", "-p", projectPath };
87+
String[] gradleCommand = { gradleWrapper, "clean", "compileJava", "-p", projectPath };
8888
return buildWithTool(gradleCommand);
8989
}
9090

0 commit comments

Comments
 (0)