Skip to content

Commit c8b8313

Browse files
authored
Merge pull request #544 from fugerit-org/543-enhancement-fj-doc-maven-plugin-init-goal-add-ci-support-for-github
543 enhancement fj doc maven plugin init goal add ci support for GitHub
2 parents 4d0a1bb + 16cd9db commit c8b8313

File tree

14 files changed

+133
-7
lines changed

14 files changed

+133
-7
lines changed

CHANGELOG.md

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

1010
### Added
1111

12+
- fj-doc-maven-plugin, init goal, add CI support for GitHub <https://github.com/fugerit-org/fj-doc/issues/543>
1213
- fj-doc-maven-plugin, init goal, 'addFormatting' <https://github.com/fugerit-org/fj-doc/issues/541>
1314

1415
### Changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ mvn org.fugerit.java:fj-doc-maven-plugin:init \
5656
-DgroupId=org.example.doc \
5757
-DartifactId=fugerit-demo-quarkus-3 \
5858
-Dflavour=quarkus-3 \
59-
-DaddJacoco=true
59+
-DaddJacoco=true \
60+
-DaddFormatting=true \
61+
-DwithCI=GitHub
6062
```
6163
It will create a new folder as for the {artifactId} parameter
6264
(in our example : *fugerit-demo-quarkus-3*)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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, add CI support for GitHub link:https://github.com/fugerit-org/fj-doc/issues/543[#543]
910
- fj-doc-maven-plugin, init goal, 'addFormatting' parameter link:https://github.com/fugerit-org/fj-doc/issues/541[#541]
1011
1112
[#doc-release-notes-8-16-9]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Project folder will be `./${artifactId}/`.
2727
| flavourVersion | false | see below | override default framework version if supported (recommended : leave default or blank)
2828
| addJacoco (*) | false | false | add jacoco coverage support
2929
| addFormatting (*) | false | false | add maven plugin formatter with rules from link:https://github.com/fugerit-org/fugerit-code-rules[fugerit-code-rules]
30+
| withCI (*) | false | | It will generate a basic CI workflow for give platform. Supported values : 'github'
3031
|====================================================================================================================================
3132

3233
(*) Currently not working on gradle flavours

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
@@ -42,6 +42,9 @@ public class MojoInit extends MojoAdd {
4242
@Parameter(property = "addFormatting", defaultValue = "false", required = false)
4343
protected boolean addFormatting;
4444

45+
@Parameter(property = "withCI", required = false)
46+
protected String withCI;
47+
4548
public MojoInit() {
4649
this.baseInitFolder = ".";
4750
}
@@ -72,6 +75,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
7275
context.setBasePackage( this.basePackage );
7376
context.setAddJacoco( this.addJacoco );
7477
context.setAddFormatting( this.addFormatting );
78+
context.setWithCI( this.withCI );
7579
this.getLog().info( String.format( "flavour context : %s", context ) );
7680
String actualVersion = FlavourFacade.initProject( context );
7781
if ( FlavourFacade.FLAVOUR_DIRECT.equals( actualVersion ) ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private static void copyResourcesList( File baseFolder, String mode, String id )
4040
protected static void insureParent( File file ) throws IOException {
4141
File parentFile = file.getParentFile();
4242
if ( !parentFile.exists() ) {
43-
log.info( "creates parent directory {}, mkdirs:?", parentFile.getCanonicalPath(), parentFile.mkdirs() );
43+
log.info( "creates parent directory {}, mkdirs:? {}", parentFile.getCanonicalPath(), parentFile.mkdirs() );
4444
}
4545
}
4646

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class FlavourContext {
5555
@Getter @Setter
5656
private boolean addFormatting;
5757

58+
@Getter @Setter
59+
private String withCI;
60+
5861
public String getDefaultJacocoVersion() {
5962
return FlavourFacade.getFlavourDefaultVersion().getProperty( "jacoco-plugin-version" );
6063
}
@@ -71,6 +74,10 @@ public String getDefaultFormatSkip() {
7174
return FlavourFacade.getFlavourDefaultVersion().getProperty( "format.skip" );
7275
}
7376

77+
public String getWithCIPath() {
78+
return FlavourFacade.getFlavourDefaultVersion().getProperty( "withCI.path."+this.withCI.toLowerCase() );
79+
}
80+
7481
private String toClassName( String base, String splitString ) {
7582
StringBuilder buf = new StringBuilder();
7683
String[] split = base.split( splitString );

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ private FlavourFacade() {}
4949

5050
private static final Properties FLAVOURS_DEFAULT_VERSION = PropsIO.loadFromClassLoaderSafe( "config/flavour/flavour_versions_default.properties" );
5151

52+
public static final String WITH_CI_GITHUB = "github";
53+
5254
public static Properties getFlavourDefaultVersion() {
5355
return new Properties( FLAVOURS_DEFAULT_VERSION );
5456
}
@@ -67,12 +69,22 @@ public static boolean isGradleKtsFlavour(String flavour ) {
6769
return prop;
6870
});
6971

72+
public static final Set<String> SUPPORTED_CI = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( WITH_CI_GITHUB ) ) );
73+
74+
private static void checkCI( FlavourContext context ) {
75+
if ( StringUtils.isNotEmpty( context.getWithCI() ) && !SUPPORTED_CI.contains( context.getWithCI().toLowerCase() ) ) {
76+
throw new ConfigRuntimeException( String.format( "withCI not supported : %s (allowed values are %s)", context.getWithCI(), SUPPORTED_CI ) );
77+
}
78+
}
79+
7080
public static String initProject( FlavourContext context ) throws IOException, TemplateException {
7181
log.info( "generate flavour : {}", context.getFlavour() );
7282
String actualFlavour = MAP_FLAVOURS.getProperty( context.getFlavour(), context.getFlavour() );
7383
if ( SUPPORTED_FLAVOURS.contains( actualFlavour ) ) {
84+
checkCI( context );
7485
checkFlavour( context, actualFlavour );
7586
initFlavour( context, actualFlavour );
87+
initCI( context, actualFlavour );
7688
} else {
7789
throw new ConfigRuntimeException( String.format( "flavour not supported : %s", context.getFlavour() ) );
7890
}
@@ -85,7 +97,7 @@ public static void checkFlavour( FlavourContext context, String actualFlavour )
8597
|| FLAVOUR_SPRINGBOOT_3.equals( actualFlavour ) || FLAVOUR_OPENLIBERTY.equals( actualFlavour ) ) && javaVersion < 17 ) {
8698
throw new ConfigRuntimeException( String.format( "Minimum java version for %s is 17", actualFlavour ) );
8799
} else if ( FLAVOUR_QUARKUS_2.equals( actualFlavour ) && javaVersion != 11 ) {
88-
log.info( "quarkus 2 is a legacy flavour, javaRelease %s will default to '11'", javaVersion );
100+
log.info( "quarkus 2 is a legacy flavour, javaRelease {} will default to '11'", javaVersion );
89101
}
90102
log.info( "checkFlavour {} done", actualFlavour );
91103
checkFlavourVersion( context, actualFlavour );
@@ -162,11 +174,26 @@ private static void initFlavour( FlavourContext context, String actualFlavour )
162174
try ( StringWriter writer = new StringWriter() ) {
163175
FreemarkerTemplateFacade.processFile( freemarkerProcessYamlPath, writer, data );
164176
FlavourConfig flavourConfig = mapper.readValue( writer.toString(), FlavourConfig.class );
165-
log.info( "floavourConfig {}", flavourConfig.getFlavour() );
177+
log.info( "flavourConfig {}", flavourConfig.getFlavour() );
166178
flavourConfig.getProcess().forEach( entry -> FeatureFacade.processEntry( entry, data ) );
167179
}
168180
}
169181

182+
private static void initCI( FlavourContext context, String actualFlavour ) throws IOException, TemplateException {
183+
if ( StringUtils.isNotEmpty( context.getWithCI() ) && !FlavourFacade.isGradleKtsFlavour( actualFlavour ) ) {
184+
String withCI = context.getWithCI().toLowerCase();
185+
String relativeDestinationPath = context.getWithCIPath();
186+
String ciTemplatePath = String.format( "ci/%s-ci.ftl", withCI );
187+
File outputCIFile = new File( context.getProjectFolder(), relativeDestinationPath );
188+
log.info( "generating CI : mkdir? {} -> {}", outputCIFile.getParentFile().mkdirs(), outputCIFile.getCanonicalPath() );
189+
try ( FileWriter writer = new FileWriter( outputCIFile ) ) {
190+
Map<String, Object> data = new HashMap<>();
191+
data.put( "context", context );
192+
FreemarkerTemplateFacade.processFile( ciTemplatePath, writer, data );
193+
}
194+
}
195+
}
196+
170197

171198

172199
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ jacoco-plugin-version=0.8.13
1616
# formatting
1717
mvn-formatter-plugin-version=2.29.0
1818
fugerit-code-rules-version=0.1.1
19-
format.skip=false
19+
format.skip=false
20+
21+
# ci
22+
withCI.path.github=.github/workflows/ci.yml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI workflow
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Set up JDK ${context.javaRelease}
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: ${context.javaRelease}
20+
distribution: 'zulu'
21+
- name: Cache Maven packages
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.m2
25+
key: ${r"${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}"}
26+
restore-keys: ${r"${{ runner.os }}"}-m2
27+
- name: Build
28+
run: mvn clean install

0 commit comments

Comments
 (0)