diff --git a/CHANGELOG.md b/CHANGELOG.md index 928c0a8ec..b98f2d8ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- [fj-doc-maven-plugin] goal : direct +- [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..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 @@ -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; @@ -111,7 +112,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,9 +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 ( version != null ) { - 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 ); 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-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/pom.xml b/fj-doc-lib-direct/pom.xml new file mode 100644 index 000000000..228d310d5 --- /dev/null +++ b/fj-doc-lib-direct/pom.xml @@ -0,0 +1,69 @@ + + 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/ + + 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..f191fb27b --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java @@ -0,0 +1,62 @@ +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(); + 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/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..d84e5190d --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java @@ -0,0 +1,77 @@ +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() ); + // config data model + this.chainList.forEach( VenusDirectConfigChain::setupDataModel ); + } + + @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..ad27e06f2 --- /dev/null +++ b/fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfigChain.java @@ -0,0 +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/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..d9ab208b2 --- /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 + 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..961bd95ac --- /dev/null +++ b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml @@ -0,0 +1,32 @@ +--- +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' \ 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 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-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..c94fc568d --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoDirect.java @@ -0,0 +1,60 @@ +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 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..13439abe1 --- /dev/null +++ b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestDirect.java @@ -0,0 +1,60 @@ +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(); + Assertions.assertTrue( new File( "./target/test-doc.html").exists() ); + } + + @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(); + Assertions.assertTrue( new File( "./target/test-doc.md").exists() ); + } + +} 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 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