Skip to content

Commit 0eb1635

Browse files
committed
Fix episode consumption and change bindingFiles to a fileCollection
1 parent bb6e726 commit 0eb1635

File tree

8 files changed

+35
-31
lines changed

8 files changed

+35
-31
lines changed

README.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ xjc {
3939

4040
Here is a list of all available properties:
4141

42-
| Property | Type | Default | Description |
43-
|----------------------------|----------------------------|-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
44-
| xsdDir | DirectoryProperty | "$projectDir/src<br>/main/resources" | The directory holding the xsd files to compile. |
45-
| includes | ListProperty\<String> | \[empty\] | An optional include pattern for the files in the xsdDir property |
46-
| excludes | ListProperty\<String> | \[empty\] | An optional exclude pattern for the files in the xsdDir property |
47-
| bindingFiles | FileCollection | \[empty\] | The binding files to use in the schema compiler |
48-
| outputJavaDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/java" | The output directory for the generated Java sources.<br>Note that it will be deleted when running XJC. |
49-
| outputResourcesDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/resources" | The output directory for the generated resources (if any).<br>Note that it will be deleted when running XJC. |
50-
| useJakarta | Provider\<Boolean> | true | Set to use the `jakarta` namespace. If false, uses the `javax` namespace. This value determines the default version of XJC and the JAXB binding provider. |
51-
| xjcVersion | Provider\<String> | "3.0.2" for jakarta / "2.3.8" for javax | The version of XJC to use. |
52-
| defaultPackage | Provider\<String> | \[not set\] | The default package for the generated Java classes.<br>If empty, XJC will infer it from the namespace. |
53-
| generateEpisode | Provider\<Boolean> | false | If true, generates an Episode file for the generated Java classes. |
54-
| markGenerated | Provider\<Boolean> | false | If true, marks the generated code with the annotation `@javax.annotation.Generated`. |
55-
| options | ListProperty\<String> | \[empty\] | Options to pass to either the XJC core, or to third party plugins in the `xjcPlugins` configuration |
56-
| groups | NamedDomainObjectContainer | \[empty\] | Allows you to group a set of XSDs and generate sources with different configurations. Requires Gradle 7.0 or higher. See below for details. |
57-
| addCompilationDependencies | Provider\<Boolean> | true | Adds dependencies to the `implementation` configuration for compiling the generated sources. These includes `jakarta.xml.bind:jakarta.xml.bind-api` and possibly `jakarta.annotation:jakarta.annotation-api`. |
42+
| Property | Type | Default | Description |
43+
|----------------------------|----------------------------|--------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
44+
| xsdDir | DirectoryProperty | "$projectDir/src<br>/main/resources" | The directory holding the xsd files to compile. |
45+
| includes | ListProperty\<String> | \[empty\] | An optional include pattern for the files in the xsdDir property |
46+
| excludes | ListProperty\<String> | \[empty\] | An optional exclude pattern for the files in the xsdDir property |
47+
| bindingFiles | FileCollection | xsdDir.asFileTree.matching<br> { include("**/*.xjb") } | The binding files to use in the schema compiler |
48+
| outputJavaDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/java" | The output directory for the generated Java sources.<br>Note that it will be deleted when running XJC. |
49+
| outputResourcesDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/resources" | The output directory for the generated resources (if any).<br>Note that it will be deleted when running XJC. |
50+
| useJakarta | Provider\<Boolean> | true | Set to use the `jakarta` namespace. If false, uses the `javax` namespace. This value determines the default version of XJC and the JAXB binding provider. |
51+
| xjcVersion | Provider\<String> | "3.0.2" for jakarta /<br> "2.3.8" for javax | The version of XJC to use. |
52+
| defaultPackage | Provider\<String> | \[not set\] | The default package for the generated Java classes.<br>If empty, XJC will infer it from the namespace. |
53+
| generateEpisode | Provider\<Boolean> | false | If true, generates an Episode file for the generated Java classes. |
54+
| markGenerated | Provider\<Boolean> | false | If true, marks the generated code with the annotation `@javax.annotation.Generated`. |
55+
| options | ListProperty\<String> | \[empty\] | Options to pass to either the XJC core, or to third party plugins in the `xjcPlugins` configuration |
56+
| groups | NamedDomainObjectContainer | \[empty\] | Allows you to group a set of XSDs and generate sources with different configurations. Requires Gradle 7.0 or higher. See below for details. |
57+
| addCompilationDependencies | Provider\<Boolean> | true | Adds dependencies to the `implementation` configuration for compiling the generated sources. These includes `jakarta.xml.bind:jakarta.xml.bind-api` and possibly `jakarta.annotation:jakarta.annotation-api`. |
5858

5959
### Choosing which schemas to generate source code for
6060

@@ -158,13 +158,14 @@ The file will be generated at META-INF/sun-jaxb.episode and added as a resource
158158
XJC can consume the episode files so that it is possible to compile java classes from a schema in one project, and consume it in XJC generators in other
159159
projects, so you don't have to compile the same schemas multiple times.
160160
To do this, you need to add the jar file to the configuration named "xjcBindings".
161+
This is done using normal Gradle dependency management.
161162

162163
For multi-projects, assuming the episode file is generated in a project called "test-producer", you can do this like this:
163164

164165
```kotlin
165166
dependencies {
166167
implementation(project(":test-producer"))
167-
xjcBindings(project(":test-producer", "apiElements"))
168+
xjcBindings(project(":test-producer"))
168169
}
169170
```
170171

@@ -174,9 +175,7 @@ You can also provide your own binding files (or custom episode files) through th
174175

175176
```kotlin
176177
xjc {
177-
bindingFiles.from(layout.projectDirectory.dir("src/main/xjb")) // Everything in the src/main/xjb directory
178-
// or
179-
bindingFiles.from(xsdDir.asFileTree.matching { include('**/*.xjb') }) // Files with an .xjb extension in the xsdDir directory (defaulting to src/main/resources)
178+
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") } // Files with an .xjb extension in the "src/main/xjb" directory
180179
}
181180
```
182181

@@ -244,7 +243,7 @@ Lastly, for both `jakarta` and `javax`, configure the plugin to use the binding
244243

245244
```kotlin
246245
xjc {
247-
bindingFiles.from(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") })
246+
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }
248247
}
249248
```
250249

integration-test/test-consumer-2x/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies {
1111
implementation(project(":test-producer-2x"))
1212
implementation("org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1") // Though called "runtime", it is required at compile time...
1313

14-
xjcBindings(project(":test-producer-2x", "apiElements"))
14+
xjcBindings(project(":test-producer-2x"))
1515
xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1")
1616

1717
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")

integration-test/test-consumer-3x/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ repositories {
88
}
99

1010
dependencies {
11+
xjcBindings(project(":test-producer-3x"))
12+
1113
implementation(project(":test-producer-3x"))
1214
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
1315
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1")

integration-test/test-producer-3x-binding-files/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repositories {
99

1010
xjc {
1111
xsdDir.set(layout.projectDirectory.dir("src/main/xsd"))
12-
bindingFiles.from(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") })
12+
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }
1313
}
1414

1515
dependencies {

src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.bjornvester.xjc
22

33
import org.gradle.api.NamedDomainObjectContainer
4+
import org.gradle.api.file.FileCollection
45
import org.gradle.api.file.ProjectLayout
56
import org.gradle.api.model.ObjectFactory
67
import javax.inject.Inject
@@ -18,7 +19,7 @@ open class XjcExtension @Inject constructor(objects: ObjectFactory, layout: Proj
1819
override val outputResourcesDir = objects.directoryProperty().convention(layout.buildDirectory.dir("generated/sources/xjc/resources"))
1920
override val defaultPackage = objects.property(String::class.java)
2021
override val generateEpisode = objects.property(Boolean::class.java).convention(false)
21-
override val bindingFiles = objects.fileCollection()
22+
override var bindingFiles: FileCollection = xsdDir.asFileTree.matching { include("**/*.xjb") }
2223
override val options = objects.listProperty(String::class.java)
2324
override val markGenerated = objects.property(Boolean::class.java).convention(false)
2425

@@ -33,7 +34,7 @@ open class XjcExtension @Inject constructor(objects: ObjectFactory, layout: Proj
3334
outputResourcesDir.convention(layout.buildDirectory.dir("generated/sources/xjc-$name/resources"))
3435
defaultPackage.convention(this@XjcExtension.defaultPackage)
3536
generateEpisode.convention(this@XjcExtension.generateEpisode)
36-
bindingFiles.from(this@XjcExtension.bindingFiles)
37+
bindingFiles = this@XjcExtension.bindingFiles
3738
options.convention(this@XjcExtension.options)
3839
markGenerated.convention(this@XjcExtension.markGenerated)
3940
}

src/main/kotlin/com/github/bjornvester/xjc/XjcExtensionGroup.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.bjornvester.xjc
22

3-
import org.gradle.api.file.ConfigurableFileCollection
43
import org.gradle.api.file.DirectoryProperty
4+
import org.gradle.api.file.FileCollection
55
import org.gradle.api.provider.ListProperty
66
import org.gradle.api.provider.Property
77

@@ -14,7 +14,7 @@ interface XjcExtensionGroup {
1414
val outputResourcesDir: DirectoryProperty
1515
val defaultPackage: Property<String>
1616
val generateEpisode: Property<Boolean>
17-
val bindingFiles: ConfigurableFileCollection
17+
var bindingFiles: FileCollection
1818
val options: ListProperty<String>
1919
val markGenerated: Property<Boolean>
2020
}

src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class XjcPlugin : Plugin<Project> {
8181
xjcConfiguration.from(project.configurations.named(XJC_CONFIGURATION_NAME))
8282
xjcBindConfiguration.from(project.configurations.named(XJC_BIND_CONFIGURATION_NAME))
8383
xjcPluginsConfiguration.from(project.configurations.named(XJC_PLUGINS_CONFIGURATION_NAME))
84-
bindingFiles.from(group.bindingFiles)
84+
bindingFiles = group.bindingFiles
8585

8686
val sourceSets = project.properties["sourceSets"] as SourceSetContainer
8787

src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.bjornvester.xjc
33
import com.github.bjornvester.xjc.XjcPlugin.Companion.XJC_EXTENSION_NAME
44
import org.gradle.api.DefaultTask
55
import org.gradle.api.GradleException
6+
import org.gradle.api.file.ArchiveOperations
67
import org.gradle.api.file.DirectoryProperty
78
import org.gradle.api.file.FileSystemOperations
89
import org.gradle.api.file.ProjectLayout
@@ -18,8 +19,9 @@ import javax.inject.Inject
1819
open class XjcTask @Inject constructor(
1920
private val workerExecutor: WorkerExecutor,
2021
private val objectFactory: ObjectFactory,
22+
private val archiveOperations: ArchiveOperations,
23+
private val fileSystemOperations: FileSystemOperations,
2124
projectLayout: ProjectLayout,
22-
private val fileSystemOperations: FileSystemOperations
2325
) : DefaultTask() {
2426
@get:Optional
2527
@get:Input
@@ -53,7 +55,7 @@ open class XjcTask @Inject constructor(
5355
@Optional
5456
@get:InputFiles
5557
@get:PathSensitive(PathSensitivity.RELATIVE)
56-
val bindingFiles = objectFactory.fileCollection().from(getXjcExtension().bindingFiles)
58+
var bindingFiles = getXjcExtension().bindingFiles
5759

5860
@get:Input
5961
val options: ListProperty<String> = objectFactory.listProperty(String::class.java).convention(getXjcExtension().options)
@@ -188,7 +190,7 @@ open class XjcTask @Inject constructor(
188190

189191
xjcBindConfiguration.forEach { bindJarFile ->
190192
if (bindJarFile.extension == "jar") {
191-
val episodeFiles = objectFactory.fileTree().from(bindJarFile).filter { it.name == "sun-jaxb.episode" }.files
193+
val episodeFiles = archiveOperations.zipTree(bindJarFile).matching { include("**/sun-jaxb.episode") }.files
192194
if (episodeFiles.isEmpty()) {
193195
logger.warn("No episodes (sun-jaxb.episode) found in bind jar file ${bindJarFile.name}")
194196
} else {

0 commit comments

Comments
 (0)