Skip to content

Commit 2215cae

Browse files
authored
Merge pull request #351 from fugerit-org/350-chore-fj-doc-maven-plugin-goal-add-simple-maven-add-project
[fj-doc-maven-plugin] goal 'add' new param 'simpleModel' #350
2 parents 5a3696f + 2e95afa commit 2215cae

File tree

8 files changed

+114
-8
lines changed

8 files changed

+114
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- [fj-doc-maven-plugin] goal 'add' new param 'simpleModel' <https://github.com/fugerit-org/fj-doc/issues/350>
13+
1014
### Fixed
1115

1216
- [fj-doc-freemarker] handling of svg in html handler <https://github.com/fugerit-org/fj-doc/issues/348>

fj-doc-guide/src/main/docs/asciidoc/chapters/02_1_maven_plugin_add.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mvn org.fugerit.java:fj-doc-maven-plugin:add \
2828
| addLombok | true | true | If set to true, it will add lombok (provided scope) and slf4j-simple (test scope)
2929
| addDependencyOnTop | true | false | If set to true, added dependencies will be added before existing ones
3030
| freemarkerVersion | true | 2.3.32 | Freemarker compatibility version (max 2.3.33)
31+
| 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.
3132
|====================================================================================================================================================================================
3233

3334
[#available-extensions]

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/maven/MojoAdd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public class MojoAdd extends AbstractMojo {
5050
@Parameter(property = "freemarkerVersion", defaultValue = "2.3.32", required = true)
5151
protected String freemarkerVersion;
5252

53+
@Parameter(property = "simpleModel", defaultValue = "false", required = true)
54+
protected boolean simpleModel;
55+
5356
protected String groupIdOverride;
5457

5558
protected String artifactIdOverride;
@@ -70,6 +73,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
7073
context.setFreemarkerVersion( this.freemarkerVersion );
7174
context.setGroupIdOverride( this.groupIdOverride );
7275
context.setArtifactIdOverride( this.artifactIdOverride );
76+
context.setSimpleModel( this.simpleModel );
7377
this.getLog().info( String.format( "add execute() context : %s", context ) );
7478
AddVenusFacade.addToProject( context );
7579
}

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/BasicVenusFacade.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,45 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
140140
}
141141
} );
142142
}
143-
// addJunit5 parameter
144-
addJunit5( model, context );
145-
// addLombok parameter
146-
addLombok( model, context );
147-
log.info( "end dependencies size : {}", model.getDependencies().size() );
148-
addPlugin( context, model );
149-
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
150-
modelIO.writeModelToStream( model, pomStream );
143+
if ( context.isSimpleModel() ) {
144+
log.warn( "simpleModel true : skipping extra dependencies and plugin" );
145+
handleSimpleModel( pomFile, context, moduleList );
146+
} else {
147+
// addJunit5 parameter
148+
addJunit5( model, context );
149+
// addLombok parameter
150+
addLombok( model, context );
151+
addPlugin( context, model );
152+
log.info( "end dependencies size : {}", model.getDependencies().size() );
153+
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
154+
modelIO.writeModelToStream( model, pomStream );
155+
}
156+
}
157+
}
158+
159+
private static void handleSimpleModel( File pomFile, VenusContext context, List<String> moduleList ) throws IOException {
160+
String pomText = FileIO.readString( pomFile );
161+
// add property fj-doc-version
162+
String properties = "</properties>";
163+
int endPropertiesIndex = pomText.indexOf( properties );
164+
if ( endPropertiesIndex != -1 ) {
165+
pomText = String.format( "%s <fj-doc-version>%s</fj-doc-version>%n %s", pomText.substring( 0, endPropertiesIndex ), context.getVersion(), pomText.substring( endPropertiesIndex ) );
166+
} else {
167+
String modelVersion = "</modelVersion>";
168+
int endArtifactIdIndex = pomText.indexOf( modelVersion )+modelVersion.length();
169+
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 ) );
170+
}
171+
// add dependencies
172+
String dependencies = "</dependencies>";
173+
int endDependenciesIndex = pomText.indexOf( dependencies );
174+
StringBuilder builder = new StringBuilder();
175+
for ( String moduleName : moduleList ) {
176+
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 ) );
151177
}
178+
pomText = String.format( "%s %s%n%n %s", pomText.substring( 0, endDependenciesIndex ), builder, pomText.substring( endDependenciesIndex ) );
179+
// write pom file
180+
FileIO.writeString( pomText, pomFile );
181+
log.warn( "simpleModel enabled, consider adding fj-doc-maven-plugin:verify and other configurations. (https://venusdocs.fugerit.org/guide/#maven-plugin-entry)" );
152182
}
153183

