Skip to content

Commit

Permalink
adds support for multi-release-jar | rework Traces.java
Browse files Browse the repository at this point in the history
Signed-off-by: OlegDokuka <odokuka@vmware.com>
  • Loading branch information
Oleh Dokuka committed Jun 30, 2023
1 parent 2b773be commit 29ca754
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 307 deletions.
13 changes: 13 additions & 0 deletions .github/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -ex

###########################################################
# JAVA
###########################################################

mkdir -p /opt/openjdk
pushd /opt/openjdk > /dev/null
JDK_URL="https://github.com/AdoptOpenJDK/openjdk9-binaries/releases/download/jdk-9.0.4%2B11/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz"
mkdir java9
pushd java9 > /dev/null
curl -L ${JDK_URL} --output OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz
121 changes: 121 additions & 0 deletions .github/workflows/ci-mrj.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: CI
on:
pull_request:
branches:
- 3.6.x
permissions: read-all
jobs:
preliminary:
name: preliminary sanity checks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
with:
fetch-depth: 0 #needed by spotless
- run: ${GITHUB_WORKSPACE}/.github/setup.sh
shell: bash
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'jdkfile'
java-version: 9.0.4
jdkFile: /opt/openjdk/java9/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'temurin'
java-version: |
21-ea
8
- uses: gradle/gradle-build-action@3fbe033aaae657f011f88f29be9e65ed26bd29ef # tag=v2
name: spotless (license header)
if: always()
with:
arguments: spotlessCheck -PspotlessFrom=origin/${{ github.base_ref }}
- uses: gradle/gradle-build-action@3fbe033aaae657f011f88f29be9e65ed26bd29ef # tag=v2
name: api compatibility
if: always()
with:
arguments: japicmp
- name: how to fix
if: failure()
# the foreground (38;5) color code 208 is orange. we also have bold, white bg (38;5;0;48;5;255m), white fg on black bg...
run: |
echo -e "\n\033[38;5;0;48;5;208m \u001b[1m How to deal with errors in preliminary job: \u001b[0m\033[0m"
echo "(Have a look at the steps above to see what failed exactly)"
echo -e "\n - \u001b[1mSpotless (license headers)\u001b[0m failures on touched java files \033[38;5;255;48;5;0m\u001b[1mcan be automatically fixed by running\u001b[0m:"
echo -e " \033[38;5;0;48;5;255m ./gradlew spotlessApply \033[0m"
echo -e "\n - \u001b[1mAPI Compatibility\u001b[0m failures should be considered carefully and \033[38;5;255;48;5;0m\u001b[1mdiscussed with maintainers in the PR\u001b[0m"
echo " If there are failures, the detail should be available in the step's log:"
echo -e " Look for the \033[38;5;0;48;5;255m API compatibility failures \033[0m block(s)."
echo " Alternatively, locally run the following command to get access to the full report:"
echo -e " \033[38;5;0;48;5;255m ./gradlew japicmp \033[0m"
echo ""
exit -1
core-fast:
name: core fast tests
runs-on: ubuntu-latest
needs: preliminary
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
- run: ${GITHUB_WORKSPACE}/.github/setup.sh
shell: bash
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'jdkfile'
java-version: 9.0.4
jdkFile: /opt/openjdk/java9/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'temurin'
java-version: |
21-ea
8
- uses: gradle/gradle-build-action@3fbe033aaae657f011f88f29be9e65ed26bd29ef # tag=v2
name: gradle
with:
arguments: :reactor-core:test --no-daemon -Pjunit-tags=!slow
core-slow:
name: core slower tests
runs-on: ubuntu-latest
needs: preliminary
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
- run: ${GITHUB_WORKSPACE}/.github/setup.sh
shell: bash
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'jdkfile'
java-version: 9.0.4
jdkFile: /opt/openjdk/java9/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'temurin'
java-version: |
21-ea
8
- uses: gradle/gradle-build-action@3fbe033aaae657f011f88f29be9e65ed26bd29ef # tag=v2
name: gradle
with:
arguments: :reactor-core:test --no-daemon -Pjunit-tags=slow
other:
name: other tests
runs-on: ubuntu-latest
needs: preliminary
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
- run: ${GITHUB_WORKSPACE}/.github/setup.sh
shell: bash
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'jdkfile'
java-version: 9.0.4
jdkFile: /opt/openjdk/java9/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz
- uses: actions/setup-java@de1bb2b0c5634f0fc4438d7aa9944e68f9bf86cc # tag=v3
with:
distribution: 'temurin'
java-version: |
21-ea
8
- uses: gradle/gradle-build-action@3fbe033aaae657f011f88f29be9e65ed26bd29ef # tag=v2
name: other tests
with:
arguments: check -x :reactor-core:test -x spotlessCheck --no-daemon
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI
on:
pull_request: {}
pull_request:
branches-ignore:
- 3.6.x
permissions: read-all
jobs:
preliminary:
Expand Down
3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=8.0.372-librca
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ plugins {
alias(libs.plugins.nohttp)
alias(libs.plugins.jcstress) apply false
alias(libs.plugins.spotless)
alias(libs.plugins.mrjar) apply false
}

