From 4b9067e53d3d0c6db32e58d4cea1b2f906bbbc26 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Sun, 25 Aug 2024 15:22:49 +0200 Subject: [PATCH] new param 'addVerifyPlugin' (default 'true') of 'add' plugin --- CHANGELOG.md | 4 ++ fj-doc-maven-plugin/README.md | 27 ++++++----- .../org/fugerit/java/doc/maven/MojoAdd.java | 4 ++ .../doc/project/facade/BasicVenusFacade.java | 47 +++++++++++++++++-- .../java/doc/project/facade/VenusContext.java | 3 ++ .../project/facade/TestAddVenusFacade.java | 4 ++ .../src/test/resources/ok1-pom/pom.xml | 4 ++ 7 files changed, 78 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a18317da..0bfd415ba 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] +### Changed + +- [fj-doc-maven-plugin] new param 'addVerifyPlugin' (default 'true') of 'add' plugin + ## [8.7.0] - 2024-08-25 ### Added diff --git a/fj-doc-maven-plugin/README.md b/fj-doc-maven-plugin/README.md index e8467ab4d..12f687213 100644 --- a/fj-doc-maven-plugin/README.md +++ b/fj-doc-maven-plugin/README.md @@ -41,15 +41,16 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \ *Parameters* -| parameter | required | default | description | -|----------------|----------|-----------------|---------------------------------------------------------------------------------------------------| -| version | true | latest stable | fj-doc version to add to the project (i.e. '8.6.5') | -| extensions | true | base,freemarker | List of fj-doc core modules to add (*) | -| projectFolder | true | . | Maven project base folder | -| addDocFacade | true | true | If true, a stub doc configuration helper will be created | -| force | false | false | Will force project setup even if fj-doc already configured (warning: can overwrite configuration) | -| 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} | +| parameter | required | default | description | +|-----------------|----------|-----------------|---------------------------------------------------------------------------------------------------| +| version | true | latest stable | fj-doc version to add to the project (i.e. '8.6.5') | +| extensions | true | base,freemarker | List of fj-doc core modules to add (*) | +| projectFolder | true | . | Maven project base folder | +| addDocFacade | true | true | If true, a stub doc configuration helper will be created | +| force | false | false | Will force project setup even if fj-doc already configured (warning: can overwrite configuration) | +| 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 | @@ -89,7 +90,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:verify -DtemplateBasePath=./src/test/re ${fj-doc-version} - daogen + freemarker-verify compile verify @@ -97,9 +98,13 @@ mvn org.fugerit.java:fj-doc-maven-plugin:verify -DtemplateBasePath=./src/test/re + ${project.basedir}/src/main/resources/fugerit-blank/template - true + true + + true + ${project.build.directory}/freemarker-syntax-verify-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 index be5a7805d..166179e95 100644 --- 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 @@ -35,6 +35,9 @@ public class MojoAdd extends AbstractMojo { @Parameter(property = "addExclusions", required = false) protected String addExclusions; + @Parameter(property = "addVerifyPlugin", defaultValue = "true", required = true) + protected boolean addVerifyPlugin; + @Override public void execute() throws MojoExecutionException, MojoFailureException { String foundVersion = VersionCheck.findVersion( this.version ); @@ -44,6 +47,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { context.setForce( this.force ); context.setAddExclusions( addExclusions ); context.setExcludeXmlApis( this.excludeXmlApis ); + context.setAddVerifyPlugin( this.addVerifyPlugin ); 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/BasicVenusFacade.java b/fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java index 53a1034a6..e191ec14d 100644 --- 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 @@ -1,12 +1,15 @@ 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.Exclusion; -import org.apache.maven.model.Model; +import org.apache.maven.model.*; +import org.apache.maven.plugin.lifecycle.Execution; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.fugerit.java.core.cfg.ConfigRuntimeException; +import org.fugerit.java.core.io.helper.HelperIOException; +import org.fugerit.java.core.lang.helpers.BooleanUtils; import org.fugerit.java.core.lang.helpers.StringUtils; +import org.fugerit.java.doc.freemarker.tool.FreeMarkerTemplateSyntaxVerifier; import org.maxxq.maven.dependency.ModelIO; import java.io.*; @@ -100,11 +103,47 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr } } log.info( "end dependencies size : {}", model.getDependencies().size() ); + // addVerifyPlugin? + log.info( "addVerifyPlugin : {}", context.isAddVerifyPlugin() ); + addPlugin( context, model ); try (OutputStream pomStream = new FileOutputStream( pomFile ) ) { modelIO.writeModelToStream( model, pomStream ); } } + private static void addPlugin( VenusContext context, Model model ) throws IOException { + if ( context.isAddVerifyPlugin() ) { + Build build = model.getBuild(); + if ( build == null ) { + build = new Build(); + model.setBuild( build ); + } + List 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.getExecutions().add( execution ); + String xml = "\n" + + " ${project.basedir}/src/main/resources/"+context.getArtificatIdForFolder()+"/template\n" + + " true\n" + + " true\n" + + " ${project.build.directory}/freemarker-syntax-verify-report\n" + + " "; + HelperIOException.apply( () -> { + try ( StringReader sr = new StringReader( xml ) ) { + Xpp3Dom dom = Xpp3DomBuilder.build( sr ); + plugin.setConfiguration( dom ); + } + }); + plugins.add( plugin ); + } + } + public static void checkDependencies( boolean force, Dependency d ) { if ( d.getGroupId().equals( GROUP_ID ) && d.getArtifactId().startsWith( "fj-doc") ) { log.warn( "fj-doc dependency found : {}", d ); 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 index 0f515f1df..377aac017 100644 --- 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 @@ -44,6 +44,9 @@ public class VenusContext { @Getter @Setter private String addExclusions; + @Getter @Setter + private boolean addVerifyPlugin; + public void setExcludeXmlApis( boolean excludeXmlApis ) { if ( excludeXmlApis ) { this.setAddExclusions( "xml-apis:xml-apis" ); 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 index 35c3a5d02..b678447f6 100644 --- 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 @@ -43,15 +43,18 @@ public void testAddVenus() throws IOException { String moduleList = "fj-doc-base,base-json,mod-fop,mod-opencsv,mod-poi"; boolean addFacade = false; boolean excludeXmlApis = false; + boolean addVerifyPlugin = false; if ( count == 0 ) { moduleList = "base,freemarker"; addFacade = true; + addVerifyPlugin = true; } else if ( count == 3 ) { excludeXmlApis = true; } VenusContext context = new VenusContext( projectDir, this.getVersion(), moduleList ); context.setExcludeXmlApis( excludeXmlApis ); context.setAddDocFacace( addFacade ); + context.setAddVerifyPlugin( addVerifyPlugin ); boolean result = AddVenusFacade.addVenusToMavenProject( context ); Assert.assertTrue( result ); Assert.assertThrows( ConfigRuntimeException.class, () -> AddVenusFacade.addVenusToMavenProject( context ) ); @@ -72,6 +75,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { this.addDocFacade = true; this.force = true; this.excludeXmlApis = true; + this.addVerifyPlugin = true; super.execute(); } }; 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 index 25012ebfc..1997a3f13 100644 --- a/fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml +++ b/fj-doc-maven-plugin/src/test/resources/ok1-pom/pom.xml @@ -22,5 +22,9 @@ https://www.fugerit.org/ + + + +