Skip to content

Commit b1622ec

Browse files
committed
Use of maven plugin for sample
1 parent 80447ef commit b1622ec

30 files changed

+192
-2604
lines changed

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenCatalogConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ private DaogenCatalogConstants() {}
99
public static final String GEN_PROP_BASE_SRC_FOLDER = "base-src-folder";
1010

1111
public static final String GEN_PROP_SRC_MAIN_JAVA = "src-main-java";
12+
1213
public static final String GEN_PROP_SRC_MAIN_RESOURCES = "src-main-resources";
1314
public static final String GEN_PROP_SRC_TEST_JAVA = "src-test-java";
1415
public static final String GEN_PROP_SRC_TEST_RESOURCES = "src-test-resources";
1516
public static final String GEN_PROP_SRC_DOC_OPENAPI = "src-doc-openapi";
1617
public static final String GEN_PROP_SRC_HELPERS = "src-helpers";
1718
public static final String GEN_PROP_SRC_HELPERS_MAIN = "SRC-MAIN-JAVA";
1819
public static final String GEN_PROP_SRC_HELPERS_GEN = "SRC-TARGET";
20+
public static final String GEN_PROP_SRC_MVN_GENERATED = "src-mvn-generated-sources";
1921

2022
public static final String GEN_PROP_RELATIONS_LAST = "relations-last";
2123

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenFacade.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collection;
66
import java.util.Collections;
77
import java.util.List;
8+
import java.util.Properties;
89

910
import org.fugerit.java.core.cfg.ConfigException;
1011
import org.fugerit.java.core.cfg.xml.FactoryType;
@@ -68,9 +69,20 @@ private static void generate( DaogenCatalogConfig daogenConfig, DaogenGeneratorC
6869
}
6970

7071

