Skip to content

Commit 954753f

Browse files
authored
Merge pull request #402 from fugerit-org/401-chore-fj-doc-lib-direct-add-configuration-option-to-create-parent-directory
401 chore fj doc lib direct add configuration option to create parent directory
2 parents 649e220 + e2cf315 commit 954753f

File tree

9 files changed

+25
-12
lines changed

9 files changed

+25
-12
lines changed

.github/ISSUE_TEMPLATE/01-submit-bug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ body:
4444
- fj-doc-mod-lib-autodoc - Bundled library for XSD auto documentation
4545
- fj-doc-mod-lib-simpletable - Bundled library handling simple table data model
4646
- fj-doc-mod-lib-simpletable-import - Bundled library handling simple table import from Excel / CSV
47+
- fj-doc-mod-lib-direct - API for Direct Document Generation
4748
- fj-doc-mod-lib-kotlin - Bundled library generating Kotlin DSL based on XSD
4849
- fj-doc-maven-plugin - Maven plugin to setup new/existing projects and validate freemarker templates
4950
- fj-doc-sample - Sample library

.github/ISSUE_TEMPLATE/03-chore.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ body:
4444
- fj-doc-mod-lib-autodoc - Bundled library for XSD auto documentation
4545
- fj-doc-mod-lib-simpletable - Bundled library handling simple table data model
4646
- fj-doc-mod-lib-simpletable-import - Bundled library handling simple table import from Excel / CSV
47+
- fj-doc-mod-lib-direct - API for Direct Document Generation
4748
- fj-doc-mod-lib-kotlin - Bundled library generating Kotlin DSL based on XSD
4849
- fj-doc-maven-plugin - Maven plugin to setup new/existing projects and validate freemarker templates
4950
- fj-doc-sample - Sample library

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- [fj-doc-lib-direct] add configuration option to create parent directory <https://github.com/fugerit-org/fj-doc/pull/401>
13+
1014
### Fixed
1115

1216
- [fj-doc-freemarker] handling link in asciidoc handler <https://github.com/fugerit-org/fj-doc/pull/399>

fj-doc-guide/src/main/docs/asciidoc/chapters/02_4_maven_plugin_direct.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Here is an edample configuration file :
5858
configId: 'venus-direct-config-1'
5959
templatePath: '${projectBasedir}/src/test/resources/template/'
6060
templateMode: 'folder'
61+
createParentDirectory: true
6162
handlerList:
6263
- type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8
6364
- type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8

fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/VenusDirectFacade.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
5+
import lombok.extern.slf4j.Slf4j;
56
import org.fugerit.java.core.cfg.ConfigRuntimeException;
67
import org.fugerit.java.core.function.SafeFunction;
78
import org.fugerit.java.core.io.StreamIO;
@@ -22,6 +23,7 @@
2223
import java.util.Map;
2324
import java.util.Properties;
2425

26+
@Slf4j
2527
public class VenusDirectFacade {
2628

2729
public static final String ATT_DATA_MODEL = "dataModel";
@@ -31,11 +33,7 @@ private VenusDirectFacade() {}
3133
private static final ObjectMapper YAML_MAPPER = new YAMLMapper();
3234

3335
public static VenusDirectConfig readConfig( Reader reader ) {
34-
return SafeFunction.get( () -> {
35-
VenusDirectConfig config = YAML_MAPPER.readValue( reader, VenusDirectConfig.class );
36-
config.setupFreemarkerDocProcessConfig();
37-
return config;
38-
} );
36+
return readConfig( reader, null );
3937
}
4038

4139
public static VenusDirectConfig readConfig(Reader reader, Map<String, String> envMap) {
@@ -74,6 +72,9 @@ public static void handleOutput(VenusDirectConfig config, String outputId) {
7472
DocProcessContext context = DocProcessContext.newContext();
7573
SafeFunction.applyIfNotNull( chain.getDataModel(), () -> context.setAttribute( ATT_DATA_MODEL, chain.getDataModel() ) );
7674
File outputFile = new File( output.getFile() );
75+
if ( config.isCreateParentDirectory() && !outputFile.getParentFile().exists() ) {
76+
log.info( "mkdir: result:{}, directory:{}", outputFile.getParentFile().mkdirs(), outputFile.getParentFile() );
77+
}
7778
try ( FileOutputStream fos = new FileOutputStream( outputFile ) ) {
7879
config.getDocProcessConfig().fullProcess(chain.getChainId(), context, output.getHandlerId(), fos );
7980
}

fj-doc-lib-direct/src/main/java/org/fugerit/java/doc/lib/direct/config/VenusDirectConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public void setupFreemarkerDocProcessConfig() throws ConfigException {
6464
@Getter @Setter
6565
private String templateMode;
6666

67+
@Getter @Setter
68+
private boolean createParentDirectory;
69+
6770
@Getter @Setter
6871
private List<VenusDirectConfigHandler> handlerList;
6972

fj-doc-lib-direct/src/test/java/org/fugerit/java/doc/lib/direct/TestVenusDirectFacade.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ void testDoc() throws IOException {
2929
void testSubstitute() throws IOException {
3030
try (Reader reader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( "config/venus-direct-config-2.yaml" ) )) {
3131
Map<String, String> envMap = new HashMap<>();
32-
envMap.put( "baseDir", "/config" );
32+
envMap.put( "baseDir", "." );
3333
VenusDirectConfig config = VenusDirectFacade.readConfig( reader, envMap );
34-
Assertions.assertEquals( "/config/src/test/resources/template/", config.getTemplatePath() );
34+
Assertions.assertEquals( "./src/test/resources/template/", config.getTemplatePath() );
35+
VenusDirectFacade.handleOutput( config, "test-doc-md" );
3536
}
3637
}
3738

fj-doc-lib-direct/src/test/resources/config/venus-direct-config-1.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
configId: 'venus-direct-config-1'
33
templatePath: 'src/test/resources/template/'
44
templateMode: 'folder'
5+
createParentDirectory: true
56
handlerList:
67
- type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8
78
- type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8
@@ -17,7 +18,7 @@ outputList:
1718
- outputId: 'test-doc-html'
1819
chainId: 'test-doc'
1920
handlerId: 'html' # a valid handler for this output type should be defined (i.e. org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8)
20-
file: 'target/test-doc.html'
21+
file: 'target/direct/test-doc.html'
2122
- outputId: 'test-doc-md'
2223
chainId: 'test-doc'
2324
handlerId: 'md'

fj-doc-lib-direct/src/test/resources/config/venus-direct-config-2.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ outputList:
1717
- outputId: 'test-doc-html'
1818
chainId: 'test-doc'
1919
handlerId: 'html' # a valid handler for this output type should be defined (i.e. org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8)
20-
file: 'target/test-doc.html'
20+
file: 'target/alt-test-doc.html'
2121
- outputId: 'test-doc-md'
2222
chainId: 'test-doc'
2323
handlerId: 'md'
24-
file: 'target/test-doc.md'
24+
file: 'target/alt-test-doc.md'
2525
- outputId: 'test-doc-json-data-model-html'
2626
chainId: 'test-doc-json-data-model'
2727
handlerId: 'html'
28-
file: 'target/test-doc-json-data-model.html'
28+
file: 'target/alt-test-doc-json-data-model.html'
2929
- outputId: 'test-doc-yaml-data-model-md'
3030
chainId: 'test-doc-yaml-data-model'
3131
handlerId: 'md'
32-
file: 'target/test-doc-json-data-model.md'
32+
file: 'target/alt-test-doc-json-data-model.md'

0 commit comments

Comments
 (0)