apply plugin: "io.reactor.gradle.detect-ci"
apply from: "gradle/asciidoc.gradle" // asciidoc (which is generated from root dir)
apply from: "gradle/releaser.gradle"
apply from: "gradle/dependencies.gradle"
apply from: "gradle/toolchains.gradle"

repositories { //needed at root for asciidoctor and nohttp-checkstyle
mavenCentral()
Expand Down Expand Up @@ -141,6 +143,7 @@ configure(subprojects) { p ->
apply plugin: 'java'
apply plugin: 'jacoco'
apply from: "${rootDir}/gradle/setup.gradle"
apply from: "${rootDir}/gradle/toolchains.gradle"

description = 'Non-Blocking Reactive Foundation for the JVM'
group = 'io.projectreactor'
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jcstress = { id = "io.github.reyerizo.gradle.jcstress", version = "0.8.15" }
nohttp = { id = "io.spring.nohttp", version = "0.0.11" }
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
spotless = { id = "com.diffplug.spotless", version = "6.13.0" }

mrjar = { id = "me.champeau.mrjar", version = "0.1.1" }
109 changes: 109 additions & 0 deletions gradle/toolchains.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2011-2023 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Apply the JVM Toolchain conventions
* See https://docs.gradle.org/current/userguide/toolchains.html
*
* One can choose the toolchain to use for compiling and running the TEST sources.
* These options apply to Java, Kotlin and Groovy test sources when available.
* {@code "./gradlew check -PtestToolchain=22"} will use a JDK22
* toolchain for compiling and running the test SourceSet.
*
* By default, the main build will fall back to using the a JDK 17
* toolchain (and 17 language level) for all main sourceSets.
* See {@link io.reactor.gradle.JavaConventions}.
*
* Gradle will automatically detect JDK distributions in well-known locations.
* The following command will list the detected JDKs on the host.
* {@code
* $ ./gradlew -q javaToolchains
* }
*
* We can also configure ENV variables and let Gradle know about them:
* {@code
* $ echo JDK17
* /opt/openjdk/java17
* $ echo JDK22
* /opt/openjdk/java22
* $ ./gradlew -Porg.gradle.java.installations.fromEnv=JDK17,JDK22 check
* }
*
* @author Brian Clozel
* @author Sam Brannen
*/

def testToolchainConfigured() {
return project.hasProperty('testToolchain') && project.testToolchain
}

def testToolchainLanguageVersion() {
if (testToolchainConfigured()) {
return JavaLanguageVersion.of(project.testToolchain.toString())
}
return JavaLanguageVersion.of(8)
}

plugins.withType(JavaPlugin).configureEach {
// Configure a specific Java Toolchain for compiling and running tests if the 'testToolchain' property is defined
if (testToolchainConfigured()) {
def testLanguageVersion = testToolchainLanguageVersion()
tasks.withType(JavaCompile).matching { it.name.contains("Test") }.configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testLanguageVersion
}
}
tasks.withType(Test).configureEach{
javaLauncher = javaToolchains.launcherFor {
languageVersion = testLanguageVersion
}
}
}
}