154184
private static final String CONST_IMPLEMENTATION = "implementation";

fj-doc-maven-plugin/src/main/java/org/fugerit/java/doc/project/facade/VenusContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public static String toResourcePathFmConfigXml( String artifactId ) {
8787
@Getter @Setter
8888
private String artifactIdOverride;
8989

90+
@Getter @Setter
91+
private boolean simpleModel;
92+
9093
public void setExcludeXmlApis( boolean excludeXmlApis ) {
9194
if ( excludeXmlApis ) {
9295
this.setAddExclusions( "xml-apis:xml-apis" );

fj-doc-maven-plugin/src/test/java/test/org/fugerit/java/doc/project/facade/TestAddVenusFacade.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ public void execute() throws MojoExecutionException, MojoFailureException {
9595
}
9696
}
9797

98+
@Test
99+
public void testMojoAddSimpleModel() throws IOException, MojoExecutionException, MojoFailureException {
100+
for ( String current : Arrays.asList( "ok3-pom", "ok5-pom" ) ) {
101+
for ( String currentConfig : Arrays.asList( current ) ) {
102+
File projectDir = this.initConfigWorker( currentConfig );
103+
MojoAdd mojoAdd = new MojoAdd() {
104+
@Override
105+
public void execute() throws MojoExecutionException, MojoFailureException {
106+
this.version = "8.12.5";
107+
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";
108+
this.projectFolder = projectDir.getAbsolutePath();
109+
this.addDocFacade = true;
110+
this.force = true;
111+
this.excludeXmlApis = true;
112+
this.simpleModel = true;
113+
super.execute();
114+
}
115+
};
116+
mojoAdd.execute();
117+
Assert.assertTrue( projectDir.exists() );
118+
}
119+
}
120+
}
121+
122+
98123
@Test
99124
public void testFail() {
100125
VenusContext context = new VenusContext( new File( "target" ), this.getVersion(),"base" );

fj-doc-maven-plugin/src/test/resources/ok3-pom/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<dependency>
3333
<groupId>org.fugerit.java</groupId>
3434
<artifactId>fj-core</artifactId>
35+
<version>8.6.6</version>
3536
</dependency>
3637
</dependencies>
3738

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>fjdocmavenpluginok5</artifactId>
6+
<groupId>org.fugerit.java.test</groupId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
9+
<name>Fugerit Doc Maven Plugin Ok POM Test 4</name>
10+
11+
<licenses>
12+
<license>
13+
<name>Apache License, Version 2.0</name>
14+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
15+
<distribution>repo</distribution>
16+
</license>
17+
</licenses>
18+
19+
<properties>
20+
<fj-core-version>8.6.6</fj-core-version>
21+
</properties>
22+
23+
<organization>
24+
<url>https://www.fugerit.org</url>
25+
<name>Fugerit</name>
26+
</organization>
27+
28+
<url>https://www.fugerit.org/</url>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.fugerit.java</groupId>
33+
<artifactId>fj-core</artifactId>
34+
<version>${fj-core-version}</version>
35+
</dependency>
36+
</dependencies>
37+
38+
</project>

0 commit comments

Comments
 (0)