Skip to content

Commit 4d0a1bb

Browse files
authored
Merge pull request #542 from fugerit-org/541-chore-fj-doc-maven-plugin-init-goal-option-for-code-formatting
541 chore fj doc maven plugin init goal option for code formatting
2 parents 9ada5e4 + bf8b60f commit 4d0a1bb

File tree

18 files changed

+173
-45
lines changed

18 files changed

+173
-45
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+
### Added
11+
12+
- fj-doc-maven-plugin, init goal, 'addFormatting' <https://github.com/fugerit-org/fj-doc/issues/541>
13+
1014
### Changed
1115

1216
- quarkus-version set to 3.28.3 across all the modules <https://github.com/fugerit-org/fj-doc/issues/539>

fj-doc-guide/src/main/docs/asciidoc/chapters/00_2_release_notes.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Whereas the link:https://github.com/fugerit-org/fj-doc/blob/main/CHANGELOG.md[CH
66
[#doc-release-notes-unreleased]
77
==== Unreleased
88

9+
- fj-doc-maven-plugin, init goal, 'addFormatting' parameter link:https://github.com/fugerit-org/fj-doc/issues/541[#541]
10+
911
[#doc-release-notes-8-16-9]
1012
==== Version 8.16.9 [2025-10-06]
1113

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ Project folder will be `./${artifactId}/`.
2525
| javaRelease | true | 21 | java release version
2626
| flavour | true | vanilla | the flavour for the new project (see below for options)
2727
| flavourVersion | false | see below | override default framework version if supported (recommended : leave default or blank)
28-
| addJacoco | false | false | add jacoco coverage support
28+
| addJacoco (*) | false | false | add jacoco coverage support
29+
| addFormatting (*) | false | false | add maven plugin formatter with rules from link:https://github.com/fugerit-org/fugerit-code-rules[fugerit-code-rules]
2930
|====================================================================================================================================
3031

32+
(*) Currently not working on gradle flavours
33+
3134
NOTE: it is possible to set any property from 'add' goal, except 'projectFolder' which is set to `./${artifactId}`.
3235

3336
[#flavour-list]

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class MojoInit extends MojoAdd {
3939
@Parameter(property = "addJacoco", defaultValue = "false", required = false)
4040
protected boolean addJacoco;
4141

42+
@Parameter(property = "addFormatting", defaultValue = "false", required = false)
43+
protected boolean addFormatting;
44+
4245
public MojoInit() {
4346
this.baseInitFolder = ".";
4447
}
@@ -68,6 +71,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6871
context.setExtensions( this.extensions );
6972
context.setBasePackage( this.basePackage );
7073
context.setAddJacoco( this.addJacoco );
74+
context.setAddFormatting( this.addFormatting );
7175
this.getLog().info( String.format( "flavour context : %s", context ) );
7276
String actualVersion = FlavourFacade.initProject( context );
7377
if ( FlavourFacade.FLAVOUR_DIRECT.equals( actualVersion ) ) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static boolean addVenusToMavenProject( File pomFile, VenusContext context
154154
} else {
155155
log.info( "Generation complete:\n{}\n* For usage open the example main() : {} *\n{}", LINE, context.getDocConfigPackage()+"."+context.getDocConfigClass()+"Example", LINE );
156156
}
157-
log.info( "for documentation refer to https://github.com/fugerit-org/fj-doc/blob/main/fj-doc-maven-plugin/README.md" );
157+
log.info( "for documentation refer to https://venusdocs.fugerit.org/guide/#maven-plugin-entry" );
158158
}
159159
return true;
160160
} );
@@ -202,14 +202,17 @@ public void generateBody() {
202202
this.println( " * " );
203203
this.println( " * Consider using a @ApplicationScoped or Singleton approach." );
204204
this.println( " */" );
205-
this.println( " private FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade.loadConfigSafe( \"cl://"+this.context.getResourcePathFmConfigXml()+"\" );" );
205+
this.println( " private final FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade" );
206+
this.println( " .loadConfigSafe(\"cl://"+this.context.getResourcePathFmConfigXml()+"\");" );
206207
this.println();
207208
this.println( " /**" );
208209
this.println( " * Accessor for FreemarkerDocProcessConfig configuration." );
209210
this.println( " *" );
210211
this.println( " * @return the FreemarkerDocProcessConfig instance associated with this helper." );
211212
this.println( " */" );
212-
this.println( " public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; }" );
213+
this.println( " public FreemarkerDocProcessConfig getDocProcessConfig() {" );
214+
this.println( " return this.docProcessConfig;" );
215+
this.println( " }" );
213216
this.println();
214217
}
215218

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,25 @@ public class FlavourContext {
5252
@Getter @Setter
5353
private boolean addJacoco;
5454

55+
@Getter @Setter
56+
private boolean addFormatting;
57+
5558
public String getDefaultJacocoVersion() {
5659
return FlavourFacade.getFlavourDefaultVersion().getProperty( "jacoco-plugin-version" );
5760
}
5861

62+
public String getDefaultFormatterPluginVersion() {
63+
return FlavourFacade.getFlavourDefaultVersion().getProperty( "mvn-formatter-plugin-version" );
64+
}
65+
66+
public String getDefaultFugeritCodeRulesVersion() {
67+
return FlavourFacade.getFlavourDefaultVersion().getProperty( "fugerit-code-rules-version" );
68+
}
69+
70+
public String getDefaultFormatSkip() {
71+
return FlavourFacade.getFlavourDefaultVersion().getProperty( "format.skip" );
72+
}
73+
5974
private String toClassName( String base, String splitString ) {
6075
StringBuilder buf = new StringBuilder();
6176
String[] split = base.split( splitString );

fj-doc-maven-plugin/src/main/resources/config/flavour/flavour_versions_default.properties

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ springboot-3=3.5.6
99
openliberty=25.0.0.9
1010

1111
# other general properties
12-
jacoco-plugin-version=0.8.13
12+
13+
# coverage
14+
jacoco-plugin-version=0.8.13
15+
16+
# formatting
17+
mvn-formatter-plugin-version=2.29.0
18+
fugerit-code-rules-version=0.1.1
19+
format.skip=false

fj-doc-maven-plugin/src/main/resources/config/template/flavour/flavour-macro.ftl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,39 @@ public class DocHelper {
109109
public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; }
110110

111111
}
112+
</#macro>
113+
114+
<#macro addFormattingPomProperties context>
115+
<!-- formatter plugin -->
116+
<mvn-formatter-plugin-version>${context.defaultFormatterPluginVersion}</mvn-formatter-plugin-version>
117+
<fugerit-code-rules-version>${context.defaultFugeritCodeRulesVersion}</fugerit-code-rules-version>
118+
<format.skip>${context.defaultFormatSkip}</format.skip>
119+
</#macro>
120+
121+
<#macro addFormattingPomPlugin context>
122+
<plugin>
123+
<groupId>net.revelc.code.formatter</groupId>
124+
<artifactId>formatter-maven-plugin</artifactId>
125+
<version>${r"${mvn-formatter-plugin-version}"}</version>
126+
<dependencies>
127+
<dependency>
128+
<groupId>org.fugerit.java</groupId>
129+
<artifactId>fugerit-code-rules</artifactId>
130+
<version>${r"${fugerit-code-rules-version}"}</version>
131+
</dependency>
132+
</dependencies>
133+
<configuration>
134+
<configFile>org/fugerit/java/coderules/eclipse-format.xml</configFile>
135+
<skip>${r"${format.skip}"}</skip>
136+
</configuration>
137+
<executions>
138+
<execution>
139+
<id>format-sources</id>
140+
<phase>process-sources</phase>
141+
<goals>
142+
<goal>format</goal>
143+
</goals>
144+
</execution>
145+
</executions>
146+
</plugin>
112147
</#macro>

fj-doc-maven-plugin/src/main/resources/config/template/flavour/micronaut-4/pom.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<exec.mainClass><@fhm.toProjectPackage context=context/>.Application</exec.mainClass>
2525
<#if context.addJacoco >
2626
<jacoco-plugin-version>${context.defaultJacocoVersion}</jacoco-plugin-version>
27+
</#if>
28+
<#if context.addFormatting >
29+
<@fhm.addFormattingPomProperties context=context/>
2730
</#if>
2831
</properties>
2932

@@ -166,6 +169,10 @@
166169
</plugin>
167170
</#if>
168171

172+
<#if context.addFormatting >
173+
<@fhm.addFormattingPomPlugin context=context/>
174+
</#if>
175+
169176
</plugins>
170177
</build>
171178

fj-doc-maven-plugin/src/main/resources/config/template/flavour/quarkus-3-properties/pom.ftl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<#import '../flavour-macro.ftl' as fhm><?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>${context.groupId}</groupId>
@@ -16,6 +16,9 @@
1616
<skipITs>true</skipITs>
1717
<surefire-plugin.version>3.3.1</surefire-plugin.version>
1818
<freemarker-native-version>1.0.0</freemarker-native-version>
19+
<#if context.addFormatting >
20+
<@fhm.addFormattingPomProperties context=context/>
21+
</#if>
1922
</properties>
2023

2124
<dependencyManagement>
@@ -128,6 +131,9 @@
128131
</systemPropertyVariables>
129132
</configuration>
130133
</plugin>
134+
<#if context.addFormatting >
135+
<@fhm.addFormattingPomPlugin context=context/>
136+
</#if>
131137
</plugins>
132138
</build>
133139

0 commit comments

Comments
 (0)