Skip to content

Commit 4812f0a

Browse files
Add failing test
1 parent c778dc2 commit 4812f0a

File tree

41 files changed

+574
-7
lines changed

Some content is hidden

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

41 files changed

+574
-7
lines changed

src/test/java/org/javamodularity/moduleplugin/ModulePluginSmokeTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void before() throws IOException {
3737
}
3838

3939
@CartesianProductTest(name = "smokeTest({arguments})")
40-
@CartesianValueSource(strings = {"test-project", "test-project-kotlin", "test-project-groovy"})
40+
@CartesianValueSource(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"})
4141
@CartesianValueSource(strings = {"5.1", "5.6", "6.3", "6.4.1", "6.5.1", "6.8.3", "7.0", "7.2"})
4242
void smokeTest(String projectName, String gradleVersion) {
4343
LOGGER.lifecycle("Executing smokeTest of {} with Gradle {}", projectName, gradleVersion);
@@ -60,7 +60,7 @@ void smokeTest(String projectName, String gradleVersion) {
6060
}
6161

6262
@CartesianProductTest(name = "smokeTestRun({arguments})")
63-
@CartesianValueSource(strings = {"test-project", "test-project-kotlin", "test-project-groovy"})
63+
@CartesianValueSource(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"})
6464
@CartesianValueSource(strings = {"5.1", "5.6", "6.3", "6.4.1", "6.5.1", "6.8.3", "7.0", "7.2"})
6565
void smokeTestRun(String projectName, String gradleVersion) {
6666
LOGGER.lifecycle("Executing smokeTestRun of {} with Gradle {}", projectName, gradleVersion);
@@ -158,7 +158,7 @@ private static void assertExpectedClassFileFormats(
158158
}
159159

160160
@CartesianProductTest(name = "smokeTestDist({arguments})")
161-
@CartesianValueSource(strings = {"test-project", "test-project-kotlin", "test-project-groovy"})
161+
@CartesianValueSource(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"})
162162
@CartesianValueSource(strings = {"5.1", "5.6", "6.3", "6.4.1", "6.5.1", "6.8.3", "7.0", "7.2"})
163163
void smokeTestDist(String projectName, String gradleVersion) {
164164
LOGGER.lifecycle("Executing smokeTestDist of {} with Gradle {}", projectName, gradleVersion);
@@ -199,7 +199,7 @@ void smokeTestDist(String projectName, String gradleVersion) {
199199
}
200200

201201
@CartesianProductTest(name = "smokeTestRunDemo({arguments})")
202-
@CartesianValueSource(strings = {"test-project", "test-project-kotlin", "test-project-groovy"})
202+
@CartesianValueSource(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"})
203203
@CartesianValueSource(strings = {"5.1", "5.6", "6.3", "6.4.1", "6.5.1", "6.8.3", "7.0", "7.2"})
204204
void smokeTestRunDemo(String projectName, String gradleVersion) {
205205
LOGGER.lifecycle("Executing smokeTestRunDemo of {} with Gradle {}", projectName, gradleVersion);
@@ -218,7 +218,7 @@ void smokeTestRunDemo(String projectName, String gradleVersion) {
218218
}
219219

220220
@CartesianProductTest(name = "smokeTestRunStartScripts({arguments})")
221-
@CartesianValueSource(strings = {"test-project", "test-project-kotlin", "test-project-groovy"})
221+
@CartesianValueSource(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"})
222222
@CartesianValueSource(strings = {"5.1", "5.6", "6.3", "6.4.1", "6.5.1", "6.8.3", "7.0", "7.2"})
223223
void smokeTestRunStartScripts(String projectName, String gradleVersion) {
224224
LOGGER.lifecycle("Executing smokeTestRunScripts of {} with Gradle {}", projectName, gradleVersion);
@@ -248,7 +248,9 @@ private static void assertTasksSuccessful(BuildResult result, String subprojectN
248248
}
249249

250250
private static boolean checkCombination(String projectName, String gradleVersion) {
251-
if(projectName.equals("test-project-kotlin") && gradleVersion.compareTo("6.4") < 0) {
251+
final boolean kotlin_NotSupported = projectName.startsWith("test-project-kotlin") && gradleVersion.compareTo("6.4") < 0;
252+
final boolean kotlin1_7_NotSupported = projectName.equals("test-project-kotlin") && gradleVersion.compareTo("6.6") < 0;
253+
if (kotlin_NotSupported || kotlin1_7_NotSupported) {
252254
LOGGER.lifecycle("Unsupported combination: {} / Gradle {}. Test skipped", projectName, gradleVersion);
253255
return false;
254256
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Introduction
2+
===
3+
4+
This Kotlin test project can be used as a standalone test project to verify the published plugin.
5+
It is also used as an internal test project for testing unpublished plugin changes.
6+
7+
Standalone test product
8+
===
9+
To run this product as a standalone test product use this command (launched from `test-project-kotlin` directory):
10+
```
11+
../gradlew clean build
12+
```
13+
14+
It will use the most recent plugin version from Gradle maven repository to compile the test project with
15+
modules and run the unit tests.
16+
17+
Testing locally published plugin
18+
===
19+
20+
You can publish the plugin locally by running this command from the root directory:
21+
22+
`./gradlew publishToMavenLocal`
23+
24+
You can test the locally published plugin by running the following command from `test-project-kotlin` directory.
25+
26+
`../gradlew -c local_maven_settings.gradle clean build`
27+
28+
It will use the locally published version of the plugin to compile the test project with
29+
modules and run the unit tests.
30+
31+
32+
Internal test project
33+
===
34+
35+
This mode is enabled in `ModulePluginSmokeTest` by passing an extra parameter (`-c smoke_test_settings.gradle`).
36+
`smoke_test_settings.gradle` script configures plugin management for `build.gradle.kts` so that the plugin cannot be resolved from
37+
a Gradle plugin repository. Instead, it relies on the smoke test to make the plugin under development available
38+
to the test project by sharing a classpath (using Gradle TestKit).
39+
40+
__CAUTION:__ This approach won't work outside of the smoke test, it will break the build because the plugin jar won't be resolved.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
kotlin("jvm") version "1.3.72" apply false
5+
id("org.javamodularity.moduleplugin") version "1.8.11" apply false
6+
}
7+
8+
subprojects {
9+
apply(plugin = "kotlin")
10+
apply(plugin = "org.javamodularity.moduleplugin")
11+
12+
//region https://docs.gradle.org/current/userguide/kotlin_dsl.html#using_kotlin_delegated_properties
13+
val test by tasks.existing(Test::class)
14+
val build by tasks
15+
val javadoc by tasks
16+
17+
val implementation by configurations
18+
val testImplementation by configurations
19+
val testRuntimeOnly by configurations
20+
21+
val jUnitVersion: String by project
22+
val jUnitPlatformVersion: String by project
23+
//endregion
24+
25+
//region KOTLIN
26+
tasks.withType<KotlinCompile> {
27+
kotlinOptions.jvmTarget = "1.8"
28+
}
29+
dependencies {
30+
implementation(kotlin("stdlib-jdk8"))
31+
}
32+
//endregion
33+
34+
repositories {
35+
mavenCentral()
36+
}
37+
38+
configure<org.javamodularity.moduleplugin.extensions.ModularityExtension> {
39+
improveEclipseClasspathFile()
40+
moduleVersion("1.2.3")
41+
}
42+
43+
test {
44+
useJUnitPlatform()
45+
46+
testLogging {
47+
events("PASSED", "FAILED", "SKIPPED", "STANDARD_OUT")
48+
}
49+
}
50+
51+
dependencies {
52+
testImplementation("org.junit.jupiter:junit-jupiter-api:$jUnitVersion")
53+
testImplementation("org.junit.jupiter:junit-jupiter-params:$jUnitVersion")
54+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
55+
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$jUnitPlatformVersion")
56+
}
57+
58+
// build.dependsOn(javadoc) // TODO: No public or protected classes found to document
59+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jUnitVersion = 5.6.2
2+
jUnitPlatformVersion = 1.6.2
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions
2+
import org.javamodularity.moduleplugin.extensions.TestModuleOptions
3+
4+
//region NO-OP (DSL testing)
5+
tasks.compileJava {
6+
extensions.configure<CompileModuleOptions> {
7+
addModules = listOf()
8+
compileModuleInfoSeparately = false
9+
}
10+
}
11+
12+
tasks.test {
13+
extensions.configure<TestModuleOptions> {
14+
addModules = listOf()
15+
runOnClasspath = false
16+
}
17+
}
18+
19+
modularity {
20+
}
21+
//endregion
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module greeter.api {
2+
exports examples.greeter.api;
3+
requires kotlin.stdlib;
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package examples.greeter.api
2+
3+
interface Greeter {
4+
fun hello(): String
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import org.javamodularity.moduleplugin.tasks.ModularJavaExec
2+
3+
val moduleName: String by project
4+
5+
dependencies {
6+
implementation(project(":greeter.api"))
7+
runtimeOnly(project(":greeter.provider"))
8+
}
9+
10+
patchModules.config = listOf(
11+
"java.annotation=jsr305-3.0.2.jar"
12+
)
13+
modularity {
14+
patchModule("java.annotation", "jsr250-api-1.0.jar")
15+
}
16+
17+
File("${project.projectDir}/src/main/kotlin/demo")
18+
.listFiles({ _, name -> Regex("Demo.*\\.kt") matches name })
19+
.forEach { file ->
20+
val demoClassName = file.name.removeSuffix(".kt")
21+
tasks.create<ModularJavaExec>("run$demoClassName") {
22+
group = "Demo"
23+
description = "Run the $demoClassName program"
24+
mainClass.set("demo.${demoClassName}Kt")
25+
mainModule.set(moduleName)
26+
jvmArgs = listOf("-Xmx128m")
27+
}
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import examples.greeter.api.Greeter;
2+
3+
module greeter.javaexec {
4+
requires greeter.api;
5+
requires kotlin.stdlib;
6+
7+
uses Greeter;
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package demo
2+
3+
import examples.greeter.api.Greeter
4+
5+
import java.util.ServiceLoader
6+
7+
fun main(args: Array<String>) {
8+
val greeter = ServiceLoader.load(Greeter::class.java)
9+
.findFirst()
10+
.orElseThrow{RuntimeException("No Greeter found!")}
11+
println("Demo1: " + greeter.hello())
12+
}

0 commit comments

Comments
 (0)