Skip to content

Commit ca8f5e3

Browse files
authored
Merge pull request #44 from fugerit-org/43-graalvm-metadata-generation
43 graalvm metadata generation
2 parents 6cdfff1 + ba55676 commit ca8f5e3

File tree

16 files changed

+188
-42
lines changed

16 files changed

+188
-42
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Sample GraalVMReflectConfigGenerator
13+
- <https://github.com/fugerit-org/native-helper-graalvm> version 1.0.0
14+
15+
### Changed
16+
17+
- Documentation for GraalVMReflectConfigGenerator, Junit4ModelGenerator, Junit5ModelGenerator,.
18+
19+
### Fixed
20+
21+
- fix name in Junit5ModelGenerator generated classes
22+
1023
## [1.5.1] - 2024-02-28
1124

1225
### Changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ There are two basic feature supplied by the library :
3131
1. [DAO Configuration dump](src/docs/dao_dump.md), this is optional, it provides a configuration dump for the 'DAO Generation' feature.
3232
2. [DAO Generation](src/docs/dao_gen.md), this is the main feature, it generates various items based on a configuration file, named 'daogen-config.xml' (see a [sample daogen-config-xml](fj-daogen-sample/src/main/daogen/fugerit-sample-daogen-config.xml))
3333

34+
[configuration entry point](https://marsdocs.fugerit.org/src/docs/config/config.html)
35+
3436
## [fj-daogen-base](fj-daogen-base/README.md) the core module
3537
This modules contains core functionalities of the library : 'DAO Configuration dump' and 'DAO Generation'
3638

fj-daogen-base/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-daogen</artifactId>
10-
<version>1.5.1</version>
10+
<version>1.5.2-SNAPSHOT</version>
1111
</parent>
1212

1313
<name>fj-daogen-base</name>
@@ -35,8 +35,14 @@
3535
<dependency>
3636
<groupId>org.fugerit.java</groupId>
3737
<artifactId>fj-doc-lib-autodoc</artifactId>
38-
</dependency>
39-
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.fugerit.java</groupId>
42+
<artifactId>native-helper-graalvm</artifactId>
43+
<version>${native-helper-graalvm-version}</version>
44+
</dependency>
45+
4046
<dependency>
4147
<groupId>org.fugerit.java</groupId>
4248
<artifactId>fj-test-helper8</artifactId>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ private DaogenCatalogConstants() {}
5454

5555
public static final String GEN_PROP_PACKAGE_FACTORY_DEF = "factory-def";
5656
public static final String GEN_PROP_PACKAGE_FACTORY_DATA_IMPL = "factory-data-impl";
57-
57+
58+
public static final String GEN_PROP_GRAALVM_REFLECT_CONFIG = "graalvm-reflect-config";
59+
5860
public static final String GEN_PROP_DEFAULT_COLUMN_TIME_INSERT = "default-column-time-insert";
5961
public static final String GEN_PROP_DEFAULT_COLUMN_TIME_UPDATE = "default-column-time-update";
6062

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.fugerit.java.daogen.base.gen;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.core.cfg.ConfigException;
5+
import org.fugerit.java.core.javagen.GeneratorNameHelper;
6+
import org.fugerit.java.daogen.base.config.*;
7+
8+
import org.fugerit.java.nhg.GenerateReflectConfig;
9+
import org.fugerit.java.nhg.reflect.config.Entry;
10+
import org.fugerit.java.nhg.reflect.config.EntryMethod;
11+
12+
import java.io.File;
13+
import java.io.IOException;
14+
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.List;
17+
import java.util.stream.Collectors;
18+
19+
@Slf4j
20+
public class GraalVMReflectConfigGenerator extends DaogenBasicGenerator {
21+
22+
public static final String KEY = GraalVMReflectConfigGenerator.class.getSimpleName();
23+
24+
@Override
25+
public String getKey() {
26+
return KEY;
27+
}
28+
29+
@Override
30+
public void init(DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity) throws ConfigException {
31+
String sourceFolder = daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_SRC_MAIN_RESOURCES );
32+
String jsonFile = daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_GRAALVM_REFLECT_CONFIG );
33+
super.setDaogenConfig( daogenConfig );
34+
super.init( sourceFolder, jsonFile, STYLE_CLASS, daogenConfig, entity );
35+
File path = new File( new File( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_BASE_SRC_FOLDER ), sourceFolder ), jsonFile );
36+
log.info( "path : {}", path );
37+
this.setJavaFile(path);
38+
}
39+
40+
@Override
41+
public void generateDaogenBody() throws IOException {
42+
// donothing()
43+
}
44+
private void handleEntity(DaogenCatalogEntity entity, List<Entry> reflectConfig ) {
45+
String[] entryNames = { fullObjectName( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL ), DaogenCatalogConstants.modelName( entity ) ),
46+
fullObjectName( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER ), DaogenCatalogConstants.helperName( entity ) ),
47+
fullObjectName( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER ), DaogenCatalogConstants.wrapperName( entity ) ) };
48+
for ( String name : entryNames ) {
49+
Entry entry = new Entry();
50+
log.info( "name : {}", name );
51+
entry.setName( name );
52+
reflectConfig.add( entry );
53+
EntryMethod initMethod = new EntryMethod();
54+
initMethod.setName( "<init>" );
55+
List<EntryMethod> methods = new ArrayList<>();
56+
methods.add( initMethod );
57+
methods.addAll( entity.stream().map( field -> {
58+
EntryMethod m = new EntryMethod();
59+
String javaSuffix = GeneratorNameHelper.toClassName( field.getId() );
60+
m.setName( "get"+javaSuffix );
61+
return m;
62+
} ).collect( Collectors.toList() ) );
63+
entry.setMethods( methods );
64+
}
65+
66+
}
67+
68+
@Override
69+
public void generate() throws IOException {
70+
List<String> entityIdList = new ArrayList<>( this.getDaogenConfig().getIdSet() );
71+
Collections.sort( entityIdList );
72+
List<Entry> reflectConfig = new ArrayList<>();
73+
// iterate over entity to generate
74+
for ( String entityId : entityIdList ) {
75+
DaogenCatalogEntity entity = this.getDaogenConfig().getListMap( entityId );
76+
log.info( "native config for : {} -> {}", entity.getId(), entity.describe() );
77+
this.handleEntity( entity, reflectConfig );
78+
}
79+
GenerateReflectConfig generateReflectConfig = new GenerateReflectConfig();
80+
generateReflectConfig.generate( this.getWriter(), reflectConfig );
81+
}
82+
83+
}

fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/Junit5ModelGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public boolean isGenerate( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity
2626

2727
public void init( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity ) throws ConfigException {
2828
super.init( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_SRC_TEST_JAVA ),
29-
fullObjectName( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_JUNIT5_MODEL ), DaogenCatalogConstants.junit4ModelName( entity ) ),
29+
fullObjectName( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_JUNIT5_MODEL ), DaogenCatalogConstants.junit5ModelName( entity ) ),
3030
STYLE_INTERFACE, daogenConfig, entity );
3131
this.setPublicClass( false );
3232
this.setJavaStyle( STYLE_CLASS );

fj-daogen-base/src/main/resources/config/daogen-config-1-0.xsd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*
77
* @project : fj-daogen
88
* @creation : 2020-11-12
9-
* @version : 1.0.0-rc.5 (2023-09-25)
9+
* @version : 1.0.0-rc.6 (2024-03-01)
1010
*
1111
* XSD for fugerit daogen configuration
1212
*/
1313
14-
The entry point for daogen-config documentation is : https://marsdocs.fugerit.org/docs/dao_gen.html
14+
The entry point for daogen-config documentation is : https://marsdocs.fugerit.org/src/docs/config/config.html
1515
1616
<daogen-config
1717
xmlns="http://daogen.fugerit.org"
@@ -240,6 +240,14 @@ The entry point for daogen-config documentation is : https://marsdocs.fugerit.or
240240
<xsd:documentation>NOTE: The junit generation is a very simple stub to start with.</xsd:documentation>
241241
</xsd:annotation>
242242
</xsd:attribute>
243+
<xsd:attribute type="xsd:string" name="graalvm-reflect-config=" use="optional">
244+
<xsd:annotation>
245+
<xsd:documentation>Path to the reflect-config.json file to be created</xsd:documentation>
246+
<xsd:documentation>(e.g. 'daogen-reflect-config.json').</xsd:documentation>
247+
<xsd:documentation>Initial folder is defined by 'src-main-resources' property.</xsd:documentation>
248+
<xsd:documentation>NOTE: Only one file for all the project will be created.</xsd:documentation>
249+
</xsd:annotation>
250+
</xsd:attribute>
243251
<xsd:attribute type="xsd:string" name="base-rest-service" use="optional">
244252
<xsd:annotation>
245253
<xsd:documentation>The base class for REST services.</xsd:documentation>

