Skip to content

Commit

Permalink
Fix issue #83
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Krishna <[email protected]>
  • Loading branch information
rahlk committed Dec 12, 2024
1 parent cb285fa commit 1ad2b92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.7
version=1.0.8
15 changes: 9 additions & 6 deletions src/main/java/com/ibm/cldk/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import static com.ibm.cldk.utils.ProjectDirectoryScanner.classFilesStream;
import static com.ibm.cldk.CodeAnalyzer.projectRootPom;
public class BuildProject {

public class BuildProject {
public static Path libDownloadPath;
private static final String LIB_DEPS_DOWNLOAD_DIR = "_library_dependencies";
private static final String MAVEN_CMD = BuildProject.getMavenCommand();
Expand Down Expand Up @@ -55,10 +55,8 @@ private static String getGradleCmd() {

if (new File(projectRootPom, gradleWrapper).exists()) {
GRADLE_CMD = gradleWrapper;
} else if (commandExists(gradle)) {
GRADLE_CMD = gradle;
} else {
throw new IllegalStateException("Could not file a valid gradle command. I did not find " + gradleWrapper + " or " + gradle + " in the project directory or in the system PATH.");
GRADLE_CMD = gradle;
}
return GRADLE_CMD;
}
Expand Down Expand Up @@ -229,6 +227,9 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
File pomFile = new File(projectRoot, "pom.xml");
if (pomFile.exists()) {
Log.info("Found pom.xml in the project directory. Using Maven to download dependencies.");
if (!commandExists(MAVEN_CMD))
throw new IllegalStateException("Could not find a valid maven command. I did not find " + MAVEN_CMD + " in the project directory or in the system PATH.");

String[] mavenCommand = {
MAVEN_CMD, "--no-transfer-progress", "-f",
Paths.get(projectRoot, "pom.xml").toString(),
Expand All @@ -237,6 +238,10 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
};
return buildWithTool(mavenCommand);
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
Log.info("Found build.gradle or build.gradle.kts in the project directory. Using gradle to download dependencies.");
if (!commandExists(GRADLE_CMD))
throw new IllegalStateException("Could not find a valid Gradle command. I did not find " + GRADLE_CMD + " in the project directory or in the system PATH.");

Log.info("Found build.gradle[.kts] in the project directory. Using Gradle to download dependencies.");
tempInitScript = Files.writeString(tempInitScript, GRADLE_DEPENDENCIES_TASK);
String[] gradleCommand;
Expand All @@ -246,8 +251,6 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
else {
gradleCommand = new String[]{GRADLE_CMD, "--init-script", tempInitScript.toFile().getAbsolutePath(), "downloadDependencies", "-PoutputDir=" + libDownloadPath.toString()};
}

System.out.println(Arrays.toString(gradleCommand));
return buildWithTool(gradleCommand);
}
return false;
Expand Down

0 comments on commit 1ad2b92

Please sign in to comment.