forked from java9-modularity/gradle-modules-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
java9-modularity#72: added test-project-mixed
tests the "modularity" extension (incl. verifying generated class file formats)
- Loading branch information
1 parent
c5b98dc
commit bf40098
Showing
40 changed files
with
461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Introduction | ||
=== | ||
|
||
This mixed test project can be used as a standalone test project to verify the published plugin. | ||
It is also used as an internal test project for testing unpublished plugin changes. | ||
|
||
This project is "mixed" in two ways: | ||
|
||
1. It produces classes targeting mixed JDKs (JDK 8 and JDK 11). The project makes use of the | ||
[`ModularityExtension`](../src/main/java/org/javamodularity/moduleplugin/extensions/ModularityExtension.java), | ||
which in turn makes use of the Java compiler | ||
[`--release`](https://docs.oracle.com/en/java/javase/11/tools/javac.html) option. | ||
2. It contains mixed build files: `build.gradle` (Groovy DSL) and `build.gradle.kts` (Kotlin DSL). | ||
|
||
Standalone test product | ||
=== | ||
To run this product as a standalone test product use this command (launched from `test-project-mixed` directory): | ||
``` | ||
../gradlew clean build | ||
``` | ||
|
||
It will use the most recent plugin version from Gradle maven repository to compile the test project with | ||
modules and run the unit tests. | ||
|
||
Testing locally published plugin | ||
=== | ||
|
||
You can publish the plugin locally by running this command from the root directory: | ||
|
||
`./gradlew publishToMavenLocal` | ||
|
||
You can test the locally published plugin by running the following command from `test-project-mixed` directory. | ||
|
||
`../gradlew -c local_maven_settings.gradle clean build` | ||
|
||
It will use the latest locally published version of the plugin to compile the test project with | ||
modules and run the unit tests. | ||
|
||
|
||
Internal test project | ||
=== | ||
|
||
This mode is enabled in `ModulePluginSmokeTest` by passing an extra parameter (`-c smoke_test_settings.gradle`). | ||
`smoke_test_settings.gradle` script configures plugin management so that the plugin cannot be resolved from | ||
a Gradle plugin repository. Instead, it relies on the smoke test to make the plugin under development available | ||
to the test project by sharing a classpath (using Gradle TestKit). | ||
|
||
__CAUTION:__ This approach won't work outside of the smoke test, it will break the build because the plugin jar won't be resolved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id 'org.javamodularity.moduleplugin' version '1.4.1' apply false | ||
} | ||
|
||
subprojects { | ||
apply plugin: 'java' | ||
apply plugin: 'org.javamodularity.moduleplugin' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
|
||
testLogging { | ||
events 'PASSED', 'FAILED', 'SKIPPED' | ||
} | ||
} | ||
|
||
dependencies { | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:$jUnitVersion" | ||
testImplementation "org.junit.jupiter:junit-jupiter-params:$jUnitVersion" | ||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion" | ||
} | ||
|
||
build.dependsOn javadoc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jUnitVersion = 5.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
dependencies { | ||
implementation project(':greeter.api-jdk8') | ||
testImplementation('org.hamcrest:hamcrest:2.1+') | ||
|
||
compile "javax.annotation:javax.annotation-api:1.3.2" | ||
compile "com.google.code.findbugs:jsr305:3.0.2" | ||
} | ||
|
||
patchModules.config = [ | ||
"java.annotation=jsr305-3.0.2.jar" | ||
] | ||
|
||
javadoc { | ||
moduleOptions { | ||
addModules = ['java.sql'] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/gradle/shared/greeter.provider.test.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencies { | ||
implementation project(':greeter.api-jdk8') | ||
} | ||
|
||
patchModules.config = [ | ||
"java.annotation=jsr305-3.0.2.jar" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
modularity.mixedJavaRelease(8) |
5 changes: 5 additions & 0 deletions
5
test-project-mixed/greeter.api-jdk8/src/main/java/examples/greeter/api/Greeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package examples.greeter.api; | ||
|
||
public interface Greeter { | ||
String hello(); | ||
} |
3 changes: 3 additions & 0 deletions
3
test-project-mixed/greeter.api-jdk8/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module greeter.api { | ||
exports examples.greeter.api; | ||
} |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk11.test-jdk11/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
modularity.standardJavaRelease(11) | ||
|
||
dependencies { | ||
runtimeOnly(project(":greeter.provider-jdk11")) | ||
} | ||
|
||
apply(from = "$rootDir/gradle/shared/greeter.provider.test.gradle") |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk11.test-jdk11/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import examples.greeter.api.Greeter; | ||
|
||
module greeter.provider.test { | ||
requires greeter.api; | ||
|
||
uses Greeter; | ||
} |
11 changes: 11 additions & 0 deletions
11
test-project-mixed/greeter.provider-jdk11.test-jdk11/src/main/java/tests/GreeterLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tests; | ||
|
||
import examples.greeter.api.Greeter; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
public class GreeterLocator { | ||
public Greeter findGreeter() { | ||
return ServiceLoader.load(Greeter.class).findFirst().orElseThrow(() -> new RuntimeException("No Greeter found")); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test-project-mixed/greeter.provider-jdk11.test-jdk11/src/test/java/tests/GreeterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tests; | ||
|
||
import examples.greeter.api.Greeter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
class GreeterTest { | ||
@Test | ||
void testLocate() { | ||
Greeter greeter = new GreeterLocator().findGreeter(); | ||
assertFalse(greeter.hello().isBlank()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
modularity.standardJavaRelease(11) | ||
|
||
apply(from = "$rootDir/gradle/shared/greeter.provider.gradle") |
18 changes: 18 additions & 0 deletions
18
test-project-mixed/greeter.provider-jdk11/src/main/java/examples/greeter/Friendly.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package examples.greeter; | ||
|
||
import examples.greeter.api.Greeter; | ||
import java.io.*; | ||
import java.util.*; | ||
import javax.annotation.Nonnull; | ||
|
||
public class Friendly implements Greeter { | ||
@Override @Nonnull | ||
public String hello() { | ||
var stream = this.getClass().getResourceAsStream("/greeting.txt"); | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "utf-8"))) { | ||
return reader.readLine(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test-project-mixed/greeter.provider-jdk11/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import examples.greeter.api.Greeter; | ||
|
||
module greeter.provider { | ||
requires greeter.api; | ||
requires java.annotation; | ||
|
||
provides Greeter with examples.greeter.Friendly; | ||
} |
1 change: 1 addition & 0 deletions
1
test-project-mixed/greeter.provider-jdk11/src/main/resources/greeting.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
welcome |
14 changes: 14 additions & 0 deletions
14
test-project-mixed/greeter.provider-jdk11/src/test/java/examples/greeter/FriendlyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package examples.greeter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FriendlyTest { | ||
@Test | ||
void testGreeting() { | ||
String greeting = new Friendly().hello(); | ||
assertTrue(greeting.contains("welcome")); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
test-project-mixed/greeter.provider-jdk11/src/test/java/examples/greeter/ScriptingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package examples.greeter; | ||
|
||
import javax.script.*; | ||
import org.junit.jupiter.api.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
class ScriptingTest { | ||
|
||
@Test | ||
void testScripting() { | ||
ScriptEngineManager manager = new ScriptEngineManager(); | ||
assertThat(manager.getEngineFactories(), not(nullValue())); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk11/src/test/java/module-info.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// make module visible | ||
--add-modules | ||
java.scripting,org.hamcrest | ||
|
||
// "requires java.scripting" | ||
--add-reads | ||
greeter.provider=java.scripting,org.hamcrest |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk8.test-jdk11/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
modularity.standardJavaRelease 11 | ||
|
||
dependencies { | ||
runtimeOnly project(':greeter.provider-jdk8') | ||
} | ||
|
||
apply from: "$rootDir/gradle/shared/greeter.provider.test.gradle" |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk8.test-jdk11/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import examples.greeter.api.Greeter; | ||
|
||
module greeter.provider.test { | ||
requires greeter.api; | ||
|
||
uses Greeter; | ||
} |
11 changes: 11 additions & 0 deletions
11
test-project-mixed/greeter.provider-jdk8.test-jdk11/src/main/java/tests/GreeterLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tests; | ||
|
||
import examples.greeter.api.Greeter; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
public class GreeterLocator { | ||
public Greeter findGreeter() { | ||
return ServiceLoader.load(Greeter.class).findFirst().orElseThrow(() -> new RuntimeException("No Greeter found")); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test-project-mixed/greeter.provider-jdk8.test-jdk11/src/test/java/tests/GreeterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tests; | ||
|
||
import examples.greeter.api.Greeter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
class GreeterTest { | ||
@Test | ||
void testLocate() { | ||
Greeter greeter = new GreeterLocator().findGreeter(); | ||
assertFalse(greeter.hello().isBlank()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test-project-mixed/greeter.provider-jdk8.test-jdk8/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
modularity.mixedJavaRelease 8 | ||
|
||
dependencies { | ||
runtimeOnly project(':greeter.provider-jdk8') | ||
} | ||
|
||
apply from: "$rootDir/gradle/shared/greeter.provider.test.gradle" |
Oops, something went wrong.