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

Commit b74fcea

Browse files
Work on XJC generation
1 parent 0189680 commit b74fcea

File tree

11 files changed

+245
-175
lines changed

11 files changed

+245
-175
lines changed

‎hibernate-core/hibernate-core.gradle‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ xjc {
112112
hbm {
113113
xsdFile = file( 'src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd' )
114114
xjcBindingFile = file( 'src/main/xjb/hbm-mapping-bindings.xjb' )
115-
xjcExtensions += ['inheritance', 'simplify']
115+
xjcPlugins('inheritance', 'simplify')
116116
}
117117
configuration {
118118
xsdFile = file( 'src/main/resources/org/hibernate/xsd/cfg/configuration-3.2.0.xsd' )
119119
xjcBindingFile = file( 'src/main/xjb/configuration-bindings.xjb' )
120-
xjcExtensions += ['inheritance', 'simplify']
120+
xjcPlugins('inheritance', 'simplify')
121121
}
122122
mapping {
123123
xsdFile = file( 'src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd' )
124124
xjcBindingFile = file( 'src/main/xjb/mapping-bindings.xjb' )
125-
xjcExtensions += ['inheritance', 'simplify']
125+
xjcPlugins('inheritance', 'simplify')
126126
}
127127
}
128128
}

‎local-build-plugins/build.gradle‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ dependencies {
2121

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

24+
implementation "org.glassfish.jaxb:jaxb-xjc:4.0.5"
25+
implementation "org.patrodyne.jvnet:hisrc-basicjaxb-tools:2.2.1"
26+
implementation "org.patrodyne.jvnet:hisrc-basicjaxb-plugins:2.2.1"
27+
2428
implementation 'io.smallrye:jandex:3.1.2'
2529
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
2630
implementation 'jakarta.json.bind:jakarta.json.bind-api:2.0.0'

‎local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcPlugin.java‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcTask.groovy‎

Lines changed: 0 additions & 71 deletions
This file was deleted.

‎local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptor.java‎ renamed to ‎local-build-plugins/src/main/java/org/hibernate/build/xjc/SchemaDescriptor.java‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
import org.gradle.api.tasks.Input;
1212
import org.gradle.api.tasks.InputFile;
1313

14-
import java.util.Arrays;
15-
import java.util.HashSet;
16-
import java.util.Set;
17-
1814
/**
15+
* Describes the XJC processing to apply for a single XSD
16+
*
1917
* @author Steve Ebersole
2018
*/
2119
public class SchemaDescriptor implements Named {
@@ -24,15 +22,15 @@ public class SchemaDescriptor implements Named {
2422

2523
private final RegularFileProperty xsdFile;
2624
private final RegularFileProperty xjcBindingFile;
27-
private final SetProperty<String> xjcExtensions;
25+
private final SetProperty<String> xjcPlugins;
2826

2927
public SchemaDescriptor(String name, Project project) {
3028
this.name = name;
3129
this.project = project;
3230

3331
xsdFile = project.getObjects().fileProperty();
3432
xjcBindingFile = project.getObjects().fileProperty();
35-
xjcExtensions = project.getObjects().setProperty( String.class );
33+
xjcPlugins = project.getObjects().setProperty( String.class );
3634
}
3735

3836
@Override
@@ -67,23 +65,11 @@ public void xjcBindingFile(Object reference) {
6765
}
6866

6967
@Input
70-
public SetProperty<String> ___xjcExtensions() {
71-
return xjcExtensions;
72-
}
73-
74-
public Set<String> getXjcExtensions() {
75-
return xjcExtensions.get();
76-
}
77-
78-
public void setXjcExtensions(Set<String> xjcExtensions) {
79-
this.xjcExtensions.set( xjcExtensions );
80-
}
81-
82-
public void setXjcExtensions(String... xjcExtensions) {
83-
xjcExtensions( xjcExtensions );
68+
public SetProperty<String> getXjcPlugins() {
69+
return xjcPlugins;
8470
}
8571

86-
public void xjcExtensions(String... xjcExtensions) {
87-
setXjcExtensions( newHashSet<>( Arrays.asList( xjcExtensions) ) );
72+
public void xjcPlugins(String... plugins) {
73+
xjcPlugins.addAll( plugins );
8874
}
8975
}

‎local-build-plugins/src/main/groovy/org/hibernate/build/xjc/SchemaDescriptorFactory.java‎ renamed to ‎local-build-plugins/src/main/java/org/hibernate/build/xjc/SchemaDescriptorFactory.java‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
* @author Steve Ebersole
2424
*/
2525
public class SchemaDescriptorFactory implements NamedDomainObjectFactory<SchemaDescriptor> {
26-
private final XjcExtensionxjcExtension;
27-
private final TaskgroupingTask;
26+
private final Provider<Directory> baseOutputDirectory;
27+
private final TaskProvider<Task> groupingTaskRef;
2828
private final Project project;
2929

30-
public SchemaDescriptorFactory(XjcExtensionxjcExtension, TaskgroupingTask, Project project) {
31-
this.xjcExtension = xjcExtension;
32-
this.groupingTask = groupingTask;
30+
public SchemaDescriptorFactory(Provider<Directory> baseOutputDirectory, TaskProvider<Task> groupingTaskRef, Project project) {
31+
this.baseOutputDirectory = baseOutputDirectory;
32+
this.groupingTaskRef = groupingTaskRef;
3333
this.project = project;
3434
}
3535

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

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

4343
// register the XjcTask for the schema
4444
final TaskProvider<XjcTask> xjcTaskRef = project.getTasks().register( taskName, XjcTask.class, (task) -> {
4545
task.setGroup( "xjc" );
4646
task.setDescription( "XJC generation for the " + name + " descriptor" );
4747

4848
// wire up the inputs and outputs
49-
task.getXsdFile().set( schemaDescriptor.getXsdFile() );
50-
task.getXjcBindingFile().set( schemaDescriptor.getXjcBindingFile() );
51-
task.getXjcExtensions().set( schemaDescriptor.___xjcExtensions() );
52-
task.getOutputDirectory().set( taskOutputDirectory );
49+
task.getSchemaName().convention( name );
50+
task.getXsdFile().convention( schemaDescriptor.getXsdFile() );
51+
task.getXjcBindingFile().convention( schemaDescriptor.getXjcBindingFile() );
52+
task.getXjcPlugins().convention( schemaDescriptor.getXjcPlugins() );
53+
task.getOutputDirectory().convention( taskOutputDirectory );
5354
} );
5455

5556
final SourceSetContainer sourceSets = project.getExtensions().getByType( SourceSetContainer.class );
5657
final SourceSet mainSourceSet = sourceSets.getByName( MAIN_SOURCE_SET_NAME );
5758
mainSourceSet.getJava().srcDir( xjcTaskRef );
5859

59-
groupingTask.dependsOn( xjcTaskRef );
60+
groupingTaskRef.configure( (groupingTask) -> {
61+
groupingTask.dependsOn( xjcTaskRef );
62+
} );
6063

6164
return schemaDescriptor;
6265
}
6366

6467
private static String determineXjcTaskName(SchemaDescriptor schemaDescriptor) {
65-
assert schemaDescriptor.getName() != null;
66-
6768
final char initialLetterCap = Character.toUpperCase( schemaDescriptor.getName().charAt( 0 ) );
6869
final String rest = schemaDescriptor.getName().substring( 1 );
6970

‎local-build-plugins/src/main/groovy/org/hibernate/build/xjc/XjcExtension.java‎ renamed to ‎local-build-plugins/src/main/java/org/hibernate/build/xjc/XjcExtension.java‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,40 @@
1010
import org.gradle.api.Project;
1111
import org.gradle.api.Task;
1212
import org.gradle.api.file.DirectoryProperty;
13-
import org.gradle.api.provider.Property;
14-
import org.gradle.api.tasks.OutputDirectory;
13+
import org.gradle.api.tasks.TaskProvider;
1514

1615
/**
16+
* DSL extension for configuring XJC processing
17+
*
1718
* @author Steve Ebersole
1819
*/
1920
public abstract class XjcExtension {
2021
private final DirectoryProperty outputDirectory;
21-
private final Property<String> jaxbBasicsVersion;
2222
private final NamedDomainObjectContainer<SchemaDescriptor> schemas;
2323

2424
@Inject
25-
public XjcExtension(Task groupingTask, Project project) {
25+
public XjcExtension(Project project) {
26+
// Create the xjc grouping task
27+
final TaskProvider<Task> groupingTaskRef = project.getTasks().register( "xjc", (groupingTask) -> {
28+
groupingTask.setGroup( "xjc" );
29+
groupingTask.setDescription( "Grouping task for executing one-or-more XJC compilations" );
30+
} );
31+
2632
outputDirectory = project.getObjects().directoryProperty();
2733
outputDirectory.convention( project.getLayout().getBuildDirectory().dir( "generated/sources/xjc/main" ) );
2834

29-
jaxbBasicsVersion = project.getObjects().property( String.class );
30-
jaxbBasicsVersion.convention( "2.2.1" );
31-
32-
// Create a dynamic container for SchemaDescriptor definitions by the user.
35+
// create a dynamic container for SchemaDescriptor definitions by the user
3336
// - for each schema they define, create a Task to perform the "compilation"
34-
schemas = project.container( SchemaDescriptor.class, new SchemaDescriptorFactory( this, groupingTask, project ) );
37+
schemas = project.container(
38+
SchemaDescriptor.class,
39+
new SchemaDescriptorFactory( outputDirectory, groupingTaskRef, project )
40+
);
3541
}
3642

37-
@OutputDirectory
3843
public DirectoryProperty getOutputDirectory() {
3944
return outputDirectory;
4045
}
4146

42-
public Property<String> getJaxbBasicsVersion() {
43-
return jaxbBasicsVersion;
44-
}
45-
4647
@SuppressWarnings("unused")
4748
public final NamedDomainObjectContainer<SchemaDescriptor> getSchemas() {
4849
return schemas;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.build.xjc;
6+
7+
import com.sun.tools.xjc.XJCListener;
8+
import org.gradle.api.Project;
9+
import org.xml.sax.SAXParseException;
10+
11+
/**
12+
* Event listener for the XJC process.
13+
*
14+
* @author Steve Ebersole
15+
*/
16+
public class XjcListenerImpl extends XJCListener {
17+
private final String schemaName;
18+
private final Project project;
19+
private boolean hadErrors;
20+
21+
public XjcListenerImpl(String schemaName, Project project) {
22+
this.schemaName = schemaName;
23+
this.project = project;
24+
}
25+
26+
public boolean hadErrors() {
27+
return hadErrors;
28+
}
29+
30+
@Override
31+
public void generatedFile(String fileName, int current, int total) {
32+
project.getLogger().info( "XJC generated file ({}) : {}", schemaName, fileName );
33+
}
34+
35+
@Override
36+
public void message(String msg) {
37+
project.getLogger().info( "XJC message ({}) : {}", schemaName, msg );
38+
}
39+
40+
@Override
41+
public void info(SAXParseException exception) {
42+
project.getLogger().info( "XJC info ({})", schemaName, exception );
43+
}
44+
45+
@Override
46+
public void warning(SAXParseException exception) {
47+
project.getLogger().warn( "XJC warning ({})",schemaName, exception );
48+
}
49+
50+
@Override
51+
public void error(SAXParseException exception) {
52+
hadErrors = true;
53+
project.getLogger().error( "XJC error ({})", schemaName, exception );
54+
}
55+
56+
@Override
57+
public void fatalError(SAXParseException exception) {
58+
hadErrors = true;
59+
project.getLogger().error( "XJC fatal error ({})", schemaName, exception );
60+
}
61+
}

0 commit comments

Comments
(0)

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