Skip to content

Commit

Permalink
Restore compatibility with Gradle 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornvester committed Apr 13, 2021
1 parent 6b8d529 commit 8ed6b82
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 32 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
java: [ '8', '11', '15' ]

name: Java ${{ matrix.java }}

steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
java-version: 11
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
Expand All @@ -30,7 +24,4 @@ jobs:
locale
./gradlew --version
- name: Build plugin
run: ./gradlew build
- name: Run integration test
working-directory: ./integration-test
run: ../gradlew build
run: ./gradlew check
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[![Gradle Plugin Release](https://img.shields.io/badge/Gradle%20plugin-1.4-blue.svg?logo=data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA5MCA2Ni4wNiI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiNmZmY7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5ncmFkbGUtZWxlcGhhbnQtaWNvbi13aGl0ZS1wcmltYXJ5PC90aXRsZT48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik04NS4xMSw0LjE4YTE0LjI3LDE0LjI3LDAsMCwwLTE5LjgzLS4zNCwxLjM4LDEuMzgsMCwwLDAsMCwyTDY3LDcuNmExLjM2LDEuMzYsMCwwLDAsMS43OC4xMkE4LjE4LDguMTgsMCwwLDEsNzkuNSwyMC4wNkM2OC4xNywzMS4zOCw1My4wNS0uMzYsMTguNzMsMTZhNC42NSw0LjY1LDAsMCwwLTIsNi41NGw1Ljg5LDEwLjE3YTQuNjQsNC42NCwwLDAsMCw2LjMsMS43M2wuMTQtLjA4LS4xMS4wOEwzMS41MywzM2E2MC4yOSw2MC4yOSwwLDAsMCw4LjIyLTYuMTMsMS40NCwxLjQ0LDAsMCwxLDEuODctLjA2aDBhMS4zNCwxLjM0LDAsMCwxLC4wNiwyQTYxLjYxLDYxLjYxLDAsMCwxLDMzLDM1LjM0bC0uMDksMC0yLjYxLDEuNDZhNy4zNCw3LjM0LDAsMCwxLTMuNjEuOTQsNy40NSw3LjQ1LDAsMCwxLTYuNDctMy43MWwtNS41Ny05LjYxQzQsMzItMi41NCw0Ni41NiwxLDY1YTEuMzYsMS4zNiwwLDAsMCwxLjMzLDEuMTFIOC42MUExLjM2LDEuMzYsMCwwLDAsMTAsNjQuODdhOS4yOSw5LjI5LDAsMCwxLDE4LjQyLDAsMS4zNSwxLjM1LDAsMCwwLDEuMzQsMS4xOUgzNS45YTEuMzYsMS4zNiwwLDAsMCwxLjM0LTEuMTksOS4yOSw5LjI5LDAsMCwxLDE4LjQyLDBBMS4zNiwxLjM2LDAsMCwwLDU3LDY2LjA2SDYzLjFhMS4zNiwxLjM2LDAsMCwwLDEuMzYtMS4zNGMuMTQtOC42LDIuNDYtMTguNDgsOS4wNy0yMy40M0M5Ni40MywyNC4xNiw5MC40MSw5LjQ4LDg1LjExLDQuMThaTTYxLjc2LDMwLjA1bC00LjM3LTIuMTloMGEyLjc0LDIuNzQsMCwxLDEsNC4zNywyLjJaIi8+PC9zdmc+)](https://plugins.gradle.org/plugin/com.github.bjornvester.xjc)
[![Gradle Plugin Release](https://img.shields.io/badge/Gradle%20plugin-1.5.1-blue.svg?logo=data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vc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M2LDAsMCwwLDEuMzYtMS4zNGMuMTQtOC42LDIuNDYtMTguNDgsOS4wNy0yMy40M0M5Ni40MywyNC4xNiw5MC40MSw5LjQ4LDg1LjExLDQuMThaTTYxLjc2LDMwLjA1bC00LjM3LTIuMTloMGEyLjc0LDIuNzQsMCwxLDEsNC4zNywyLjJaIi8+PC9zdmc+)](https://plugins.gradle.org/plugin/com.github.bjornvester.xjc)
[![GitHub Actions status](https://github.com/bjornvester/xjc-gradle-plugin/workflows/CI/badge.svg)](https://github.com/bjornvester/xjc-gradle-plugin/actions)

# xjc-gradle-plugin
A Gradle plugin for running the XJC binding compiler to generate Java source code from XML schemas (xsd files) using JAXB.

## Requirements and features
* **The plugin requires Gradle version 6.0 or later**.
* **The plugin requires Gradle version 6.0 or later**. (Tested with Gradle 6.0 and 7.0.)

* It has been tested with Java 8, Java 11 and Java 15.
* It has been tested with Java 8, Java 11 and Java 16.

* It has been tested with XJC version 2.3.3 and 3.0.0 (from Jakarta EE). Defaults to 2.3.3.

Expand All @@ -27,7 +27,7 @@ Apply the plugin ID "com.github.bjornvester.xjc" as documented in the [Gradle Pl

```kotlin
plugins {
id("com.github.bjornvester.xjc") version "1.5.0"
id("com.github.bjornvester.xjc") version "1.5.1"
}
```

Expand Down Expand Up @@ -122,7 +122,7 @@ If you like to have the generated source code marked with the `@javax.annotation

```kotlin
xjc {
markGenerated.set(false)
markGenerated.set(true)
}
```

Expand Down Expand Up @@ -199,7 +199,9 @@ dependencies {
}
```

Then create a binding file with content with the types you like to map, e.g.:
Then create a binding file with content with the types you like to map.

For XJC 2.x, it could be:

```xml
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1"
Expand All @@ -213,6 +215,12 @@ Then create a binding file with content with the types you like to map, e.g.:
</bindings>
```

For XJC 3.x, it could be:

```xml
TODO
```

Lastly, configure XJC to use the binding file (in this case it is called `src/main/bindings/bindings.xml`):

```kotlin
Expand Down
35 changes: 26 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile

plugins {
`kotlin-dsl`
id("java-gradle-plugin")
id("com.gradle.plugin-publish") version "0.13.0"
id("com.gradle.plugin-publish") version "0.14.0"
}

group = "com.github.bjornvester"
version = "1.5.0"
version = "1.5.1"

allprojects {
repositories {
jcenter()
mavenCentral()
}
}

dependencies {
compileOnly("org.glassfish.jaxb:jaxb-xjc:2.3.3")
testImplementation("commons-io:commons-io:2.8.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
tasks.withType<Test>().configureEach {
useJUnitPlatform()
systemProperty("GRADLE_ROOT_FOLDER", projectDir.absolutePath)
systemProperty("GRADLE_PLUGIN_VERSION", version)
}

tasks.withType<Wrapper> {
gradleVersion = "6.8.3"
gradleVersion = "7.0"
}

val compiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
}

tasks.withType<KotlinJvmCompile>().configureEach {
kotlinOptions.jdkHome = compiler.get().metadata.installationPath.asFile.absolutePath
}

gradlePlugin {
Expand All @@ -31,7 +47,8 @@ gradlePlugin {
id = "com.github.bjornvester.xjc"
implementationClass = "com.github.bjornvester.xjc.XjcPlugin"
displayName = "Gradle XJC plugin"
description = "A plugin that generates Java source code for XML schemas (xsd files) using the XJC tool. Supports the Gradle build cache and has been tested with Java 8 and 11. Please see the Github project page for details."
description = """A plugin that generates Java source code for XML schemas (xsd files) using the XJC tool.
|Please see the Github project page for details.""".trimMargin()
}
}
}
Expand All @@ -42,8 +59,8 @@ pluginBundle {
tags = listOf("xjc", "jaxb", "xsd")
(plugins) {
"xjcPlugin" {
description = "Changes:\n" +
"- Support XJC 3.0.0"
description = """Changes:
|- Restore support for Gradle 6.0 (while also supporting Gradle 7.0)""".trimMargin()
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 7 additions & 0 deletions integration-test/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("java")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
2 changes: 1 addition & 1 deletion integration-test/test-consumer-2x/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("com.github.bjornvester.xjc")
id("com.github.bjornvester.xjc.internal.java-conventions")
}

repositories {
Expand Down
4 changes: 3 additions & 1 deletion integration-test/test-consumer-3x/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("com.github.bjornvester.xjc")
id("com.github.bjornvester.xjc.internal.java-conventions")
}

repositories {
Expand All @@ -9,6 +9,7 @@ repositories {

dependencies {
implementation(project(":test-producer-3x"))
//implementation("io.github.threeten-jaxb:threeten-jaxb-core:1.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1")
}
Expand All @@ -19,4 +20,5 @@ tasks.test {

xjc {
xjcVersion.set("3.0.0")
//bindingFiles = files("$projectDir/src/main/bindings/bindings.xml")
}
2 changes: 1 addition & 1 deletion integration-test/test-producer-2x/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("com.github.bjornvester.xjc")
id("com.github.bjornvester.xjc.internal.java-conventions")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion integration-test/test-producer-3x/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java")
id("com.github.bjornvester.xjc")
id("com.github.bjornvester.xjc.internal.java-conventions")
}

repositories {
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ class XjcPlugin : Plugin<Project> {
addLater(extension.xjcVersion.map { project.dependencies.create("org.glassfish.jaxb:jaxb-xjc:$it") })
}

project.dependencies.addProvider(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, extension.xjcVersion.map { "jakarta.xml.bind:jakarta.xml.bind-api:$it" }, DO_NOTHING)
if (GradleVersion.current() <= GradleVersion.version("6.8")) {
project.afterEvaluate {
project.dependencies.add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, "jakarta.xml.bind:jakarta.xml.bind-api:${extension.xjcVersion.get()}")
}
} else {
// The 'addProvider' method was only added in 6.8. It is a better way to add the dependency lazily than 'afterEvaluate' (to ensure the version read from the extension is evaluated as late as possible)
project.dependencies.addProvider(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, extension.xjcVersion.map { "jakarta.xml.bind:jakarta.xml.bind-api:$it" }, DO_NOTHING)
}

project.tasks.register(XJC_TASK_NAME, XjcTask::class.java) {
val sourceSets = project.properties["sourceSets"] as SourceSetContainer
Expand Down
79 changes: 79 additions & 0 deletions src/test/kotlin/com/github/bjornvester/IntegrationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.github.bjornvester

import org.apache.commons.io.FileUtils
import org.gradle.testkit.runner.GradleRunner
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.io.File
import java.lang.management.ManagementFactory
import java.util.stream.Stream
import kotlin.text.RegexOption.DOT_MATCHES_ALL

open class IntegrationTest {
@ParameterizedTest(name = "Test plugin with Java version {0} and Gradle version {1}")
@MethodSource("provideVersions")
fun thePluginWorks(javaVersion: String, gradleVersion: String, @TempDir tempDir: File) {
runGenericBuild(javaVersion, gradleVersion, tempDir)
}

private fun runGenericBuild(javaVersion: String, gradleVersion: String, tempDir: File) {
copyIntegrationTestProject(tempDir)

// Remove the "includedBuild" declaration from the settings file
tempDir.resolve(SETTINGS_FILE).writeText(tempDir.resolve(SETTINGS_FILE).readText().replace("includeBuild(\"..\")", ""))

if (gradleVersion == "6.0") {
// If we test with an old version of Gradle that does not support toolchains, remove it
// Unfortunately, this means we have to test with whatever we are running the build with
tempDir.resolve(JAVA_CONVENTIONS_FILE)
.writeText(tempDir.resolve(JAVA_CONVENTIONS_FILE).readText().replace("toolchain \\{.*?}".toRegex(DOT_MATCHES_ALL), ""))
} else {
// Set the Java version
tempDir.resolve(JAVA_CONVENTIONS_FILE)
.writeText(tempDir.resolve(JAVA_CONVENTIONS_FILE).readText().replace("JavaLanguageVersion.of(8)", "JavaLanguageVersion.of($javaVersion)"))
}
GradleRunner
.create()
.forwardOutput()
.withProjectDir(tempDir)
.withPluginClasspath()
.withArguments("clean", "check", "-i", "--no-build-cache")
.withGradleVersion(gradleVersion)
.withDebug(isDebuggerAttached())
.build()
}

private fun copyIntegrationTestProject(tempDir: File) {
val rootFolder = File(System.getProperty("GRADLE_ROOT_FOLDER"))
val integrationTestDir = rootFolder.resolve("integration-test")
val ignoredDirNames = arrayOf("out", ".gradle", "build")

FileUtils.copyDirectory(integrationTestDir, tempDir) { copiedResource ->
ignoredDirNames.none { ignoredDir ->
copiedResource.isDirectory && copiedResource.name.toString() == ignoredDir
}
}
}

private fun isDebuggerAttached(): Boolean {
return ManagementFactory.getRuntimeMXBean().inputArguments.toString().indexOf("-agentlib:jdwp") > 0
}

companion object {
const val SETTINGS_FILE = "settings.gradle.kts"
const val JAVA_CONVENTIONS_FILE = "buildSrc/src/main/kotlin/com.github.bjornvester.xjc.internal.java-conventions.gradle.kts"

@JvmStatic
@Suppress("unused")
fun provideVersions(): Stream<Arguments?>? {
return Stream.of(
Arguments.of("8", "7.0"),
Arguments.of("11", "6.0"),
Arguments.of("11", "7.0"),
Arguments.of("16", "7.0")
)
}
}
}

0 comments on commit 8ed6b82

Please sign in to comment.