From 2ea64bc8c85d581637e0331adef1fd78e708392e Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 01:18:35 +0200 Subject: [PATCH 1/7] new module to generate documents from a configuration file #391 --- CHANGELOG.md | 4 + .../FreemarkerDocProcessConfigFacade.java | 11 +++ .../fj-doc-freemarker/reflect-config.json | 6 ++ .../TestFreemarkerDocProcessConfig.java | 7 ++ fj-doc-lib-direct/pom.xml | 97 +++++++++++++++++++ .../doc/lib/direct/VenusDirectFacade.java | 64 ++++++++++++ .../lib/direct/config/VenusDirectConfig.java | 75 ++++++++++++++ .../direct/config/VenusDirectConfigChain.java | 16 +++ .../config/VenusDirectConfigHandler.java | 11 +++ .../config/VenusDirectConfigOutput.java | 20 ++++ .../doc/lib/direct/TestVenusDirectFacade.java | 26 +++++ .../config/venus-direct-config-1.yaml | 20 ++++ .../src/test/resources/template/test-doc.ftl | 44 +++++++++ .../java/doc/core/val/TestTiffValidator.java | 3 + pom.xml | 7 ++ 15 files changed, 411 insertions(+) create mode 100644 fj-doc-lib-direct/pom.xml create mode 100644 fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java create mode 100644 fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java create mode 100644 fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java create mode 100644 fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigHandler.java create mode 100644 fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigOutput.java create mode 100644 fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java create mode 100644 fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml create mode 100644 fj-doc-lib-direct/src/test/resources/template/test-doc.ftl diff --git a/CHANGELOG.md b/CHANGELOG.md index 928c0a8ec..cf36119f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- [fj-doc-lib-direct] new module to generate documents from a configuration file + ### Changed - graalvm '24' instead of '23' for build_fj-doc-native-quarkus_test.yml workflow diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java index 625bf68c1..f452aab14 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java @@ -111,7 +111,15 @@ private FreemarkerDocProcessConfigFacade() {} return new ConfigRuntimeException(e); }; + public static FreemarkerDocProcessConfig newSimpleConfigMode( String id, String templatePath, String mode ) throws ConfigException { + return newSimpleConfig( id, templatePath, null, mode ); + } + public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath, String version ) throws ConfigException { + return newSimpleConfig( id, templatePath, version, null ); + } + + public static FreemarkerDocProcessConfig newSimpleConfig( String id, String templatePath, String version, String mode ) throws ConfigException { return ConfigException.get( () -> { FreemarkerDocProcessConfig config = new FreemarkerDocProcessConfig(); config.setDefaultChain( @@ -122,6 +130,9 @@ public static FreemarkerDocProcessConfig newSimpleConfig( String id, String temp FreeMarkerConfigStep configStep = new FreeMarkerConfigStep(); Properties configParams = new Properties(); configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , templatePath ); + if ( mode != null ) { + configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , mode ); + } if ( version != null ) { configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , version ); } diff --git a/fj-doc-freemarker/src/main/resources/META-INF/native-image/org.fugerit.java/fj-doc-freemarker/reflect-config.json b/fj-doc-freemarker/src/main/resources/META-INF/native-image/org.fugerit.java/fj-doc-freemarker/reflect-config.json index d04c9e283..47e440547 100644 --- a/fj-doc-freemarker/src/main/resources/META-INF/native-image/org.fugerit.java/fj-doc-freemarker/reflect-config.json +++ b/fj-doc-freemarker/src/main/resources/META-INF/native-image/org.fugerit.java/fj-doc-freemarker/reflect-config.json @@ -456,6 +456,12 @@ }, { "name" : "newSimpleConfig", "parameterTypes" : [ "java.lang.String", "java.lang.String", "java.lang.String" ] + }, { + "name" : "newSimpleConfig", + "parameterTypes" : [ "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" ] + }, { + "name" : "newSimpleConfigMode", + "parameterTypes" : [ "java.lang.String", "java.lang.String", "java.lang.String" ] }, { "name" : "notify", "parameterTypes" : [ ] diff --git a/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java b/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java index 9f8337194..d96d97501 100644 --- a/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java +++ b/fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java @@ -39,6 +39,13 @@ class TestFreemarkerDocProcessConfig extends BasicTest { private static final String MAIN_CONFIG = "fj_doc_test/freemarker-doc-process.xml"; + @Test + void testSimpleConfig() throws ConfigException { + FreemarkerDocProcessConfig configFolder = FreemarkerDocProcessConfigFacade.newSimpleConfigMode( + "test-mode", "path/", "folder" ); + Assertions.assertNotNull( configFolder ); + } + @Test void testConfigRead001() throws Exception { String[] configList = { MAIN_CONFIG, "fj_doc_test/freemarker-doc-process-1.xml", "fj_doc_test/freemarker-doc-process-2.xml", "fj_doc_test/freemarker-doc-process-3.xml" }; diff --git a/fj-doc-lib-direct/pom.xml b/fj-doc-lib-direct/pom.xml new file mode 100644 index 000000000..7c64880fd --- /dev/null +++ b/fj-doc-lib-direct/pom.xml @@ -0,0 +1,97 @@ + + 4.0.0 + + fj-doc-lib-direct + + + org.fugerit.java + fj-doc + 8.12.9-SNAPSHOT + + + fj-doc-lib-direct + API for Direct Document Generation + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + + + + org.fugerit.java + fj-core + + + + org.fugerit.java + fj-doc-base + + + + org.fugerit.java + fj-doc-base-json + + + + org.fugerit.java + fj-doc-base-yaml + + + + org.fugerit.java + fj-doc-freemarker + + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + https://www.fugerit.org + Fugerit + + + https://www.fugerit.org/perm/venus/ + + + + + full + + + + org.apache.maven.plugins + maven-javadoc-plugin + + src/main/javadoc/stylesheet.css + ${autodoc-detail-package-name},${autodoc-meta-package-name} + + + + attach-javadocs + + jar + + + + + + + + + + + diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java new file mode 100644 index 000000000..d112e8a0b --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java @@ -0,0 +1,64 @@ +package org.fugerit.java.doc.lib.direct; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import org.fugerit.java.core.cfg.ConfigRuntimeException; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.doc.base.config.DocConfig; +import org.fugerit.java.doc.base.process.DocProcessContext; +import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep; +import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade; +import org.fugerit.java.doc.lib.direct.config.VenusDirectConfig; +import org.fugerit.java.doc.lib.direct.config.VenusDirectConfigChain; +import org.fugerit.java.doc.lib.direct.config.VenusDirectConfigOutput; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.Reader; + +public class VenusDirectFacade { + + public static final String ATT_DATA_MODEL = "dataModel"; + + private VenusDirectFacade() {} + + private static final ObjectMapper YAML_MAPPER = new YAMLMapper(); + + public static VenusDirectConfig readConfig( Reader reader ) { + return SafeFunction.get( () -> { + VenusDirectConfig config = YAML_MAPPER.readValue( reader, VenusDirectConfig.class ); + config.setupFreemarkerDocProcessConfig(); + return config; + } ); + } + + public static void handleAllOutput(VenusDirectConfig config) { + SafeFunction.applyIfNotNull( config.getOutputList(), () -> + config.getOutputList().forEach( output -> handleOutput( config, output.getOutputId() ) ) ); + } + + public static void handleOutput(VenusDirectConfig config, String outputId) { + SafeFunction.apply( () -> { + VenusDirectConfigOutput output = config.getOutputMap().get( outputId ); + if ( output == null ) { + throw new ConfigRuntimeException( String.format( "Output not found : %s", outputId ) ); + } + VenusDirectConfigChain chain = config.getChainMap().get( output.getChainId() ); + if ( chain == null ) { + throw new ConfigRuntimeException( String.format( "Chain not found : %s", output.getChainId() ) ); + } + DocProcessContext context = DocProcessContext.newContext(); + if ( chain.getDataModel() != null ) { + context.setAttribute( ATT_DATA_MODEL, chain.getDataModel() ); + } + File outputFile = new File( output.getFile() ); + try ( FileOutputStream fos = new FileOutputStream( outputFile ) ) { + config.getDocProcessConfig().fullProcess(chain.getChainId(), context, output.getHandlerId(), fos ); + } + } ); + + } + +} diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java new file mode 100644 index 000000000..5ce3f2999 --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java @@ -0,0 +1,75 @@ +package org.fugerit.java.doc.lib.direct.config; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.fugerit.java.core.cfg.ConfigException; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.core.lang.helpers.ClassHelper; +import org.fugerit.java.doc.base.config.DocTypeHandler; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade; + +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +public class VenusDirectConfig { + + @Getter + private FreemarkerDocProcessConfig docProcessConfig; + + @Getter + private Map chainMap; + + @Getter + private Map outputMap; + + public void setupFreemarkerDocProcessConfig() throws ConfigException { + log.info( "configId: {}, init", this.getConfigId() ); + log.info( "templatePath: {}, templateMode: {}", this.getTemplatePath(), this.getTemplateMode() ); + this.docProcessConfig = FreemarkerDocProcessConfigFacade.newSimpleConfigMode( + this.getConfigId(), this.getTemplatePath(), this.getTemplateMode() ); + // config handlers + SafeFunction.applyIfNotNull( this.getHandlerList(), () -> { + for ( VenusDirectConfigHandler handler : this.getHandlerList() ) { + String handlerType = handler.getType(); + log.info( "configId: {}, handlerType: {}", this.getConfigId(), handlerType ); + ConfigException.apply( () -> + this.docProcessConfig.getFacade().registerHandler( + (DocTypeHandler) ClassHelper.newInstance( handlerType ) ) ); + } + } ); + // config chain + SafeFunction.applyIfNotNull( this.getChainList(), + () -> this.chainMap = this.getChainList().stream().collect( Collectors.toMap( chain -> chain.getChainId(), chain -> chain ) ) ); + log.info( "chainMap ids: {}", this.chainMap.keySet() ); + // config output + SafeFunction.applyIfNotNull( this.getOutputList(), + () -> this.outputMap = this.getOutputList().stream().collect( Collectors.toMap( output -> output.getOutputId(), output -> output ) ) ); + log.info( "outputMap ids: {}", this.outputMap.keySet() ); + } + + @Getter @Setter + private String configId; + + @Getter @Setter + private String templatePath; + + @Getter @Setter + private String templateMode; + + @Getter @Setter + private List handlerList; + + @Getter @Setter + private List chainList; + + @Getter @Setter + private List outputList; + + +} diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java new file mode 100644 index 000000000..f732119cb --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java @@ -0,0 +1,16 @@ +package org.fugerit.java.doc.lib.direct.config; + +import lombok.Getter; +import lombok.Setter; + +import java.util.LinkedHashMap; + +public class VenusDirectConfigChain { + + @Getter @Setter + private String chainId; + + @Getter @Setter + private LinkedHashMap dataModel; + +} diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigHandler.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigHandler.java new file mode 100644 index 000000000..fa351b28e --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigHandler.java @@ -0,0 +1,11 @@ +package org.fugerit.java.doc.lib.direct.config; + +import lombok.Getter; +import lombok.Setter; + +public class VenusDirectConfigHandler { + + @Getter @Setter + private String type; + +} diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigOutput.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigOutput.java new file mode 100644 index 000000000..fdd5e7987 --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigOutput.java @@ -0,0 +1,20 @@ +package org.fugerit.java.doc.lib.direct.config; + +import lombok.Getter; +import lombok.Setter; + +public class VenusDirectConfigOutput { + + @Getter @Setter + private String outputId; + + @Getter @Setter + private String chainId; + + @Getter @Setter + private String handlerId; + + @Getter @Setter + private String file; + +} diff --git a/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java b/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java new file mode 100644 index 000000000..3354345e2 --- /dev/null +++ b/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java @@ -0,0 +1,26 @@ +package org.fugerit.java.doc.lib.direct; + +import org.fugerit.java.core.cfg.ConfigRuntimeException; +import org.fugerit.java.core.lang.helpers.ClassHelper; +import org.fugerit.java.doc.lib.direct.config.VenusDirectConfig; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +class TestVenusDirectFacade { + + @Test + public void testDoc() throws IOException { + try (Reader reader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( "config/venus-direct-config-1.yaml" ) )) { + VenusDirectConfig config = VenusDirectFacade.readConfig( reader ); + VenusDirectFacade.handleAllOutput( config ); + Assertions.assertThrows( ConfigRuntimeException.class, () -> VenusDirectFacade.handleOutput( config, "not-existing-output-id" ) ); + config.getChainMap().remove( "test-doc" ); + Assertions.assertThrows( ConfigRuntimeException.class, () -> VenusDirectFacade.handleOutput( config, "test-doc-html" ) ); + } + } + +} diff --git a/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml new file mode 100644 index 000000000..4cc1d51d9 --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml @@ -0,0 +1,20 @@ +--- +configId: 'venus-direct-config-1' +templatePath: 'src/test/resources/template/' +templateMode: 'folder' +handlerList: + - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 + - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 +chainList: + - chainId: 'test-doc' + dataModel: + docTitle: 'Venus Direct Extension - Test Doc' +outputList: + - outputId: 'test-doc-html' + chainId: 'test-doc' + handlerId: 'html' + file: 'target/test-doc.html' + - outputId: 'test-doc-md' + chainId: 'test-doc' + handlerId: 'md' + file: 'target/test-doc.md' \ No newline at end of file diff --git a/fj-doc-lib-direct/src/test/resources/template/test-doc.ftl b/fj-doc-lib-direct/src/test/resources/template/test-doc.ftl new file mode 100644 index 000000000..cfef82862 --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/template/test-doc.ftl @@ -0,0 +1,44 @@ +<#ftl output_format="XML"> + + + + + + + + + 10;10;10;30 + + + excel-table=print + 450 + + excel-table + + + + ${r"${currentPage}"} / ${r"${pageCount}"} + + + + + + ${dataModel.docTitle} + ${.output_format} - ${testKey!'not present'} + + + Name + Surname + Title + +
+ + +
\ No newline at end of file diff --git a/fj-doc-val-core/src/test/java/test/org/fugerit/java/doc/core/val/TestTiffValidator.java b/fj-doc-val-core/src/test/java/test/org/fugerit/java/doc/core/val/TestTiffValidator.java index 44c829cc6..eec796578 100644 --- a/fj-doc-val-core/src/test/java/test/org/fugerit/java/doc/core/val/TestTiffValidator.java +++ b/fj-doc-val-core/src/test/java/test/org/fugerit/java/doc/core/val/TestTiffValidator.java @@ -4,6 +4,8 @@ import org.fugerit.java.doc.val.core.basic.ImageValidator; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.JRE; class TestTiffValidator extends TestDocValidatorFacade { @@ -13,6 +15,7 @@ class TestTiffValidator extends TestDocValidatorFacade { // note : only supported for java 9+ @Test + @EnabledOnJre( JRE.JAVA_11 ) void testTiffAsTiff() { boolean ok = this.worker(FACADE, "tiff_as_tiff.tiff", true ); Assertions.assertTrue( ok ); diff --git a/pom.xml b/pom.xml index 4a9fafc1a..533495b78 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,7 @@ fj-doc-freemarker fj-doc-lib-simpletable fj-doc-lib-simpletable-import + fj-doc-lib-direct fj-doc-lib-autodoc fj-doc-lib-kotlin fj-doc-mod-poi @@ -206,6 +207,12 @@ ${fj-doc-version} + + org.fugerit.java + fj-doc-lib-direct + ${fj-doc-version} + + org.fugerit.java fj-doc-lib-kotlin From 60a7d68433792db30b64e94eea775ee5863c02ac Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 01:34:40 +0200 Subject: [PATCH 2/7] fix javadoc generation #391 --- fj-doc-lib-direct/pom.xml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/fj-doc-lib-direct/pom.xml b/fj-doc-lib-direct/pom.xml index 7c64880fd..228d310d5 100644 --- a/fj-doc-lib-direct/pom.xml +++ b/fj-doc-lib-direct/pom.xml @@ -66,32 +66,4 @@ https://www.fugerit.org/perm/venus/ - - - - full - - - - org.apache.maven.plugins - maven-javadoc-plugin - - src/main/javadoc/stylesheet.css - ${autodoc-detail-package-name},${autodoc-meta-package-name} - - - - attach-javadocs - - jar - - - - - - - - - - From 7c9336a3ff91a7124176be30e3b780b34fc203fc Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 01:52:06 +0200 Subject: [PATCH 3/7] coverage #391 --- .../process/FreemarkerDocProcessConfigFacade.java | 9 +++------ .../fugerit/java/doc/lib/direct/VenusDirectFacade.java | 4 +--- .../java/doc/lib/direct/TestVenusDirectFacade.java | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java index f452aab14..ec9a2641b 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java @@ -15,6 +15,7 @@ import org.fugerit.java.core.cfg.ConfigurableObject; import org.fugerit.java.core.cfg.helpers.UnsafeHelper; import org.fugerit.java.core.cfg.xml.XmlBeanHelper; +import org.fugerit.java.core.function.SafeFunction; import org.fugerit.java.core.io.helper.StreamHelper; import org.fugerit.java.core.lang.helpers.BooleanUtils; import org.fugerit.java.core.lang.helpers.ClassHelper; @@ -130,12 +131,8 @@ public static FreemarkerDocProcessConfig newSimpleConfig( String id, String temp FreeMarkerConfigStep configStep = new FreeMarkerConfigStep(); Properties configParams = new Properties(); configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , templatePath ); - if ( mode != null ) { - configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , mode ); - } - if ( version != null ) { - configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , version ); - } + SafeFunction.applyIfNotNull( version, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , mode ) ); + SafeFunction.applyIfNotNull( mode, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , version ) ); configStep.setParam01( id ); configStep.setCustomConfig( convertConfiguration( configParams ) ); defaultChain.getFilterChain().add( configStep ); diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java index d112e8a0b..f191fb27b 100644 --- a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java @@ -50,9 +50,7 @@ public static void handleOutput(VenusDirectConfig config, String outputId) { throw new ConfigRuntimeException( String.format( "Chain not found : %s", output.getChainId() ) ); } DocProcessContext context = DocProcessContext.newContext(); - if ( chain.getDataModel() != null ) { - context.setAttribute( ATT_DATA_MODEL, chain.getDataModel() ); - } + SafeFunction.applyIfNotNull( chain.getDataModel(), () -> context.setAttribute( ATT_DATA_MODEL, chain.getDataModel() ) ); File outputFile = new File( output.getFile() ); try ( FileOutputStream fos = new FileOutputStream( outputFile ) ) { config.getDocProcessConfig().fullProcess(chain.getChainId(), context, output.getHandlerId(), fos ); diff --git a/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java b/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java index 3354345e2..d9ab208b2 100644 --- a/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java +++ b/fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java @@ -13,7 +13,7 @@ class TestVenusDirectFacade { @Test - public void testDoc() throws IOException { + void testDoc() throws IOException { try (Reader reader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( "config/venus-direct-config-1.yaml" ) )) { VenusDirectConfig config = VenusDirectFacade.readConfig( reader ); VenusDirectFacade.handleAllOutput( config ); From a040e4194fed73b4c487042ac230fdb661c08ffd Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 01:59:52 +0200 Subject: [PATCH 4/7] coverage #391 --- .../freemarker/process/FreemarkerDocProcessConfigFacade.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java index ec9a2641b..e5b1b992d 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/process/FreemarkerDocProcessConfigFacade.java @@ -131,8 +131,8 @@ public static FreemarkerDocProcessConfig newSimpleConfig( String id, String temp FreeMarkerConfigStep configStep = new FreeMarkerConfigStep(); Properties configParams = new Properties(); configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH , templatePath ); - SafeFunction.applyIfNotNull( version, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , mode ) ); - SafeFunction.applyIfNotNull( mode, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , version ) ); + SafeFunction.applyIfNotNull( mode, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE , mode ) ); + SafeFunction.applyIfNotNull( version, () -> configParams.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION , version ) ); configStep.setParam01( id ); configStep.setCustomConfig( convertConfiguration( configParams ) ); defaultChain.getFilterChain().add( configStep ); From d2435bba455179605b372f3677886ad25154a00e Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 02:03:06 +0200 Subject: [PATCH 5/7] maven plugin goal : direct #391 --- CHANGELOG.md | 1 + fj-doc-maven-plugin/pom.xml | 5 ++ .../fugerit/java/doc/maven/MojoDirect.java | 63 +++++++++++++++++++ .../java/doc/project/facade/TestDirect.java | 58 +++++++++++++++++ .../direct/config/venus-direct-config-1.yaml | 20 ++++++ .../resources/direct/template/test-doc.ftl | 44 +++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java create mode 100644 fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java create mode 100644 fj-doc-maven-plugin/src/test/resources/direct/config/venus-direct-config-1.yaml create mode 100644 fj-doc-maven-plugin/src/test/resources/direct/template/test-doc.ftl diff --git a/CHANGELOG.md b/CHANGELOG.md index cf36119f4..b98f2d8ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [fj-doc-maven-plugin] goal : direct - [fj-doc-lib-direct] new module to generate documents from a configuration file ### Changed diff --git a/fj-doc-maven-plugin/pom.xml b/fj-doc-maven-plugin/pom.xml index 809aa2d55..ab29d6d07 100644 --- a/fj-doc-maven-plugin/pom.xml +++ b/fj-doc-maven-plugin/pom.xml @@ -83,6 +83,11 @@ fj-doc-base-yaml + + org.fugerit.java + fj-doc-lib-direct + + org.maxxq.maven maxxq-maven diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java new file mode 100644 index 000000000..26208a319 --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java @@ -0,0 +1,63 @@ +package org.fugerit.java.doc.maven; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.core.lang.helpers.CollectionUtils; +import org.fugerit.java.doc.lib.direct.VenusDirectFacade; +import org.fugerit.java.doc.lib.direct.config.VenusDirectConfig; +import org.fugerit.java.doc.project.facade.AddVenusFacade; +import org.fugerit.java.doc.project.facade.VenusContext; +import org.fugerit.java.doc.project.facade.VersionCheck; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.List; + +@Mojo( name = "direct" ) +public class MojoDirect extends AbstractMojo { + + @Parameter(property = "configPath", required = false) + protected String configPath; + + @Parameter(property = "outputAll", defaultValue = "true", required = false) + protected boolean outputAll; + + @Parameter(property = "outputId") + protected List outputId; + + public static void checkConfiguration( File configFile, boolean outputAll, List outputId ) throws MojoExecutionException { + if ( !configFile.exists() ) { + throw new MojoExecutionException( String.format( "Config file does not exist : %s", configFile.getAbsolutePath() ) ); + } + if ( outputAll && !CollectionUtils.isEmpty( outputId ) ) { + throw new MojoExecutionException( String.format( "If outputAll is set to 'true' no outputId can be provided : %s", outputId ) ); + } + if ( !outputAll && CollectionUtils.isEmpty( outputId ) ) { + throw new MojoExecutionException( String.format( "If outputAll is set to 'false' at least one outputId should be provided : %s", outputId ) ); + } + } + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + File configFile = new File( this.configPath ); + this.getLog().info( String.format( "Direct config file : %s", configFile.getAbsolutePath() ) ); + checkConfiguration( configFile, this.outputAll, this.outputId ); + SafeFunction.apply( () -> { + try (Reader reader = new InputStreamReader( new FileInputStream( configFile ))) { + VenusDirectConfig config = VenusDirectFacade.readConfig( reader ); + if ( this.outputAll ) { + VenusDirectFacade.handleAllOutput( config ); + } else { + this.outputId.forEach( id -> VenusDirectFacade.handleOutput( config, id ) ); + } + } + } ); + } + +} diff --git a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java new file mode 100644 index 000000000..9f7565d0c --- /dev/null +++ b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java @@ -0,0 +1,58 @@ +package test.org.fugerit.java.doc.project.facade; + +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.fugerit.java.doc.maven.MojoDirect; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; + +@Slf4j +class TestDirect { + + private static final File CONFIG_FILE_EXISTS = new File( "./src/test/resources/direct/config/venus-direct-config-1.yaml" ); + + @Test + void testCheckConfig() { + File configNotExists = new File( "do-not-exists.yaml" ); + Assertions.assertThrows(MojoExecutionException.class, () -> + MojoDirect.checkConfiguration(configNotExists, Boolean.TRUE, null )); + Assertions.assertThrows(MojoExecutionException.class, () -> + MojoDirect.checkConfiguration(CONFIG_FILE_EXISTS, Boolean.FALSE, null )); + Assertions.assertThrows(MojoExecutionException.class, () -> + MojoDirect.checkConfiguration(CONFIG_FILE_EXISTS, Boolean.TRUE, Arrays.asList( "1" ) )); + } + + @Test + void mojoDirectAll() throws MojoExecutionException, MojoFailureException { + MojoDirect mojoDirect = new MojoDirect() { + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + this.configPath = CONFIG_FILE_EXISTS.getAbsolutePath(); + this.outputAll = Boolean.TRUE; + this.outputId = new ArrayList<>(); + super.execute(); + } + }; + mojoDirect.execute(); + } + + @Test + void mojoDirectId() throws MojoExecutionException, MojoFailureException { + MojoDirect mojoDirect = new MojoDirect() { + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + this.configPath = CONFIG_FILE_EXISTS.getAbsolutePath(); + this.outputAll = Boolean.FALSE; + this.outputId = Arrays.asList( "test-doc-md" ); + super.execute(); + } + }; + mojoDirect.execute(); + } + +} diff --git a/fj-doc-maven-plugin/src/test/resources/direct/config/venus-direct-config-1.yaml b/fj-doc-maven-plugin/src/test/resources/direct/config/venus-direct-config-1.yaml new file mode 100644 index 000000000..ee5496640 --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/direct/config/venus-direct-config-1.yaml @@ -0,0 +1,20 @@ +--- +configId: 'venus-direct-config-1' +templatePath: 'src/test/resources/direct/template/' +templateMode: 'folder' +handlerList: + - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 + - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 +chainList: + - chainId: 'test-doc' + dataModel: + docTitle: 'Venus Direct Extension - Test Doc' +outputList: + - outputId: 'test-doc-html' + chainId: 'test-doc' + handlerId: 'html' + file: 'target/test-doc.html' + - outputId: 'test-doc-md' + chainId: 'test-doc' + handlerId: 'md' + file: 'target/test-doc.md' \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/test/resources/direct/template/test-doc.ftl b/fj-doc-maven-plugin/src/test/resources/direct/template/test-doc.ftl new file mode 100644 index 000000000..cfef82862 --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/direct/template/test-doc.ftl @@ -0,0 +1,44 @@ +<#ftl output_format="XML"> + + + + + + + + + 10;10;10;30 + + + excel-table=print + 450 + + excel-table + + + + ${r"${currentPage}"} / ${r"${pageCount}"} + + + + + + ${dataModel.docTitle} + ${.output_format} - ${testKey!'not present'} + + + Name + Surname + Title + +
+ + +
\ No newline at end of file From 4f0dcef430670b14931438520a69680a232d98b4 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 02:37:13 +0200 Subject: [PATCH 6/7] documentation #391 --- .../chapters/02_4_maven_plugin_direct.adoc | 89 +++++++++++++++++++ .../src/main/docs/asciidoc/index.adoc | 1 + .../lib/direct/config/VenusDirectConfig.java | 2 + .../direct/config/VenusDirectConfigChain.java | 23 +++++ .../config/venus-direct-config-1.yaml | 20 ++++- .../resources/data-model/data-model-1.json | 3 + .../resources/data-model/data-model-1.yaml | 2 + .../template/test-doc-json-data-model.ftl | 44 +++++++++ .../template/test-doc-yaml-data-model.ftl | 44 +++++++++ 9 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 fj-doc-guide/src/main/docs/asciidoc/chapters/02_4_maven_plugin_direct.adoc create mode 100644 fj-doc-lib-direct/src/test/resources/data-model/data-model-1.json create mode 100644 fj-doc-lib-direct/src/test/resources/data-model/data-model-1.yaml create mode 100644 fj-doc-lib-direct/src/test/resources/template/test-doc-json-data-model.ftl create mode 100644 fj-doc-lib-direct/src/test/resources/template/test-doc-yaml-data-model.ftl diff --git a/fj-doc-guide/src/main/docs/asciidoc/chapters/02_4_maven_plugin_direct.adoc b/fj-doc-guide/src/main/docs/asciidoc/chapters/02_4_maven_plugin_direct.adoc new file mode 100644 index 000000000..bab37e9fb --- /dev/null +++ b/fj-doc-guide/src/main/docs/asciidoc/chapters/02_4_maven_plugin_direct.adoc @@ -0,0 +1,89 @@ +[#maven-plugin-goal-direct] +=== Goal 'direct' + +Allow direct generation + +==== Verify at command line + +[source,shell] +---- +mvn org.fugerit.java:fj-doc-maven-plugin:verify -DtemplateBasePath=./src/test/resources/fj_doc_test/template-fail +---- + +==== Verify at maven build time + +[source,xml] +---- + + org.fugerit.java + fj-doc-maven-plugin + ${fj-doc-version} + + + venus-direct + compile + + direct + + + + + ${project.basedir}/config/venus-direct-config-1.yaml + true + + +---- + +==== Goal 'direct' available parameters + +[cols="4*", options="header"] +|==================================================================================================================================================================== +| parameter | required | default | description +| configPath | true | | Path to the direct generation configuration file +| outputAll | false | | set to 'true' to generate all the output in configuration +| outputId | false | | List of outputId to generate +|==================================================================================================================================================================== + +==== Goal 'direct' generation configuration file + +Here is an edample configuration file : + +[source,yaml] +---- +--- +configId: 'venus-direct-config-1' +templatePath: 'src/test/resources/template/' +templateMode: 'folder' +handlerList: + - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 + - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 +chainList: # a template named ${chainId}.ftl must exist in 'templatePath' folder + - chainId: 'test-doc' + dataModel: # inline data model definition + docTitle: 'Venus Direct Extension - Test Doc' + - chainId: 'test-doc-json-data-model' + dataModelJson: 'src/test/resources/data-model/data-model-1.json' # JSON file data model + - chainId: 'test-doc-yaml-data-model' + dataModelYaml: 'src/test/resources/data-model/data-model-1.yaml' # YAML file data model +outputList: + - outputId: 'test-doc-html' + chainId: 'test-doc' + handlerId: 'html' # a valid handler for this output type should be defined (i.e. org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8) + file: 'target/test-doc.html' + - outputId: 'test-doc-md' + chainId: 'test-doc' + handlerId: 'md' + file: 'target/test-doc.md' + - outputId: 'test-doc-json-data-model-html' + chainId: 'test-doc-json-data-model' + handlerId: 'html' + file: 'target/test-doc-json-data-model.html' + - outputId: 'test-doc-yaml-data-model-md' + chainId: 'test-doc-yaml-data-model' + handlerId: 'md' + file: 'target/test-doc-json-data-model.md' +---- + +TIP: _dataModel_ property in chain contains a map that can be used in the template (accessibile as 'dataModel' attribute). + +NOTE: Instead of maven plugin gola, it is possible to use [fj-doc-lib-direct] module as a standalone library. \ No newline at end of file diff --git a/fj-doc-guide/src/main/docs/asciidoc/index.adoc b/fj-doc-guide/src/main/docs/asciidoc/index.adoc index 60d28107a..39a348cc7 100644 --- a/fj-doc-guide/src/main/docs/asciidoc/index.adoc +++ b/fj-doc-guide/src/main/docs/asciidoc/index.adoc @@ -19,6 +19,7 @@ include::chapters/02_maven_plugin.adoc[] include::chapters/02_1_maven_plugin_add.adoc[] include::chapters/02_2_maven_plugin_init.adoc[] include::chapters/02_3_maven_plugin_verify.adoc[] +include::chapters/02_4_maven_plugin_direct.adoc[] include::chapters/03_doc_format.adoc[] include::chapters/03_1_doc_format_xml.adoc[] diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java index 5ce3f2999..d84e5190d 100644 --- a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java @@ -51,6 +51,8 @@ public void setupFreemarkerDocProcessConfig() throws ConfigException { SafeFunction.applyIfNotNull( this.getOutputList(), () -> this.outputMap = this.getOutputList().stream().collect( Collectors.toMap( output -> output.getOutputId(), output -> output ) ) ); log.info( "outputMap ids: {}", this.outputMap.keySet() ); + // config data model + this.chainList.forEach( VenusDirectConfigChain::setupDataModel ); } @Getter @Setter diff --git a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java index f732119cb..ad27e06f2 100644 --- a/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java @@ -1,16 +1,39 @@ package org.fugerit.java.doc.lib.direct.config; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import lombok.Getter; import lombok.Setter; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.core.io.FileIO; import java.util.LinkedHashMap; public class VenusDirectConfigChain { + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + + private static final ObjectMapper YAML_MAPPER = new YAMLMapper(); + @Getter @Setter private String chainId; @Getter @Setter private LinkedHashMap dataModel; + @Getter @Setter + private String dataModelJson; + + @Getter @Setter + private String dataModelYaml; + + public void setupDataModel() { + if ( this.dataModel == null ) { + SafeFunction.applyIfNotNull( this.getDataModelJson(), () -> + this.setDataModel( JSON_MAPPER.readValue( FileIO.readString( this.getDataModelJson() ), LinkedHashMap.class ) ) ); + SafeFunction.applyIfNotNull( this.getDataModelYaml(), () -> + this.setDataModel( YAML_MAPPER.readValue( FileIO.readString( this.getDataModelYaml() ), LinkedHashMap.class ) ) ); + } + } + } diff --git a/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml index 4cc1d51d9..961bd95ac 100644 --- a/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml +++ b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml @@ -5,16 +5,28 @@ templateMode: 'folder' handlerList: - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 -chainList: +chainList: # a template named ${chainId}.ftl must exist in 'templatePath' folder - chainId: 'test-doc' - dataModel: + dataModel: # inline data model definition docTitle: 'Venus Direct Extension - Test Doc' + - chainId: 'test-doc-json-data-model' + dataModelJson: 'src/test/resources/data-model/data-model-1.json' # JSON file data model + - chainId: 'test-doc-yaml-data-model' + dataModelYaml: 'src/test/resources/data-model/data-model-1.yaml' # YAML file data model outputList: - outputId: 'test-doc-html' chainId: 'test-doc' - handlerId: 'html' + handlerId: 'html' # a valid handler for this output type should be defined (i.e. org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8) file: 'target/test-doc.html' - outputId: 'test-doc-md' chainId: 'test-doc' handlerId: 'md' - file: 'target/test-doc.md' \ No newline at end of file + file: 'target/test-doc.md' + - outputId: 'test-doc-json-data-model-html' + chainId: 'test-doc-json-data-model' + handlerId: 'html' + file: 'target/test-doc-json-data-model.html' + - outputId: 'test-doc-yaml-data-model-md' + chainId: 'test-doc-yaml-data-model' + handlerId: 'md' + file: 'target/test-doc-json-data-model.md' \ No newline at end of file diff --git a/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.json b/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.json new file mode 100644 index 000000000..42dba827f --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.json @@ -0,0 +1,3 @@ +{ + "docTitle": "Venus Direct Extension - Test Doc - JSON" +} \ No newline at end of file diff --git a/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.yaml b/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.yaml new file mode 100644 index 000000000..dc30924cb --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/data-model/data-model-1.yaml @@ -0,0 +1,2 @@ +--- +docTitle: 'Venus Direct Extension - Test Doc - YAML' \ No newline at end of file diff --git a/fj-doc-lib-direct/src/test/resources/template/test-doc-json-data-model.ftl b/fj-doc-lib-direct/src/test/resources/template/test-doc-json-data-model.ftl new file mode 100644 index 000000000..cfef82862 --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/template/test-doc-json-data-model.ftl @@ -0,0 +1,44 @@ +<#ftl output_format="XML"> + + + + + + + + + 10;10;10;30 + + + excel-table=print + 450 + + excel-table + + + + ${r"${currentPage}"} / ${r"${pageCount}"} + + + + + + ${dataModel.docTitle} + ${.output_format} - ${testKey!'not present'} + + + Name + Surname + Title + +
+ + +
\ No newline at end of file diff --git a/fj-doc-lib-direct/src/test/resources/template/test-doc-yaml-data-model.ftl b/fj-doc-lib-direct/src/test/resources/template/test-doc-yaml-data-model.ftl new file mode 100644 index 000000000..cfef82862 --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/template/test-doc-yaml-data-model.ftl @@ -0,0 +1,44 @@ +<#ftl output_format="XML"> + + + + + + + + + 10;10;10;30 + + + excel-table=print + 450 + + excel-table + + + + ${r"${currentPage}"} / ${r"${pageCount}"} + + + + + + ${dataModel.docTitle} + ${.output_format} - ${testKey!'not present'} + + + Name + Surname + Title + +
+ + +
\ No newline at end of file From 2a215858d0534972b4aa01b006fea759601d6e23 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 24 Apr 2025 02:40:40 +0200 Subject: [PATCH 7/7] sonar issue #391 --- .../src/main/java/org/fugerit/java/doc/maven/MojoDirect.java | 3 --- .../test/org/fugerit/java/doc/project/facade/TestDirect.java | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java index 26208a319..c94fc568d 100644 --- a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java @@ -9,9 +9,6 @@ import org.fugerit.java.core.lang.helpers.CollectionUtils; import org.fugerit.java.doc.lib.direct.VenusDirectFacade; import org.fugerit.java.doc.lib.direct.config.VenusDirectConfig; -import org.fugerit.java.doc.project.facade.AddVenusFacade; -import org.fugerit.java.doc.project.facade.VenusContext; -import org.fugerit.java.doc.project.facade.VersionCheck; import java.io.File; import java.io.FileInputStream; diff --git a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java index 9f7565d0c..13439abe1 100644 --- a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java +++ b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java @@ -39,6 +39,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } }; mojoDirect.execute(); + Assertions.assertTrue( new File( "./target/test-doc.html").exists() ); } @Test @@ -53,6 +54,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } }; mojoDirect.execute(); + Assertions.assertTrue( new File( "./target/test-doc.md").exists() ); } }