fj-daogen-base/src/main/resources/config/default-generator-catalog.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,23 @@
7878
info="package-spring-rest-load"/>
7979
</factory>
8080

81-
<factory id="factory_generators">
81+
<factory id="factory_generators_base">
82+
<!-- graalvm specific generators -->
83+
<data id="GraalVMReflectConfigGenerator"
84+
type="org.fugerit.java.daogen.base.gen.GraalVMReflectConfigGenerator"
85+
info="graalvm-reflect-config"/>
86+
</factory>
87+
88+
<factory id="factory_generators" extends="factory_generators_base">
8289
<data id="FactoryDefGenerator"
8390
type="org.fugerit.java.daogen.base.gen.FactoryDefGenerator"
8491
info="factory-def"/>
8592
<data id="FactoryDataImplGenerator"
8693
type="org.fugerit.java.daogen.base.gen.FactoryDataImplGenerator"
87-
info="factory-data-impl"/>
94+
info="factory-data-impl"/>
8895
</factory>
8996

90-
<factory id="factory_generators_helper">
97+
<factory id="factory_generators_helper" extends="factory_generators_base">
9198
<data id="FactoryDefHelperGenerator"
9299
type="org.fugerit.java.daogen.base.gen.helper.FactoryDefHelperGenerator"
93100
info="factory-def"/>

fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
@Slf4j
1919
public class TestDaogenRun extends MemDBTestBase {
2020

21-
private void testDaoGenerationWorker( File baseDir, Properties overrideProperties ) throws IOException, ConfigException {
22-
overrideProperties.setProperty( DaogenCatalogConstants.GEN_PROP_BASE_SRC_FOLDER , baseDir.getCanonicalPath() );
23-
log.info( "overrideProperties : {}", overrideProperties );
24-
try ( FileInputStream fis = new FileInputStream( new File( "src/test/resources/sample/daogenruntest-sample-daogen-config.xml" ) ) ) {
25-
log.info( "DAOGEN start!" );
26-
DaogenFacade.generate( fis, overrideProperties );
27-
log.info( "DAOGEN end!" );
28-
}
21+
private void testDaoGenerationWorker( File baseDir, Properties overrideProperties ) {
22+
try {
23+
overrideProperties.setProperty( DaogenCatalogConstants.GEN_PROP_BASE_SRC_FOLDER , baseDir.getCanonicalPath() );
24+
log.info( "overrideProperties : {}", overrideProperties );
25+
try ( FileInputStream fis = new FileInputStream( new File( "src/test/resources/sample/daogenruntest-sample-daogen-config.xml" ) ) ) {
26+
log.info( "DAOGEN start!" );
27+
DaogenFacade.generate( fis, overrideProperties );
28+
log.info( "DAOGEN end!" );
29+
}
30+
} catch ( Exception e ) {
31+
logger.info( "Errore : "+e, e );
32+
}
2933
}
3034

3135
@Test

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
base-rest-service="org.fugerit.java.daogen.sample.helper.ServiceProviderHelper"
3030
factory-def="org.fugerit.java.daogen.sample.def.facade.FugeritLogicFacade"
3131
factory-data-impl="org.fugerit.java.daogen.sample.impl.facade.data.FugeritDataLogicFacade"
32+
graalvm-reflect-config="daogen-reflect-config.json"
3233
default-sequence="seq_id_fugerit"
3334
openapi_host="http://localhost:9080"
3435
openapi_path="/fugerit-sample-web/jax-rs"

0 commit comments

Comments
 (0)