Skip to content

Commit

Permalink
Ensure the output directory is created only after clean is performed …
Browse files Browse the repository at this point in the history
…in the project lifecycle

Signed-off-by: Rahul Krishna <[email protected]>
  • Loading branch information
rahlk committed Jun 3, 2024
1 parent d7fe0b9 commit 9aec5ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
23 changes: 7 additions & 16 deletions src/main/java/com/ibm/northstar/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,6 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG

symbolTable = symbolTableExtractionResult.getLeft();

if (output != null) {
Path outputPath = Paths.get(output);
if (!Files.exists(outputPath)) {
Files.createDirectories(outputPath);
}
// Make parse error as a list/csv
// 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
// If noBuild is not true, and build is also not provided, we will use "auto" as the build command
Expand Down Expand Up @@ -156,15 +143,19 @@ private static void analyze() throws IOException, ClassHierarchyException, CallG
combinedJsonObject.add("symbol_table", symbolTableJSON);

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

private static void emit(String consolidatedJSONString, String filename) throws IOException {
private static void emit(String consolidatedJSONString) throws IOException {
if (output == null) {
System.out.println(consolidatedJSONString);
} else {
Path outputPath = Paths.get(output);
if (!Files.exists(outputPath)) {
Files.createDirectories(outputPath);
}
// If output is not null, export to a file
File file = new File(output, filename);
File file = new File(output, "analysis.json");
try (FileWriter fileWriter = new FileWriter(file)) {
fileWriter.write(consolidatedJSONString);
Log.done("Analysis output saved at " + output);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ibm/northstar/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static boolean mavenBuild(String projectPath) {
return false;
}
String[] mavenCommand = {
MAVEN_CMD, "package", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip",
MAVEN_CMD, "clean", "package", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip",
"-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip",
"-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true",
"-Drat.skip=true", "-Dspotless.check.skip=true" };
Expand All @@ -84,7 +84,7 @@ private static boolean mavenBuild(String projectPath) {
public static boolean gradleBuild(String projectPath) {
// Adjust Gradle command as needed
String gradleWrapper = projectPath + File.separator + GRADLE_CMD;
String[] gradleCommand = { gradleWrapper, "compileJava", "-p", projectPath };
String[] gradleCommand = { gradleWrapper, "clean", "compileJava", "-p", projectPath };
return buildWithTool(gradleCommand);
}

Expand Down

0 comments on commit 9aec5ff

Please sign in to comment.