71-
public static void generate( InputStream fis ) throws ConfigException {
72+
public static void generate( InputStream fis, Properties overrideProperties ) throws ConfigException {
7273
try {
7374
DaogenCatalogConfig daogenConfig = DaogenCatalogConfig.loadConfig( fis );
75+
if ( overrideProperties != null ) {
76+
log.info( "override properties -> {}", overrideProperties );
77+
for ( Object k : overrideProperties.keySet() ) {
78+
String key = k.toString();
79+
String value = overrideProperties.getProperty(key);
80+
log.info( "ovverride {} -> {}", key, value );
81+
daogenConfig.getGeneralProps().setProperty(key, value);
82+
}
83+
daogenConfig.getGeneralProps().keySet().stream().sorted().forEach(
84+
k -> log.info( "prop key : {} value : {}", k, daogenConfig.getGeneralProps().getProperty( k.toString() ) ) );
85+
}
7486
for ( DaogenGeneratorCatalog generatorCatalog : daogenConfig.getGeneratorCatalogs() ) {
7587
generate(daogenConfig, generatorCatalog);
7688
}
@@ -79,4 +91,8 @@ public static void generate( InputStream fis ) throws ConfigException {
7991
}
8092
}
8193

94+
public static void generate( InputStream fis ) throws ConfigException {
95+
generate(fis, null);
96+
}
97+
8298
}

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/config/DaogenHelperGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class DaogenHelperGenerator {
55
private DaogenHelperGenerator() {}
66

77
public static String toHelperSourceFolder( DaogenCatalogConfig config ) {
8-
return config.getGeneralProps().getProperty( DaogenCatalogConstants.GEN_PROP_SRC_HELPERS, DaogenCatalogConstants.GEN_PROP_SRC_HELPERS_MAIN );
8+
return config.getGeneralProps().getProperty( DaogenCatalogConstants.GEN_PROP_SRC_MVN_GENERATED, DaogenCatalogConstants.GEN_PROP_SRC_HELPERS_MAIN );
99
}
1010

1111
public static String toHelperClassName( String className ) {

fj-daogen-base/src/test/resources/sample/fugerit-sample-daogen-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<daogen-config
2-
base-src-folder="../fj-daogen-sample"
2+
base-src-folder="target/daogen-run"
33
database-type="oracle"
44
gen-version="1.0.0"
55
gen-author="fugerit"

fj-daogen-maven-plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<dependency>
3434
<groupId>org.apache.maven</groupId>
3535
<artifactId>maven-plugin-api</artifactId>
36+
<scope>provided</scope>
3637
</dependency>
3738

3839
<dependency>

fj-daogen-maven-plugin/src/main/java/org/fugerit/java/daogen/maven/MojoGenerate.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,52 @@
22

33
import java.io.File;
44
import java.io.FileInputStream;
5+
import java.util.Properties;
56

67
import org.apache.maven.plugin.AbstractMojo;
78
import org.apache.maven.plugin.MojoExecutionException;
89
import org.apache.maven.plugins.annotations.Mojo;
910
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;
1013
import org.fugerit.java.daogen.base.config.DaogenFacade;
1114

12-
@Mojo( name = "generate")
15+
@Mojo( name = "generate" )
1316
public class MojoGenerate extends AbstractMojo {
1417

1518
public static final String PARAM_DAOGEN_CONFIG = "daogen.config";
1619

20+
21+
public static final String PARAM_GENERATED_SOURCE_HELPER = "generated.source.helper";
22+
23+
public static final String PARAM_GEN_BASE_DIR = "gen.base.dir";
24+
1725
@Parameter(property = "daogenConfig", required = true, alias = PARAM_DAOGEN_CONFIG )
1826
private String daogenConfig;
27+
28+
@Parameter(property = "genBaseDir", required = false, alias = PARAM_GEN_BASE_DIR )
29+
private String genBaseDir;
30+
31+
@Parameter(property = "generatedSourceHelper", required = false, alias = PARAM_GENERATED_SOURCE_HELPER )
32+
private String generatedSourceHelper;
33+
34+
private void addProperty( Properties overrideProperties, String key, String value ) {
35+
if ( StringUtils.isNotEmpty(value) ) {
36+
getLog().info( "override property, key : "+key+", value : "+value );
37+
overrideProperties.setProperty(key, value);
38+
}
39+
}
1940

2041
public void execute() throws MojoExecutionException {
2142
getLog().info( "using parameter "+PARAM_DAOGEN_CONFIG+" : "+this.daogenConfig );
2243
File file = new File( this.daogenConfig );
2344
try {
2445
getLog().info( "daogen config path : "+file.getCanonicalPath() );
46+
Properties overrideProperties = new Properties();
47+
this.addProperty(overrideProperties, DaogenCatalogConstants.GEN_PROP_BASE_SRC_FOLDER, this.genBaseDir);
48+
this.addProperty(overrideProperties, DaogenCatalogConstants.GEN_PROP_SRC_MVN_GENERATED, this.generatedSourceHelper);
2549
try ( FileInputStream fis = new FileInputStream( file ) ) {
26-
DaogenFacade.generate( fis );
50+
DaogenFacade.generate( fis, overrideProperties );
2751
}
2852
} catch (Exception e) {
2953
throw new MojoExecutionException( "Error generating code : "+e, e );

fj-daogen-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<pluginExecutionFilter>
55
<goals>
66
<goal>compile</goal>
7+
<goal>generate</goal>
78
</goals>
89
</pluginExecutionFilter>
910
<action>

fj-daogen-sample/pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<name>fj-daogen-sample</name>
1414
<description></description>
1515

16+
<properties>
17+
<gen.base.dir>${project.basedir}</gen.base.dir>
18+
<generated.source.daogen>target/generated-sources/daogen</generated.source.daogen>
19+
</properties>
20+
1621
<licenses>
1722
<license>
1823
<name>Apache License, Version 2.0</name>
@@ -23,6 +28,49 @@
2328

2429
<build>
2530

31+
<plugins>
32+
33+
<plugin>
34+
<groupId>org.fugerit.java</groupId>
35+
<artifactId>fj-daogen-maven-plugin</artifactId>
36+
<executions>
37+
<execution>
38+
<id>daogen</id>
39+
<phase>generate-sources</phase>
40+
<goals>
41+
<goal>generate</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
<configuration>
46+
<daogenConfig>${project.basedir}/src/main/daogen/fugerit-sample-daogen-config.xml</daogenConfig>
47+
<genBaseDir>${gen.base.dir}</genBaseDir>
48+
<generatedSourceHelper>${generated.source.daogen}</generatedSourceHelper>
49+
</configuration>
50+
</plugin>
51+
52+
<plugin>
53+
<groupId>org.codehaus.mojo</groupId>
54+
<artifactId>build-helper-maven-plugin</artifactId>
55+
<version>3.4.0</version>
56+
<executions>
57+
<execution>
58+
<id>add-source</id>
59+
<phase>generate-sources</phase>
60+
<goals>
61+
<goal>add-source</goal>
62+
</goals>
63+
<configuration>
64+
<sources>
65+
<source>${gen.base.dir}/${generated.source.daogen}</source>
66+
</sources>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
72+
</plugins>
73+
2674
</build>
2775

2876
<dependencies>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<daogen-config
2+
database-type="oracle"
3+
gen-version="1.0.0"
4+
gen-author="fugerit"
5+
src-main-java="src/main/java"
6+
src-test-java="src/test/java"
7+
src-main-resources="src/main/resources"
8+
src-test-resources="src/test/resources"
9+
src-helpers="SRC-MAIN-JAVA"
10+
src-doc-openapi="src/main/doc/openapi_rest"
11+
class-config="cl://config/daogen_default_class_config.xml"
12+
type-mapper="org.fugerit.java.daogen.base.config.DaogenTypeMapper"
13+
type-map-config="cl://config/daogen_default_type_mapping.xml"
14+
generator-catalog="cl://config/default-generator-catalog.xml"
15+
decorator-catalog="cl://config/default-decorator-catalog.xml"
16+
default-column-time-insert="DATE_INSERT"
17+
default-column-time-update="DATE_UPDATE"
18+
struct_prefix="OBJ_"
19+
package-model="org.fugerit.java.daogen.sample.def.model"
20+
package-helper="org.fugerit.java.daogen.sample.impl.helper"
21+
package-struct="org.fugerit.java.daogen.sample.impl.struct"
22+
package-rse="org.fugerit.java.daogen.sample.impl.rse"
23+
package-facade-def="org.fugerit.java.daogen.sample.def.facade"
24+
package-facade-data-impl="org.fugerit.java.daogen.sample.impl.facade.data"
25+
package-rest-load="org.fugerit.java.daogen.sample.impl.rest.load"
26+
base-rest-service="org.fugerit.java.daogen.sample.helper.ServiceProviderHelper"
27+
factory-def="org.fugerit.java.daogen.sample.def.facade.FugeritLogicFacade"
28+
factory-data-impl="org.fugerit.java.daogen.sample.impl.facade.data.FugeritDataLogicFacade"
29+
default-sequence="seq_id_fugerit"
30+
openapi_host="http://localhost:9080"
31+
openapi_path="/fugerit-sample-web/jax-rs"
32+
check-empty-interface="1"
33+
>
34+
35+
<relation id="userToAddress" name="USER_ADDRESSES" from="PUBLIC.FUGERIT.USER" to="PUBLIC.FUGERIT.ADDRESS" mode="many" key="ID_USER"/>
36+
<relation id="addressToUser" name="USER" from="PUBLIC.FUGERIT.ADDRESS" to="PUBLIC.FUGERIT.USER" mode="one" key="ID_USER"/>
37+
38+
<entity catalog="PUBLIC" comments="Contains users data" id="PUBLIC.FUGERIT.USER" name="USER" primaryKey="ID" schema="FUGERIT">
39+
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
40+
<field comments="User chosen id" id="USERNAME" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
41+
<field comments="Password hash" id="PASSWORD" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
42+
<field comments="Time of last user login" id="LAST_LOGIN" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
43+
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
44+
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
45+
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
46+
</entity>
47+
<entity catalog="PUBLIC" comments="Contains addresses data" foreignKeys="PUBLIC.FUGERIT.USER" id="PUBLIC.FUGERIT.ADDRESS" name="ADDRESS" primaryKey="ID" schema="FUGERIT">
48+
<field comments="Address system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
49+
<field comments="User linked to to address" id="ID_USER" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
50+
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
51+
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
52+
<field comments="Address info" id="INFO" javaType="java.lang.String" nullable="no" size="256" sqlType="12" sqlTypeName="VARCHAR"/>
53+
</entity>
54+
<entity catalog="PUBLIC" comments="Contains upload blob" id="PUBLIC.FUGERIT.UPLOAD" name="UPLOAD" primaryKey="ID" schema="FUGERIT">
55+
<field comments="" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
56+
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
57+
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
58+
<field comments="" id="CONTENT" javaType="java.sql.Blob" nullable="yes" size="1073741824" sqlType="2004" sqlTypeName="BLOB"/>
59+
</entity>
60+
<entity catalog="PUBLIC" id="PUBLIC.FUGERIT.LOG_DATA" name="LOG_DATA" schema="FUGERIT">
61+
<field comments="" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
62+
<field comments="" id="LOG_TIME" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
63+
<field comments="" id="INFO" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
64+
</entity>
65+
<entity catalog="PUBLIC" id="PUBLIC.FUGERIT.TEST_TWO_FIELD_KEY" name="TEST_TWO_FIELD_KEY" primaryKey="ID_ONE,ID_TWO" schema="FUGERIT">
66+
<field comments="" id="ID_ONE" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
67+
<field comments="" id="ID_TWO" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
68+
<field comments="" id="INFO" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
69+
</entity>
70+
71+
<entity catalog="PUBLIC" comments="Contains users data" id="PUBLIC.FUGERIT.USER_DATA" name="USER_DATA" primaryKey="ID" schema="FUGERIT" mapToTable="USER">
72+
<field comments="User system id" id="ID" javaType="java.lang.Long" nullable="no" size="0" sqlType="-5" sqlTypeName="BIGINT"/>
73+
<field comments="User chosen id" id="USERNAME" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
74+
<field comments="Password hash" id="PASSWORD" javaType="java.lang.String" nullable="no" size="128" sqlType="12" sqlTypeName="VARCHAR"/>
75+
<field comments="Time of last user login" id="LAST_LOGIN" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
76+
<field comments="" id="DATE_INSERT" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
77+
<field comments="" id="DATE_UPDATE" javaType="java.sql.Timestamp" nullable="yes" size="0" sqlType="93" sqlTypeName="TIMESTAMP"/>
78+
<field comments="1 active, 0 not active" id="STATE" javaType="java.lang.Integer" nullable="no" size="0" sqlType="4" sqlTypeName="INTEGER"/>
79+
</entity>
80+
81+
82+
</daogen-config>

fj-daogen-sample/src/main/java/org/fugerit/java/daogen/sample/def/facade/EntityAddressFacadeHelper.java

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

0 commit comments

Comments
 (0)