11package org .fugerit .java .daogen .maven ;
22
3- import java .io .File ;
4- import java .io .FileInputStream ;
5- import java .util .Properties ;
6-
7- import org .apache .maven .plugin .AbstractMojo ;
8- import org .apache .maven .plugin .MojoExecutionException ;
93import org .apache .maven .plugins .annotations .Mojo ;
10- import org .apache .maven .plugins .annotations .Parameter ;
11- import org .fugerit .java .core .lang .helpers .StringUtils ;
12- import org .fugerit .java .daogen .base .config .DaogenCatalogConstants ;
13- import org .fugerit .java .daogen .base .config .DaogenFacade ;
144
155/**
166 *
2111 * <p>Many parameters override 'daogen-config.xml' general properties
2212 * (in this case they always have an alias with the same name of the property they override.</p>
2313 *
14+ * <p>NOTE: if using eclipse and the build are too slow, considering using the {@link MojoGenerateLazy} plugin,
15+ * it is the same as this plugin bug run on goal generate-lazy and m2e lifecycle is configured to run only on full builds.</p>
16+ *
2417 */
2518@ Mojo ( name = "generate" )
26- public class MojoGenerate extends AbstractMojo {
27-
28- public static final String PARAM_DAOGEN_CONFIG = "daogen.config" ;
29-
19+ public class MojoGenerate extends AbstractMojoGenerate {
3020
31- public static final String PARAM_GENERATED_SOURCE_HELPER = "generated.source.helper" ;
32-
33- /**
34- * <p>The path to 'daogen-config.xml'</p>
35- *
36- * <p>If it is a file, it is recommended to set it to the full path, for instance :
37- * <code>file://${project.basedir}/src/main/daogen/daogen-config.xml</code></p>
38- *
39- * @since 1.1.0
40- */
41- @ Parameter (property = "daogenConfig" , required = true , alias = PARAM_DAOGEN_CONFIG )
42- protected String daogenConfig ;
43-
44- /**
45- * <p>The generation source base directory, overrides <code>'base-src-folder'</code> daogen general property.</p>
46- *
47- * <p>It is recommended to set it to the full path, for instance : <code>file://${project.basedir}</code></p>
48- *
49- * @since 1.1.0
50- */
51- @ Parameter (property = "genBaseDir" , required = true , alias = DaogenCatalogConstants .GEN_PROP_BASE_SRC_FOLDER )
52- protected String genBaseDir ;
53-
54- /**
55- * <p>Overrides <code>'src-mvn-generated-sources'</code> daogen general property.</p>
56- *
57- * <p>It represents the generation source directory for maven generated sources
58- * (for instance 'target/generated-sources/daogen'),
59- * relative to <code>'base-src-folder'</code></p>
60- *
61- * @since 1.1.1
62- */
63- @ Parameter (property = "generatedSourceHelper" , required = false , alias = DaogenCatalogConstants .GEN_PROP_SRC_MVN_GENERATED )
64- protected String generatedSourceHelper ;
65-
66- /**
67- * <p>Overrides <code>'generator-catalog'</code> daogen general property.</p>
68- *
69- * <p>If it is a file, it is recommended to set it to the full path, for instance :
70- * <code>file://${project.basedir}/src/main/daogen/generator-catalog.xml</code></p>
71- *
72- * @since 1.1.1
73- */
74- @ Parameter (property = "generatorCatalog" , required = false , alias = DaogenCatalogConstants .GEN_PROP_GENERATOR_CATALOG )
75- protected String generatorCatalog ;
76-
77- /**
78- * <p>Overrides <code>'decorator-catalog'</code> daogen general property.</p>
79- *
80- * <p>If it is a file, it is recommended to set it to the full path, for instance :
81- * <code>file://${project.basedir}/src/main/daogen/decorator-catalog.xml</code></p>
82- *
83- * @since 1.1.1
84- */
85- @ Parameter (property = "decoratorCatalog" , required = false , alias = DaogenCatalogConstants .GEN_PROP_DECORATOR_CATALOG )
86- protected String decoratorCatalog ;
87-
88- private void addProperty ( Properties overrideProperties , String key , String value ) {
89- if ( StringUtils .isNotEmpty (value ) ) {
90- getLog ().info ( "override property, key : " +key +", value : " +value );
91- overrideProperties .setProperty (key , value );
92- }
93- }
94-
95- public void execute () throws MojoExecutionException {
96- getLog ().info ( "using parameter " +PARAM_DAOGEN_CONFIG +" : " +this .daogenConfig );
97- File file = new File ( this .daogenConfig );
98- try {
99- getLog ().info ( "daogen config path : " +file .getCanonicalPath () );
100- Properties overrideProperties = new Properties ();
101- this .addProperty (overrideProperties , DaogenCatalogConstants .GEN_PROP_BASE_SRC_FOLDER , this .genBaseDir );
102- this .addProperty (overrideProperties , DaogenCatalogConstants .GEN_PROP_SRC_MVN_GENERATED , this .generatedSourceHelper );
103- this .addProperty (overrideProperties , DaogenCatalogConstants .GEN_PROP_GENERATOR_CATALOG , this .generatorCatalog );
104- this .addProperty (overrideProperties , DaogenCatalogConstants .GEN_PROP_DECORATOR_CATALOG , this .decoratorCatalog );
105- try ( FileInputStream fis = new FileInputStream ( file ) ) {
106- DaogenFacade .generate ( fis , overrideProperties );
107- }
108- } catch (Exception e ) {
109- throw new MojoExecutionException ( "Error generating code : " +e , e );
110- }
111- }
11221
11322}
0 commit comments