Skip to content

405 enhancement fj doc lib direct add support to maven goal init and add #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/build_fj-doc-native-quarkus_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ on:
push:
branches:
- develop
pull_request:
types:
- opened
- synchronize
- reopened
- branch-deploy

# only allow one workflow at time on the give activation
concurrency:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- [fj-doc-maven-plugin] support add 'direct' goal to maven goal 'init' and 'add' <https://github.com/fugerit-org/fj-doc/pull/405>
- [fj-doc-playground-quarkus] project init - add verify and direct plugin options

## [8.13.5] - 2025-04-25

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
| excludeXmlApis | false | false | It will exclude dependency xml-apis:xml-apis
| addExclusions | false | | Add comma separated exclusion, for instance : xml-apis:xml-apis,${groupId}:${artificatId}
| addVerifyPlugin | true | true | If set to true, it will configure the 'verify' goal on the project
| addDirectPlugin | false | true | If set to true, it will configure the 'direct' goal on the project
| addJunit5 | true | true | If set to true, it will add junit5 (test scope) and basic test
| addLombok | true | true | If set to true, it will add lombok (provided scope) and slf4j-simple (test scope)
| addDependencyOnTop | true | false | If set to true, added dependencies will be added before existing ones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class MojoAdd extends AbstractMojo {
@Parameter(property = "addVerifyPlugin", defaultValue = "true", required = true)
protected boolean addVerifyPlugin;

@Parameter(property = "addDirectPlugin", defaultValue = "false", required = true)
protected boolean addDirectPlugin;

@Parameter(property = "addJunit5", defaultValue = "true", required = true)
protected boolean addJunit5;

Expand Down Expand Up @@ -67,6 +70,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
context.setAddExclusions( addExclusions );
context.setExcludeXmlApis( this.excludeXmlApis );
context.setAddVerifyPlugin( this.addVerifyPlugin );
context.setAddDirectPlugin( this.addDirectPlugin );
context.setAddJunit5( this.addJunit5 );
context.setAddLombok( this.addLombok );
context.setAddDependencyOnTop( this.addDependencyOnTop );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
context.setVersion( VersionCheck.findVersion( this.version ) );
context.setExtensions( this.extensions );
this.getLog().info( String.format( "flavour context : %s", context ) );
FlavourFacade.initProject( context );
String actualVersion = FlavourFacade.initProject( context );
if ( FlavourFacade.FLAVOUR_DIRECT.equals( actualVersion ) ) {
super.addDirectPlugin = true;
}
} );
super.groupIdOverride = this.groupId;
super.artifactIdOverride = this.artifactId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.maven.model.*;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.io.FileIO;
import org.fugerit.java.core.io.helper.HelperIOException;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.maxxq.maven.dependency.ModelIO;

