Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HHH-19754 - Migrate XjcPlugin to using direct Java calls #10872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sebersole wants to merge 1 commit into hibernate:main from sebersole:xjc-plugin
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hibernate-core/hibernate-core.gradle
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ xjc {
hbm {
xsdFile = file( 'src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd' )
xjcBindingFile = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
xjcExtensions += ['inheritance', 'simplify']
xjcPlugins('inheritance', 'simplify')
}
configuration {
xsdFile = file( 'src/main/resources/org/hibernate/xsd/cfg/configuration-3.2.0.xsd' )
xjcBindingFile = file( 'src/main/xjb/configuration-bindings.xjb' )
xjcExtensions += ['inheritance', 'simplify']
xjcPlugins('inheritance', 'simplify')
}
mapping {
xsdFile = file( 'src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd' )
xjcBindingFile = file( 'src/main/xjb/mapping-bindings.xjb' )
xjcExtensions += ['inheritance', 'simplify']
xjcPlugins('inheritance', 'simplify')
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions local-build-plugins/build.gradle
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ dependencies {

implementation "jakarta.inject:jakarta.inject-api:2.0.0"

implementation "org.glassfish.jaxb:jaxb-xjc:4.0.5"
implementation "org.patrodyne.jvnet:hisrc-basicjaxb-tools:2.2.1"
implementation "org.patrodyne.jvnet:hisrc-basicjaxb-plugins:2.2.1"

implementation 'io.smallrye:jandex:3.1.2'
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'jakarta.json.bind:jakarta.json.bind-api:2.0.0'
Expand Down
View file Open in desktop

This file was deleted.

View file Open in desktop

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
* Describes the XJC processing to apply for a single XSD
*
* @author Steve Ebersole
*/
public class SchemaDescriptor implements Named {
Expand All @@ -24,15 +22,15 @@ public class SchemaDescriptor implements Named {

private final RegularFileProperty xsdFile;
private final RegularFileProperty xjcBindingFile;
private final SetProperty<String> xjcExtensions;
private final SetProperty<String> xjcPlugins;

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 );
xjcPlugins = project.getObjects().setProperty( String.class );
}

@Override
Expand Down Expand Up @@ -67,23 +65,11 @@ public void xjcBindingFile(Object reference) {
}

@Input
public SetProperty<String> ___xjcExtensions() {
return xjcExtensions;
}

public Set<String> getXjcExtensions() {
return xjcExtensions.get();
}

public void setXjcExtensions(Set<String> xjcExtensions) {
this.xjcExtensions.set( xjcExtensions );
}

public void setXjcExtensions(String... xjcExtensions) {
xjcExtensions( xjcExtensions );
public SetProperty<String> getXjcPlugins() {
return xjcPlugins;
}

public void xjcExtensions(String... xjcExtensions) {
setXjcExtensions( new HashSet<>( Arrays.asList( xjcExtensions) ) );
public void xjcPlugins(String... plugins) {
xjcPlugins.addAll( plugins );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* @author Steve Ebersole
*/
public class SchemaDescriptorFactory implements NamedDomainObjectFactory<SchemaDescriptor> {
private final XjcExtension xjcExtension;
private final Task groupingTask;
private final Provider<Directory> baseOutputDirectory;
private final TaskProvider<Task> groupingTaskRef;
private final Project project;

public SchemaDescriptorFactory(XjcExtension xjcExtension, Task groupingTask, Project project) {
this.xjcExtension = xjcExtension;
this.groupingTask = groupingTask;
public SchemaDescriptorFactory(Provider<Directory> baseOutputDirectory, TaskProvider<Task> groupingTaskRef, Project project) {
this.baseOutputDirectory = baseOutputDirectory;
this.groupingTaskRef = groupingTaskRef;
this.project = project;
}

Expand All @@ -38,32 +38,33 @@ public SchemaDescriptor create(String name) {
final SchemaDescriptor schemaDescriptor = new SchemaDescriptor( name, project );

final String taskName = determineXjcTaskName( schemaDescriptor );
final Provider<Directory> taskOutputDirectory = xjcExtension.getOutputDirectory().dir( name );
final Provider<Directory> taskOutputDirectory = baseOutputDirectory.map( directory -> directory.dir( name ) );

// register the XjcTask for the schema
final TaskProvider<XjcTask> 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 );
task.getSchemaName().convention( name );
task.getXsdFile().convention( schemaDescriptor.getXsdFile() );
task.getXjcBindingFile().convention( schemaDescriptor.getXjcBindingFile() );
task.getXjcPlugins().convention( schemaDescriptor.getXjcPlugins() );
task.getOutputDirectory().convention( 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 );
groupingTaskRef.configure( (groupingTask) -> {
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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,40 @@
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;
import org.gradle.api.tasks.TaskProvider;

/**
* DSL extension for configuring XJC processing
*
* @author Steve Ebersole
*/
public abstract class XjcExtension {
private final DirectoryProperty outputDirectory;
private final Property<String> jaxbBasicsVersion;
private final NamedDomainObjectContainer<SchemaDescriptor> schemas;

@Inject
public XjcExtension(Task groupingTask, Project project) {
public XjcExtension(Project project) {
// Create the xjc grouping task
final TaskProvider<Task> groupingTaskRef = project.getTasks().register( "xjc", (groupingTask) -> {
groupingTask.setGroup( "xjc" );
groupingTask.setDescription( "Grouping task for executing one-or-more XJC compilations" );
} );

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.
// 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 ) );
schemas = project.container(
SchemaDescriptor.class,
new SchemaDescriptorFactory( outputDirectory, groupingTaskRef, project )
);
}

@OutputDirectory
public DirectoryProperty getOutputDirectory() {
return outputDirectory;
}

public Property<String> getJaxbBasicsVersion() {
return jaxbBasicsVersion;
}

@SuppressWarnings("unused")
public final NamedDomainObjectContainer<SchemaDescriptor> getSchemas() {
return schemas;
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.build.xjc;

import com.sun.tools.xjc.XJCListener;
import org.gradle.api.Project;
import org.xml.sax.SAXParseException;

/**
* Event listener for the XJC process.
*
* @author Steve Ebersole
*/
public class XjcListenerImpl extends XJCListener {
private final String schemaName;
private final Project project;
private boolean hadErrors;

public XjcListenerImpl(String schemaName, Project project) {
this.schemaName = schemaName;
this.project = project;
}

public boolean hadErrors() {
return hadErrors;
}

@Override
public void generatedFile(String fileName, int current, int total) {
project.getLogger().info( "XJC generated file ({}) : {}", schemaName, fileName );
}

@Override
public void message(String msg) {
project.getLogger().info( "XJC message ({}) : {}", schemaName, msg );
}

@Override
public void info(SAXParseException exception) {
project.getLogger().info( "XJC info ({})", schemaName, exception );
}

@Override
public void warning(SAXParseException exception) {
project.getLogger().warn( "XJC warning ({})",schemaName, exception );
}

@Override
public void error(SAXParseException exception) {
hadErrors = true;
project.getLogger().error( "XJC error ({})", schemaName, exception );
}

@Override
public void fatalError(SAXParseException exception) {
hadErrors = true;
project.getLogger().error( "XJC fatal error ({})", schemaName, exception );
}
}
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /