-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fj-doc-maven-plugin] added init fugerit venus goal
- Loading branch information
Showing
4 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); | ||
} | ||
} ) ); | ||
} | ||
|
||
} |