Skip to content

Commit

Permalink
New flavour : micronaut-4
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Sep 9, 2024
1 parent e5bd1ac commit f75102a
Show file tree
Hide file tree
Showing 24 changed files with 540 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [fj-doc-maven-plugin] goal add, new parameter : freemarkerVersion (default : 2.3.32)
- [fj-doc-maven-plugin] goal init, new flavour : micronaut-4
- [fj-doc-playground-quarkus] doc project init default version set to 8.8.0

## [8.8.0] - 2024-09-09
Expand Down
1 change: 1 addition & 0 deletions fj-doc-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
| 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 |
| freemarkerVersion | true | 2.3.32 | Freemarker compatibility version (max 2.3.33) |

### Add Fugerit Venus, available extensions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class MojoAdd extends AbstractMojo {
@Parameter(property = "addDependencyOnTop", defaultValue = "false", required = true)
protected boolean addDependencyOnTop;

@Parameter(property = "freemarkerVersion", defaultValue = "2.3.32", required = true)
protected String freemarkerVersion;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
String foundVersion = VersionCheck.findVersion( this.version );
Expand All @@ -60,6 +63,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
context.setAddJunit5( this.addJunit5 );
context.setAddLombok( this.addLombok );
context.setAddDependencyOnTop( this.addDependencyOnTop );
context.setFreemarkerVersion( this.freemarkerVersion );
this.getLog().info( String.format( "add execute() context : %s", context ) );
AddVenusFacade.addVenusToMavenProject( context );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
this.projectFolder = initFolder.getCanonicalPath();
FlavourContext context = new FlavourContext( new File( this.projectFolder ), this.groupId, this.artifactId, this.projectVersion, this.javaRelease, this.flavour );
context.setModules( ModuleFacade.toModuleList( this.extensions ) );
context.setAddLombok( this.addLombok );
this.getLog().info( String.format( "flavour context : %s", context ) );
FlavourFacade.initProject( context );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@ public class FlavourContext {
@Getter @Setter
private List<String> modules;

@Getter @Setter
private boolean addLombok;

private String toClassName( String base, String splitString ) {
StringBuilder buf = new StringBuilder();
String[] split = base.split( splitString );
for ( String part : split ) {
if ( part.length() > 0 ) {
buf.append( part.substring( 0, 1 ).toLowerCase()+part.substring( 1 ) );
}
}
return buf.toString();
}

public String getArtifactIdAsClassName() {
String res = toClassName( this.artifactId, "-" );
return toClassName( res, "\\." );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private FlavourFacade() {}

public static final String FLAVOUR_QUARKUS_LATEST = "quarkus-latest";

public static final Set<String> SUPPORTED_FLAVOURS = Collections.unmodifiableSet( new HashSet<>( Arrays.asList( FLAVOUR_VANILLA, FLAVOUR_QUARKUS_3, FLAVOUR_QUARKUS_2 ) ) );
public static final String FLAVOUR_MICRONAUT_4 = "micronaut-4";

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

private static final Properties MAP_FLAVOURS = SafeFunction.get( () -> {
Properties prop = new Properties();
Expand All @@ -48,8 +50,8 @@ public static void initProject( FlavourContext context ) throws IOException, Tem

public static void checkFlavour( FlavourContext context, String actualFlavour ) {
int javaVersion = Integer.parseInt( context.getJavaRelease() );
if ( FLAVOUR_QUARKUS_3.equals( actualFlavour ) && javaVersion < 17 ) {
throw new ConfigRuntimeException( "Minimum java version for quarkus 3 is 17" );
if ( ( FLAVOUR_QUARKUS_3.equals( actualFlavour ) || FLAVOUR_MICRONAUT_4.equals( actualFlavour ) ) && javaVersion < 17 ) {
throw new ConfigRuntimeException( String.format( "Minimum java version for %s is 17", actualFlavour ) );
} else if ( FLAVOUR_QUARKUS_2.equals( actualFlavour ) && javaVersion != 11 ) {
log.info( "quarkus 2 is a legacy flavour, javaRelease %s will default to '11'", javaVersion );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class VenusContext {
@Getter @Setter
private boolean addDependencyOnTop;

@Getter @Setter
private String freemarkerVersion;

public void setExcludeXmlApis( boolean excludeXmlApis ) {
if ( excludeXmlApis ) {
this.setAddExclusions( "xml-apis:xml-apis" );
Expand All @@ -80,6 +83,7 @@ public VenusContext(File projectDir, String version, String extensions ) {
this.addJunit5 = true;
this.addLombok = true;
this.addDependencyOnTop = false;
this.freemarkerVersion = FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_DEFAULT;
}

public String getGroupId() {
Expand All @@ -102,10 +106,6 @@ public String getResourcePathFmConfigXml() {
return this.getArtificatIdForFolder()+"/fm-doc-process-config.xml";
}

public String getFreemarkerVersion() {
return FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_LATEST;
}

public String getDocConfigPackage() {
return this.getGroupId()+"."+this.getArtificatIdForName();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
aot-jar.properties
aot-native-image.properties
openapi.properties
micronaut-cli.yml
src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# AOT configuration properties for jar packaging
# Please review carefully the optimizations enabled below
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details

# Caches environment property values: environment properties will be deemed immutable after application startup.
cached.environment.enabled=true

# Precomputes Micronaut configuration property keys from the current environment variables
precompute.environment.properties.enabled=true

# Replaces logback.xml with a pure Java configuration
logback.xml.to.java.enabled=true

# Converts YAML configuration files to Java configuration
yaml.to.java.config.enabled=true

# Scans for service types ahead-of-time, avoiding classpath scanning at startup
serviceloading.jit.enabled=true

# Scans reactive types at build time instead of runtime
scan.reactive.types.enabled=true

# Deduces the environment at build time instead of runtime
deduce.environment.enabled=true

# Checks of existence of some types at build time instead of runtime
known.missing.types.enabled=true

# Precomputes property sources at build time
sealed.property.source.enabled=true

# The list of service types to be scanned (comma separated)
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver

# A list of types that the AOT analyzer needs to check for existence (comma separated)
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# AOT configuration properties for native-image packaging
# Please review carefully the optimizations enabled below
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details

# Caches environment property values: environment properties will be deemed immutable after application startup.
cached.environment.enabled=true

# Precomputes Micronaut configuration property keys from the current environment variables
precompute.environment.properties.enabled=true

# Replaces logback.xml with a pure Java configuration
logback.xml.to.java.enabled=true

# Converts YAML configuration files to Java configuration
yaml.to.java.config.enabled=false

# Generates GraalVM configuration files required to load the AOT optimizations
graalvm.config.enabled=true

# Scans for service types ahead-of-time, avoiding classpath scanning at startup
serviceloading.native.enabled=false

# Scans reactive types at build time instead of runtime
scan.reactive.types.enabled=true

# Deduces the environment at build time instead of runtime
deduce.environment.enabled=true

# Checks of existence of some types at build time instead of runtime
known.missing.types.enabled=true

# Precomputes property sources at build time
sealed.property.source.enabled=true

# The list of service types to be scanned (comma separated)
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver

# A list of types that the AOT analyzer needs to check for existence (comma separated)
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
applicationType: default
defaultPackage: org.fugerit.java.demo
testFramework: junit
sourceLanguage: java
buildTool: maven
features: [app-name, graalvm, http-client-test, java, java-application, junit, logback, maven, maven-enforcer-plugin, micronaut-aot, micronaut-http-validation, netty-server, openapi, openapi-explorer, readme, serialization-jackson, shade, static-resources, yaml, yaml-build]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
swagger-ui.enabled=false
redoc.enabled=false
openapi-explorer.enabled=true
rapidoc.enabled=false
rapidoc.bg-color=#14191f
rapidoc.text-color=#aec2e0
rapidoc.sort-endpoints-by=method
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#import 'flavour-macro.ftl' as fhm>
---
flavour: micronaut-4
process:
- from: flavour/micronaut-4/pom.ftl
to: ${context.projectFolder}/pom.xml
- from: flavour/micronaut-4/README.ftl
to: ${context.projectFolder}/README.md
- from: flavour/micronaut-4/gitignore.ftl
to: ${context.projectFolder}/.gitignore
- from: flavour/micronaut-4/MicronautController.ftl
to: ${context.projectFolder}/src/main/java/<@fhm.toProjectPackageFolder context=context/>/${context.artifactIdAsClassName}Controller.java
- from: flavour/micronaut-4/DocController.ftl
to: ${context.projectFolder}/src/main/java/<@fhm.toProjectPackageFolder context=context/>/DocController.java
- from: flavour/micronaut-4/Application.ftl
to: ${context.projectFolder}/src/main/java/<@fhm.toProjectPackageFolder context=context/>/Application.java
- from: flavour/micronaut-4/MicronautTest.ftl
to: ${context.projectFolder}/src/test/java/test/<@fhm.toProjectPackageFolder context=context/>/${context.artifactIdAsClassName}Test.java
- from: flavour/micronaut-4/application_yml.ftl
to: ${context.projectFolder}/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#import '../flavour-macro.ftl' as fhm>
package <@fhm.toProjectPackage context=context/>;


import io.micronaut.runtime.Micronaut;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.info.*;

@OpenAPIDefinition(
info = @Info(
title = "${context.artifactId}",
version = "${context.projectVersion}"
)
)
public class Application {

public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<#import
'../flavour-macro.ftl' as fhm>
package <@fhm.toProjectPackage context=context/>;

import io.micronaut.http.annotation.*;

import org.fugerit.java.core.cfg.ConfigRuntimeException;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.doc.base.config.DocConfig;
import org.fugerit.java.doc.base.process.DocProcessContext;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.List;

@Slf4j
@Controller("/doc")
public class DocController {

byte[] processDocument(String handlerId) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
// creates the doc helper
DocHelper docHelper = new DocHelper();
// create custom data for the fremarker template 'document.ftl'
List<People> listPeople = Arrays.asList(new People("Luthien", "Tinuviel", "Queen"), new People("Thorin", "Oakshield", "King"));
// output generation
docHelper.getDocProcessConfig().fullProcess("document", DocProcessContext.newContext("listPeople", listPeople), handlerId, baos);
// return the output
return baos.toByteArray();
} catch (Exception e) {
log.error(String.format("Error processing %s, error:%s", handlerId, e), e);
throw new ConfigRuntimeException(e);
}
}

@Get(uri="/example.md", produces="text/markdown")
public byte[] markdownExample() {
return processDocument(DocConfig.TYPE_MD);
}

@Get(uri="/example.html", produces="text/html")
public byte[] markdownHtml() {
return processDocument(DocConfig.TYPE_HTML);
}

<#if context.modules?seq_contains("fj-doc-mod-fop")>
@Get(uri="/example.pdf", produces="application/pdf")
public byte[] pdfExample() {
return processDocument(DocConfig.TYPE_PDF);
}
</#if>

<#if context.modules?seq_contains("fj-doc-mod-poi")>
@Get(uri="/example.xlsx", produces="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
public byte[] xlsxExample() {
return processDocument(DocConfig.TYPE_XLSX);
}
</#if>

<#if context.modules?seq_contains("fj-doc-mod-opencsv")>
@Get(uri="/example.csv", produces="text/csv")
public byte[] csvExample() {
return processDocument(DocConfig.TYPE_CSV);
}
</#if>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<#import '../flavour-macro.ftl' as fhm>
package <@fhm.toProjectPackage context=context/>;

import io.micronaut.http.annotation.*;

@Controller("${context.artifactId}")
public class ${context.artifactIdAsClassName}Controller {

@Get(uri="/", produces="text/plain")
public String index() {
return "Example Response";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#import '../flavour-macro.ftl' as fhm>
package test.<@fhm.toProjectPackage context=context/>;

import io.micronaut.runtime.EmbeddedApplication;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import jakarta.inject.Inject;

@MicronautTest
class ${context.artifactIdAsClassName}Test {

@Inject
EmbeddedApplication<?> application;

@Test
void testItWorks() {
Assertions.assertTrue(application.isRunning());
}

}
Loading

0 comments on commit f75102a

Please sign in to comment.