Skip to content

Commit 545fe76

Browse files
committed
Update copy depenedencies rule to ensure the copied JAR files have write/delete permissions. Don't clean before compile.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 676e267 commit 545fe76

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ dependencies {
124124
implementation('com.github.javaparser:javaparser-core:3.26.3')
125125

126126
// TestContainers
127-
testImplementation 'org.testcontainers:testcontainers:1.19.3'
128-
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'
127+
testImplementation 'org.testcontainers:testcontainers:1.20.6'
128+
testImplementation 'org.testcontainers:junit-jupiter:1.20.6'
129129

130130
// JUnit 5
131131
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'

gradle.properties

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

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public static String getGradleCommand() {
5656
}
5757
}
5858

59-
private static final String GRADLE_DEPENDENCIES_TASK = "allprojects { afterEvaluate { project -> task downloadDependencies(type: Copy) {\n" + " def configs = project.configurations.findAll { it.canBeResolved }\n\n" + " dependsOn configs\n" + " from configs\n" + " into project.hasProperty('outputDir') ? project.property('outputDir') : \"${project.buildDir}/libs\"\n\n" + " doFirst {\n" + " println \"Downloading dependencies for project ${project.name} to: ${destinationDir}\"\n" + " configs.each { config ->\n" + " println \"Configuration: ${config.name}\"\n" + " config.resolvedConfiguration.resolvedArtifacts.each { artifact ->\n" + " println \"\t${artifact.moduleVersion.id}:${artifact.extension}\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
60-
59+
private static final String GRADLE_DEPENDENCIES_TASK = "allprojects { afterEvaluate { project -> task downloadDependencies(type: Copy) { def configs = project.configurations.findAll { it.canBeResolved }; dependsOn configs; from configs; into project.hasProperty('outputDir') ? project.property('outputDir') : \"${project.buildDir}/libs\"; eachFile { fileCopyDetails -> fileCopyDetails.file.setWritable(true) }; doFirst { println \"Downloading dependencies for project ${project.name} to: ${destinationDir}\"; configs.each { config -> println \"Configuration: ${config.name}\"; config.resolvedConfiguration.resolvedArtifacts.each { artifact -> println \"\\t${artifact.moduleVersion.id}:${artifact.extension}\" } } } } } }";
6160
private static AbstractMap.SimpleEntry<Boolean, String> commandExists(File command) {
6261
StringBuilder output = new StringBuilder();
6362
if (!command.exists()) {
@@ -143,10 +142,10 @@ private static boolean mavenBuild(String projectPath) {
143142
String[] mavenCommand;
144143
if (includeTestClasses) {
145144
Log.warn("Hidden flag `--include-test-classes` is turned on. We'll including test classes in WALA analysis");
146-
mavenCommand = new String[]{MAVEN_CMD, "clean", "test-compile", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip", "-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip", "-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true", "-Drat.skip=true", "-Dspotless.check.skip=true"};
145+
mavenCommand = new String[]{MAVEN_CMD, "test-compile", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip", "-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip", "-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true", "-Drat.skip=true", "-Dspotless.check.skip=true"};
147146
}
148147
else
149-
mavenCommand = new String[]{MAVEN_CMD, "clean", "compile", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip", "-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip", "-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true", "-Drat.skip=true", "-Dspotless.check.skip=true"};
148+
mavenCommand = new String[]{MAVEN_CMD, "compile", "-f", projectPath + "/pom.xml", "-B", "-V", "-e", "-Drat.skip", "-Dfindbugs.skip", "-Dcheckstyle.skip", "-Dpmd.skip=true", "-Dspotbugs.skip", "-Denforcer.skip", "-Dmaven.javadoc.skip", "-DskipTests", "-Dmaven.test.skip.exec", "-Dlicense.skip=true", "-Drat.skip=true", "-Dspotless.check.skip=true"};
150149

151150
return buildWithTool(mavenCommand);
152151
}
@@ -155,14 +154,14 @@ public static boolean gradleBuild(String projectPath) {
155154
// Adjust Gradle command as needed
156155
String[] gradleCommand;
157156
if (GRADLE_CMD.equals("gradlew") || GRADLE_CMD.equals("gradlew.bat")) {
158-
gradleCommand = new String[]{projectPath + File.separator + GRADLE_CMD, "clean", "compileJava", "-p", projectPath};
157+
gradleCommand = new String[]{projectPath + File.separator + GRADLE_CMD, "compileJava", "-p", projectPath};
159158
} else {
160159
if (includeTestClasses) {
161160
Log.warn("Hidden flag `--include-test-classes` is turned on. We'll including test classes in WALA analysis");
162-
gradleCommand = new String[]{GRADLE_CMD, "clean", "compileTestJava", "-p", projectPath};
161+
gradleCommand = new String[]{GRADLE_CMD, "compileTestJava", "-p", projectPath};
163162
}
164163
else
165-
gradleCommand = new String[]{GRADLE_CMD, "clean", "compileJava", "-p", projectPath};
164+
gradleCommand = new String[]{GRADLE_CMD, "compileJava", "-p", projectPath};
166165
}
167166
return buildWithTool(gradleCommand);
168167
}
@@ -240,7 +239,7 @@ public static boolean downloadLibraryDependencies(String projectPath, String pro
240239
));
241240
}
242241
Log.info("Found pom.xml in the project directory. Using Maven to download dependencies.");
243-
String[] mavenCommand = {MAVEN_CMD, "--no-transfer-progress", "-f", Paths.get(projectRoot, "pom.xml").toAbsolutePath().toString(), "dependency:copy-dependencies", "-DoutputDirectory=" + libDownloadPath.toString()};
242+
String[] mavenCommand = {MAVEN_CMD, "--no-transfer-progress", "-f", Paths.get(projectRoot, "pom.xml").toAbsolutePath().toString(), "dependency:copy-dependencies", "-DoutputDirectory=" + libDownloadPath.toString(), "-Doverwrite=true"};
244243
return buildWithTool(mavenCommand);
245244
} else if (new File(projectRoot, "build.gradle").exists() || new File(projectRoot, "build.gradle.kts").exists()) {
246245
libDownloadPath = Paths.get(projectPath, "build", LIB_DEPS_DOWNLOAD_DIR).toAbsolutePath();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
import java.util.stream.Collectors;
1010
import java.util.stream.Stream;
1111

12-
import static com.ibm.cldk.CodeAnalyzer.includeTestClasses;
13-
1412
public class ProjectDirectoryScanner {
1513
public static List<Path> classFilesStream(String projectPath) throws IOException {
1614
Path projectDir = Paths.get(projectPath).toAbsolutePath();
1715
Log.info("Finding *.class files in " + projectDir);
1816
if (Files.exists(projectDir)) {
1917
try (Stream<Path> paths = Files.walk(projectDir)) {
20-
return paths.filter(file -> !Files.isDirectory(file) && file.toString().endsWith(".class")).collect(Collectors.toList());
18+
return paths.filter(file -> !Files.isDirectory(file) && file.toString().endsWith(".class"))
19+
.collect(Collectors.toList());
2120
}
2221
}
2322
return null;

src/test/java/com/ibm/cldk/CodeAnalyzerIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.google.gson.JsonArray;
55
import com.google.gson.JsonElement;
66
import com.google.gson.JsonObject;
7+
import org.junit.jupiter.api.Assertions;
78
import org.junit.jupiter.api.BeforeAll;
89
import org.junit.jupiter.api.Test;
9-
import org.junit.jupiter.api.Assertions;
1010
import org.testcontainers.containers.GenericContainer;
1111
import org.testcontainers.junit.jupiter.Container;
1212
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -31,6 +31,7 @@ public class CodeAnalyzerIntegrationTest {
3131
static String codeanalyzerVersion;
3232
static final String javaVersion = "17";
3333
static String javaHomePath;
34+
3435
static {
3536
// Build project first
3637
try {
@@ -120,8 +121,8 @@ void shouldBeAbleToRunCodeAnalyzer() throws Exception {
120121
var runCodeAnalyzerJar = container.execInContainer(
121122
"bash", "-c",
122123
String.format("export JAVA_HOME=%s && java -jar /opt/jars/codeanalyzer-%s.jar --help",
123-
javaHomePath, codeanalyzerVersion
124-
));
124+
javaHomePath, codeanalyzerVersion
125+
));
125126

126127
Assertions.assertEquals(0, runCodeAnalyzerJar.getExitCode(),
127128
"Command should execute successfully");

0 commit comments

Comments
 (0)