Skip to content

Commit a51ac9c

Browse files
authored
Merge pull request #425 from fugerit-org/424-chore-direct-goal-add-init-configure-support-for-extra-modules
feat: 'direct' goal + 'add' / 'init' configure support for extra modu…
2 parents d6ff130 + d1a4494 commit a51ac9c

File tree

10 files changed

+133
-56
lines changed

10 files changed

+133
-56
lines changed

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+
### Changed
11+
12+
- [CHORE]: 'direct' goal + 'add' / 'init' configure support for extra modules <https://github.com/fugerit-org/fj-doc/pull/424>
13+
1014
## [8.13.9] - 2025-04-28
1115

1216
### Changed

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import org.maxxq.maven.dependency.ModelIO;
1010

1111
import java.io.*;
12-
import java.util.Collections;
13-
import java.util.Iterator;
14-
import java.util.List;
15-
import java.util.Properties;
12+
import java.util.*;
1613

1714
@Slf4j
1815
public class BasicVenusFacade {
@@ -37,6 +34,10 @@ private static void addOrOverwrite( List<Dependency> deps, Dependency d ) {
3734
}
3835

3936
private static void addCurrentModule( VenusContext context, String currentModule, List<Dependency> dependencies) {
37+
addCurrentModule( context, currentModule, dependencies, null );
38+
}
39+
40+
private static void addCurrentModule( VenusContext context, String currentModule, List<Dependency> dependencies, String version) {
4041
Dependency d = new Dependency();
4142
d.setArtifactId( currentModule );
4243
d.setGroupId( GROUP_ID );
@@ -47,6 +48,9 @@ private static void addCurrentModule( VenusContext context, String currentModule
4748
e.setGroupId( parts[0] );
4849
e.setArtifactId( parts[1] );
4950
d.getExclusions().add( e );
51+
if ( version != null ) {
52+
d.setVersion(version);
53+
}
5054
}
5155
}
5256
addOrOverwrite( dependencies, d );
@@ -106,7 +110,7 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
106110
Dependency fjDocBom = new Dependency();
107111
fjDocBom.setArtifactId( "fj-doc" );
108112
fjDocBom.setGroupId( GROUP_ID );
109-
fjDocBom.setVersion( "${"+KEY_VERSION+"}" );
113+
fjDocBom.setVersion( VenusConsts.KEY_VERSION_VAR );
110114
fjDocBom.setType( "pom" );
111115
fjDocBom.setScope( "import" );
112116
addOrOverwrite( dm.getDependencies(), fjDocBom );
@@ -233,9 +237,17 @@ private static void addDirectPlugin(VenusContext context, Model model ) throws I
233237
"src/main/resources/"+context.getVenusDirectConfig()+"/template",
234238
"freemarker-syntax-verify-direct-report");
235239
}
236-
FeatureFacade.copyFeatureList( context.getProjectDir(), "direct" );
240+
String featureId = "direct";
241+
FeatureFacade.copyFeatureList( context.getProjectDir(), featureId);
242+
FeatureFacade.processFeature( context, featureId );
237243
log.info("addDirectPlugin true, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_DIRECT_PLUGIN);
238244
Plugin plugin = PluginUtils.findOrCreatePLugin( model );
245+
// configure dependencies
246+
List<String> moduleList = ModuleFacade.toModuleListOptimizedOrder( context.getExtensions() );
247+
for ( String currentModule : moduleList ) {
248+
String moduleName = ModuleFacade.toModuleName( currentModule );
249+
addCurrentModule( context, moduleName, plugin.getDependencies(), VenusConsts.KEY_VERSION_VAR );
250+
}
239251
PluginExecution execution = PluginUtils.createPluginExecution(
240252
"venus-direct", LifecyclePhase.COMPILE.id(), PluginUtils.GOAL_DIRECT );
241253
plugin.getExecutions().add( execution );

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FeatureFacade.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package org.fugerit.java.doc.project.facade;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5+
import freemarker.template.TemplateException;
36
import lombok.extern.slf4j.Slf4j;
47
import org.fugerit.java.core.function.SafeFunction;
58
import org.fugerit.java.core.io.StreamIO;
69
import org.fugerit.java.core.lang.helpers.ClassHelper;
10+
import org.fugerit.java.doc.project.facade.flavour.FlavourConfig;
11+
import org.fugerit.java.doc.project.facade.flavour.ProcessEntry;
712

813
import java.io.*;
14+
import java.util.HashMap;
15+
import java.util.Map;
916

1017
@Slf4j
1118
public class FeatureFacade {
@@ -50,4 +57,30 @@ protected static void copyFile(String path, File baseFolder, String basePath ) {
5057
} );
5158
}
5259

