Skip to content

Remove no copy deps and add path to root pom #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 5 additions & 10 deletions src/main/java/com/ibm/cldk/CodeAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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));

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