Skip to content

Commit 10b48d8

Browse files
committed
Update command checker to proactively set maven/gradle. Update make -> makeWithRoot to build even when dependencies are missing.
Add test containers to test build and add integration tests. Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 65ebcf2 commit 10b48d8

File tree

7,630 files changed

+1172488
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,630 files changed

+1172488
-40
lines changed

build.gradle

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ sourceSets {
5454
srcDirs= ["src/test/resources"]
5555
}
5656
}
57+
integrationTest {
58+
java { srcDir file('src/it/java') }
59+
resources { srcDir file('src/it/resources') }
60+
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
61+
runtimeClasspath += output + compileClasspath
62+
}
5763
}
5864

5965
// Remove that nagging bin folder vscode seems to generate every single time
@@ -119,7 +125,25 @@ dependencies {
119125
implementation('org.jgrapht:jgrapht-ext:1.5.2')
120126
implementation('com.github.javaparser:javaparser-symbol-solver-core:3.25.9')
121127

122-
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
128+
// TestContainers
129+
testImplementation 'org.testcontainers:testcontainers:1.19.3'
130+
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'
131+
132+
// JUnit 5
133+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
134+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.1' // for @ParameterizedTest
135+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
136+
137+
// SLF4J - for TestContainers logging
138+
testImplementation 'org.slf4j:slf4j-api:2.0.9'
139+
testImplementation 'org.slf4j:slf4j-simple:2.0.9'
140+
141+
}
142+
143+
test {
144+
useJUnitPlatform()
145+
// Optional: Enable TestContainers reuse to speed up tests
146+
systemProperty 'testcontainers.reuse.enable', 'true'
123147
}
124148

