diff --git a/gradle.properties b/gradle.properties index 0ca44e84..26daa7a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.0.2 \ No newline at end of file +version=1.0.3 \ No newline at end of file diff --git a/src/main/java/com/ibm/cldk/CodeAnalyzer.java b/src/main/java/com/ibm/cldk/CodeAnalyzer.java index b1502ab8..0e8ade44 100644 --- a/src/main/java/com/ibm/cldk/CodeAnalyzer.java +++ b/src/main/java/com/ibm/cldk/CodeAnalyzer.java @@ -69,8 +69,8 @@ public class CodeAnalyzer implements Runnable { @Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.") private static boolean noBuild = false; - @Option(names = {"--no-copy-dependencies"}, description = "Do copy dependencies to a temporary directory.") - private static boolean noCopyDeps = false; + @Option(names = {"-f", "--project-root-pom"}, description = "Do copy dependencies to a temporary directory.") + private static String projectRootPom; @Option(names = {"-a", "--analysis-level"}, description = "Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1") @@ -122,15 +122,10 @@ private static void analyze() throws Exception { else { // download library dependencies of project for type resolution String dependencies = null; - - if (!noCopyDeps) { - if (BuildProject.downloadLibraryDependencies(input)) { - dependencies = String.valueOf(BuildProject.libDownloadPath); - } else { - Log.warn("Failed to download library dependencies of project"); - } + if (BuildProject.downloadLibraryDependencies(input, projectRootPom)) { + dependencies = String.valueOf(BuildProject.libDownloadPath); } else { - Log.warn("--no-copy-dependencies is activated, skipping library dependencies download"); + Log.warn("Failed to download library dependencies of project"); } boolean analysisFileExists = output != null && Files.exists(Paths.get(output + File.separator + outputFileName)); diff --git a/src/main/java/com/ibm/cldk/utils/BuildProject.java b/src/main/java/com/ibm/cldk/utils/BuildProject.java index a237ff9f..6616be4b 100644 --- a/src/main/java/com/ibm/cldk/utils/BuildProject.java +++ b/src/main/java/com/ibm/cldk/utils/BuildProject.java @@ -155,8 +155,9 @@ public static List buildProjectAndStreamClassFiles(String projectPath, Str * @param projectPath Path to the project under analysis * @return true if dependency download succeeds; false otherwise */ - public static boolean downloadLibraryDependencies(String projectPath) throws IOException { + public static boolean downloadLibraryDependencies(String projectPath, String projectRootPom) throws IOException { // created download dir if it does not exist + String projectRoot = projectRootPom != null ? projectRootPom : projectPath; libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath(); if (!Files.exists(libDownloadPath)) { try { @@ -166,20 +167,20 @@ public static boolean downloadLibraryDependencies(String projectPath) throws IOE return false; } } - File pomFile = new File(projectPath, "pom.xml"); + File pomFile = new File(projectRoot, "pom.xml"); if (pomFile.exists()) { Log.info("Found pom.xml in the project directory. Using Maven to download dependencies."); String[] mavenCommand = { MAVEN_CMD, "--no-transfer-progress", "-f", - Paths.get(projectPath, "pom.xml").toString(), + Paths.get(projectRoot, "pom.xml").toString(), "dependency:copy-dependencies", "-DoutputDirectory=" + libDownloadPath.toString() }; return buildWithTool(mavenCommand); - } else if (new File(projectPath, "build.gradle").exists() || new File(projectPath, "build.gradle.kts").exists()) { + } else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) { Log.info("Found build.gradle[.kts] in the project directory. Using Gradle to download dependencies."); tempInitScript = Files.writeString(tempInitScript, GRADLE_DEPENDENCIES_TASK); - String[] gradleCommand = {projectPath + File.separator + GRADLE_CMD, "--init-script", tempInitScript.toFile().getAbsolutePath(), "downloadDependencies", "-PoutputDir="+libDownloadPath.toString()}; + String[] gradleCommand = {projectRoot + File.separator + GRADLE_CMD, "--init-script", tempInitScript.toFile().getAbsolutePath(), "downloadDependencies", "-PoutputDir="+libDownloadPath.toString()}; System.out.println(Arrays.toString(gradleCommand)); return buildWithTool(gradleCommand); }