Skip to content

Commit 9f4d867

Browse files
authored
Merge pull request #408 from fugerit-org/405-enhancement-fj-doc-lib-direct-add-support-to-maven-goal-init-and-add
405 enhancement fj doc lib direct add support to maven goal init and add
2 parents 5b55679 + 4d385a1 commit 9f4d867

File tree

28 files changed

+442
-66
lines changed

28 files changed

+442
-66
lines changed

.github/workflows/build_fj-doc-native-quarkus_test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ on:
1717
push:
1818
branches:
1919
- develop
20-
pull_request:
21-
types:
22-
- opened
23-
- synchronize
24-
- reopened
20+
- branch-deploy
2521

2622
# only allow one workflow at time on the give activation
2723
concurrency:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ 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] support add 'direct' goal to maven goal 'init' and 'add' <https://github.com/fugerit-org/fj-doc/pull/405>
13+
- [fj-doc-playground-quarkus] project init - add verify and direct plugin options
14+
1015
## [8.13.5] - 2025-04-25
1116

1217
### Added

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
2424
| excludeXmlApis | false | false | It will exclude dependency xml-apis:xml-apis
2525
| addExclusions | false | | Add comma separated exclusion, for instance : xml-apis:xml-apis,${groupId}:${artificatId}
2626
| addVerifyPlugin | true | true | If set to true, it will configure the 'verify' goal on the project
27+
| addDirectPlugin | false | true | If set to true, it will configure the 'direct' goal on the project
2728
| addJunit5 | true | true | If set to true, it will add junit5 (test scope) and basic test
2829
| addLombok | true | true | If set to true, it will add lombok (provided scope) and slf4j-simple (test scope)
2930
| addDependencyOnTop | true | false | If set to true, added dependencies will be added before existing ones

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class MojoAdd extends AbstractMojo {
3838
@Parameter(property = "addVerifyPlugin", defaultValue = "true", required = true)
3939
protected boolean addVerifyPlugin;
4040

41+
@Parameter(property = "addDirectPlugin", defaultValue = "false", required = true)
42+
protected boolean addDirectPlugin;
43+
4144
@Parameter(property = "addJunit5", defaultValue = "true", required = true)
4245
protected boolean addJunit5;
4346

@@ -67,6 +70,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6770
context.setAddExclusions( addExclusions );
6871
context.setExcludeXmlApis( this.excludeXmlApis );
6972
context.setAddVerifyPlugin( this.addVerifyPlugin );
73+
context.setAddDirectPlugin( this.addDirectPlugin );
7074
context.setAddJunit5( this.addJunit5 );
7175
context.setAddLombok( this.addLombok );
7276
context.setAddDependencyOnTop( this.addDependencyOnTop );

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6464
context.setVersion( VersionCheck.findVersion( this.version ) );
6565
context.setExtensions( this.extensions );
6666
this.getLog().info( String.format( "flavour context : %s", context ) );
67-
FlavourFacade.initProject( context );
67+
String actualVersion = FlavourFacade.initProject( context );
68+
if ( FlavourFacade.FLAVOUR_DIRECT.equals( actualVersion ) ) {
69+
super.addDirectPlugin = true;
70+
}
6871
} );
6972
super.groupIdOverride = this.groupId;
7073
super.artifactIdOverride = this.artifactId;

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

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.apache.maven.model.*;
5-
import org.codehaus.plexus.util.xml.Xpp3Dom;
6-
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
5+
import org.apache.maven.plugins.annotations.LifecyclePhase;
76
import org.fugerit.java.core.cfg.ConfigRuntimeException;
87
import org.fugerit.java.core.io.FileIO;
9-
import org.fugerit.java.core.io.helper.HelperIOException;
108
import org.fugerit.java.core.lang.helpers.StringUtils;
119
import org.maxxq.maven.dependency.ModelIO;
1210

