Skip to content

Commit 6180850

Browse files
committed
Attempt fix for issue 74 by moving dowloaded dependencies to the projectPath/target folder and add a flag to turn off cleanup operations (flag defaults to no clean up).
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 5cf8398 commit 6180850

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=1.1.0
1+
version=1.1.1
22

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class CodeAnalyzer implements Runnable {
7676
@Option(names = {"-v", "--verbose"}, description = "Print logs to console.")
7777
private static boolean verbose = false;
7878

79+
@Option(names = {"--no-clean-dependencies"}, description = "Do not attempt to auto-clean dependencies")
80+
public static boolean noCleanDependencies = true;
81+
7982
private static final String outputFileName = "analysis.json";
8083

8184
public static Gson gson = new GsonBuilder()

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.ibm.cldk.utils.ProjectDirectoryScanner.classFilesStream;
2020
import static com.ibm.cldk.CodeAnalyzer.projectRootPom;
21+
import static com.ibm.cldk.CodeAnalyzer.noCleanDependencies;
2122

2223
public class BuildProject {
2324
public static Path libDownloadPath;
@@ -188,6 +189,17 @@ public static List<Path> buildProjectAndStreamClassFiles(String projectPath, Str
188189
return buildProject(projectPath, build) ? classFilesStream(projectPath) : new ArrayList<>();
189190
}
190191

192+
private static boolean mkLibDepDirs(String projectPath) {
193+
if (!Files.exists(libDownloadPath)) {
194+
try {
195+
Files.createDirectories(libDownloadPath);
196+
} catch (IOException e) {
197+
Log.error("Error creating library dependency directory for " + projectPath + ": " + e.getMessage());
198+
return false;
199+
}
200+
}
201+
return true;
202+
}
191203
/**
192204
* Downloads library dependency jars of the given project so that the jars can be used
193205
* for type resolution during symbol table creation.
@@ -198,17 +210,15 @@ public static List<Path> buildProjectAndStreamClassFiles(String projectPath, Str
198210
public static boolean downloadLibraryDependencies(String projectPath, String projectRootPom) throws IOException {
199211
// created download dir if it does not exist
200212
String projectRoot = projectRootPom != null ? projectRootPom : projectPath;
201-
libDownloadPath = Paths.get(projectPath, LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
202-
if (!Files.exists(libDownloadPath)) {
203-
try {
204-
Files.createDirectory(libDownloadPath);
205-
} catch (IOException e) {
206-
Log.error("Error creating library dependency directory for " + projectPath + ": " + e.getMessage());
207-
return false;
208-
}
209-
}
213+
210214
File pomFile = new File(projectRoot, "pom.xml");
211215
if (pomFile.exists()) {
216+
libDownloadPath = Paths.get(projectPath, "target", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
217+
if (mkLibDepDirs(projectPath))
218+
Log.debug("Dependencies found/created in " + libDownloadPath);
219+
else
220+
throw new IllegalStateException("Error creating library dependency directory in " + libDownloadPath);
221+
212222
if (MAVEN_CMD == null || !commandExists(new File(MAVEN_CMD)).getKey()) {
213223
String msg = MAVEN_CMD == null ?
214224
"Could not find Maven or a valid Maven Wrapper" :
@@ -225,6 +235,12 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
225235
return buildWithTool(mavenCommand);
226236
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
227237
if (GRADLE_CMD == null || !commandExists(new File(GRADLE_CMD)).getKey()) {
238+
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();
239+
if (mkLibDepDirs(projectPath))
240+
Log.debug("Dependencies found/created in " + libDownloadPath);
241+
else
242+
throw new IllegalStateException("Error creating library dependency directory in " + libDownloadPath);
243+
228244
String msg = GRADLE_CMD == null ?
229245
"Could not find Gradle or valid Gradle Wrapper" :
230246
MessageFormat.format("Could not verify that {0} exists", GRADLE_CMD);
@@ -249,6 +265,9 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
249265
}
250266

251267
public static void cleanLibraryDependencies() {
268+
if (noCleanDependencies) {
269+
return;
270+
}
252271
if (libDownloadPath != null) {
253272
Log.info("Cleaning up library dependency directory: " + libDownloadPath);
254273
try {

0 commit comments

Comments
 (0)