Expand All @@ -21,9 +19,9 @@ public class BasicVenusFacade {

protected BasicVenusFacade() {}

protected static final String GROUP_ID = "org.fugerit.java";
protected static final String GROUP_ID = VenusConsts.GROUP_ID;

protected static final String KEY_VERSION = "fj-doc-version";
protected static final String KEY_VERSION = VenusConsts.KEY_VERSION;

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

private static void addPlugin( VenusContext context, Model model ) throws IOException {
private static void addDirectPlugin(VenusContext context, Model model ) throws IOException {
// addDirectPlugin?
if ( context.isAddDirectPlugin() ) {
if (context.isDirectPluginNotAvailable()) {
log.warn("addDirectPlugin skipped, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_DIRECT_PLUGIN);
} else {
FeatureFacade.copyFeatureList( context.getProjectDir(), "direct" );
log.info("addDirectPlugin true, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_DIRECT_PLUGIN);
Plugin plugin = PluginUtils.findOrCreatePLugin( model );
PluginExecution execution = PluginUtils.createPluginExecution(
"venus-direct", LifecyclePhase.COMPILE.id(), PluginUtils.GOAL_DIRECT );
plugin.getExecutions().add( execution );
String xml = "<configuration>\n" +
" <configPath>${project.basedir}/src/main/resources/venus-direct-config/venus-direct-config.yaml</configPath>\n" +
" <outputAll>true</outputAll>\n" +
" <directEnv>\n" +
" <projectBasedir>${project.basedir}</projectBasedir>\n" +
" </directEnv>\n" +
"</configuration>";
execution.setConfiguration( PluginUtils.getPluginConfiguration( xml ) );
}
} else {
log.info( "addDirectPlugin : false" );
}
}

private static void addVerifyPlugin(VenusContext context, Model model ) throws IOException {
// addVerifyPlugin?
if ( context.isAddVerifyPlugin() ) {
if ( context.isVerifyPluginNotAvailable() ) {
log.warn( "addVerifyPlugin skipped, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_VERIFY_PLUGIN );
} else {
log.info( "addVerifyPlugin true, version {} has been selected, minimum required version is : {}", context.getVersion(), VenusContext.VERSION_NA_VERIFY_PLUGIN );
Build build = model.getBuild();
if ( build == null ) {
build = new Build();
model.setBuild( build );
}
List<Plugin> plugins = model.getBuild().getPlugins();
Plugin plugin = new Plugin();
plugin.setGroupId( GROUP_ID );
plugin.setArtifactId( "fj-doc-maven-plugin" );
plugin.setVersion( "${"+KEY_VERSION+"}" );
PluginExecution execution = new PluginExecution();
execution.setId( "freemarker-verify" );
execution.setPhase( "compile" );
execution.addGoal( "verify" );
Plugin plugin = PluginUtils.findOrCreatePLugin( model );
PluginExecution execution = PluginUtils.createPluginExecution(
"freemarker-verify", LifecyclePhase.COMPILE.id(), LifecyclePhase.VERIFY.id() );
plugin.getExecutions().add( execution );
String xml = "<configuration>\n" +
" <templateBasePath>${project.basedir}/src/main/resources/"+context.getArtificatIdForFolder()+"/template</templateBasePath>\n" +
" <generateReport>true</generateReport>\n" +
" <failOnErrors>true</failOnErrors>\n" +
" <reportOutputFolder>${project.build.directory}/freemarker-syntax-verify-report</reportOutputFolder>\n" +
" </configuration>";
HelperIOException.apply( () -> {
try ( StringReader sr = new StringReader( xml ) ) {
Xpp3Dom dom = Xpp3DomBuilder.build( sr );
plugin.setConfiguration( dom );
}
});
plugins.add( plugin );
execution.setConfiguration( PluginUtils.getPluginConfiguration( xml ) );
}
} else {
log.info( "addVerifyPlugin : false" );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.fugerit.java.doc.project.facade;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.io.StreamIO;
import org.fugerit.java.core.lang.helpers.ClassHelper;

import java.io.*;

@Slf4j
public class FeatureFacade {

private FeatureFacade() {}

public static void copyFlavourList( File baseFolder, String actualFlavour ) throws IOException {
copyResourcesList( baseFolder, "flavour", actualFlavour );
}

public static void copyFeatureList( File baseFolder, String featureId ) throws IOException {
copyResourcesList( baseFolder, "feature", featureId );
}

private static void copyResourcesList( File baseFolder, String mode, String id ) throws IOException {
// copy all resources
String listFilePath = String.format( "config/%s/%s-copy.txt", mode, id );
String baseFlavourPath = String.format( "config/%s/%s/", mode, id );
log.info( "loading list file {}, base flavour path {}", listFilePath, baseFlavourPath );
try (BufferedReader reader = new BufferedReader( new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( listFilePath ) ) ) ) {
reader.lines().forEach( s -> copyFile( s, baseFolder, baseFlavourPath ) );
}
}

protected static void insureParent( File file ) throws IOException {
File parentFile = file.getParentFile();
if ( !parentFile.exists() ) {
log.info( "creates parent directory {}, mkdirs:?", parentFile.getCanonicalPath(), parentFile.mkdirs() );
}
}

protected static void copyFile(String path, File baseFolder, String basePath ) {
SafeFunction.apply( () -> {
File outputFile = new File( baseFolder, path );
insureParent( outputFile );
String fullPath = basePath+path;
log.info( "copy path '{}' to file '{}'", fullPath, outputFile.getCanonicalPath() );
try (InputStream is = ClassHelper.loadFromDefaultClassLoader( fullPath );
FileOutputStream os = new FileOutputStream( outputFile ) ) {
StreamIO.pipeStream( is, os, StreamIO.MODE_CLOSE_NONE );
}
} );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.io.StreamIO;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.lang.helpers.reflect.MethodHelper;
Expand All @@ -19,7 +18,6 @@

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;

@Slf4j
Expand All @@ -29,6 +27,8 @@ private FlavourFacade() {}

public static final String FLAVOUR_VANILLA = "vanilla";

public static final String FLAVOUR_DIRECT = "direct";

public static final String FLAVOUR_QUARKUS_3 = "quarkus-3";

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

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

public static boolean isGradleKtsFlavour(String flavour ) {
Expand All @@ -63,7 +63,7 @@ public static boolean isGradleKtsFlavour(String flavour ) {
return prop;
});

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

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

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

private static void insureParent( File file ) throws IOException {
File parentFile = file.getParentFile();
if ( !parentFile.exists() ) {
log.info( "creates parent directory {}, mkdirs:?", parentFile.getCanonicalPath(), parentFile.mkdirs() );
}
}

private static void copyFlavourFile( String path, File baseFolder, String basePath ) {
SafeFunction.apply( () -> {
File outputFile = new File( baseFolder, path );
insureParent( outputFile );
String fullPath = basePath+path;
log.info( "copy path '{}' to file '{}'", fullPath, outputFile.getCanonicalPath() );
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( fullPath );
FileOutputStream os = new FileOutputStream( outputFile ) ) {
StreamIO.pipeStream( is, os, StreamIO.MODE_CLOSE_NONE );
}
} );
}

private static void processEntry( ProcessEntry entry, Map<String, Object> data ) {
log.info( "process entry : {}", entry );
SafeFunction.apply( () -> {
File toFile = new File( entry.getTo() );
insureParent( toFile );
FeatureFacade.insureParent( toFile );
FreemarkerTemplateFacade.processFile( entry.getFrom(), toFile, data );
} );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.fugerit.java.doc.project.facade;

import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.fugerit.java.core.io.helper.HelperIOException;

import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;

public class PluginUtils {

public static final String GOAL_DIRECT = "direct";

public static final String FJ_DOC_MAVEN_PLUGIN = "fj-doc-maven-plugin";

private PluginUtils() {}

public static Object getPluginConfiguration( String xml ) throws IOException {
return HelperIOException.get( () -> {
try ( StringReader sr = new StringReader( xml ) ) {
return Xpp3DomBuilder.build( sr );
}
});
}

public static Plugin findOrCreatePLugin( Model model ) {
Plugin plugin = null;
Build build = getBuild( model );
for ( Plugin current : build.getPlugins() ) {
if ( FJ_DOC_MAVEN_PLUGIN.equals( current.getArtifactId() ) ) {
plugin = current;
}
}
if ( plugin == null ) {
plugin = new Plugin();
plugin.setGroupId( VenusConsts.GROUP_ID );
plugin.setArtifactId( FJ_DOC_MAVEN_PLUGIN );
plugin.setVersion( "${"+VenusConsts.KEY_VERSION+"}" );
build.getPlugins().add( plugin );
}
return plugin;
}

public static PluginExecution createPluginExecution(String id, String phase, String... goal ) {
PluginExecution execution = new PluginExecution();
execution.setId( id );
execution.setPhase( phase );
execution.setGoals(Arrays.asList( goal ));
return execution;
}

public static Build getBuild(Model model) {
Build build = model.getBuild();
if ( build == null ) {
build = new Build();
model.setBuild( build );
}
return build;
}

}
Loading