Skip to content

Commit

Permalink
Add samples and test runner for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed May 11, 2022
1 parent 93e9fd2 commit b6103da
Show file tree
Hide file tree
Showing 45 changed files with 506 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build Plugin
on: [ push, pull_request ]
jobs:
gradle-build:
runs-on: ubuntu-latest
steps:
- name: git clone
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: 11
- name: gradle build
id: gradle
uses: gradle/[email protected]
with:
arguments: :build
16 changes: 16 additions & 0 deletions samples/use-all-java-module-plugins/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id("org.my.gradle.java-module")
id("application")
}

application {
applicationDefaultJvmArgs = listOf("-ea")
mainClass.set("org.my.app.App")
mainModule.set("org.my.app")
}

dependencies {
javaModuleDependencies {
runtimeOnly(gav("org.slf4j.simple"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open module org.my.app.integtest {
requires org.my.app;
requires org.junit.jupiter.api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.my.app.integtest;

import org.junit.jupiter.api.Test;
import org.my.app.App;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class AppIntegTest {

@Test
public void appDoesNotExplode() throws IOException {
assertTrue(App.doWork());

try (InputStream is = AppIntegTest.class.getResourceAsStream("AppTestData.txt")) {
System.out.println(new BufferedReader(new InputStreamReader(is)).readLine());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is balackbox test data
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module org.my.app {
requires org.slf4j;
requires org.my.lib;
requires org.apache.xmlbeans;

exports org.my.app;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.my.app;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.spi.LoggerFactoryBinder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class App {
public static void main(String[] args) throws IOException {
doWork();
}

public static boolean doWork() throws IOException {
ObjectMapper om = new ObjectMapper();
if (!om.canSerialize(LoggerFactoryBinder.class)) {
throw new RuntimeException("Boom!");
}
System.out.println(App.class.getModule().getName());

printData();

return true;
}

protected static void printData() throws IOException {
try (InputStream is = App.class.getResourceAsStream("AppData.txt")) {
System.out.println(new BufferedReader(new InputStreamReader(is)).readLine());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is data
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.my.app;

import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AppWhiteboxTest {

@Test
public void printDataTest() throws IOException {
App.printData();
assertEquals("org.my.app", AppWhiteboxTest.class.getModule().getName());

try (InputStream is = AppWhiteboxTest.class.getResourceAsStream("AppTestData.txt")) {
System.out.println(new BufferedReader(new InputStreamReader(is)).readLine());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is whitebox test data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation("de.jjohannes.gradle:extra-java-module-info:0.12")
implementation("de.jjohannes.gradle:java-module-dependencies:0.7")
implementation("de.jjohannes.gradle:java-module-testing:0.1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
repositories.gradlePluginPortal()
}

// This is for testing against the latest version of the plugin, remove if you copied this for a real project
includeBuild(extra.properties["pluginLocation"] ?: rootDir.parentFile.parentFile.parent)

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("de.jjohannes.extra-java-module-info")
id("de.jjohannes.java-module-dependencies")
}

group = "org.my"

extraJavaModuleInfo {
automaticModule("org.apache.commons:commons-math3", "commons.math3")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id("java")
id("org.my.gradle.base")
id("de.jjohannes.java-module-testing")
}

javaModuleTesting.whitebox(
testing.suites.getByName<JvmTestSuite>("test") {
useJUnitJupiter("")
targets.all {
testTask { jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error") }
}
}
) {
requires.add("org.junit.jupiter.api")
opensTo.add("org.junit.platform.commons")
}

javaModuleTesting.blackbox(
testing.suites.create<JvmTestSuite>("integtest") {
useJUnitJupiter("")
testType.set("blackbox")
dependencies {
implementation(project.dependencies.platform(project(":platform")))
}
targets.all {
testTask { jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error") }
}
tasks.check { dependsOn(targets) }
}
)

dependencies {
implementation(platform(project(":platform")))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
id("java-platform")
id("org.my.gradle.base")
}

javaPlatform.allowDependencies() // Use existing Platforms/BOMs
3 changes: 3 additions & 0 deletions samples/use-all-java-module-plugins/build.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> Task :app:run
org.my.app
This is data
2 changes: 2 additions & 0 deletions samples/use-all-java-module-plugins/build.sample.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
executable: gradlew
expected-output-file: build.out
4 changes: 4 additions & 0 deletions samples/use-all-java-module-plugins/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id("org.my.gradle.java-module")
id("java-library")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open module org.my.lib.integtest {
requires org.my.lib;
requires org.junit.jupiter.api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module org.my.lib {
requires transitive com.fasterxml.jackson.databind;

// Patched to be a module
requires commons.math3;

// JDK modules
requires java.logging;
requires jdk.charsets;
}
18 changes: 18 additions & 0 deletions samples/use-all-java-module-plugins/platform/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("org.my.gradle.platform")
}


dependencies {
api(platform("com.fasterxml.jackson:jackson-bom:2.13.2"))
api(platform("org.junit:junit-bom:5.7.2"))
}

dependencies.constraints {
javaModuleDependencies {
api(gav("commons.math3", "3.6.1"))
api(gav("org.apache.xmlbeans", "5.0.1"))
api(gav("org.slf4j", "1.7.28"))
api(gav("org.slf4j.simple", "1.7.28"))
}
}
9 changes: 9 additions & 0 deletions samples/use-all-java-module-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pluginManagement {
includeBuild("build-logic")
}
dependencyResolutionManagement {
repositories.mavenCentral()
}

include("app", "lib")
include("platform")
20 changes: 20 additions & 0 deletions samples/use-only-java-module-testing-plugin/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id("org.my.gradle.java-module")
id("application")
}

application {
applicationDefaultJvmArgs = listOf("-ea")
mainClass.set("org.my.app.App")
mainModule.set("org.my.app")
}

dependencies {
implementation(project(":lib"))
implementation("org.apache.xmlbeans:xmlbeans")
implementation("org.slf4j:slf4j-api")

integtestImplementation(project(path))

runtimeOnly("org.slf4j:slf4j-simple")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open module org.my.app.integtest {
requires org.my.app;
requires org.junit.jupiter.api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.my.app.integtest;

import org.junit.jupiter.api.Test;
import org.my.app.App;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class AppIntegTest {

@Test
public void appDoesNotExplode() throws IOException {
assertTrue(App.doWork());

try (InputStream is = AppIntegTest.class.getResourceAsStream("AppTestData.txt")) {
System.out.println(new BufferedReader(new InputStreamReader(is)).readLine());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is balackbox test data
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module org.my.app {
requires org.slf4j;
requires org.my.lib;
requires org.apache.xmlbeans;

exports org.my.app;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.my.app;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.spi.LoggerFactoryBinder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class App {
public static void main(String[] args) throws IOException {
doWork();
}

public static boolean doWork() throws IOException {
ObjectMapper om = new ObjectMapper();
if (!om.canSerialize(LoggerFactoryBinder.class)) {
throw new RuntimeException("Boom!");
}
System.out.println(App.class.getModule().getName());
printData();

return true;
}

protected static void printData() throws IOException {
try (InputStream is = App.class.getResourceAsStream("AppData.txt")) {
System.out.println(new BufferedReader(new InputStreamReader(is)).readLine());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is data
Loading

0 comments on commit b6103da

Please sign in to comment.