60+
public static void processFeature( VenusContext context, String featureId ) {
61+
SafeFunction.apply( () -> {
62+
Map<String, Object> data = new HashMap<>();
63+
data.put( "context", context );
64+
data.put( "featureId", featureId );
65+
String freemarkerProcessYamlPath = String.format( "feature/%s-fm-yml.ftl", featureId );
66+
log.info( "freemarkerProcessYamlPath feature process {}", freemarkerProcessYamlPath );
67+
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
68+
try ( StringWriter writer = new StringWriter() ) {
69+
FreemarkerTemplateFacade.processFile( freemarkerProcessYamlPath, writer, data );
70+
FlavourConfig featureConfig = mapper.readValue( writer.toString(), FlavourConfig.class );
71+
log.info( "featureConfig {}", featureConfig.getFlavour() );
72+
featureConfig.getProcess().forEach( entry -> processEntry( entry, data ) );
73+
}
74+
});
75+
}
76+
77+
public static void processEntry(ProcessEntry entry, Map<String, Object> data ) {
78+
log.info( "process entry : {}", entry );
79+
SafeFunction.apply( () -> {
80+
File toFile = new File( entry.getTo() );
81+
FeatureFacade.insureParent( toFile );
82+
FreemarkerTemplateFacade.processFile( entry.getFrom(), toFile, data );
83+
} );
84+
}
85+
5386
}

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FlavourFacade.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,10 @@ private static void initFlavour( FlavourContext context, String actualFlavour )
159159
FreemarkerTemplateFacade.processFile( freemarkerProcessYamlPath, writer, data );
160160
FlavourConfig flavourConfig = mapper.readValue( writer.toString(), FlavourConfig.class );
161161
log.info( "floavourConfig {}", flavourConfig.getFlavour() );
162-
flavourConfig.getProcess().forEach( entry -> processEntry( entry, data ) );
162+
flavourConfig.getProcess().forEach( entry -> FeatureFacade.processEntry( entry, data ) );
163163
}
164164
}
165165

166-
private static void processEntry( ProcessEntry entry, Map<String, Object> data ) {
167-
log.info( "process entry : {}", entry );
168-
SafeFunction.apply( () -> {
169-
File toFile = new File( entry.getTo() );
170-
FeatureFacade.insureParent( toFile );
171-
FreemarkerTemplateFacade.processFile( entry.getFrom(), toFile, data );
172-
} );
173-
}
166+
174167

175168
}

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/PluginUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static Plugin findOrCreatePLugin( Model model ) {
3939
plugin = new Plugin();
4040
plugin.setGroupId( VenusConsts.GROUP_ID );
4141
plugin.setArtifactId( FJ_DOC_MAVEN_PLUGIN );
42-
plugin.setVersion( "${"+VenusConsts.KEY_VERSION+"}" );
42+
plugin.setVersion( VenusConsts.KEY_VERSION_VAR );
4343
build.getPlugins().add( plugin );
4444
}
4545
return plugin;

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusConsts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ private VenusConsts() {}
88

99
public static final String KEY_VERSION = "fj-doc-version";
1010

11+
public static final String KEY_VERSION_VAR = "${fj-doc-version}";
12+
1113
}

fj-doc-maven-plugin/src/main/resources/config/feature/direct-copy.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
src/main/resources/venus-direct-config/venus-direct-config.yaml
21
src/main/resources/venus-direct-config/template/sample-doc.ftl
32
src/main/resources/venus-direct-config/data-model/sample-model.json
43
src/main/resources/venus-direct-config/data-model/sample-model.yaml

