Skip to content

Commit

Permalink
Add root pom path to the CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Krishna <[email protected]>
  • Loading branch information
rahlk committed Nov 7, 2024
2 parents 934a54f + bb56aca commit 1acec4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Codeanalyzer CI
on:
push:
branches:
- GA
- 1.X.X

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.2
version=1.0.3
3 changes: 1 addition & 2 deletions src/main/java/com/ibm/cldk/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public class CodeAnalyzer implements Runnable {

@Option(names = {"-f", "--project-root-path"}, description = "Path to the root pom.xml file of the project.")
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")
private static int analysisLevel = 1;

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/ibm/cldk/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ public static List<Path> 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 {
Expand All @@ -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);
}
Expand Down

0 comments on commit 1acec4a

Please sign in to comment.