125149
task fatJar(type: Jar) {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.0.10
1+
version=1.0.11
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.ibm.cldk;
2+
3+
import org.junit.jupiter.api.BeforeAll;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.testcontainers.containers.BindMode;
7+
import org.testcontainers.containers.GenericContainer;
8+
import org.testcontainers.junit.jupiter.Container;
9+
import org.testcontainers.junit.jupiter.Testcontainers;
10+
11+
import java.io.FileInputStream;
12+
import java.io.IOException;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
15+
import java.text.MessageFormat;
16+
import java.util.Properties;
17+
18+
@Testcontainers
19+
@SuppressWarnings("resource")
20+
public class CodeAnalyzerIntegrationTest {
21+
22+
/**
23+
* Creates a Java 11 test container that mounts the build/libs folder.
24+
*/
25+
static String codeanalyzerVersion;
26+
@Container
27+
static final GenericContainer<?> container = new GenericContainer<>("openjdk:11-jdk")
28+
.withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh"))
29+
.withCommand("-c", "while true; do sleep 1; done") // Keep container running
30+
.withFileSystemBind(
31+
String.valueOf(Paths.get(System.getProperty("user.dir")).resolve("build/libs")),
32+
"/opt/jars",
33+
BindMode.READ_WRITE);
34+
35+
@BeforeAll
36+
static void setUp() {
37+
Properties properties = new Properties();
38+
Path propertiesPath = Paths.get(System.getProperty("user.dir"), "gradle.properties");
39+
40+
try (FileInputStream fis = new FileInputStream(propertiesPath.toFile())) {
41+
properties.load(fis);
42+
} catch (IOException e) {
43+
throw new RuntimeException(e);
44+
}
45+
46+
codeanalyzerVersion = properties.getProperty("version");
47+
}
48+
49+
@Test
50+
void shouldHaveJava11Installed() throws Exception {
51+
var result = container.execInContainer("java", "-version");
52+
Assertions.assertTrue(result.getStderr().contains("openjdk version \"11"));
53+
}
54+
55+
@Test
56+
void shouldHaveCodeAnalyzerJar() throws Exception {
57+
var dirContents = container.execInContainer("ls", "/opt/jars/");
58+
Assertions.assertTrue(dirContents.getStdout().length() > 0, "Directory listing should not be empty");
59+
Assertions.assertTrue(dirContents.getStdout().contains("codeanalyzer"), "Codeanalyzer.jar not found in the container.");
60+
}
61+
62+
@Test void shouldBeAbleToRunCodeAnalyzer() throws Exception {
63+
var runCodeAnalyzerJar = container.execInContainer(
64+
"java",
65+
"-jar",
66+
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
67+
"--help"
68+
);
69+
70+
Assertions.assertEquals(0, runCodeAnalyzerJar.getExitCode(),
71+
"Command should execute successfully");
72+
Assertions.assertTrue(runCodeAnalyzerJar.getStdout().length() > 0,
73+
"Should have some output"); }
74+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.ibm.cldk;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Test;
6+
import org.testcontainers.containers.BindMode;
7+
import org.testcontainers.containers.GenericContainer;
8+
import org.testcontainers.junit.jupiter.Container;
9+
import org.testcontainers.junit.jupiter.Testcontainers;
10+
11+
import java.io.FileInputStream;
12+
import java.io.IOException;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
15+
import java.util.Properties;
16+
17+
@Testcontainers
18+
@SuppressWarnings("resource")
19+
public class MavenApplicationIntegrationTest {
20+
21+
/**
22+
* Creates a Java 11 test container that mounts the build/libs folder.
23+
*/
24+
static String codeanalyzerVersion;
25+
@Container
26+
static final GenericContainer<?> baseJavaContainer = new GenericContainer<>("openjdk:11-jdk")
27+
.withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh"))
28+
.withCommand("-c", "while true; do sleep 1; done") // Keep container running
29+
.withFileSystemBind(
30+
String.valueOf(Paths.get(System.getProperty("user.dir")).resolve("build/libs")),
31+
"/opt/jars",
32+
BindMode.READ_WRITE)
33+
// Copy the java project to the
34+
.withFileSystemBind(
35+
MavenApplicationIntegrationTest.class.getResource("/test-applications/simple-maven-project").getPath(),
36+
"/projects/simple-maven-project",
37+
BindMode.READ_ONLY);
38+
39+
@Container
40+
static final GenericContainer<?> mavenContainer = new GenericContainer<>("maven:3.9-eclipse-temurin-11")
41+
.withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh"))
42+
.withCommand("-c", "while true; do sleep 1; done")
43+
.withFileSystemBind(
44+
String.valueOf(Paths.get(System.getProperty("user.dir")).resolve("build/libs")),
45+
"/opt/jars",
46+
BindMode.READ_WRITE);
47+
48+
@BeforeAll
49+
static void setUp() {
50+
Properties properties = new Properties();
51+
Path propertiesPath = Paths.get(System.getProperty("user.dir"), "gradle.properties");
52+
53+
try (FileInputStream fis = new FileInputStream(propertiesPath.toFile())) {
54+
properties.load(fis);
55+
} catch (IOException e) {
56+
throw new RuntimeException(e);
57+
}
58+
59+
codeanalyzerVersion = properties.getProperty("version");
60+
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.ear
17+
*.zip
18+
*.tar.gz
19+
*.rar
20+
21+
# Don't ignore jar files in any level of binary and dependencies
22+
!**/binaries/**/*.jar
23+
!**/libs/**/*.jar
24+
25+
# virtual machine crash logs
26+
hs_err_pid*
27+
28+
# Ignore Gradle files
29+
.gradle/
30+
build/
31+
32+
# Ignore Maven target folder
33+
target/
34+
35+
# Ignore IntelliJ IDEA files
36+
.idea/
37+
*.iml
38+
*.iws
39+
*.ipr
40+
41+
# Ignore Eclipse files
42+
.settings/
43+
*.classpath
44+
*.project
45+
46+
# Ignore VS Code files
47+
.vscode/
48+
49+
# Ignore everything in codeql-db except the directory itself
50+
codeql-db/*
51+
!codeql-db/.keep
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
com/coveros/training/mathematics/Calculator$iBar
2+
com/coveros/training/authentication/LoginUtils
3+
com/coveros/training/mathematics/TailRecursive
4+
com/coveros/training/library/domainobjects/Book
5+
com/coveros/training/cartesianproduct/CartesianProduct
6+
com/coveros/training/mathematics/Calculator$iFoo
7+
com/coveros/training/mathematics/FunctionalField
8+
com/coveros/training/mathematics/Fibonacci
9+
com/coveros/training/expenses/AlcoholCalculator
10+
com/coveros/training/persistence/NotImplementedException
11+
com/coveros/training/mathematics/AckermannIterative
12+
com/coveros/training/library/domainobjects/Loan
13+
com/coveros/training/authentication/domainobjects/User
14+
com/coveros/training/mathematics/Calculator$Bar
15+
com/coveros/training/mathematics/AckermannIterative$$$FunctionalAckermann
16+
com/coveros/training/authentication/RegistrationUtils
17+
com/coveros/training/expenses/AlcoholResult
18+
com/coveros/training/authentication/domainobjects/RegistrationResult
19+
com/coveros/training/helpers/AssertionException
20+
com/coveros/training/persistence/SqlData
21+
com/coveros/training/mathematics/Calculator
22+
com/coveros/training/persistence/EmptyDataSource
23+
com/coveros/training/library/domainobjects/LibraryActionResults
24+
com/coveros/training/persistence/ParameterObject
25+
com/coveros/training/mathematics/FibonacciIterative
26+
com/coveros/training/persistence/IPersistenceLayer
27+
com/coveros/training/authentication/domainobjects/PasswordResult
28+
com/coveros/training/library/domainobjects/Borrower
29+
com/coveros/training/persistence/SqlRuntimeException
30+
com/coveros/training/helpers/StringUtils
31+
com/coveros/training/authentication/domainobjects/RegistrationStatusEnums
32+
com/coveros/training/mathematics/Calculator$Foo
33+
com/coveros/training/library/LibraryUtils
34+
com/coveros/training/expenses/DinnerPrices
35+
com/coveros/training/tomcat/WebAppListener
36+
com/coveros/training/mathematics/Ackermann
37+
com/coveros/training/mathematics/AckermannIterative$1
38+
com/coveros/training/mathematics/TailRecursive$$
39+
com/coveros/training/authentication/domainobjects/PasswordResultEnums
40+
com/coveros/training/helpers/ServletUtils
41+
com/coveros/training/mathematics/AckermannIterative$$$Field
42+
com/coveros/training/persistence/PersistenceLayer
43+
com/coveros/training/persistence/PersistenceLayer$ThrowingFunction
44+
com/coveros/training/mathematics/AckermannIterative$$
45+
com/coveros/training/helpers/CheckUtils
46+
com/coveros/training/mathematics/Calculator$Baz
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
com/coveros/training/mathematics/Calculator$iBar
2+
com/coveros/training/authentication/LoginUtils
3+
com/coveros/training/mathematics/TailRecursive
4+
com/coveros/training/library/domainobjects/Book
5+
com/coveros/training/cartesianproduct/CartesianProduct
6+
com/coveros/training/mathematics/Calculator$iFoo
7+
com/coveros/training/library/LibraryBookListSearchServlet
8+
com/coveros/training/mathematics/FunctionalField
9+
com/coveros/training/mathematics/Fibonacci
10+
com/coveros/training/expenses/AlcoholCalculator
11+
com/coveros/training/library/LibraryBorrowerListSearchServlet
12+
com/coveros/training/persistence/NotImplementedException
13+
com/coveros/training/mathematics/AckermannIterative
14+
com/coveros/training/library/domainobjects/Loan
15+
com/coveros/training/authentication/domainobjects/User
16+
com/coveros/training/mathematics/AckServlet
17+
com/coveros/training/authentication/LoginServlet
18+
com/coveros/training/mathematics/Calculator$Bar
19+
com/coveros/training/mathematics/FibServlet
20+
com/coveros/training/mathematics/AckermannIterative$$$FunctionalAckermann
21+
com/coveros/training/authentication/RegistrationUtils
22+
com/coveros/training/library/LibraryBookListAvailableServlet
23+
com/coveros/training/expenses/AlcoholResult
24+
com/coveros/training/authentication/domainobjects/RegistrationResult
25+
com/coveros/training/helpers/AssertionException
26+
com/coveros/training/persistence/SqlData
27+
com/coveros/training/mathematics/Calculator
28+
com/coveros/training/persistence/EmptyDataSource
29+
com/coveros/training/library/domainobjects/LibraryActionResults
30+
com/coveros/training/library/LibraryRegisterBookServlet
31+
com/coveros/training/persistence/ParameterObject
32+
com/coveros/training/persistence/DbServlet
33+
com/coveros/training/mathematics/FibonacciIterative
34+
com/coveros/training/persistence/IPersistenceLayer
35+
com/coveros/training/authentication/domainobjects/PasswordResult
36+
com/coveros/training/library/domainobjects/Borrower
37+
com/coveros/training/persistence/SqlRuntimeException
38+
com/coveros/training/helpers/StringUtils
39+
com/coveros/training/authentication/domainobjects/RegistrationStatusEnums
40+
com/coveros/training/mathematics/Calculator$Foo
41+
com/coveros/training/library/LibraryUtils
42+
com/coveros/training/expenses/DinnerPrices
43+
com/coveros/training/tomcat/WebAppListener
44+
com/coveros/training/library/LibraryRegisterBorrowerServlet
45+
com/coveros/training/mathematics/Ackermann
46+
com/coveros/training/mathematics/AckermannIterative$1
47+
com/coveros/training/mathematics/TailRecursive$$
48+
com/coveros/training/authentication/domainobjects/PasswordResultEnums
49+
com/coveros/training/authentication/RegisterServlet
50+
com/coveros/training/helpers/ServletUtils
51+
com/coveros/training/mathematics/AckermannIterative$$$Field
52+
com/coveros/training/persistence/PersistenceLayer$ThrowingFunction
53+
com/coveros/training/mathematics/MathServlet
54+
com/coveros/training/mathematics/Calculator$Baz
55+
com/coveros/training/persistence/PersistenceLayer
56+
com/coveros/training/mathematics/AckermannIterative$$
57+
com/coveros/training/helpers/CheckUtils
58+
com/coveros/training/library/LibraryLendServlet
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
com/coveros/training/mathematics/Calculator$iBar
2+
com/coveros/training/authentication/LoginUtils
3+
com/coveros/training/mathematics/TailRecursive
4+
com/coveros/training/library/domainobjects/Book
5+
com/coveros/training/cartesianproduct/CartesianProduct
6+
com/coveros/training/mathematics/Calculator$iFoo
7+
com/coveros/training/library/LibraryBookListSearchServlet
8+
com/coveros/training/mathematics/FunctionalField
9+
com/coveros/training/mathematics/Fibonacci
10+
com/coveros/training/expenses/AlcoholCalculator
11+
com/coveros/training/library/LibraryBorrowerListSearchServlet
12+
com/coveros/training/persistence/NotImplementedException
13+
com/coveros/training/mathematics/AckermannIterative
14+
com/coveros/training/library/domainobjects/Loan
15+
com/coveros/training/authentication/domainobjects/User
16+
com/coveros/training/mathematics/AckServlet
17+
com/coveros/training/authentication/LoginServlet
18+
com/coveros/training/mathematics/Calculator$Bar
19+
com/coveros/training/mathematics/FibServlet
20+
com/coveros/training/mathematics/AckermannIterative$$$FunctionalAckermann
21+
com/coveros/training/authentication/RegistrationUtils
22+
com/coveros/training/library/LibraryBookListAvailableServlet
23+
com/coveros/training/expenses/AlcoholResult
24+
com/coveros/training/authentication/domainobjects/RegistrationResult
25+
com/coveros/training/helpers/AssertionException
26+
com/coveros/training/persistence/SqlData
27+
com/coveros/training/mathematics/Calculator
28+
javax/servlet/http/HttpServlet
29+
com/coveros/training/persistence/EmptyDataSource
30+
com/coveros/training/library/domainobjects/LibraryActionResults
31+
com/coveros/training/library/LibraryRegisterBookServlet
32+
com/coveros/training/persistence/ParameterObject
33+
com/coveros/training/persistence/DbServlet
34+
com/coveros/training/mathematics/FibonacciIterative
35+
com/coveros/training/persistence/IPersistenceLayer
36+
com/coveros/training/authentication/domainobjects/PasswordResult
37+
com/coveros/training/library/domainobjects/Borrower
38+
com/coveros/training/persistence/SqlRuntimeException
39+
com/coveros/training/helpers/StringUtils
40+
com/coveros/training/authentication/domainobjects/RegistrationStatusEnums
41+
com/coveros/training/mathematics/Calculator$Foo
42+
com/coveros/training/library/LibraryUtils
43+
com/coveros/training/expenses/DinnerPrices
44+
com/coveros/training/tomcat/WebAppListener
45+
com/coveros/training/library/LibraryRegisterBorrowerServlet
46+
com/coveros/training/mathematics/Ackermann
47+
com/coveros/training/mathematics/AckermannIterative$1
48+
com/coveros/training/mathematics/TailRecursive$$
49+
com/coveros/training/authentication/domainobjects/PasswordResultEnums
50+
com/coveros/training/authentication/RegisterServlet
51+
com/coveros/training/helpers/ServletUtils
52+
com/coveros/training/mathematics/AckermannIterative$$$Field
53+
com/coveros/training/persistence/PersistenceLayer
54+
com/coveros/training/persistence/PersistenceLayer$ThrowingFunction
55+
com/coveros/training/mathematics/MathServlet
56+
com/coveros/training/mathematics/AckermannIterative$$
57+
com/coveros/training/helpers/CheckUtils
58+
com/coveros/training/mathematics/Calculator$Baz
59+
com/coveros/training/library/LibraryLendServlet

0 commit comments

Comments
 (0)