fj-doc-maven-plugin/src/main/resources/config/feature/direct/src/main/resources/venus-direct-config/venus-direct-config.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
flavour: ${featureId}
3+
process:
4+
- from: feature/${featureId}/venus-direct-config.ftl
5+
to: ${context.projectDir}/src/main/resources/venus-direct-config/venus-direct-config.yaml
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
configId: 'venus-direct-config-sample'
3+
templatePath: '${r"${projectBasedir}"}/src/main/resources/venus-direct-config/template/'
4+
templateMode: 'folder'
5+
createParentDirectory: true
6+
handlerList:
7+
- type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8
8+
- type: org.fugerit.java.doc.base.typehandler.markdown.SimpleMarkdownExtTypeHandlerNoCommentsUTF8
9+
- type: org.fugerit.java.doc.freemarker.asciidoc.FreeMarkerAsciidocTypeHandlerUTF8
10+
- type: org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerEscapeUTF8<#if context.modules?seq_contains("fj-doc-mod-fop")>
11+
- type: org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandlerUTF8
12+
- type: org.fugerit.java.doc.mod.fop.PdfFopTypeHandler</#if><#if context.modules?seq_contains("fj-doc-mod-poi")>
13+
- type: org.fugerit.java.doc.mod.poi.XlsPoiTypeHandler
14+
- type: org.fugerit.java.doc.mod.poi.XlsxPoiTypeHandler</#if><#if context.modules?seq_contains("fj-doc-mod-opencsv")>
15+
- type: org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler</#if><#if context.modules?seq_contains("fj-doc-mod-openpdf-ext")>
16+
- type: org.fugerit.java.doc.mod.openpdf.ext.PdfTypeHandler
17+
- type: org.fugerit.java.doc.mod.openpdf.ext.HtmlTypeHandler</#if><#if context.modules?seq_contains("fj-doc-mod-openrtf-ext")>
18+
- type: org.fugerit.java.doc.mod.openrtf.ext.RtfTypeHandler</#if>
19+
chainList: # a template named ${r"${chainId}"}.ftl or ${r"${useChainId}"}.ftl must exist in 'templatePath' folder
20+
- chainId: 'sample-doc'
21+
dataModel: # inline data model definition
22+
docTitle: 'Venus Direct Extension - Test Doc'
23+
listPeople:
24+
- name: "Luthien"
25+
surname: "Tinuviel"
26+
title: "Queen"
27+
- name: "Thorin"
28+
surname: "Oakshield"
29+
title: "King"
30+
- chainId: 'sample-doc-json-data-model'
31+
useChainId: 'sample-doc'
32+
dataModelJson: '${r"${projectBasedir}"}/src/main/resources/venus-direct-config/data-model/sample-model.json' # JSON file data model
33+
- chainId: 'sample-doc-yaml-data-model'
34+
useChainId: 'sample-doc'
35+
dataModelYaml: '${r"${projectBasedir}"}/src/main/resources/venus-direct-config/data-model/sample-model.yaml' # YAML file data model
36+
outputList:
37+
- outputId: 'sample-doc-html'
38+
chainId: 'sample-doc'
39+
handlerId: 'html' # a valid handler for this output type should be defined (i.e. org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8)
40+
file: '${r"${projectBasedir}"}/target/sample-doc.html'
41+
- outputId: 'sample-doc-md'
42+
chainId: 'sample-doc-json-data-model'
43+
handlerId: 'md'
44+
file: '${r"${projectBasedir}"}/target/sample-doc.md'
45+
- outputId: 'sample-doc-adoc'
46+
chainId: 'sample-doc-yaml-data-model'
47+
handlerId: 'adoc'
48+
file: '${r"${projectBasedir}"}/target/sample-doc.adoc'
49+
<#if context.modules?seq_contains("fj-doc-mod-fop")> - outputId: 'sample-doc-pdf'
50+
chainId: 'sample-doc'
51+
handlerId: 'pdf-fop' # of simply use 'pdf' if it is the only pdf handler
52+
file: '${r"${projectBasedir}"}/target/sample-doc.pdf'</#if>
53+
<#if context.modules?seq_contains("fj-doc-mod-poi")> - outputId: 'sample-doc-xlsx'
54+
chainId: 'sample-doc'
55+
handlerId: 'xlsx-poi' # of simply use 'xlsx' if it is the only excel handler
56+
file: '${r"${projectBasedir}"}/target/sample-doc.xlsx'</#if>
57+
<#if context.modules?seq_contains("fj-doc-mod-opencsv")> - outputId: 'sample-doc-csv'
58+
chainId: 'sample-doc'
59+
handlerId: 'csv'
60+
file: '${r"${projectBasedir}"}/target/sample-doc.csv'</#if>
61+
<#if context.modules?seq_contains("fj-doc-mod-openpdf-ext")> - outputId: 'sample-doc-openpdf-ext'
62+
chainId: 'sample-doc'
63+
handlerId: 'pdf-openpdf-ext'
64+
file: '${r"${projectBasedir}"}/target/sample-doc-openpdf-ext.pdf'</#if>
65+
<#if context.modules?seq_contains("fj-doc-mod-openrtf-ext")> - outputId: 'sample-doc-openrtf-ext'
66+
chainId: 'sample-doc'
67+
handlerId: 'rtf-openrtf-ext'
68+
file: '${r"${projectBasedir}"}/target/sample-doc-openrtf-ext.rtf'</#if>

0 commit comments

Comments
 (0)