Skip to content

Commit

Permalink
[fj-doc-maven-plugin] added init fugerit venus goal
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Aug 28, 2024
1 parent 39b640d commit 211461f
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [fj-doc-maven-plugin] added init fugerit venus goal
- [fj-doc-maven-plugin] build order changed, now will build before fj-doc-sample
- [fj-doc-maven-plugin] new param 'reportOutputFormat' (default 'html') of 'verify' plugin

Expand Down
32 changes: 27 additions & 5 deletions fj-doc-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
-Dextensions=base,freemarker,mod-fop
```

*Parameters*
### Add Fugerit Venus, parameters

| parameter | required | default | description |
|-----------------|----------|-----------------|---------------------------------------------------------------------------------------------------|
Expand All @@ -51,10 +51,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 |



*Available extensions*
### Add Fugerit Venus, available extensions

| short name | full name | type handler | description |
|-----------------|------------------------|--------------|---------------------------------------------------------------------------------------------------------|
Expand All @@ -69,6 +66,31 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
| base-yaml | fj-doc-base-yaml | | add support to use yaml documents as format for document template |


## Goal : init

Create a new project and add Venus Doc Configuration to it.

*Quickstart* :

```shell
mvn org.fugerit.java:fj-doc-maven-plugin:init \
-DgroupId=org.example.doc \
-DartifactId=fugerit-demo
```

Project folder will be `./${artifactId}/`.

### Init Fugerit Venus, parameters

| parameter | required | default | description |
|----------------|----------|----------------|----------------------|
| groupId | true | | new project group id |
| artifactId | true | | new project group id |
| projectVersion | true | 1.0.0-SNAPSHOT | new project version |
| javaRelease | true | 21 | java release version |

NOTE: it is possible to set any property from 'add' goal, except 'projectFolder' which is set to `./${artifactId}`.

## Goal : verify

verify the templates in a FreeMarker configuration (folder), note: it can be used on any Apache FreeMarker configuration, not only Fugerit Venus Doc.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.fugerit.java.doc.maven;

import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.fugerit.java.core.function.UnsafeVoid;
import org.maxxq.maven.dependency.ModelIO;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

@Mojo( name = "init", requiresProject = false, defaultPhase = LifecyclePhase.NONE )
public class MojoInit extends MojoAdd {

@Parameter(property = "groupId", required = true)
protected String groupId;

@Parameter(property = "artifactId", required = true)
protected String artifactId;

@Parameter(property = "projectVersion", defaultValue = "1.0.0-SNAPSHOT", required = true)
protected String projectVersion;

@Parameter(property = "javaRelease", defaultValue = "21", required = true)
protected String javaRelease;

protected String baseInitFolder;

public MojoInit() {
this.baseInitFolder = ".";
}

public void apply(UnsafeVoid<Exception> fun) throws MojoFailureException {
try {
fun.apply();
} catch (Exception e) {
throw new MojoFailureException( String.format( "Project init failed: %s", e.getMessage() ), e );
}
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File initFolder = new File( this.baseInitFolder, this.artifactId );
if ( initFolder.exists() ) {
throw new MojoFailureException( String.format( "Folder %s already exists.", initFolder.getAbsolutePath() ) );
} else {
this.getLog().info( String.format( "project folder %s -> %s", initFolder.getAbsolutePath(), initFolder.mkdir() ) );
File pomFile = new File( initFolder, "pom.xml" );
Model model = new Model();
model.setGroupId( this.groupId );
model.setArtifactId( this.artifactId );
model.setVersion( this.projectVersion );
model.setModelVersion( "4.0.0" );
Properties props = new Properties();
props.setProperty( "maven.compiler.release", this.javaRelease );
props.setProperty( "project.build.sourceEncoding", StandardCharsets.UTF_8.name() );
model.setProperties( props );
this.apply( () -> {
this.projectFolder = initFolder.getCanonicalPath();
ModelIO modelIO = new ModelIO();
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
modelIO.writeModelToStream( model, pomStream );
}
} );
}
super.execute();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.cfg.ConfigException;
import org.fugerit.java.doc.maven.MojoInit;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.util.UUID;

@Slf4j
public class TestInit {

private String getVersion() {
return "8.7.1";
}

private File initConfigWorker() {
File outputFolder = new File( "target", "init_"+UUID.randomUUID().toString() );
outputFolder.mkdir();
return outputFolder;
}

@Test
public void testMojoInit() throws MojoExecutionException, MojoFailureException {
File projectDir = this.initConfigWorker( );
MojoInit mojoInit = new MojoInit() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
this.baseInitFolder = projectDir.getAbsolutePath();
this.projectVersion = "1.0.0-SNAPSHOT";
this.groupId = "org.fugerit.java.test";
this.artifactId = "fugerit-test1";
this.javaRelease = "21";
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.addDocFacade = true;
this.force = true;
this.excludeXmlApis = true;
this.addVerifyPlugin = true;
super.execute();
}
};
mojoInit.execute();
Assert.assertTrue( projectDir.exists() );
Assert.assertThrows( MojoFailureException.class, () -> mojoInit.execute() );
Assert.assertThrows( MojoFailureException.class, () -> mojoInit.apply( () -> {
if ( Boolean.TRUE ) {
throw new ConfigException( "Scenario excetion" );
}
} ) );
}

}

0 comments on commit 211461f

Please sign in to comment.