Skip to content

Commit 7a4fb10

Browse files
authored
Merge pull request #68 from IBM/remove-no-copy-deps-and-add-path-to-root-pom
Remove no copy deps and add path to root pom
2 parents 3e73301 + ffdef39 commit 7a4fb10

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.0.2
1+
version=1.0.3

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class CodeAnalyzer implements Runnable {
6969
@Option(names = {"--no-build"}, description = "Do not build your application. Use this option if you have already built your application.")
7070
private static boolean noBuild = false;
7171

72-
@Option(names = {"--no-copy-dependencies"}, description = "Do copy dependencies to a temporary directory.")
73-
private static boolean noCopyDeps = false;
72+
@Option(names = {"-f", "--project-root-pom"}, description = "Do copy dependencies to a temporary directory.")
73+
private static String projectRootPom;
7474

7575

7676
@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 {
122122
else {
123123
// download library dependencies of project for type resolution
124124
String dependencies = null;
125-
126-
if (!noCopyDeps) {
127-
if (BuildProject.downloadLibraryDependencies(input)) {
128-
dependencies = String.valueOf(BuildProject.libDownloadPath);
129-
} else {
130-
Log.warn("Failed to download library dependencies of project");
131-
}
125+
if (BuildProject.downloadLibraryDependencies(input, projectRootPom)) {
126+
dependencies = String.valueOf(BuildProject.libDownloadPath);
132127
} else {
133-
Log.warn("--no-copy-dependencies is activated, skipping library dependencies download");
128+
Log.warn("Failed to download library dependencies of project");
134129
}
135130
boolean analysisFileExists = output != null && Files.exists(Paths.get(output + File.separator + outputFileName));
136131

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ public static List<Path> buildProjectAndStreamClassFiles(String projectPath, Str
155155
* @param projectPath Path to the project under analysis
156156
* @return true if dependency download succeeds; false otherwise
157157
*/
158-
public static boolean downloadLibraryDependencies(String projectPath) throws IOException {
158+
public static boolean downloadLibraryDependencies(String projectPath, String projectRootPom) throws IOException {
159159
// created download dir if it does not exist
160+
String projectRoot = projectRootPom != null ? projectRootPom : projectPath;
160161
libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
161162
if (!Files.exists(libDownloadPath)) {
162163
try {
@@ -166,20 +167,20 @@ public static boolean downloadLibraryDependencies(String projectPath) throws IOE
166167
return false;
167168
}
168169
}
169-
File pomFile = new File(projectPath, "pom.xml");
170+
File pomFile = new File(projectRoot, "pom.xml");
170171
if (pomFile.exists()) {
171172
Log.info("Found pom.xml in the project directory. Using Maven to download dependencies.");
172173
String[] mavenCommand = {
173174
MAVEN_CMD, "--no-transfer-progress", "-f",
174-
Paths.get(projectPath, "pom.xml").toString(),
175+
Paths.get(projectRoot, "pom.xml").toString(),
175176
"dependency:copy-dependencies",
176177
"-DoutputDirectory=" + libDownloadPath.toString()
177178
};
178179
return buildWithTool(mavenCommand);
179-
} else if (new File(projectPath, "build.gradle").exists() || new File(projectPath, "build.gradle.kts").exists()) {
180+
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
180181
Log.info("Found build.gradle[.kts] in the project directory. Using Gradle to download dependencies.");
181182
tempInitScript = Files.writeString(tempInitScript, GRADLE_DEPENDENCIES_TASK);
182-
String[] gradleCommand = {projectPath + File.separator + GRADLE_CMD, "--init-script", tempInitScript.toFile().getAbsolutePath(), "downloadDependencies", "-PoutputDir="+libDownloadPath.toString()};
183+
String[] gradleCommand = {projectRoot + File.separator + GRADLE_CMD, "--init-script", tempInitScript.toFile().getAbsolutePath(), "downloadDependencies", "-PoutputDir="+libDownloadPath.toString()};
183184
System.out.println(Arrays.toString(gradleCommand));
184185
return buildWithTool(gradleCommand);
185186
}

0 commit comments

Comments
 (0)