// Configure the JMH plugin to use the toolchain for generating and running JMH bytecode
pluginManager.withPlugin("me.champeau.jmh") {
if (testToolchainConfigured()) {
tasks.matching { it.name.contains('jmh') && it.hasProperty('javaLauncher') }.configureEach {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(testToolchainLanguageVersion())
})
}
tasks.withType(JavaCompile).matching { it.name.contains("Jmh") }.configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testToolchainLanguageVersion()
}
}
}
}

// Store resolved Toolchain JVM information as custom values in the build scan.
rootProject.ext {
resolvedMainToolchain = false
resolvedTestToolchain = false
}
gradle.taskGraph.afterTask { Task task, TaskState state ->
if (!resolvedMainToolchain && task instanceof JavaCompile && task.javaCompiler.isPresent()) {
def metadata = task.javaCompiler.get().metadata
task.project.buildScan.value('Main toolchain', "$metadata.vendor $metadata.languageVersion ($metadata.installationPath)")
resolvedMainToolchain = true
}
if (testToolchainConfigured() && !resolvedTestToolchain && task instanceof Test && task.javaLauncher.isPresent()) {
def metadata = task.javaLauncher.get().metadata
task.project.buildScan.value('Test toolchain', "$metadata.vendor $metadata.languageVersion ($metadata.installationPath)")
resolvedTestToolchain = true
}
}
46 changes: 11 additions & 35 deletions reactor-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apply plugin: 'biz.aQute.bnd.builder'
apply plugin: 'jvm-test-suite'
apply plugin: 'jcstress'
apply plugin: 'java-library'
apply plugin: 'me.champeau.mrjar'

ext {
bndOptions = [
Expand All @@ -43,6 +44,10 @@ ext {
]
}

multiRelease {
targetVersions 8, 9, 21
}

testing {
suites {
test {
Expand Down Expand Up @@ -347,6 +352,12 @@ if (!JavaVersion.current().isJava9Compatible()) {
}
}

if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
blockHoundTest {
jvmArgs = ["-XX:+AllowRedefinitionToAddDeleteMethods"]
}
}

jar {
manifest {
attributes 'Implementation-Title': 'reactor-core',
Expand All @@ -369,39 +380,4 @@ jacocoTestReport.dependsOn test
check.dependsOn jacocoTestReport
check.dependsOn japicmp


if (JavaVersion.current().java9Compatible) {
// SharedSecretsCallSiteSupplierFactory is a Java 8 specific optimization.
// It uses sun.misc.SharedSecrets which is unavailable on Java 9+, and the compilation would fail with JDK 9.
// This workaround allows compiling the main sourceset on JDK 9+ while still referring to the Java 8 classes.

sourceSets {
java8stubs.java.srcDirs = ['src/main/java8stubs']
}

tasks.withType(JavaCompile).all {
sourceCompatibility = targetCompatibility = 8
}

tasks.withType(Javadoc).all {
excludes = ["reactor/core/publisher/Traces.java"]
}

dependencies {
compileOnly sourceSets.java8stubs.output
}
}
else {
// reactor.core.publisher.Traces contains a strategy that only works with Java 9+.
// While compiling on Java 8, we can't access Java 9+ APIs.
// To workaround this, we "link" the main sourceset to the stubs of Java 9 APIs without having to use the Java 9 target.
sourceSets {
java9stubs.java.srcDirs = ['src/main/java9stubs']
}

dependencies {
compileOnly sourceSets.java9stubs.output
}
}

// docs.zip is added in afterEvaluate block in setup.gradle
Loading

0 comments on commit 29ca754

Please sign in to comment.