From afcf3bfaf38c45276eccab16484fe6a0d89419b7 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Tue, 20 Aug 2024 00:43:57 +0200 Subject: [PATCH] Added fj-doc-maven-plugin --- CHANGELOG.md | 4 + README.md | 14 ++ .../fj_doc_test/freemarker-doc-process.xml | 2 + fj-doc-maven-plugin/README.md | 52 +++++++ fj-doc-maven-plugin/pom.xml | 112 +++++++++++++++ .../org/fugerit/java/doc/maven/MojoAdd.java | 36 +++++ .../doc/project/facade/AddVenusFacade.java | 132 ++++++++++++++++++ .../doc/project/facade/BasicVenusFacade.java | 93 ++++++++++++ .../java/doc/project/facade/VenusContext.java | 75 ++++++++++ .../config/example/DocHelperExample.java | 54 +++++++ .../resources/config/example/document.ftl | 59 ++++++++ .../resources/config/example/fop-config.xml | 31 ++++ .../fm-doc-process-config-template.ftl | 67 +++++++++ .../project/facade/TestAddVenusFacade.java | 83 +++++++++++ .../src/test/resources/log4j2.xml | 13 ++ .../src/test/resources/ok1-pom/pom.xml | 26 ++++ .../src/test/resources/ok2-pom/pom.xml | 49 +++++++ .../src/test/resources/ok3-pom/pom.xml | 49 +++++++ pom.xml | 1 + 19 files changed, 952 insertions(+) create mode 100644 fj-doc-maven-plugin/README.md create mode 100644 fj-doc-maven-plugin/pom.xml create mode 100644 fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoAdd.java create mode 100644 fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java create mode 100644 fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java create mode 100644 fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusContext.java create mode 100644 fj-doc-maven-plugin/src/main/resources/config/example/DocHelperExample.java create mode 100644 fj-doc-maven-plugin/src/main/resources/config/example/document.ftl create mode 100644 fj-doc-maven-plugin/src/main/resources/config/example/fop-config.xml create mode 100644 fj-doc-maven-plugin/src/main/resources/config/template/fm-doc-process-config-template.ftl create mode 100644 fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestAddVenusFacade.java create mode 100644 fj-doc-maven-plugin/src/test/resources/log4j2.xml create mode 100644 fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml create mode 100644 fj-doc-maven-plugin/src/test/resources/ok2-pom/pom.xml create mode 100644 fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d5ce8249..67e794507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- fj-doc-maven-plugin (configure a maven project for Fugerit Venus Doc usage) + ## [8.5.2] - 2024-08-14 ### Changed diff --git a/README.md b/README.md index 26f9da9c2..be404bf3d 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ A quick start is available in module [fj-doc-sample](fj-doc-sample/README.md) There are five kinds of components (each components README.md contains module status) : ### 1. Framework core : + * [Core library (fj-doc-base)](fj-doc-base/README.md) (contains a simple renderer for [Markdown BASIC](fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehandler/markdown/SimpleMarkdownBasicTypeHandler.java) and [Markdown EXT](fj-doc-base/src/main/java/org/fugerit/java/doc/base/typehandler/markdown/SimpleMarkdownExtTypeHandler.java)) * [Json extension (fj-doc-base-json)](fj-doc-base-json/README.md) (allow for using json as document generator instead of standard xml generator) [since 0.7.0] * [Yaml extension (fj-doc-base-yaml)](fj-doc-base-yaml/README.md) (allow for using yaml as document generator instead of standard xml generator) [since 0.7.0] @@ -134,10 +135,23 @@ You can find in them in a dedicated repository [fj-doc-ext](https://gitlab.com/f * [Java EE extension (fj-doc-ent)](https://github.com/fugerit-org/fj-doc-ent.git) (deprecated as not the module fj-mod-freemarker provided mostly the same features, but in a standalone mode) (deprecated since version 0.5.0) ### 9. GraalVM native support + Beginning with version 1.4.0-rc.001, *GraalVM* metadata started to be added (*reflect-config.json* and *resources-config.json*). Initially only the *fj-doc-base* and *fj-doc-freemarker* have full support. Actual support for other module will be added as soon as possible, but sometimes is dependent on underlying dependencies support (for example *Apache FOP* for *fj-doc-mod-fop*). It is possible to check the current status on the module documentation, in the section *native support* +### 10. Maven Plugin + +A [maven plugin](fj-doc-maven-plugin/README.md) is also available. It allows to configure a maven project for document generation, it is as simple as : + +```shell +mvn org.fugerit.java:fj-doc-maven-plugin:add \ +-Dextensions=base,freemarker,mod-fop \ +-Dversion=8.5.3 +``` + +See [Documentation](fj-doc-maven-plugin/README.md) for further details. + *About javadoc* Javadoc are far from being complete, but you can find latest version at [https://www.fugerit.org](https://www.fugerit.org/data/java/javadoc/) Note that, being an open source project hosted on maven central, you can find release javadoc on [javadoc.io](https://javadoc.io/doc/org.fugerit.java/fj-doc-base/) diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml b/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml index d84bb419b..87244fcad 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/freemarker-doc-process.xml @@ -4,6 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://freemarkerdocprocess.fugerit.org https://www.fugerit.org/data/java/doc/xsd/freemarker-doc-process-1-0.xsd" > + + + 4.0.0 + + fj-doc-maven-plugin + + + org.fugerit.java + fj-doc + 8.5.3-SNAPSHOT + + + maven-plugin + + fj-doc-maven-plugin + + Maven plugin to add Fugerit Venus Doc to a mavne project (fj-doc:generate) + + + 3.12.1 + 3.6.0 + + 3.13.1 + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${mvn-plugin-version} + + + org.apache.maven.plugins + maven-site-plugin + ${mvn-site-plugin-version} + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${mvn-project-info-reports-plugin} + + + + + + + + + + org.apache.maven + maven-plugin-api + provided + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + + + + org.fugerit.java + fj-core + + + + org.fugerit.java + fj-doc-freemarker + + + + org.maxxq.maven + maxxq-maven + 1.3.0 + + + + + + https://www.fugerit.org + Fugerit + + + https://www.fugerit.org/perm/venus + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + + report + + + + + + + + diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoAdd.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoAdd.java new file mode 100644 index 000000000..ad7c75320 --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoAdd.java @@ -0,0 +1,36 @@ +package org.fugerit.java.doc.maven; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.fugerit.java.doc.project.facade.AddVenusFacade; +import org.fugerit.java.doc.project.facade.VenusContext; + +import java.io.File; + +@Mojo( name = "add" ) +public class MojoAdd extends AbstractMojo { + + @Parameter(property = "version", defaultValue = "8.5.2", required = true) + protected String version; + + @Parameter(property = "extensions", defaultValue = "base,freemarker", required = true) + protected String extensions; + + @Parameter(property = "projectFolder", defaultValue = ".", required = true) + protected String projectFolder; + + @Parameter(property = "addDocFacade", defaultValue = "true", required = true) + protected boolean addDocFacade; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + VenusContext context = new VenusContext( new File( this.projectFolder ), this.version ,this.extensions ); + context.setAddDocFacace( this.addDocFacade ); + this.getLog().info( String.format( "add execute() context : %s", context ) ); + AddVenusFacade.addVenusToMavenProject( context ); + } + +} diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java new file mode 100644 index 000000000..c230076bd --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/AddVenusFacade.java @@ -0,0 +1,132 @@ +package org.fugerit.java.doc.project.facade; + +import freemarker.cache.ClassTemplateLoader; +import freemarker.cache.StringTemplateLoader; +import freemarker.template.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Model; +import org.fugerit.java.core.cfg.ConfigException; +import org.fugerit.java.core.function.SafeFunction; +import org.fugerit.java.core.io.FileIO; +import org.fugerit.java.core.io.StreamIO; +import org.fugerit.java.core.javagen.JavaGenerator; +import org.fugerit.java.core.javagen.SimpleJavaGenerator; +import org.fugerit.java.core.lang.helpers.ClassHelper; +import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep; +import org.fugerit.java.doc.freemarker.fun.SimpleMessageFun; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig; +import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade; +import org.maxxq.maven.dependency.ModelIO; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +public class AddVenusFacade extends BasicVenusFacade { + + private AddVenusFacade() {} + + private static final String EXAMPLE_FOLDER = "config/example/"; + + private static void addDocFacade( VenusContext context ) throws IOException, TemplateException, ConfigException { + // freemarker configuration + Configuration configuration = new Configuration( new Version( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_LATEST ) ); + configuration.clearTemplateCache(); + ClassTemplateLoader loader = new ClassTemplateLoader( AddVenusFacade.class, "/config/template/" ); + configuration.setTemplateExceptionHandler( TemplateExceptionHandler.RETHROW_HANDLER ); + configuration.setTemplateLoader( loader ); + configuration.setDefaultEncoding(StandardCharsets.UTF_8.name()); + // config generation + Template fmConfigTemplate = configuration.getTemplate( "fm-doc-process-config-template.ftl" ); + Map data = new HashMap<>(); + data.put( "context" , context ); + File fmConfigFile = new File( context.getProjectDir(), "src/main/resources/"+context.getResourcePathFmConfigXml() ); + log.info( "fmConfigFile : {}, mk parent? : {}", fmConfigFile.getCanonicalPath(), fmConfigFile.getParentFile().mkdirs() ); + File templateDir = new File( fmConfigFile.getParentFile(), context.getTemplateSubPath() ); + log.info( "templateDir : {}, mk parent? : {}", templateDir.getCanonicalPath(), templateDir.mkdirs() ); + try ( Writer writer = new FileWriter( fmConfigFile ) ) { + fmConfigTemplate.process( data, writer ); + } + configuration.clearTemplateCache(); + // copy sample template + String fileName = "document.ftl"; + File documentExample = new File( templateDir, fileName ); + try ( InputStream documentExampleIS = ClassHelper.loadFromDefaultClassLoader( EXAMPLE_FOLDER+fileName ) ) { + String documentContent = StreamIO.readString( documentExampleIS ); + FileIO.writeString( documentContent, documentExample ); + } + // create doc config + File sourceFolder = new File( context.getProjectDir(), "src/main/java" ); + log.info( "sourceFolder : {}, mk parent? : {}", sourceFolder.getCanonicalPath(), sourceFolder.mkdirs() ); + File resourceFolder = new File( context.getProjectDir(), "src/main/resources" ); + log.info( "resourceFolder : {}, mk parent? : {}", resourceFolder.getCanonicalPath(), resourceFolder.mkdirs() ); + DocConfigGenerator javaGenerator = new DocConfigGenerator( context ); + Properties generatorProps = new Properties(); + javaGenerator.init( sourceFolder, context.getDocConfigPackage()+"."+context.getDocConfigClass(), SimpleJavaGenerator.STYLE_CLASS, generatorProps); + javaGenerator.generate(); + javaGenerator.write(); + // create examples + String docExampleFileName = "DocHelperExample.java"; + try ( InputStream documentExampleIS = ClassHelper.loadFromDefaultClassLoader( EXAMPLE_FOLDER+docExampleFileName ) ) { + String documentContent = StreamIO.readString( documentExampleIS ).replace( "[PACKAGE]", context.getDocConfigPackage() ); + File docExampleFile = new File( new File( sourceFolder, context.getDocConfigPackage().replace( '.', '/' ) ), docExampleFileName ); + FileIO.writeString( documentContent, docExampleFile ); + } + if ( context.getModules().contains( "fj-doc-mod-fop" ) ) { + String fopConfigName = "fop-config.xml"; + File fopConfig = new File( new File( resourceFolder, context.getArtificatIdForFolder() ), fopConfigName ); + try ( InputStream fopConfigExampleIS = ClassHelper.loadFromDefaultClassLoader( EXAMPLE_FOLDER+fopConfigName ) ) { + String fopConfigContent = StreamIO.readString( fopConfigExampleIS ); + FileIO.writeString( fopConfigContent, fopConfig ); + } + } + } + + public static boolean addVenusToMavenProject( VenusContext context ) { + return SafeFunction.get( () -> { + File pomFile = new File( context.getProjectDir(), "pom.xml" ); + log.info( "project dir : {}", context.getProjectDir().getCanonicalPath() ); + if ( pomFile.exists() ) { + addExtensionList( pomFile, context ); + if ( context.isAddDocFacace() ) { + addDocFacade( context ); + } + } else { + addErrorAndLog( String.format( "No pom file in project dir : %s", pomFile.getCanonicalPath() ), context ); + return false; + } + return true; + } ); + } + +} + +class DocConfigGenerator extends SimpleJavaGenerator { + + private VenusContext context; + + public DocConfigGenerator(VenusContext context) { + this.context = context; + } + + @Override + public void init(File sourceFolder, String fullObjectBName, String javaStyle, Properties config) throws ConfigException { + super.init(sourceFolder, fullObjectBName, javaStyle, config); + this.setNoCustomComment( true ); + this.getImportList().add( FreemarkerDocProcessConfig.class.getName() ); + this.getImportList().add( FreemarkerDocProcessConfigFacade.class.getName() ); + } + + @Override + public void generateBody() throws IOException { + this.println( " private FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade.loadConfigSafe( \"cl://"+this.context.getResourcePathFmConfigXml()+"\" );" ); + this.println(); + this.println( " public FreemarkerDocProcessConfig getDocProcessConfig() { return this.docProcessConfig; }" ); + this.println(); + } + +} \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java new file mode 100644 index 000000000..91f934046 --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java @@ -0,0 +1,93 @@ +package org.fugerit.java.doc.project.facade; + +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Model; +import org.maxxq.maven.dependency.ModelIO; + +import java.io.*; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; + +@Slf4j +public class BasicVenusFacade { + + protected BasicVenusFacade() {} + + protected static final String MODULE_PREFIX = "fj-doc-"; + + protected static final String GROUP_ID = "org.fugerit.java"; + + protected static final String KEY_VERSION = "fj-doc-version"; + + private static void addOrOverwrite( List deps, Dependency d ) { + Iterator it = deps.iterator(); + while ( it.hasNext() ) { + Dependency dep = it.next(); + if ( ( dep.getGroupId()+":"+dep.getArtifactId() ).equals( d.getGroupId()+":"+d.getArtifactId() ) ) { + it.remove(); + } + } + deps.add( d ); + } + + private static void addCurrentModule(String currentModule, List dependencies) { + Dependency d = new Dependency(); + d.setArtifactId( currentModule ); + d.setGroupId( GROUP_ID ); + addOrOverwrite( dependencies, d ); + } + + private static Model readModel(ModelIO modelIO, File pomFile ) throws IOException { + try (InputStream pomStream = new FileInputStream( pomFile ) ) { + return modelIO.getModelFromInputStream( pomStream ); + } + } + + protected static void addErrorAndLog( String message, VenusContext context ) { + log.warn( message ); + context.getErrors().add( message ); + } + + protected static void addExtensionList( File pomFile, VenusContext context ) throws IOException { + String[] extensionList = context.getExtensions().split( "," ); + ModelIO modelIO = new ModelIO(); + Model model = readModel( modelIO, pomFile ); + // add pom data + context.setMavenModel( model ); + if ( model.getDependencyManagement() == null ) { + model.setDependencyManagement( new DependencyManagement() ); + } + DependencyManagement dm = model.getDependencyManagement(); + Properties props = model.getProperties(); + props.setProperty( KEY_VERSION, context.getVersion() ); + Dependency fjDocBom = new Dependency(); + fjDocBom.setArtifactId( "fj-doc" ); + fjDocBom.setGroupId( GROUP_ID ); + fjDocBom.setVersion( "${"+KEY_VERSION+"}" ); + fjDocBom.setType( "pom" ); + fjDocBom.setScope( "import" ); + addOrOverwrite( dm.getDependencies(), fjDocBom ); + log.info( "start dependencies size : {}, version : {}", model.getDependencies().size(), context.getVersion() ); + for ( String currentModule : Arrays.asList( extensionList ).stream().map(e -> { + if ( e.startsWith( MODULE_PREFIX ) ) { + return e; + } else { + return MODULE_PREFIX + e; + } + } ).collect(Collectors.toList()) ) { + log.info( "Adding module : {}", currentModule ); + addCurrentModule( currentModule, model.getDependencies() ); + context.getModules().add( currentModule ); + } + log.info( "end dependencies size : {}", model.getDependencies().size() ); + try (OutputStream pomStream = new FileOutputStream( pomFile ) ) { + modelIO.writeModelToStream( model, pomStream ); + } + } + +} diff --git a/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusContext.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusContext.java new file mode 100644 index 000000000..6c57ffa5f --- /dev/null +++ b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusContext.java @@ -0,0 +1,75 @@ +package org.fugerit.java.doc.project.facade; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.maven.model.Model; +import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@ToString +public class VenusContext { + + @Getter + private File projectDir; + + @Getter + private String extensions; + + @Getter + private String version; + + @Getter @Setter + private boolean addDocFacace; + + @Getter + private List errors; + + @Getter + private Set modules; + + @Getter @Setter + private Model mavenModel; + + public VenusContext(File projectDir, String version, String extensions ) { + this.projectDir = projectDir; + this.version = version; + this.extensions = extensions; + this.errors = new ArrayList<>(); + this.modules = new HashSet<>(); + } + + public String getArtificatIdForFolder() { + return this.getMavenModel().getArtifactId().toLowerCase(); + } + + public String getArtificatIdForName() { + return this.getArtificatIdForFolder().replace( "-", "" ).toLowerCase(); + } + + 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.getMavenModel().getGroupId()+"."+this.getArtificatIdForName(); + } + + public String getTemplateSubPath() { + return "template"; + } + + public String getDocConfigClass() { + return "DocHelper"; + } + +} diff --git a/fj-doc-maven-plugin/src/main/resources/config/example/DocHelperExample.java b/fj-doc-maven-plugin/src/main/resources/config/example/DocHelperExample.java new file mode 100644 index 000000000..ce69519ca --- /dev/null +++ b/fj-doc-maven-plugin/src/main/resources/config/example/DocHelperExample.java @@ -0,0 +1,54 @@ +package [PACKAGE]; + +import org.fugerit.java.doc.base.config.DocConfig; +import org.fugerit.java.doc.base.config.DocOutput; +import org.fugerit.java.doc.base.config.DocTypeHandler; +import org.fugerit.java.doc.base.process.DocProcessContext; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; + +public class DocHelperExample { + + public static void main(String[] args) { + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { + DocHelper docHelper = new DocHelper(); + DocTypeHandler docTypeHandler = docHelper.getDocProcessConfig().getFacade().findHandler(DocConfig.TYPE_MD); + List listPeople = Arrays.asList( new DocHelperExample.People( "Luthien", "Tinuviel", "Queen" ), new DocHelperExample.People( "Thorin", "Oakshield", "King" ) ); + docHelper.getDocProcessConfig().fullProcess( "document", DocProcessContext.newContext( "listPeople", listPeople ), docTypeHandler, DocOutput.newOutput( baos ) ); + System.out.println( "html output : \n"+ new String( baos.toByteArray(), StandardCharsets.UTF_8 ) ); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static class People { + + private String name; + + private String surname; + + private String title; + + public People(String name, String surname, String title) { + this.name = name; + this.surname = surname; + this.title = title; + } + + public String getName() { + return name; + } + + public String getSurname() { + return surname; + } + + public String getTitle() { + return title; + } + } + +} diff --git a/fj-doc-maven-plugin/src/main/resources/config/example/document.ftl b/fj-doc-maven-plugin/src/main/resources/config/example/document.ftl new file mode 100644 index 000000000..7d6bff4d9 --- /dev/null +++ b/fj-doc-maven-plugin/src/main/resources/config/example/document.ftl @@ -0,0 +1,59 @@ + + + + <#-- + This is a Venus Fugerit Doc (https://github.com/fugerit-org/fj-doc) FreeMarker Template XML (ftl[x]). + For consideration of Venus Fugerit Doc and Apache FreeMarker integration see : + https://venusguides.fugerit.org/src/docs/common/doc_format_freemarker.html + The result will be a : + --> + + + <#assign defaultTitle="My sample title"> + + + + 10;10;10;30 + + ${docTitle!defaultTitle} + fj doc venus sample source FreeMarker Template XML - ftlx + fugerit79 + en + + TitilliumWeb + + data-table=print + + data-table + + ${r"${currentPage}"} / ${r"${pageCount}"} + + + + ${docTitle!defaultTitle} + + + Name + Surname + Title + + <#if listPeople??> + <#list listPeople as current> + + ${current.name} + ${current.surname} + ${current.title} + + + +
+ + +
\ No newline at end of file diff --git a/fj-doc-maven-plugin/src/main/resources/config/example/fop-config.xml b/fj-doc-maven-plugin/src/main/resources/config/example/fop-config.xml new file mode 100644 index 000000000..2c48ed65b --- /dev/null +++ b/fj-doc-maven-plugin/src/main/resources/config/example/fop-config.xml @@ -0,0 +1,31 @@ + + + + true + + + true + + + . + + + . + + + + 1.4 + + + + + + 72 + + 72 + + + + + \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/main/resources/config/template/fm-doc-process-config-template.ftl b/fj-doc-maven-plugin/src/main/resources/config/template/fm-doc-process-config-template.ftl new file mode 100644 index 000000000..7ffd3a49b --- /dev/null +++ b/fj-doc-maven-plugin/src/main/resources/config/template/fm-doc-process-config-template.ftl @@ -0,0 +1,67 @@ + + + + <#-- configuration version 001 --> + + + + + + + + + + + + <#if context.modules?seq_contains("fj-doc-mod-fop")> + + + + + + + + <#if context.modules?seq_contains("fj-doc-mod-poi")> + + + + + + <#if context.modules?seq_contains("fj-doc-mod-opencsv")> + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestAddVenusFacade.java b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestAddVenusFacade.java new file mode 100644 index 000000000..b5319bdf2 --- /dev/null +++ b/fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestAddVenusFacade.java @@ -0,0 +1,83 @@ +package test.org.fugerit.java.doc.project.facade; + +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.fugerit.java.core.io.FileIO; +import org.fugerit.java.doc.maven.MojoAdd; +import org.fugerit.java.doc.project.facade.BasicVenusFacade; +import org.fugerit.java.doc.project.facade.VenusContext; +import org.fugerit.java.doc.project.facade.AddVenusFacade; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.UUID; + +@Slf4j +public class TestAddVenusFacade { + + private String getVersion() { + return "8.5.2"; + } + + private File initConfigWorker(String configId ) throws IOException { + File outputFolder = new File( "target", configId+"_"+UUID.randomUUID().toString() ); + outputFolder.mkdir(); + File pomFile = new File( outputFolder, "pom.xml" ); + FileIO.writeString( FileIO.readString( new File( "src/test/resources/"+configId+"/pom.xml" ) ), pomFile ); + return outputFolder; + } + + @Test + public void testAddVenus() throws IOException { + int count = 0; + for ( String currentConfig : Arrays.asList( "ok1-pom", "ok2-pom" ) ) { + File projectDir = this.initConfigWorker( currentConfig ); + log.info( "projectDir: {}, exists:{}", projectDir, projectDir.exists() ); + Assert.assertTrue( projectDir.exists() ); + String moduleList = "fj-doc-base,base-json,mod-fop,mod-opencsv,mod-poi"; + if ( count == 0 ) { + moduleList = "base,freemarker"; + } + VenusContext context = new VenusContext( projectDir, this.getVersion(), moduleList ); + boolean result = AddVenusFacade.addVenusToMavenProject( context ); + Assert.assertTrue( result ); + count++; + } + } + + @Test + public void testMojoAdd() throws IOException, MojoExecutionException, MojoFailureException { + for ( String currentConfig : Arrays.asList( "ok3-pom" ) ) { + File projectDir = this.initConfigWorker( currentConfig ); + MojoAdd mojoAdd = new MojoAdd() { + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + this.version = getVersion(); + this.extensions = "fj-doc-base,fj-doc-base-json,fj-doc-base-yaml,fj-doc-freemarker,fj-doc-mod-fop,fj-doc-mod-poi,fj-doc-mod-opencsv"; + this.projectFolder = projectDir.getAbsolutePath(); + this.addDocFacade = true; + super.execute(); + } + }; + mojoAdd.execute(); + Assert.assertTrue( projectDir.exists() ); + } + } + + @Test + public void testFail() { + VenusContext context = new VenusContext( new File( "target" ), this.getVersion(),"base" ); + boolean result = AddVenusFacade.addVenusToMavenProject( context ); + Assert.assertFalse( result ); + } + + @Test + public void testAdditional() { + Assert.assertNotNull( new BasicVenusFacade() {} ); + } + +} diff --git a/fj-doc-maven-plugin/src/test/resources/log4j2.xml b/fj-doc-maven-plugin/src/test/resources/log4j2.xml new file mode 100644 index 000000000..51b9129fc --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml b/fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml new file mode 100644 index 000000000..25012ebfc --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + fjdocmavenpluginok1 + org.fugerit.java.test + 1.0.0-SNAPSHOT + + Fugerit Doc Maven Plugin Ok POM Test 1 + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + https://www.fugerit.org + Fugerit + + + https://www.fugerit.org/ + + diff --git a/fj-doc-maven-plugin/src/test/resources/ok2-pom/pom.xml b/fj-doc-maven-plugin/src/test/resources/ok2-pom/pom.xml new file mode 100644 index 000000000..26609d4ee --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/ok2-pom/pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + + fjdocmavenpluginok2 + org.fugerit.java.test + 1.0.0-SNAPSHOT + + Fugerit Doc Maven Plugin Ok POM Test 2 + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + https://www.fugerit.org + Fugerit + + + https://www.fugerit.org/ + + + + + org.fugerit.java + fj-doc + ${fj-doc-version} + pom + import + + + + + + + org.fugerit.java + fj-core + + + org.fugerit.java + fj-doc-base + + + + diff --git a/fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml b/fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml new file mode 100644 index 000000000..7ff1e5b54 --- /dev/null +++ b/fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + + fjdocmavenpluginok3 + org.fugerit.java.test + 1.0.0-SNAPSHOT + + Fugerit Doc Maven Plugin Ok POM Test 3 + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + https://www.fugerit.org + Fugerit + + + https://www.fugerit.org/ + + + + + org.fugerit.java + fj-doc + ${fj-doc-version} + pom + import + + + + + + + org.fugerit.java + fj-core + + + org.fugerit.java + fj-doc-base + + + + diff --git a/pom.xml b/pom.xml index 2fd27a605..e6d3810e4 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,7 @@ fj-doc-tool fj-doc-sample fj-doc-playground-quarkus + fj-doc-maven-plugin