Skip to content

Commit

Permalink
Merge pull request #24 from IntershopCommunicationsAG/rework
Browse files Browse the repository at this point in the history
Move used language to kotlin and add also tests for kts.
  • Loading branch information
m-raab authored Dec 9, 2019
2 parents 2cfadbb + b3f84a6 commit 6541d8c
Show file tree
Hide file tree
Showing 24 changed files with 3,045 additions and 1,447 deletions.
56 changes: 51 additions & 5 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ This plugin generates Java code from schema files (see https://jaxb.java.net/jax
== Usage
To apply the JAXB Gradle Plugin to your projects, add the following in your build script:

++++
<details open>
<summary>Groovy</summary>
++++

[source,groovy]
[subs=+attributes]
.build.gradle
Expand Down Expand Up @@ -40,6 +45,49 @@ jaxb {
}
----

++++
</details>
++++

++++
<details>
<summary>Kotlin</summary>
++++

[source,kotlin]
[source,kotlin]
[subs=+attributes]
.build.gradle.kts
----
plugins {
id("com.intershop.gradle.jaxb") version "{latestRevision}"
}
jaxb {
// generate java code from schema
javaGen {
//generates a 'project' schema file from existing java code
register("name") {
schema = file("schema.xsd")
binding = file("binding.xjb")
}
}
//generates schema from java code
schemaGen {
//generates java code for project from project schema
register("name") {
javaFiles = fileTree("dir" to "src/main/java", "include" to "com/corporate/annotated/**/binding/**/*.java")
namespaceconfigs = mapOf("http://www.corporate.com/xml/ns/corporate/feature/1.0" to "feature.xsd")
}
}
}
----

++++
</details>
++++

If the JavaBasePlugin is applied to the project, generated java sources will be added to the specified source set. Per default the main source set is used.

IMPORTANT: This plugin uses the following dependencies: +
Expand All @@ -52,6 +100,8 @@ The classpath of the xjc can be extended with a project configuration 'jaxb' and

This configuration is used, because 'org.glassfish.jaxb:jaxb-runtime:2.3.2' does not contain a classpath configuration in the manifest.

It is possible to add additional dependencies to the configured "jaxb" with the configuration "jaxbext".

== Tasks
The JAXB Gradle plugin adds one task `jaxb` to the project. This task depends on all other plugin task. It is a task added for each configuration in schemaGen and javaGen.

Expand Down Expand Up @@ -203,10 +253,6 @@ plugins {
def xewFile = file('staticfiles/definition/xew-includes.txt')
def args = ['-Xxew', '-Xxew:instantiate early', '-Xxew:delete', "-Xxew:includeFile \${xewFile.absolutePath.replace('\\','/')}"]
configurations {
xjc
}
jaxb {
javaGen {
gcdm {
Expand All @@ -220,7 +266,7 @@ plugins {
}
dependencies {
xjc 'com.github.jaxb-xew-plugin:jaxb-xew-plugin:1.1'
jaxbext 'com.github.jaxb-xew-plugin:jaxb-xew-plugin:1.1'
}
----

Expand Down
44 changes: 28 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
// project plugins
`java-gradle-plugin`
groovy
id("nebula.kotlin") version "1.3.61"

// test coverage
jacoco
Expand All @@ -37,6 +38,12 @@ plugins {
// plugin for documentation
id("org.asciidoctor.jvm.convert") version "2.3.0"

// documentation
id("org.jetbrains.dokka") version "0.10.0"

// code analysis for kotlin
id("io.gitlab.arturbosch.detekt") version "1.1.1"

// plugin for publishing to Gradle Portal
id("com.gradle.plugin-publish") version "0.10.1"

Expand Down Expand Up @@ -77,18 +84,16 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets.main {
java.setSrcDirs(listOf<String>())
withConvention(GroovySourceSet::class) {
groovy.setSrcDirs(mutableListOf("src/main/groovy", "src/main/java"))
}
}

// set correct project status
if (project.version.toString().endsWith("-SNAPSHOT")) {
status = "snapshot'"
}

detekt {
input = files("src/main/kotlin")
config = files("detekt.yml")
}

tasks {
withType<Test>().configureEach {
systemProperty("intershop.gradle.versions", "5.6.4, 6.0")
Expand Down Expand Up @@ -165,7 +170,18 @@ tasks {
getByName("bintrayUpload")?.dependsOn("asciidoctor")
getByName("jar")?.dependsOn("asciidoctor")

val compileKotlin by getting(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
kotlinOptions.jvmTarget = "1.8"
}

val dokka by existing(org.jetbrains.dokka.gradle.DokkaTask::class) {
outputFormat = "javadoc"
outputDirectory = "$buildDir/javadoc"

// Java 8 is only version supported both by Oracle/OpenJDK and Dokka itself
// https://github.com/Kotlin/dokka/issues/294
enabled = JavaVersion.current().isJava8
}

register<Jar>("sourceJar") {
description = "Creates a JAR that contains the source code."
Expand All @@ -175,9 +191,9 @@ tasks {
}

register<Jar>("javaDoc") {
dependsOn(groovydoc)
from(groovydoc)
getArchiveClassifier().set("javadoc")
dependsOn(dokka)
from(dokka)
archiveClassifier.set("javadoc")
}
}

Expand Down Expand Up @@ -253,16 +269,12 @@ bintray {

dependencies {
compileOnly("org.jetbrains:annotations:17.0.0")

implementation(gradleKotlinDsl())

testImplementation("commons-io:commons-io:2.2")
testImplementation("com.intershop.gradle.test:test-gradle-plugin:3.4.0")
testImplementation(gradleTestKit())

//testImplementation("org.glassfish.jaxb:jaxb-runtime:2.3.3-b01")
//testImplementation("com.sun.xml.bind:jaxb-jxc:2.2.11")
//testImplementation("com.sun.xml.bind:jaxb-xjc:2.2.11")
//testImplementation("com.sun.xml.bind:jaxb-core:2.2.11")

}

repositories {
Expand Down
Loading

0 comments on commit 6541d8c

Please sign in to comment.