diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 4eb19a21c7..ce7be417b9 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -7,7 +7,7 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { - id 'org.hibernate.build.xjc-jakarta' + id "local-xjc-plugin" } description = 'Hibernate\'s core ORM functionality' @@ -87,10 +87,6 @@ dependencies { // dependency here. antlr libs.antlr antlr libs.antlrRuntime - - xjc jakartaLibs.xjc - xjc jakartaLibs.jaxb - xjc rootProject.fileTree(dir: 'patched-libs/jaxb2-basics', include: '*.jar') } jar { diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd index 77a5a32899..eef9f757bf 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd @@ -9,7 +9,7 @@ + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:inheritance="http://jvnet.org/basicjaxb/xjc/inheritance" + jaxb:extensionBindingPrefixes="inheritance" + version="3.0"> diff --git a/hibernate-core/src/main/xjb/mapping-bindings.xjb b/hibernate-core/src/main/xjb/mapping-bindings.xjb index a7dc20984a..cfbbfabfa0 100644 --- a/hibernate-core/src/main/xjb/mapping-bindings.xjb +++ b/hibernate-core/src/main/xjb/mapping-bindings.xjb @@ -4,8 +4,8 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:extensionBindingPrefixes="inheritance simplify" - xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" - xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify" + xmlns:inheritance="http://jvnet.org/basicjaxb/xjc/inheritance" + xmlns:simplify="http://jvnet.org/basicjaxb/xjc/simplify" version="3.0"> diff --git a/local-build-plugins/build.gradle b/local-build-plugins/build.gradle index c5f42d6716..87e451545a 100644 --- a/local-build-plugins/build.gradle +++ b/local-build-plugins/build.gradle @@ -4,18 +4,24 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ +plugins { + id "java-gradle-plugin" + id "groovy" +} + repositories { mavenCentral() } -apply plugin: 'java-gradle-plugin' - group = 'org.hibernate.build' version = '1.0.0-SNAPSHOT' buildDir = "target" dependencies { implementation gradleApi() + + implementation "jakarta.inject:jakarta.inject-api:2.0.0" + implementation 'io.smallrye:jandex:3.1.2' implementation 'org.apache.httpcomponents:httpclient:4.5.13' implementation 'jakarta.json.bind:jakarta.json.bind-api:2.0.0' @@ -89,6 +95,10 @@ gradlePlugin { id = "org.hibernate.build.maven-embedder" implementationClass = "org.hibernate.build.maven.embedder.MavenEmbedderPlugin" } + register( "xjc-plugin" ) { + id = "local-xjc-plugin" + implementationClass = "org.hibernate.build.xjc.XjcPlugin" + } } } diff --git a/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptor.java b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptor.java new file mode 100644 index 0000000000..ce330ada92 --- /dev/null +++ b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptor.java @@ -0,0 +1,85 @@ +package org.hibernate.build.xjc; + +import org.gradle.api.Named; +import org.gradle.api.Project; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.SetProperty; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Steve Ebersole + */ +public class SchemaDescriptor implements Named { + private final String name; + private final Project project; + + private final RegularFileProperty xsdFile; + private final RegularFileProperty xjcBindingFile; + private final SetProperty xjcExtensions; + + public SchemaDescriptor(String name, Project project) { + this.name = name; + this.project = project; + + xsdFile = project.getObjects().fileProperty(); + xjcBindingFile = project.getObjects().fileProperty(); + xjcExtensions = project.getObjects().setProperty( String.class ); + } + + @Override + public final String getName() { + return name; + } + + @InputFile + public RegularFileProperty getXsdFile() { + return xsdFile; + } + + public void setXsdFile(Object reference) { + xsdFile.set( project.file( reference ) ); + } + + public void xsdFile(Object reference) { + setXsdFile( reference ); + } + + @InputFile + public RegularFileProperty getXjcBindingFile() { + return xjcBindingFile; + } + + public void setXjcBindingFile(Object reference) { + xjcBindingFile.set( project.file( reference ) ); + } + + public void xjcBindingFile(Object reference) { + setXjcBindingFile( reference ); + } + + @Input + public SetProperty ___xjcExtensions() { + return xjcExtensions; + } + + public Set getXjcExtensions() { + return xjcExtensions.get(); + } + + public void setXjcExtensions(Set xjcExtensions) { + this.xjcExtensions.set( xjcExtensions ); + } + + public void setXjcExtensions(String... xjcExtensions) { + xjcExtensions( xjcExtensions ); + } + + public void xjcExtensions(String... xjcExtensions) { + setXjcExtensions( new HashSet<>( Arrays.asList( xjcExtensions) ) ); + } +} diff --git a/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptorFactory.java b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptorFactory.java new file mode 100644 index 0000000000..707cc447d9 --- /dev/null +++ b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptorFactory.java @@ -0,0 +1,68 @@ +package org.hibernate.build.xjc; + +import org.gradle.api.NamedDomainObjectFactory; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.file.Directory; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.TaskProvider; + +import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME; + +/** + * Used as the factory for instances added to the {@link XjcExtension#getSchemas()} container. + *

+ * For each schema descriptor, an XjcTask is created and wired up. + * + * @author Steve Ebersole + */ +public class SchemaDescriptorFactory implements NamedDomainObjectFactory { + private final XjcExtension xjcExtension; + private final Task groupingTask; + private final Project project; + + public SchemaDescriptorFactory(XjcExtension xjcExtension, Task groupingTask, Project project) { + this.xjcExtension = xjcExtension; + this.groupingTask = groupingTask; + this.project = project; + } + + @Override + public SchemaDescriptor create(String name) { + final SchemaDescriptor schemaDescriptor = new SchemaDescriptor( name, project ); + + final String taskName = determineXjcTaskName( schemaDescriptor ); + final Provider taskOutputDirectory = xjcExtension.getOutputDirectory().dir( name ); + + // register the XjcTask for the schema + final TaskProvider xjcTaskRef = project.getTasks().register( taskName, XjcTask.class, (task) -> { + task.setGroup( "xjc" ); + task.setDescription( "XJC generation for the " + name + " descriptor" ); + + // wire up the inputs and outputs + task.getXsdFile().set( schemaDescriptor.getXsdFile() ); + task.getXjcBindingFile().set( schemaDescriptor.getXjcBindingFile() ); + task.getXjcExtensions().set( schemaDescriptor.___xjcExtensions() ); + task.getOutputDirectory().set( taskOutputDirectory ); + } ); + + final SourceSetContainer sourceSets = project.getExtensions().getByType( SourceSetContainer.class ); + final SourceSet mainSourceSet = sourceSets.getByName( MAIN_SOURCE_SET_NAME ); + mainSourceSet.getJava().srcDir( xjcTaskRef ); + + groupingTask.dependsOn( xjcTaskRef ); + + return schemaDescriptor; + } + + private static String determineXjcTaskName(SchemaDescriptor schemaDescriptor) { + assert schemaDescriptor.getName() != null; + + final char initialLetterCap = Character.toUpperCase( schemaDescriptor.getName().charAt( 0 ) ); + final String rest = schemaDescriptor.getName().substring( 1 ); + + return "xjc" + initialLetterCap + rest; + } +} diff --git a/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcExtension.java b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcExtension.java new file mode 100644 index 0000000000..e8f4271b9c --- /dev/null +++ b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcExtension.java @@ -0,0 +1,52 @@ +package org.hibernate.build.xjc; + +import groovy.lang.Closure; +import jakarta.inject.Inject; +import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.OutputDirectory; + +/** + * @author Steve Ebersole + */ +public abstract class XjcExtension { + private final DirectoryProperty outputDirectory; + private final Property jaxbBasicsVersion; + private final NamedDomainObjectContainer schemas; + + @Inject + public XjcExtension(Task groupingTask, Project project) { + outputDirectory = project.getObjects().directoryProperty(); + outputDirectory.convention( project.getLayout().getBuildDirectory().dir( "generated/sources/xjc/main" ) ); + + jaxbBasicsVersion = project.getObjects().property( String.class ); + jaxbBasicsVersion.convention( "2.2.1" ); + + // Create a dynamic container for SchemaDescriptor definitions by the user. + // - for each schema they define, create a Task to perform the "compilation" + schemas = project.container( SchemaDescriptor.class, new SchemaDescriptorFactory( this, groupingTask, project ) ); + } + + @OutputDirectory + public DirectoryProperty getOutputDirectory() { + return outputDirectory; + } + + public Property getJaxbBasicsVersion() { + return jaxbBasicsVersion; + } + + @SuppressWarnings("unused") + public final NamedDomainObjectContainer getSchemas() { + return schemas; + } + + @SuppressWarnings({ "unused", "rawtypes" }) + public NamedDomainObjectContainer schemas(Closure closure) { + return schemas.configure( closure ); + } + +} diff --git a/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcPlugin.java b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcPlugin.java new file mode 100644 index 0000000000..610027db5f --- /dev/null +++ b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcPlugin.java @@ -0,0 +1,47 @@ +package org.hibernate.build.xjc; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.dsl.DependencyHandler; + +import java.util.LinkedHashMap; + +/** + * @author Steve Ebersole + */ +public class XjcPlugin implements Plugin { + public static final String XJC_BASIC_PLUGIN = "org.patrodyne.jvnet:hisrc-basicjaxb-plugins:2.2.1"; + public static final String XJC_BASIC_TOOLS = "org.patrodyne.jvnet:hisrc-basicjaxb-tools:2.2.1"; + public static final String XJC_BASIC_ANT = "org.patrodyne.jvnet:hisrc-basicjaxb-ant:2.2.1"; + + public static final String ANT_TASK_NAME = "org.jvnet.basicjaxb.xjc.XJC2Task"; + + @Override + public void apply(Project project) { + // Create the xjc grouping task + final Task groupingTask = project.getTasks().create( "xjc", xjcTask -> { + xjcTask.setGroup( "xjc" ); + xjcTask.setDescription( "Grouping task for executing one-or-more XJC compilations" ); + } ); + + // Create the Plugin extension object (for users to configure our execution). + project.getExtensions().create( "xjc", XjcExtension.class, groupingTask, project ); + + final DependencyHandler dependencyHandler = project.getDependencies(); + final Configuration antTaskDependencies = project.getConfigurations().detachedConfiguration( + dependencyHandler.create( XJC_BASIC_ANT ), + dependencyHandler.create( XJC_BASIC_PLUGIN ), + dependencyHandler.create( XJC_BASIC_TOOLS ), + dependencyHandler.gradleApi() + ); + + final LinkedHashMap map = new LinkedHashMap<>( 3 ); + map.put( "name", "xjc" ); + map.put( "classname", ANT_TASK_NAME ); + map.put( "classpath", antTaskDependencies.getAsPath() ); + project.getAnt().invokeMethod( "taskdef", new Object[] { map } ); + project.getAnt().setSaveStreams( false ); + } +} diff --git a/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcTask.groovy b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcTask.groovy new file mode 100644 index 0000000000..3335c546f9 --- /dev/null +++ b/local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcTask.groovy @@ -0,0 +1,71 @@ +package org.hibernate.build.xjc + +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.SetProperty +import org.gradle.api.tasks.* + +/** + * @author Steve Ebersole + */ +@CacheableTask +class XjcTask extends DefaultTask { + private final DirectoryProperty outputDirectory + + private final RegularFileProperty xsdFile + private final RegularFileProperty xjcBindingFile + private final SetProperty xjcExtensions + + XjcTask() { + xsdFile = project.getObjects().fileProperty() + xjcBindingFile = project.getObjects().fileProperty() + xjcExtensions = project.objects.setProperty( String.class ) + + outputDirectory = project.objects.directoryProperty() + } + + @InputFile + @PathSensitive( PathSensitivity.RELATIVE ) + RegularFileProperty getXsdFile() { + return xsdFile + } + + @InputFile + @PathSensitive( PathSensitivity.RELATIVE ) + RegularFileProperty getXjcBindingFile() { + return xjcBindingFile + } + + @Input + SetProperty getXjcExtensions() { + return xjcExtensions + } + + @OutputDirectory + DirectoryProperty getOutputDirectory() { + return outputDirectory + } + + @TaskAction + void generateJaxbBindings() { + project.delete( outputDirectory.get().asFileTree ) + + project.ant.xjc( + destdir: outputDirectory.get().asFile.absolutePath, + binding: xjcBindingFile.get().asFile.absolutePath, + schema: xsdFile.get().asFile.absolutePath, + extension: 'true') { + project.ant.arg line: '-no-header' + project.ant.arg line: '-npa' + + if ( xjcExtensions.isPresent() ) { + def extensionsToEnable = xjcExtensions.get() + if ( ! extensionsToEnable.isEmpty() ) { + def extensionsSwitches = extensionsToEnable.collect { "-X${it}" }.join( " " ) + project.ant.arg line: extensionsSwitches + } + } + } + } +} diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched-sources.jar b/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched-sources.jar deleted file mode 100644 index 3cdd2a9a9b..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched-sources.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched.jar b/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched.jar deleted file mode 100644 index f1fbce66ec..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-ant-patched.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-patched-sources.jar b/patched-libs/jaxb2-basics/jaxb2-basics-patched-sources.jar deleted file mode 100644 index f04c832848..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-patched-sources.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-patched.jar b/patched-libs/jaxb2-basics/jaxb2-basics-patched.jar deleted file mode 100644 index e9ad751601..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-patched.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched-sources.jar b/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched-sources.jar deleted file mode 100644 index 319d896706..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched-sources.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched.jar b/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched.jar deleted file mode 100644 index f14e70f38e..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-plugins-patched.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched-sources.jar b/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched-sources.jar deleted file mode 100644 index 8cf2f8b912..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched-sources.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched.jar b/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched.jar deleted file mode 100644 index 42a37cc5e9..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-runtime-patched.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched-sources.jar b/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched-sources.jar deleted file mode 100644 index 7e8d38c0fd..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched-sources.jar and /dev/null differ diff --git a/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched.jar b/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched.jar deleted file mode 100644 index cbfad6b997..0000000000 Binary files a/patched-libs/jaxb2-basics/jaxb2-basics-tools-patched.jar and /dev/null differ