@@ -21,9 +19,9 @@ public class BasicVenusFacade {
2119

2220
protected BasicVenusFacade() {}
2321

24-
protected static final String GROUP_ID = "org.fugerit.java";
22+
protected static final String GROUP_ID = VenusConsts.GROUP_ID;
2523

26-
protected static final String KEY_VERSION = "fj-doc-version";
24+
protected static final String KEY_VERSION = VenusConsts.KEY_VERSION;
2725

2826
private static void addOrOverwrite( List<Dependency> deps, Dependency d ) {
2927
Iterator<Dependency> it = deps.iterator();
@@ -148,7 +146,8 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
148146
addJunit5( model, context );
149147
// addLombok parameter
150148
addLombok( model, context );
151-
addPlugin( context, model );
149+
addDirectPlugin( context, model );
150+
addVerifyPlugin( context, model );
152151
log.info( "end dependencies size : {}", model.getDependencies().size() );
153152
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
154153
modelIO.writeModelToStream( model, pomStream );
@@ -221,41 +220,50 @@ protected static void addExtensionGradleList( File gradleFile, VenusContext cont
221220
FileIO.writeString( gradleFileContent, gradleFile );
222221
}
223222

224-
private static void addPlugin( VenusContext context, Model model ) throws IOException {
223+
private static void addDirectPlugin(VenusContext context, Model model ) throws IOException {
224+
// addDirectPlugin?
225+
if ( context.isAddDirectPlugin() ) {
226+
if (context.isDirectPluginNotAvailable()) {
227+
log.warn("addDirectPlugin skipped, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_DIRECT_PLUGIN);
228+
} else {
229+
FeatureFacade.copyFeatureList( context.getProjectDir(), "direct" );
230+
log.info("addDirectPlugin true, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_DIRECT_PLUGIN);
231+
Plugin plugin = PluginUtils.findOrCreatePLugin( model );
232+
PluginExecution execution = PluginUtils.createPluginExecution(
233+
"venus-direct", LifecyclePhase.COMPILE.id(), PluginUtils.GOAL_DIRECT );
234+
plugin.getExecutions().add( execution );
235+
String xml = "<configuration>\n" +
236+
" <configPath>${project.basedir}/src/main/resources/venus-direct-config/venus-direct-config.yaml</configPath>\n" +
237+
" <outputAll>true</outputAll>\n" +
238+
" <directEnv>\n" +
239+
" <projectBasedir>${project.basedir}</projectBasedir>\n" +
240+
" </directEnv>\n" +
241+
"</configuration>";
242+
execution.setConfiguration( PluginUtils.getPluginConfiguration( xml ) );
243+
}
244+
} else {
245+
log.info( "addDirectPlugin : false" );
246+
}
247+
}
248+
249+
private static void addVerifyPlugin(VenusContext context, Model model ) throws IOException {
225250
// addVerifyPlugin?
226251
if ( context.isAddVerifyPlugin() ) {
227252
if ( context.isVerifyPluginNotAvailable() ) {
228253
log.warn( "addVerifyPlugin skipped, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_VERIFY_PLUGIN );
229254
} else {
230255
log.info( "addVerifyPlugin true, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_VERIFY_PLUGIN );
231-
Build build = model.getBuild();
232-
if ( build == null ) {
233-
build = new Build();
234-
model.setBuild( build );
235-
}
236-
List<Plugin> plugins = model.getBuild().getPlugins();
237-
Plugin plugin = new Plugin();
238-
plugin.setGroupId( GROUP_ID );
239-
plugin.setArtifactId( "fj-doc-maven-plugin" );
240-
plugin.setVersion( "${"+KEY_VERSION+"}" );
241-
PluginExecution execution = new PluginExecution();
242-
execution.setId( "freemarker-verify" );
243-
execution.setPhase( "compile" );
244-
execution.addGoal( "verify" );
256+
Plugin plugin = PluginUtils.findOrCreatePLugin( model );
257+
PluginExecution execution = PluginUtils.createPluginExecution(
258+
"freemarker-verify", LifecyclePhase.COMPILE.id(), LifecyclePhase.VERIFY.id() );
245259
plugin.getExecutions().add( execution );
246260
String xml = "<configuration>\n" +
247261
" <templateBasePath>${project.basedir}/src/main/resources/"+context.getArtificatIdForFolder()+"/template</templateBasePath>\n" +
248262
" <generateReport>true</generateReport>\n" +
249263
" <failOnErrors>true</failOnErrors>\n" +
250264
" <reportOutputFolder>${project.build.directory}/freemarker-syntax-verify-report</reportOutputFolder>\n" +
251265
" </configuration>";
252-
HelperIOException.apply( () -> {
253-
try ( StringReader sr = new StringReader( xml ) ) {
254-
Xpp3Dom dom = Xpp3DomBuilder.build( sr );
255-
plugin.setConfiguration( dom );
256-
}
257-
});
258-
plugins.add( plugin );
266+
execution.setConfiguration( PluginUtils.getPluginConfiguration( xml ) );
259267
}
260268
} else {
261269
log.info( "addVerifyPlugin : false" );
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.fugerit.java.doc.project.facade;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.core.function.SafeFunction;
5+
import org.fugerit.java.core.io.StreamIO;
6+
import org.fugerit.java.core.lang.helpers.ClassHelper;
7+
8+
import java.io.*;
9+
10+
@Slf4j
11+
public class FeatureFacade {
12+
13+
private FeatureFacade() {}
14+
15+
public static void copyFlavourList( File baseFolder, String actualFlavour ) throws IOException {
16+
copyResourcesList( baseFolder, "flavour", actualFlavour );
17+
}
18+
19+
public static void copyFeatureList( File baseFolder, String featureId ) throws IOException {
20+
copyResourcesList( baseFolder, "feature", featureId );
21+
}
22+
23+
private static void copyResourcesList( File baseFolder, String mode, String id ) throws IOException {
24+
// copy all resources
25+
String listFilePath = String.format( "config/%s/%s-copy.txt", mode, id );
26+
String baseFlavourPath = String.format( "config/%s/%s/", mode, id );
27+
log.info( "loading list file {}, base flavour path {}", listFilePath, baseFlavourPath );
28+
try (BufferedReader reader = new BufferedReader( new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( listFilePath ) ) ) ) {
29+
reader.lines().forEach( s -> copyFile( s, baseFolder, baseFlavourPath ) );
30+
}
31+
}
32+
33+
protected static void insureParent( File file ) throws IOException {
34+
File parentFile = file.getParentFile();
35+
if ( !parentFile.exists() ) {
36+
log.info( "creates parent directory {}, mkdirs:?", parentFile.getCanonicalPath(), parentFile.mkdirs() );
37+
}
38+
}
39+
40+
protected static void copyFile(String path, File baseFolder, String basePath ) {
41+
SafeFunction.apply( () -> {
42+
File outputFile = new File( baseFolder, path );
43+
insureParent( outputFile );
44+
String fullPath = basePath+path;
45+
log.info( "copy path '{}' to file '{}'", fullPath, outputFile.getCanonicalPath() );
46+
try (InputStream is = ClassHelper.loadFromDefaultClassLoader( fullPath );
47+
FileOutputStream os = new FileOutputStream( outputFile ) ) {
48+
StreamIO.pipeStream( is, os, StreamIO.MODE_CLOSE_NONE );
49+
}
50+
} );
51+
}
52+
53+
}

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import lombok.extern.slf4j.Slf4j;
77
import org.fugerit.java.core.cfg.ConfigRuntimeException;
88
import org.fugerit.java.core.function.SafeFunction;
9-
import org.fugerit.java.core.io.StreamIO;
109
import org.fugerit.java.core.lang.helpers.ClassHelper;
1110
import org.fugerit.java.core.lang.helpers.StringUtils;
1211
import org.fugerit.java.core.lang.helpers.reflect.MethodHelper;
@@ -19,7 +18,6 @@
1918

2019
import java.io.*;
2120
import java.lang.reflect.Field;
22-
import java.lang.reflect.Method;
2321
import java.util.*;
2422

2523
@Slf4j
@@ -29,6 +27,8 @@ private FlavourFacade() {}
2927

3028
public static final String FLAVOUR_VANILLA = "vanilla";
3129

30+
public static final String FLAVOUR_DIRECT = "direct";
31+
3232
public static final String FLAVOUR_QUARKUS_3 = "quarkus-3";
3333

3434
public static final String FLAVOUR_QUARKUS_3_GRADLE = "quarkus-3-gradle";
@@ -50,7 +50,7 @@ private FlavourFacade() {}
5050
private static final Properties FLAVOURS_DEFAULT_VERSION = PropsIO.loadFromClassLoaderSafe( "config/flavour/flavour_versions_default.properties" );
5151

5252
public static final Set<String> SUPPORTED_FLAVOURS = Collections.unmodifiableSet(
53-
new HashSet<>( Arrays.asList( FLAVOUR_VANILLA, FLAVOUR_QUARKUS_3, FLAVOUR_QUARKUS_3_GRADLE, FLAVOUR_QUARKUS_3_GRADLE_KTS,
53+
new HashSet<>( Arrays.asList( FLAVOUR_VANILLA, FLAVOUR_DIRECT, FLAVOUR_QUARKUS_3, FLAVOUR_QUARKUS_3_GRADLE, FLAVOUR_QUARKUS_3_GRADLE_KTS,
5454
FLAVOUR_QUARKUS_3_PROPERTIES, FLAVOUR_QUARKUS_2, FLAVOUR_MICRONAUT_4, FLAVOUR_SPRINGBOOT_3, FLAVOUR_OPENLIBERTY ) ) );
5555

5656
public static boolean isGradleKtsFlavour(String flavour ) {
@@ -63,7 +63,7 @@ public static boolean isGradleKtsFlavour(String flavour ) {
6363
return prop;
6464
});
6565

66-
public static void initProject( FlavourContext context ) throws IOException, TemplateException {
66+
public static String initProject( FlavourContext context ) throws IOException, TemplateException {
6767
log.info( "generate flavour : {}", context.getFlavour() );
6868
String actualFlavour = MAP_FLAVOURS.getProperty( context.getFlavour(), context.getFlavour() );
6969
if ( SUPPORTED_FLAVOURS.contains( actualFlavour ) ) {
@@ -72,6 +72,7 @@ public static void initProject( FlavourContext context ) throws IOException, Tem
7272
} else {
7373
throw new ConfigRuntimeException( String.format( "flavour not supported : %s", context.getFlavour() ) );
7474
}
75+
return actualFlavour;
7576
}
7677

7778
public static void checkFlavour( FlavourContext context, String actualFlavour ) {
@@ -147,12 +148,7 @@ public static Object readField( FlavourContext context, Field field, String fiel
147148

148149
private static void initFlavour( FlavourContext context, String actualFlavour ) throws IOException, TemplateException {
149150
// copy all resources
150-
String listFilePath = String.format( "config/flavour/%s-copy.txt", actualFlavour );
151-
String baseFlavourPath = String.format( "config/flavour/%s/", actualFlavour );
152-
log.info( "loading list file {}, base flavour path {}", listFilePath, baseFlavourPath );
153-
try (BufferedReader reader = new BufferedReader( new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( listFilePath ) ) ) ) {
154-
reader.lines().forEach( s -> copyFlavourFile( s, context.getProjectFolder(), baseFlavourPath ) );
155-
}
151+
FeatureFacade.copyFlavourList( context.getProjectFolder(), actualFlavour );
156152
// freemarker resources
157153
Map<String, Object> data = new HashMap<>();
158154
data.put( "context", context );
@@ -167,31 +163,11 @@ private static void initFlavour( FlavourContext context, String actualFlavour )
167163
}
168164
}
169165

170-
private static void insureParent( File file ) throws IOException {
171-
File parentFile = file.getParentFile();
172-
if ( !parentFile.exists() ) {
173-
log.info( "creates parent directory {}, mkdirs:?", parentFile.getCanonicalPath(), parentFile.mkdirs() );
174-
}
175-
}
176-
177-
private static void copyFlavourFile( String path, File baseFolder, String basePath ) {
178-
SafeFunction.apply( () -> {
179-
File outputFile = new File( baseFolder, path );
180-
insureParent( outputFile );
181-
String fullPath = basePath+path;
182-
log.info( "copy path '{}' to file '{}'", fullPath, outputFile.getCanonicalPath() );
183-
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( fullPath );
184-
FileOutputStream os = new FileOutputStream( outputFile ) ) {
185-
StreamIO.pipeStream( is, os, StreamIO.MODE_CLOSE_NONE );
186-
}
187-
} );
188-
}
189-
190166
private static void processEntry( ProcessEntry entry, Map<String, Object> data ) {
191167
log.info( "process entry : {}", entry );
192168
SafeFunction.apply( () -> {
193169
File toFile = new File( entry.getTo() );
194-
insureParent( toFile );
170+
FeatureFacade.insureParent( toFile );
195171
FreemarkerTemplateFacade.processFile( entry.getFrom(), toFile, data );
196172
} );
197173
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.fugerit.java.doc.project.facade;
2+
3+
import org.apache.maven.model.Build;
4+
import org.apache.maven.model.Model;
5+
import org.apache.maven.model.Plugin;
6+
import org.apache.maven.model.PluginExecution;
7+
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
8+
import org.fugerit.java.core.io.helper.HelperIOException;
9+
10+
import java.io.IOException;
11+
import java.io.StringReader;
12+
import java.util.Arrays;
13+
14+
public class PluginUtils {
15+
16+
public static final String GOAL_DIRECT = "direct";
17+
18+
public static final String FJ_DOC_MAVEN_PLUGIN = "fj-doc-maven-plugin";
19+
20+
private PluginUtils() {}
21+
22+
public static Object getPluginConfiguration( String xml ) throws IOException {
23+
return HelperIOException.get( () -> {
24+
try ( StringReader sr = new StringReader( xml ) ) {
25+
return Xpp3DomBuilder.build( sr );
26+
}
27+
});
28+
}
29+
30+
public static Plugin findOrCreatePLugin( Model model ) {
31+
Plugin plugin = null;
32+
Build build = getBuild( model );
33+
for ( Plugin current : build.getPlugins() ) {
34+
if ( FJ_DOC_MAVEN_PLUGIN.equals( current.getArtifactId() ) ) {
35+
plugin = current;
36+
}
37+
}
38+
if ( plugin == null ) {
39+
plugin = new Plugin();
40+
plugin.setGroupId( VenusConsts.GROUP_ID );
41+
plugin.setArtifactId( FJ_DOC_MAVEN_PLUGIN );
42+
plugin.setVersion( "${"+VenusConsts.KEY_VERSION+"}" );
43+
build.getPlugins().add( plugin );
44+
}
45+
return plugin;
46+
}
47+
48+
public static PluginExecution createPluginExecution(String id, String phase, String... goal ) {
49+
PluginExecution execution = new PluginExecution();
50+
execution.setId( id );
51+
execution.setPhase( phase );
52+
execution.setGoals(Arrays.asList( goal ));
53+
return execution;
54+
}
55+
56+
public static Build getBuild(Model model) {
57+
Build build = model.getBuild();
58+
if ( build == null ) {
59+
build = new Build();
60+
model.setBuild( build );
61+
}
62+
return build;
63+
}
64+
65+
}

0 commit comments

Comments
 (0)