diff --git a/.github/ISSUE_TEMPLATE/01-submit-bug.yml b/.github/ISSUE_TEMPLATE/01-submit-bug.yml index f35bec41c..55e90b638 100644 --- a/.github/ISSUE_TEMPLATE/01-submit-bug.yml +++ b/.github/ISSUE_TEMPLATE/01-submit-bug.yml @@ -44,6 +44,7 @@ body: - fj-doc-mod-lib-autodoc - Bundled library for XSD auto documentation - fj-doc-mod-lib-simpletable - Bundled library handling simple table data model - fj-doc-mod-lib-simpletable-import - Bundled library handling simple table import from Excel / CSV + - fj-doc-mod-lib-direct - API for Direct Document Generation - fj-doc-mod-lib-kotlin - Bundled library generating Kotlin DSL based on XSD - fj-doc-maven-plugin - Maven plugin to setup new/existing projects and validate freemarker templates - fj-doc-sample - Sample library diff --git a/.github/ISSUE_TEMPLATE/03-chore.yml b/.github/ISSUE_TEMPLATE/03-chore.yml index 2642f21ad..ba2e3d017 100644 --- a/.github/ISSUE_TEMPLATE/03-chore.yml +++ b/.github/ISSUE_TEMPLATE/03-chore.yml @@ -44,6 +44,7 @@ body: - fj-doc-mod-lib-autodoc - Bundled library for XSD auto documentation - fj-doc-mod-lib-simpletable - Bundled library handling simple table data model - fj-doc-mod-lib-simpletable-import - Bundled library handling simple table import from Excel / CSV + - fj-doc-mod-lib-direct - API for Direct Document Generation - fj-doc-mod-lib-kotlin - Bundled library generating Kotlin DSL based on XSD - fj-doc-maven-plugin - Maven plugin to setup new/existing projects and validate freemarker templates - fj-doc-sample - Sample library diff --git a/CHANGELOG.md b/CHANGELOG.md index dd83c4f91..3ad368e38 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] add configuration option to create parent directory + ### Fixed - [fj-doc-freemarker] handling link in asciidoc handler 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 index 826e066d7..f6c871382 100644 --- 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 @@ -58,6 +58,7 @@ Here is an edample configuration file : configId: 'venus-direct-config-1' templatePath: '${projectBasedir}/src/test/resources/template/' templateMode: 'folder' +createParentDirectory: true handlerList: - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 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 6e6a90942..f52daf301 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 @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import lombok.extern.slf4j.Slf4j; import org.fugerit.java.core.cfg.ConfigRuntimeException; import org.fugerit.java.core.function.SafeFunction; import org.fugerit.java.core.io.StreamIO; @@ -22,6 +23,7 @@ import java.util.Map; import java.util.Properties; +@Slf4j public class VenusDirectFacade { public static final String ATT_DATA_MODEL = "dataModel"; @@ -31,11 +33,7 @@ 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; - } ); + return readConfig( reader, null ); } public static VenusDirectConfig readConfig(Reader reader, Map envMap) { @@ -74,6 +72,9 @@ public static void handleOutput(VenusDirectConfig config, String outputId) { DocProcessContext context = DocProcessContext.newContext(); SafeFunction.applyIfNotNull( chain.getDataModel(), () -> context.setAttribute( ATT_DATA_MODEL, chain.getDataModel() ) ); File outputFile = new File( output.getFile() ); + if ( config.isCreateParentDirectory() && !outputFile.getParentFile().exists() ) { + log.info( "mkdir: result:{}, directory:{}", outputFile.getParentFile().mkdirs(), outputFile.getParentFile() ); + } 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 index d84e5190d..578ff6850 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 @@ -64,6 +64,9 @@ public void setupFreemarkerDocProcessConfig() throws ConfigException { @Getter @Setter private String templateMode; + @Getter @Setter + private boolean createParentDirectory; + @Getter @Setter private List handlerList; 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 b537be4f0..51e135a9e 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 @@ -29,9 +29,10 @@ void testDoc() throws IOException { void testSubstitute() throws IOException { try (Reader reader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( "config/venus-direct-config-2.yaml" ) )) { Map envMap = new HashMap<>(); - envMap.put( "baseDir", "/config" ); + envMap.put( "baseDir", "." ); VenusDirectConfig config = VenusDirectFacade.readConfig( reader, envMap ); - Assertions.assertEquals( "/config/src/test/resources/template/", config.getTemplatePath() ); + Assertions.assertEquals( "./src/test/resources/template/", config.getTemplatePath() ); + VenusDirectFacade.handleOutput( config, "test-doc-md" ); } } 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 961bd95ac..fd606fc64 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 @@ -2,6 +2,7 @@ configId: 'venus-direct-config-1' templatePath: 'src/test/resources/template/' templateMode: 'folder' +createParentDirectory: true handlerList: - type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8 - type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8 @@ -17,7 +18,7 @@ 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' + file: 'target/direct/test-doc.html' - outputId: 'test-doc-md' chainId: 'test-doc' handlerId: 'md' diff --git a/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-2.yaml b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-2.yaml index 66c072644..bbc153914 100644 --- a/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-2.yaml +++ b/fj-doc-lib-direct/src/test/resources/config/venus-direct-config-2.yaml @@ -17,16 +17,16 @@ 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' + file: 'target/alt-test-doc.html' - outputId: 'test-doc-md' chainId: 'test-doc' handlerId: 'md' - file: 'target/test-doc.md' + file: 'target/alt-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' + file: 'target/alt-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 + file: 'target/alt-test-doc-json-data-model.md' \ No newline at end of file