1515import org .gradle .api .tasks .Input ;
1616import org .gradle .api .tasks .InputFile ;
1717import org .gradle .api .tasks .Internal ;
18+ import org .gradle .api .tasks .Optional ;
1819import org .gradle .api .tasks .OutputDirectory ;
1920import org .gradle .api .tasks .PathSensitive ;
2021import org .gradle .api .tasks .PathSensitivity ;
2122import org .gradle .api .tasks .TaskAction ;
2223
24+ import javax .inject .Inject ;
2325import java .util .ArrayList ;
2426import java .util .Collections ;
2527import java .util .Set ;
3032 * @author Steve Ebersole
3133 */
3234@ CacheableTask
33- public class XjcTask extends DefaultTask {
34- private final Property <String > schemaName ;
35- private final DirectoryProperty outputDirectory ;
36- private final RegularFileProperty xsdFile ;
37- private final RegularFileProperty xjcBindingFile ;
38- private final SetProperty <String > xjcPlugins ;
35+ public abstract class XjcTask extends DefaultTask {
3936
37+ @ Inject
4038 public XjcTask () {
41- schemaName = getProject ().getObjects ().property ( String .class );
42-
43- xsdFile = getProject ().getObjects ().fileProperty ();
44- xjcBindingFile = getProject ().getObjects ().fileProperty ();
45- xjcPlugins = getProject ().getObjects ().setProperty ( String .class );
46-
47- outputDirectory = getProject ().getObjects ().directoryProperty ();
48-
49- schemaName .convention ( xsdFile .map ( regularFile -> regularFile .getAsFile ().getName () ) );
5039 }
5140
5241 @ Internal
53- public Property <String > getSchemaName () {
54- return schemaName ;
55- }
42+ public abstract Property <String > getSchemaName ();
5643
5744 @ InputFile
5845 @ PathSensitive (PathSensitivity .RELATIVE )
59- public RegularFileProperty getXsdFile () {
60- return xsdFile ;
61- }
46+ public abstract RegularFileProperty getXsdFile ();
6247
48+ @ Optional
6349 @ InputFile
6450 @ PathSensitive (PathSensitivity .RELATIVE )
65- public RegularFileProperty getXjcBindingFile () {
66- return xjcBindingFile ;
67- }
51+ public abstract RegularFileProperty getXjcBindingFile ();
6852
6953 @ Input
70- public SetProperty <String > getXjcPlugins () {
71- return xjcPlugins ;
72- }
54+ public abstract SetProperty <String > getXjcPlugins ();
7355
7456 @ OutputDirectory
75- public DirectoryProperty getOutputDirectory () {
76- return outputDirectory ;
77- }
57+ public abstract DirectoryProperty getOutputDirectory ();
7858
7959 @ TaskAction
8060 public void generateJaxbBindings () {
81- getProject ().delete ( outputDirectory .get ().getAsFileTree () );
82-
83- final XjcListenerImpl listener = new XjcListenerImpl ( schemaName .get (), getProject () );
61+ final XjcListenerImpl listener = new XjcListenerImpl ( getSchemaName ().get (), getLogger () );
8462 final String [] args = buildXjcArgs ();
8563
8664 try {
@@ -94,23 +72,23 @@ public void generateJaxbBindings() {
9472 private String [] buildXjcArgs () {
9573 final ArrayList <String > argsList = new ArrayList <>();
9674
97- Collections .addAll ( argsList , "-d" , outputDirectory .get ().getAsFile ().getAbsolutePath () );
98- Collections .addAll ( argsList , "-b" , xjcBindingFile .get ().getAsFile ().getAbsolutePath ());
75+ Collections .addAll ( argsList , "-d" , getOutputDirectory () .get ().getAsFile ().getAbsolutePath () );
76+ Collections .addAll ( argsList , "-b" , getXjcBindingFile () .get ().getAsFile ().getAbsolutePath ());
9977
10078 argsList .add ( "-extension" );
10179 argsList .add ( "-no-header" );
10280 argsList .add ( "-npa" );
10381
104- if ( xjcPlugins .isPresent () ) {
105- final Set <String > xjcPluginsToEnable = xjcPlugins .get ();
82+ if ( getXjcPlugins () .isPresent () ) {
83+ final Set <String > xjcPluginsToEnable = getXjcPlugins () .get ();
10684 if ( !xjcPluginsToEnable .isEmpty () ) {
10785 xjcPluginsToEnable .forEach ( (ext ) -> {
10886 argsList .add ( "-X" + ext );
10987 } );
11088 }
11189 }
11290
113- argsList .add ( xsdFile .get ().getAsFile ().getAbsolutePath () );
91+ argsList .add ( getXsdFile () .get ().getAsFile ().getAbsolutePath () );
11492
11593 return argsList .toArray ( new String [0 ] );
11694 }
0 commit comments