diff --git a/CHANGELOG.md b/CHANGELOG.md index bbe0cd289..f40f7b5a6 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-maven-plugin, init goal, 'addFormatting' + ### Changed - quarkus-version set to 3.28.3 across all the modules diff --git a/fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc b/fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc index 492bdc31b..2049bf8c4 100644 --- a/fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc +++ b/fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc @@ -6,6 +6,8 @@ Whereas the link:https://github.com/fugerit-org/fj-doc/blob/main/CHANGELOG.md[CH [#doc-release-notes-unreleased] ==== Unreleased +- fj-doc-maven-plugin, init goal, 'addFormatting' parameter link:https://github.com/fugerit-org/fj-doc/issues/541[#541] + [#doc-release-notes-8-16-9] ==== Version 8.16.9 [2025-10-06] diff --git a/fj-doc-guide/src/main/docs/asciidoc/chapters/02_2_maven_plugin_init.adoc b/fj-doc-guide/src/main/docs/asciidoc/chapters/02_2_maven_plugin_init.adoc index d8785b963..ff0f0a39a 100644 --- a/fj-doc-guide/src/main/docs/asciidoc/chapters/02_2_maven_plugin_init.adoc +++ b/fj-doc-guide/src/main/docs/asciidoc/chapters/02_2_maven_plugin_init.adoc @@ -25,9 +25,12 @@ Project folder will be `./${artifactId}/`. | javaRelease | true | 21 | java release version | flavour | true | vanilla | the flavour for the new project (see below for options) | flavourVersion | false | see below | override default framework version if supported (recommended : leave default or blank) -| addJacoco | false | false | add jacoco coverage support +| addJacoco (*) | false | false | add jacoco coverage support +| addFormatting (*) | false | false | add maven plugin formatter with rules from link:https://github.com/fugerit-org/fugerit-code-rules[fugerit-code-rules] |==================================================================================================================================== +(*) Currently not working on gradle flavours + NOTE: it is possible to set any property from 'add' goal, except 'projectFolder' which is set to `./${artifactId}`. [#flavour-list] diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java index 2938d3661..babd0d465 100644 --- a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java @@ -39,6 +39,9 @@ public class MojoInit extends MojoAdd { @Parameter(property = "addJacoco", defaultValue = "false", required = false) protected boolean addJacoco; + @Parameter(property = "addFormatting", defaultValue = "false", required = false) + protected boolean addFormatting; + public MojoInit() { this.baseInitFolder = "."; } @@ -68,6 +71,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { context.setExtensions( this.extensions ); context.setBasePackage( this.basePackage ); context.setAddJacoco( this.addJacoco ); + context.setAddFormatting( this.addFormatting ); this.getLog().info( String.format( "flavour context : %s", context ) ); String actualVersion = FlavourFacade.initProject( context ); if ( FlavourFacade.FLAVOUR_DIRECT.equals( actualVersion ) ) { diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java index 0bfa7d5ad..2275dc7e1 100644 --- a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java @@ -154,7 +154,7 @@ public static boolean addVenusToMavenProject( File pomFile, VenusContext context } else { log.info( "Generation complete:\n{}\n* For usage open the example main() : {} *\n{}", LINE, context.getDocConfigPackage()+"."+context.getDocConfigClass()+"Example", LINE ); } - log.info( "for documentation refer to https://github.com/fugerit-org/fj-doc/blob/main/fj-doc-maven-plugin/README.md" ); + log.info( "for documentation refer to https://venusdocs.fugerit.org/guide/#maven-plugin-entry" ); } return true; } ); @@ -202,14 +202,17 @@ public void generateBody() { this.println( " * " ); this.println( " * Consider using a @ApplicationScoped or Singleton approach." ); this.println( " */" ); - this.println( " private FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade.loadConfigSafe( \"cl://"+this.context.getResourcePathFmConfigXml()+"\" );" ); + this.println( " private final FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade" ); + this.println( " .loadConfigSafe(\"cl://"+this.context.getResourcePathFmConfigXml()+"\");" ); this.println(); this.println( " /**" ); this.println( " * Accessor for FreemarkerDocProcessConfig configuration." ); this.println( " *" ); this.println( " * @return the FreemarkerDocProcessConfig instance associated with this helper." ); this.println( " */" ); - this.println( " public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; }" ); + this.println( " public FreemarkerDocProcessConfig getDocProcessConfig() {" ); + this.println( " return this.docProcessConfig;" ); + this.println( " }" ); this.println(); } diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FlavourContext.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FlavourContext.java index 6566ec270..9b9347ced 100644 --- a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FlavourContext.java +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/FlavourContext.java @@ -52,10 +52,25 @@ public class FlavourContext { @Getter @Setter private boolean addJacoco; + @Getter @Setter + private boolean addFormatting; + public String getDefaultJacocoVersion() { return FlavourFacade.getFlavourDefaultVersion().getProperty( "jacoco-plugin-version" ); } + public String getDefaultFormatterPluginVersion() { + return FlavourFacade.getFlavourDefaultVersion().getProperty( "mvn-formatter-plugin-version" ); + } + + public String getDefaultFugeritCodeRulesVersion() { + return FlavourFacade.getFlavourDefaultVersion().getProperty( "fugerit-code-rules-version" ); + } + + public String getDefaultFormatSkip() { + return FlavourFacade.getFlavourDefaultVersion().getProperty( "format.skip" ); + } + private String toClassName( String base, String splitString ) { StringBuilder buf = new StringBuilder(); String[] split = base.split( splitString ); diff --git a/fj-doc-maven-plugin/src/main/resources/config/flavour/flavour_versions_default.properties b/fj-doc-maven-plugin/src/main/resources/config/flavour/flavour_versions_default.properties index 9a3883475..7c6a78664 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/flavour/flavour_versions_default.properties +++ b/fj-doc-maven-plugin/src/main/resources/config/flavour/flavour_versions_default.properties @@ -9,4 +9,11 @@ springboot-3=3.5.6 openliberty=25.0.0.9 # other general properties -jacoco-plugin-version=0.8.13 \ No newline at end of file + +# coverage +jacoco-plugin-version=0.8.13 + +# formatting +mvn-formatter-plugin-version=2.29.0 +fugerit-code-rules-version=0.1.1 +format.skip=false \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/flavour-macro.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/flavour-macro.ftl index 15318d2ab..eddae59c7 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/flavour-macro.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/flavour-macro.ftl @@ -109,4 +109,39 @@ public class DocHelper { public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; } } + + +<#macro addFormattingPomProperties context> + + ${context.defaultFormatterPluginVersion} + ${context.defaultFugeritCodeRulesVersion} + ${context.defaultFormatSkip} + + +<#macro addFormattingPomPlugin context> + + net.revelc.code.formatter + formatter-maven-plugin + ${r"${mvn-formatter-plugin-version}"} + + + org.fugerit.java + fugerit-code-rules + ${r"${fugerit-code-rules-version}"} + + + + org/fugerit/java/coderules/eclipse-format.xml + ${r"${format.skip}"} + + + + format-sources + process-sources + + format + + + + \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/micronaut-4/pom.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/micronaut-4/pom.ftl index 72443df83..14e68aea3 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/micronaut-4/pom.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/micronaut-4/pom.ftl @@ -24,6 +24,9 @@ <@fhm.toProjectPackage context=context/>.Application <#if context.addJacoco > ${context.defaultJacocoVersion} + +<#if context.addFormatting > + <@fhm.addFormattingPomProperties context=context/> @@ -166,6 +169,10 @@ + <#if context.addFormatting > + <@fhm.addFormattingPomPlugin context=context/> + + diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3-properties/pom.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3-properties/pom.ftl index 2ac1d5a7a..85089ca15 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3-properties/pom.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3-properties/pom.ftl @@ -1,4 +1,4 @@ - +<#import '../flavour-macro.ftl' as fhm> 4.0.0 ${context.groupId} @@ -16,6 +16,9 @@ true 3.3.1 1.0.0 + <#if context.addFormatting > + <@fhm.addFormattingPomProperties context=context/> + @@ -128,6 +131,9 @@ + <#if context.addFormatting > + <@fhm.addFormattingPomPlugin context=context/> + diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3/pom.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3/pom.ftl index eed3cdb98..51fccf0d2 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3/pom.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3/pom.ftl @@ -1,4 +1,4 @@ - +<#import '../flavour-macro.ftl' as fhm> 4.0.0 ${context.groupId} @@ -16,6 +16,9 @@ true 3.3.1 1.0.0 + <#if context.addFormatting > + <@fhm.addFormattingPomProperties context=context/> + @@ -132,6 +135,9 @@ + <#if context.addFormatting > + <@fhm.addFormattingPomPlugin context=context/> + diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/springboot-3/pom.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/springboot-3/pom.ftl index a305b1b50..c8b42d6c1 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/springboot-3/pom.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/springboot-3/pom.ftl @@ -1,4 +1,4 @@ - +<#import '../flavour-macro.ftl' as fhm> 4.0.0 @@ -17,6 +17,9 @@ ${context.javaRelease} 2.8.13 5.11.3 + <#if context.addFormatting > + <@fhm.addFormattingPomProperties context=context/> + @@ -66,6 +69,9 @@ + <#if context.addFormatting > + <@fhm.addFormattingPomPlugin context=context/> + diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/vanilla/pom.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/vanilla/pom.ftl index 41b29bb58..4adca910b 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/flavour/vanilla/pom.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/flavour/vanilla/pom.ftl @@ -1,4 +1,4 @@ - +<#import '../flavour-macro.ftl' as fhm> 4.0.0 ${context.groupId} @@ -10,33 +10,39 @@ UTF-8 <#if context.addJacoco > ${context.defaultJacocoVersion} + +<#if context.addFormatting > +<@fhm.addFormattingPomProperties context=context/> - <#if context.addJacoco > - - - - org.jacoco - jacoco-maven-plugin - ${r"${jacoco-plugin-version}"} - - - - prepare-agent - - - - report - prepare-package - - report - - - - - - - + + + <#if context.addJacoco > + + org.jacoco + jacoco-maven-plugin + ${r"${jacoco-plugin-version}"} + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + <#if context.addFormatting > + <@fhm.addFormattingPomPlugin context=context/> + + + diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/macro/DocHelperMacro.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/macro/DocHelperMacro.ftl index 5bb090758..23f1fdb62 100644 --- a/fj-doc-maven-plugin/src/main/resources/config/template/macro/DocHelperMacro.ftl +++ b/fj-doc-maven-plugin/src/main/resources/config/template/macro/DocHelperMacro.ftl @@ -10,33 +10,35 @@ * https://github.com/fugerit-org/fj-doc * * NOTE: This is a 'Hello World' style example, adapt it to your scenario, especially :<#if !context.addLombok > - * - remove system out and system err with your logging system - * - change the doc handler and the output mode (here a ByteArrayOutputStream buffer is used) + * - remove system out and system err with your logging system + * - change the doc handler and the output mode (here a ByteArrayOutputStream buffer is used) */ <#macro createExampleBody context junit className> - try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { // creates the doc helper DocHelper docHelper = new DocHelper(); // create custom data for the fremarker template 'document.ftl' - List listPeople = Arrays.asList( new People( "Luthien", "Tinuviel", "Queen" ), new People( "Thorin", "Oakshield", "King" ) ); - <#if context.modules?seq_contains("fj-doc-base-json")>// json source supported, if you want to try it, use the chainId "document-json" - <#if context.modules?seq_contains("fj-doc-base-yaml")>// yaml source supported, if you want to try it, use the chainId "document-yaml" + List listPeople = Arrays.asList( + new People("Luthien", "Tinuviel", "Queen"), new People("Thorin", "Oakshield", "King")); +<#if context.modules?seq_contains("fj-doc-base-json")>// json source supported, if you want to try it, use the chainId "document-json"<#if context.modules?seq_contains("fj-doc-base-yaml")>// yaml source supported, if you want to try it, use the chainId "document-yaml" String chainId = "document"; <#if context.preVersion862 > // find the handler for the output : DocTypeHandler docTypeHandler = docHelper.getDocProcessConfig().getFacade().findHandler(DocConfig.TYPE_MD); // output generation - docHelper.getDocProcessConfig().fullProcess( chainId, DocProcessContext.newContext( "listPeople", listPeople ), docTypeHandler, DocOutput.newOutput( baos ) ); + docHelper.getDocProcessConfig().fullProcess(chainId, + DocProcessContext.newContext("listPeople", listPeople), docTypeHandler, DocOutput.newOutput(baos)); <#else> // handler id String handlerId = DocConfig.TYPE_MD; // output generation - docHelper.getDocProcessConfig().fullProcess( chainId, DocProcessContext.newContext( "listPeople", listPeople ), handlerId, baos ); + docHelper.getDocProcessConfig().fullProcess(chainId, + DocProcessContext.newContext("listPeople", listPeople), handlerId, baos); // print the output - <#if context.addLombok >log.info( "{} output : \n{}", handlerId, new String( baos.toByteArray(), StandardCharsets.UTF_8 ) );<#else>System.out.println( handlerId+" output : \n"+ new String( baos.toByteArray(), StandardCharsets.UTF_8 ) ); - <#if junit >Assertions.assertNotEquals( 0, baos.size() ); + <#if context.addLombok >log.info("{} output : \n{}", handlerId, new String(baos.toByteArray(), StandardCharsets.UTF_8));<#else>System.out.println(handlerId+" output : \n"+ new String(baos.toByteArray(), StandardCharsets.UTF_8)); + <#if junit >Assertions.assertNotEquals(0, baos.size()); } \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestInit.java b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestInit.java index 7e84f7c95..36e4def18 100644 --- a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestInit.java +++ b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestInit.java @@ -56,6 +56,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { this.addJunit5 = true; this.addLombok = true; this.addJacoco = true; + this.addFormatting = true; this.flavour = currentFlavour; if ( FlavourFacade.FLAVOUR_QUARKUS_3.equals( currentFlavour ) ) { this.basePackage = "org.fugerit.java.basepack"; diff --git a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectInitInput.java b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectInitInput.java index bd80a13dc..cea888711 100644 --- a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectInitInput.java +++ b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectInitInput.java @@ -62,4 +62,8 @@ public class ProjectInitInput { @Setter private boolean addJacoco; + @Getter + @Setter + private boolean addFormatting; + } diff --git a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java index 05fe52886..3057bd17f 100644 --- a/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java +++ b/fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/init/ProjectRest.java @@ -80,6 +80,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { this.addVerifyPlugin = data.isAddVerifyPlugin(); this.addDirectPlugin = data.isAddDirectPlugin(); this.addJacoco = data.isAddJacoco(); + this.addFormatting = data.isAddFormatting(); super.execute(); } }; diff --git a/fj-doc-playground-quarkus/src/main/react/src/playground/DocProjectInit.jsx b/fj-doc-playground-quarkus/src/main/react/src/playground/DocProjectInit.jsx index 28cc92002..fdb90348a 100644 --- a/fj-doc-playground-quarkus/src/main/react/src/playground/DocProjectInit.jsx +++ b/fj-doc-playground-quarkus/src/main/react/src/playground/DocProjectInit.jsx @@ -39,6 +39,7 @@ const DocProjectInit = ({setHelpContent}) => { const [addVerifyPlugin, setAddVerifyPlugin] = useState(true); // State to handle addVerifyPlugin selection const [addDirectPlugin, setAddDirectPlugin] = useState(false); // State to handle addDirectPlugin selection const [addJacoco, setAddJacoco] = useState(false); // State to handle addJacoco selection + const [addFormatting, setAddFormatting] = useState(false); // State to handle addJacoco selection // useEffect to fetch data from the API when the component mounts useEffect(() => { @@ -115,6 +116,7 @@ const DocProjectInit = ({setHelpContent}) => { addVerifyPlugin, addDirectPlugin, addJacoco, + addFormatting, extensionList: selectedExtensions, }; try { @@ -284,7 +286,21 @@ const DocProjectInit = ({setHelpContent}) => { - + + {/* Text field for addFormatting */} + + Add formatting + setAddFormatting(e.target.value === 'true')} + > + } label="true" /> + } label="false" /> + + + + {/* Text field for flavourVersion */}