Skip to content

[fj-doc-maven-plugin] goal 'add' new param 'simpleModel' #350 #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- [fj-doc-maven-plugin] goal 'add' new param 'simpleModel' <https://github.com/fugerit-org/fj-doc/issues/350>

### Fixed

- [fj-doc-freemarker] handling of svg in html handler <https://github.com/fugerit-org/fj-doc/issues/348>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
| 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)
| simpleMpdel | true | false | If set to true, modification to pom.xml will be light, dependencies for addLombok and addJunit will be ignored. addVerifyPlugin param will be ignored.
|====================================================================================================================================================================================

[#available-extensions]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class MojoAdd extends AbstractMojo {
@Parameter(property = "freemarkerVersion", defaultValue = "2.3.32", required = true)
protected String freemarkerVersion;

@Parameter(property = "simpleModel", defaultValue = "false", required = true)
protected boolean simpleModel;

protected String groupIdOverride;

protected String artifactIdOverride;
Expand All @@ -70,6 +73,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
context.setFreemarkerVersion( this.freemarkerVersion );
context.setGroupIdOverride( this.groupIdOverride );
context.setArtifactIdOverride( this.artifactIdOverride );
context.setSimpleModel( this.simpleModel );
this.getLog().info( String.format( "add execute() context : %s", context ) );
AddVenusFacade.addToProject( context );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,45 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
}
} );
}
// addJunit5 parameter
addJunit5( model, context );
// addLombok parameter
addLombok( model, context );
log.info( "end dependencies size : {}", model.getDependencies().size() );
addPlugin( context, model );
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
modelIO.writeModelToStream( model, pomStream );
if ( context.isSimpleModel() ) {
log.warn( "simpleModel true : skipping extra dependencies and plugin" );
handleSimpleModel( pomFile, context, moduleList );
} else {
// addJunit5 parameter
addJunit5( model, context );
// addLombok parameter
addLombok( model, context );
addPlugin( context, model );
log.info( "end dependencies size : {}", model.getDependencies().size() );
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
modelIO.writeModelToStream( model, pomStream );
}
}
}

private static void handleSimpleModel( File pomFile, VenusContext context, List<String> moduleList ) throws IOException {
String pomText = FileIO.readString( pomFile );
// add property fj-doc-version
String properties = "</properties>";
int endPropertiesIndex = pomText.indexOf( properties );
if ( endPropertiesIndex != -1 ) {
pomText = String.format( "%s <fj-doc-version>%s</fj-doc-version>%n %s", pomText.substring( 0, endPropertiesIndex ), context.getVersion(), pomText.substring( endPropertiesIndex ) );
} else {
String modelVersion = "</modelVersion>";
int endArtifactIdIndex = pomText.indexOf( modelVersion )+modelVersion.length();
pomText = String.format( "%s%n%n <properties>%n <fj-doc-version>%s</fj-doc-version>%n </properties>%n%s", pomText.substring( 0, endArtifactIdIndex ), context.getVersion(), pomText.substring( endArtifactIdIndex ) );
}
// add dependencies
String dependencies = "</dependencies>";
int endDependenciesIndex = pomText.indexOf( dependencies );
StringBuilder builder = new StringBuilder();
for ( String moduleName : moduleList ) {
builder.append( String.format( "%n <dependency>%n <groupId>org.fugerit.java</groupId>%n <artifactId>%s</artifactId>%n <version>${fj-doc-version}</version>%n </dependency>", moduleName ) );
}
pomText = String.format( "%s %s%n%n %s", pomText.substring( 0, endDependenciesIndex ), builder, pomText.substring( endDependenciesIndex ) );
// write pom file
FileIO.writeString( pomText, pomFile );
log.warn( "simpleModel enabled, consider adding fj-doc-maven-plugin:verify and other configurations. (https://venusdocs.fugerit.org/guide/#maven-plugin-entry)" );
}

private static final String CONST_IMPLEMENTATION = "implementation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public static String toResourcePathFmConfigXml( String artifactId ) {
@Getter @Setter
private String artifactIdOverride;

@Getter @Setter
private boolean simpleModel;

public void setExcludeXmlApis( boolean excludeXmlApis ) {
if ( excludeXmlApis ) {
this.setAddExclusions( "xml-apis:xml-apis" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

@Test
public void testMojoAddSimpleModel() throws IOException, MojoExecutionException, MojoFailureException {
for ( String current : Arrays.asList( "ok3-pom", "ok5-pom" ) ) {
for ( String currentConfig : Arrays.asList( current ) ) {
File projectDir = this.initConfigWorker( currentConfig );
MojoAdd mojoAdd = new MojoAdd() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
this.version = "8.12.5";
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;
this.force = true;
this.excludeXmlApis = true;
this.simpleModel = true;
super.execute();
}
};
mojoAdd.execute();
Assert.assertTrue( projectDir.exists() );
}
}
}


@Test
public void testFail() {
VenusContext context = new VenusContext( new File( "target" ), this.getVersion(),"base" );
Expand Down
1 change: 1 addition & 0 deletions fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-core</artifactId>
<version>8.6.6</version>
</dependency>
</dependencies>

Expand Down
38 changes: 38 additions & 0 deletions fj-doc-maven-plugin/src/test/resources/ok5-pom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>fjdocmavenpluginok5</artifactId>
<groupId>org.fugerit.java.test</groupId>
<version>1.0.0-SNAPSHOT</version>

<name>Fugerit Doc Maven Plugin Ok POM Test 4</name>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<fj-core-version>8.6.6</fj-core-version>
</properties>

<organization>
<url>https://www.fugerit.org</url>
<name>Fugerit</name>
</organization>

<url>https://www.fugerit.org/</url>

<dependencies>
<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-core</artifactId>
<version>${fj-core-version}</version>
</dependency>
</dependencies>

</project>