Skip to content

401 chore fj doc lib direct add configuration option to create parent directory #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/01-submit-bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/03-chore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/fugerit-org/fj-doc/pull/401>

### Fixed

- [fj-doc-freemarker] handling link in asciidoc handler <https://github.com/fugerit-org/fj-doc/pull/399>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
import java.util.Map;
import java.util.Properties;

@Slf4j
public class VenusDirectFacade {

public static final String ATT_DATA_MODEL = "dataModel";
Expand All @@ -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<String, String> envMap) {
Expand Down Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public void setupFreemarkerDocProcessConfig() throws ConfigException {
@Getter @Setter
private String templateMode;

@Getter @Setter
private boolean createParentDirectory;

@Getter @Setter
private List<VenusDirectConfigHandler> handlerList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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" );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
file: 'target/alt-test-doc-json-data-model.md'