Skip to content

Commit 0762805

Browse files
committed
graalvm metadata generation #43
1 parent 843d10c commit 0762805

File tree

9 files changed

+168
-33
lines changed

9 files changed

+168
-33
lines changed

fj-daogen-base/pom.xml

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
*/
@@ -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"

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<maven.compiler.release>${java-version-compliance}</maven.compiler.release>
2727
<fj-version>8.4.10</fj-version>
2828
<fj-doc-version>3.4.3</fj-doc-version>
29-
<javax-rs-api-version>2.1.1</javax-rs-api-version>
29+
<javax-rs-api-version>2.1.1</javax-rs-api-version>
30+
<native-helper-graalvm-version>1.0.0</native-helper-graalvm-version>
3031
<fj-daogen-version>${project.version}</fj-daogen-version>
3132
</properties>
3233

src/docs/config/daogen-config-xsd-ref.html

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,78 +465,89 @@ <h1 style="font-weight: bold;">Reference daogen-config.xsd documentation for Ma
465465
</tr>
466466
<tr>
467467
<td id="cell_32_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
468-
<span >base-rest-service</span>
468+
<span >graalvm-reflect-config=</span>
469469
</td>
470470
<td id="cell_32_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
471-
<span >The base class for REST services. (e.g. 'org.fugerit.java.daogen.sample.helper.ServiceProviderHelper'). NOTE: REST services generation is not recommended, if not as a starting stub.</span>
471+
<span >Path to the reflect-config.json file to be created (e.g. 'daogen-reflect-config.json'). Initial folder is defined by 'src-main-resources' property. NOTE: Only one file for all the project will be created.</span>
472472
</td>
473473
<td id="cell_32_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
474474
<span >string</span>
475475
</td>
476476
</tr>
477477
<tr>
478478
<td id="cell_33_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
479-
<span >openapi_host</span>
479+
<span >base-rest-service</span>
480480
</td>
481481
<td id="cell_33_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
482-
<span >The host to be used for openapi specification and implementation specification.</span>
482+
<span >The base class for REST services. (e.g. 'org.fugerit.java.daogen.sample.helper.ServiceProviderHelper'). NOTE: REST services generation is not recommended, if not as a starting stub.</span>
483483
</td>
484484
<td id="cell_33_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
485-
<span >anyURI</span>
485+
<span >string</span>
486486
</td>
487487
</tr>
488488
<tr>
489489
<td id="cell_34_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
490-
<span >openapi_path</span>
490+
<span >openapi_host</span>
491491
</td>
492492
<td id="cell_34_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
493-
<span >The path to be used for openapi specification and implementation specification.</span>
493+
<span >The host to be used for openapi specification and implementation specification.</span>
494494
</td>
495495
<td id="cell_34_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
496-
<span >string</span>
496+
<span >anyURI</span>
497497
</td>
498498
</tr>
499499
<tr>
500500
<td id="cell_35_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
501-
<span >default-sequence</span>
501+
<span >openapi_path</span>
502502
</td>
503503
<td id="cell_35_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
504-
<span >The default sequence name to be used for the entities (it is possible to override it).</span>
504+
<span >The path to be used for openapi specification and implementation specification.</span>
505505
</td>
506506
<td id="cell_35_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
507507
<span >string</span>
508508
</td>
509509
</tr>
510510
<tr>
511511
<td id="cell_36_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
512-
<span >check-empty-interface</span>
512+
<span >default-sequence</span>
513513
</td>
514514
<td id="cell_36_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
515-
<span >If set to '1' will check if interfaces have no methods. NOTE: currently ignored.</span>
515+
<span >The default sequence name to be used for the entities (it is possible to override it).</span>
516516
</td>
517517
<td id="cell_36_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
518518
<span >string</span>
519519
</td>
520520
</tr>
521521
<tr>
522522
<td id="cell_37_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
523-
<span >jdk-target-version</span>
523+
<span >check-empty-interface</span>
524524
</td>
525525
<td id="cell_37_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
526-
<span >The jdk target version.</span>
526+
<span >If set to '1' will check if interfaces have no methods. NOTE: currently ignored.</span>
527527
</td>
528528
<td id="cell_37_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
529-
<span >jdkTargetVersionType , base : string , enumeration : [ 8 , 11 , 17 , 21 ]</span>
529+
<span >string</span>
530530
</td>
531531
</tr>
532532
<tr>
533533
<td id="cell_38_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
534-
<span >jee-target-mode</span>
534+
<span >jdk-target-version</span>
535535
</td>
536536
<td id="cell_38_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
537-
<span >The enterprise edition target environment.</span>
537+
<span >The jdk target version.</span>
538538
</td>
539539
<td id="cell_38_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
540+
<span >jdkTargetVersionType , base : string , enumeration : [ 8 , 11 , 17 , 21 ]</span>
541+
</td>
542+
</tr>
543+
<tr>
544+
<td id="cell_39_0" style="width: 20%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
545+
<span >jee-target-mode</span>
546+
</td>
547+
<td id="cell_39_1" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
548+
<span >The enterprise edition target environment.</span>
549+
</td>
550+
<td id="cell_39_2" style="width: 40%; border-top: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; padding: 2px;">
540551
<span >jeeTargetModeType , base : string , enumeration : [ javax , jakarta ]</span>
541552
</td>
542553
</tr>

0 commit comments

Comments
 (0)