Files
gbrodmanandGitHub c9aba86833 Split XJC code into separate eppbindings subproject (#3244)
The generated XML / XJC code pretty much never changes but because
everything is lumped together in one compile task, we had to recompile
this every time anything else in core/ changes. It's technically
possible to use a separate source set for the XJC code while having it
remain in core/, but splitting it into a separate subproject gives
better separation and makes the caching / dependency graph clearer.

Pretty much all, except for the caching configuration, of the new
xjc/build.gradle is taken from the previous core/build.gradle.
2026-10-13 17:57:07 +00:00

130 lines
4.2 KiB
Groovy

// Copyright 2026 The Nomulus Authors. 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
//
// http://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.
plugins {
id 'java-library'
}
// Path to code generated by ad hoc tasks in this project. A separate path is
// used for easy inspection.
def generatedDir = "${project.buildDir}/generated/sources/custom/java/main"
sourceSets {
main {
java {
srcDirs += generatedDir
}
resources {
exclude '**/*.xjb'
}
}
}
configurations {
jaxb
}
dependencies {
def deps = rootProject.dependencyMap
api deps['com.google.code.findbugs:jsr305']
api deps['com.google.guava:guava']
api deps['jakarta.xml.bind:jakarta.xml.bind-api']
implementation deps['com.google.re2j:re2j']
implementation project(':common')
runtimeOnly deps['org.glassfish.jaxb:jaxb-runtime']
// Dependencies needed for jaxb compilation.
jaxb deps['jakarta.xml.bind:jakarta.xml.bind-api']
jaxb deps['org.glassfish.jaxb:jaxb-runtime']
jaxb deps['org.glassfish.jaxb:jaxb-xjc']
testImplementation deps['com.google.truth:truth']
testImplementation deps['org.junit.jupiter:junit-jupiter-api']
testImplementation deps['org.junit.jupiter:junit-jupiter-engine']
testImplementation deps['org.junit.jupiter:junit-jupiter-params']
testImplementation deps['org.junit.platform:junit-platform-launcher']
}
task jaxbToJava {
def xsdFilesDir = "${javaDir}/google/registry/xml/xsd"
def bindingsFile = "${javaDir}/google/registry/xjc/bindings.xjb"
def pkgInfoTemplate = "${javaDir}/google/registry/xjc/package-info.java.in"
def pkgInfoMap = "${javaDir}/google/registry/xjc/package-info.map"
def outputDir = "${generatedDir}/google/registry/xjc"
inputs.dir(xsdFilesDir).withPathSensitivity(PathSensitivity.RELATIVE)
inputs.files(bindingsFile, pkgInfoTemplate, pkgInfoMap)
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.files(configurations.jaxb).withNormalizer(ClasspathNormalizer)
outputs.dir outputDir
outputs.cacheIf { true }
doLast {
file(generatedDir).mkdirs()
// Temp dir to hold schema and bindings files. Files must be in the same
// directory because the bindings (.xjb) file does not declare relative
// paths to schema (.xsd) files.
def xjcTempSourceDir = file("${temporaryDir}/xjc")
xjcTempSourceDir.mkdirs()
ant.copy(
todir: "${xjcTempSourceDir}",
overwrite: true) {
fileSet(
dir: xsdFilesDir,
includes: '**.xsd')
}
ant.copy(
todir: "${xjcTempSourceDir}",
overwrite: true,
file: bindingsFile)
ant.taskdef(
name: 'xjc',
classname: 'com.sun.tools.xjc.XJCTask',
classpath: configurations.jaxb.asPath)
ant.xjc(
destdir: "${generatedDir}",
binding: "${xjcTempSourceDir}/bindings.xjb",
removeOldOutput: 'yes', extension: 'true') {
fileTree(
dir: new File("$xjcTempSourceDir"),
include: ['**/*.xsd'])
.addToAntBuilder(ant, 'schema', FileCollection.AntType.FileSet)
// -npa: do not generate package-info.java files. They will be generated
// below.
arg(line: '-npa -quiet -extension')
}
new File(pkgInfoMap).eachLine { line ->
def (packageName, namespace) = line.split()
ant.copy(
tofile: "${outputDir}/${packageName}/package-info.java",
overwrite: true,
file: "${pkgInfoTemplate}") {
filterSet() {
filter(token: 'PACKAGE', value: packageName)
filter(token: 'NAMESPACE', value: namespace)
}
}
}
execInBash(
"find . -name *.java -exec sed -i -e '/" + /\* <p>$/ + "/d' {} +",
generatedDir)
}
}
compileJava.dependsOn jaxbToJava