Skip to content

Commit 9e5f04b

Browse files
authored
Merge pull request #467 from fugerit-org/466-bug-fj-doc-maven-plugin-checj-fj-core-version-at-project-creation
466 bug fj doc maven plugin checj fj core version at project creation
2 parents 34ad7ab + 62755a6 commit 9e5f04b

File tree

11 files changed

+211
-35
lines changed

11 files changed

+211
-35
lines changed

CHANGELOG.md

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

1010
### Changed
1111

12+
- fj-core version set to 8.7.0
1213
- quarkus-version set to 3.24.2 across all the modules <https://github.com/fugerit-org/fj-doc/issues/464>
1314

1415
## [8.13.13] - 2025-06-24

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import org.apache.maven.model.*;
55
import org.apache.maven.plugins.annotations.LifecyclePhase;
66
import org.fugerit.java.core.cfg.ConfigRuntimeException;
7+
import org.fugerit.java.core.cfg.VersionCompare;
78
import org.fugerit.java.core.io.FileIO;
89
import org.fugerit.java.core.lang.helpers.StringUtils;
10+
import org.fugerit.java.core.util.mvn.FJCoreMaven;
911
import org.maxxq.maven.dependency.ModelIO;
12+
import org.maxxq.maven.model.MavenModel;
1013

1114
import java.io.*;
1215
import java.util.*;
@@ -16,12 +19,35 @@ public class BasicVenusFacade {
1619

1720
protected BasicVenusFacade() {}
1821

22+
private static final String STAR = "\n****************************************************************************************************************************";
23+
private static final String FJCORE_VERSION_LOG1 = STAR+"\n[fj-doc-maven-plugin] goal add, org.fugerit.java:fj-core version {}, upgrade at least to {} if possible."+STAR;
24+
private static final String FJCORE_VERSION_LOG2 = STAR+"\n[fj-doc-maven-plugin] goal add, org.fugerit.java:fj-core version {}, minimum required version {}."+STAR;
25+
1926
protected static final String GROUP_ID = VenusConsts.GROUP_ID;
2027

2128
protected static final String KEY_VERSION = VenusConsts.KEY_VERSION;
2229

2330
private static final String PROJECT_LOMBOK = "org.projectlombok:lombok";
2431

32+
private static final String MIN_FJ_VERSION = "8.6.9";
33+
34+
public static String versionToCheck(String groupIdToCheck, String artifactIdToCheck, Model model) {
35+
List<Dependency> dependencies = model.getDependencies();
36+
for (Dependency dep : dependencies) {
37+
if (dep.getGroupId().equals(groupIdToCheck) &&
38+
dep.getArtifactId().equals(artifactIdToCheck)) {
39+
String version = dep.getVersion();
40+
if (version != null && version.startsWith("${")) {
41+
String propertyKey = version.substring(2, version.length() - 1);
42+
return model.getProperties().getProperty(propertyKey);
43+
}
44+
return version;
45+
}
46+
}
47+
return null;
48+
}
49+
50+
2551
private static void addOrOverwrite( List<Dependency> deps, Dependency d ) {
2652
Iterator<Dependency> it = deps.iterator();
2753
while ( it.hasNext() ) {
@@ -159,6 +185,24 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
159185
modelIO.writeModelToStream( model, pomStream );
160186
}
161187
}
188+
// check fj-core
189+
String projectPomFjCoreVersion = versionToCheck( FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, model );
190+
Optional<String> fjCoreVersion = FJCoreMaven.getFJCoreVersion();
191+
fjVersionCheck( projectPomFjCoreVersion, fjCoreVersion );
192+
}
193+
194+
public static void fjVersionCheck(String projectPomFjCoreVersion, Optional<String> fjCoreVersion ) {
195+
if ( StringUtils.isNotEmpty( projectPomFjCoreVersion ) ) {
196+
// required version
197+
if ( VersionCompare.isGreaterThan( MIN_FJ_VERSION, projectPomFjCoreVersion ) ) {
198+
log.error( FJCORE_VERSION_LOG2, projectPomFjCoreVersion, MIN_FJ_VERSION );
199+
throw new ConfigRuntimeException( String.format( "minimum org.fugerit.java:fj-core version is : %s", MIN_FJ_VERSION ) );
200+
}
201+
// suggested version
202+
if ( fjCoreVersion.isPresent() && VersionCompare.isGreaterThan( fjCoreVersion.get(), projectPomFjCoreVersion ) ) {
203+
log.warn( FJCORE_VERSION_LOG1, projectPomFjCoreVersion, fjCoreVersion.get() );
204+
}
205+
}
162206
}
163207

164208
private static void handleSimpleModel( File pomFile, VenusContext context, List<String> moduleList ) throws IOException {
Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.fugerit.java.doc.project.facade;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.core.cfg.VersionCompare;
45
import org.fugerit.java.core.lang.helpers.ClassHelper;
6+
import org.fugerit.java.core.lang.helpers.StringUtils;
57
import org.fugerit.java.core.util.PropsIO;
8+
import org.fugerit.java.core.util.mvn.FJCoreMaven;
9+
import org.fugerit.java.core.util.mvn.MavenProps;
610

711
import java.util.Properties;
812

@@ -15,44 +19,17 @@ private VersionCheck() {}
1519

1620
public static final String FALLBACK = "8.6.2";
1721

18-
public static String findFromPropsFile( String path ) {
19-
Properties props = PropsIO.loadFromClassLoaderSafe( path );
20-
if ( props.containsKey( "version" ) ) {
21-
String latest = props.getProperty( "version" );
22-
log.info( "findVersion() latest : {}", latest );
23-
return latest;
24-
} else {
25-
log.info( "findVersion() fallback : {}", FALLBACK );
26-
return FALLBACK;
27-
}
28-
}
29-
3022
public static String findVersion( String version ) {
3123
if ( version == null || version.equals(LATEST) ) {
32-
return findFromPropsFile( "META-INF/maven/org.fugerit.java/fj-doc-maven-plugin/pom.properties" );
24+
return StringUtils.valueWithDefault( MavenProps.getProperty(FJCoreMaven.FJ_CORE_GROUP_ID, "fj-doc-maven-plugin", MavenProps.VERSION ), FALLBACK );
3325
} else {
3426
log.info( "findVersion() input : {}", version );
3527
return version;
3628
}
3729
}
3830

39-
public static int convertVersionPart( String versionPart ) {
40-
if ( versionPart.contains( "-" ) ) {
41-
return Integer.parseInt( versionPart.substring( 0, versionPart.indexOf( "-" ) ) );
42-
} else {
43-
return Integer.parseInt( versionPart );
44-
}
45-
}
46-
4731
public static boolean isMajorThan( String v1, String v2 ) {
48-
String[] split1 = v1.split( "\\." );
49-
String[] split2 = v2.split( "\\." );
50-
for ( int i = 0 ; i < split1.length ; i++ ) {
51-
if ( convertVersionPart( split1[i] ) > convertVersionPart( split2[i]) ) {
52-
return true;
53-
}
54-
}
55-
return false;
32+
return VersionCompare.isGreaterThan( v1, v2 );
5633
}
5734

5835
}

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package test.org.fugerit.java.doc.project.facade;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.logging.log4j.core.util.Assert;
45
import org.apache.maven.model.Dependency;
6+
import org.apache.maven.model.Model;
57
import org.apache.maven.plugin.MojoExecutionException;
68
import org.apache.maven.plugin.MojoFailureException;
79
import org.fugerit.java.core.cfg.ConfigRuntimeException;
810
import org.fugerit.java.core.io.FileIO;
11+
import org.fugerit.java.core.util.mvn.FJCoreMaven;
912
import org.fugerit.java.doc.maven.MojoAdd;
1013
import org.fugerit.java.doc.project.facade.BasicVenusFacade;
1114
import org.fugerit.java.doc.project.facade.VenusContext;
@@ -15,7 +18,9 @@
1518

1619
import java.io.File;
1720
import java.io.IOException;
21+
import java.util.ArrayList;
1822
import java.util.Arrays;
23+
import java.util.Optional;
1924
import java.util.UUID;
2025

2126
@Slf4j
@@ -152,4 +157,70 @@ void testAdditional() {
152157
BasicVenusFacade.checkDependencies( true, d );
153158
}
154159

160+
@Test
161+
void testMojoAddFjCoreVersion1() throws IOException, MojoExecutionException, MojoFailureException {
162+
for ( String currentConfig : Arrays.asList( "ok6-pom" ) ) {
163+
File projectDir = this.initConfigWorker( currentConfig );
164+
MojoAdd mojoAdd = new MojoAdd() {
165+
@Override
166+
public void execute() throws MojoExecutionException, MojoFailureException {
167+
this.version = VenusContext.VERSION_NA_VERIFY_PLUGIN;
168+
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";
169+
this.projectFolder = projectDir.getAbsolutePath();
170+
this.addDocFacade = true;
171+
this.force = true;
172+
this.excludeXmlApis = true;
173+
this.addVerifyPlugin = true;
174+
this.addJunit5 = true;
175+
this.addLombok = true;
176+
super.execute();
177+
}
178+
};
179+
mojoAdd.execute();
180+
Assertions.assertTrue( projectDir.exists() );
181+
}
182+
}
183+
184+
@Test
185+
void testMojoAddFjCoreVersion2() throws IOException {
186+
for ( String currentConfig : Arrays.asList( "ko2-pom" ) ) {
187+
File projectDir = this.initConfigWorker( currentConfig );
188+
MojoAdd mojoAdd = new MojoAdd() {
189+
@Override
190+
public void execute() throws MojoExecutionException, MojoFailureException {
191+
this.version = VenusContext.VERSION_NA_VERIFY_PLUGIN;
192+
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";
193+
this.projectFolder = projectDir.getAbsolutePath();
194+
this.addDocFacade = true;
195+
this.force = true;
196+
this.excludeXmlApis = true;
197+
this.addVerifyPlugin = true;
198+
this.addJunit5 = true;
199+
this.addLombok = true;
200+
super.execute();
201+
}
202+
};
203+
Assertions.assertThrows( ConfigRuntimeException.class, mojoAdd::execute );
204+
}
205+
}
206+
207+
@Test
208+
void testFjVersionCheck() {
209+
Model model = new Model();
210+
String projectPomFjCoreVersion = BasicVenusFacade.versionToCheck( FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, model );
211+
Assertions.assertNull( projectPomFjCoreVersion );
212+
model.setDependencies( new ArrayList<>() );
213+
Dependency d = new Dependency();
214+
d.setGroupId( FJCoreMaven.FJ_CORE_GROUP_ID );
215+
d.setArtifactId( FJCoreMaven.FJ_CORE_ARTIFACT_ID );
216+
model.getDependencies().add( d );
217+
projectPomFjCoreVersion = BasicVenusFacade.versionToCheck( FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, model );
218+
Assertions.assertNull( projectPomFjCoreVersion );
219+
Optional<String> fjCoreVersion = Optional.empty();
220+
BasicVenusFacade.fjVersionCheck( projectPomFjCoreVersion, fjCoreVersion );
221+
BasicVenusFacade.fjVersionCheck( "8.6.9", Optional.of( "8.7.0" ) );
222+
BasicVenusFacade.fjVersionCheck( "8.7.1", Optional.of( "8.7.0" ) );
223+
Assertions.assertNull( projectPomFjCoreVersion );
224+
}
225+
155226
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ void testVersionCheck() {
1818
Assertions.assertTrue(VersionCheck.isMajorThan( V_8_6_2, "8.6.1-SNAPSHOT" ));
1919
Assertions.assertFalse(VersionCheck.isMajorThan( "8.5.1", "8.5.2" ));
2020
VenusContext context = new VenusContext( new File( "target" ), V_8_6_2, "base" );
21-
Assertions.assertFalse( context.isPreVersion862() );
2221
log.info( "version from null to : {}", VersionCheck.findVersion( null ) );
2322
log.info( "version from null to : {}", VersionCheck.findVersion( VersionCheck.LATEST ) );
24-
Assertions.assertEquals( V_8_6_2, VersionCheck.findFromPropsFile( "maven/pom.properties" ) );
23+
Assertions.assertFalse( context.isPreVersion862() );
2524
}
2625

2726
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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>fjdocmavenpluginok1</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 1</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+
<organization>
20+
<url>https://www.fugerit.org</url>
21+
<name>Fugerit</name>
22+
</organization>
23+
24+
<url>https://www.fugerit.org/</url>
25+
26+
<properties>
27+
<fj-core-version>8.6.8</fj-core-version>
28+
</properties>
29+
30+
<build>
31+
32+
</build>
33+
34+
<dependencies>
35+
36+
<dependency>
37+
<groupId>org.fugerit.java</groupId>
38+
<artifactId>fj-core</artifactId>
39+
<version>${fj-core-version}</version>
40+
</dependency>
41+
42+
</dependencies>
43+
44+
</project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>org.fugerit.java</groupId>
4646
<artifactId>fj-core</artifactId>
47-
<version>8.6.5</version>
47+
<version>8.6.9</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>org.fugerit.java</groupId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependency>
3333
<groupId>org.fugerit.java</groupId>
3434
<artifactId>fj-core</artifactId>
35-
<version>8.6.6</version>
35+
<version>8.7.0</version>
3636
</dependency>
3737
</dependencies>
3838

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</licenses>
1818

1919
<properties>
20-
<fj-core-version>8.6.6</fj-core-version>
20+
<fj-core-version>8.7.0</fj-core-version>
2121
</properties>
2222

2323
<organization>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>fjdocmavenpluginok1</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 1</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+
<organization>
20+
<url>https://www.fugerit.org</url>
21+
<name>Fugerit</name>
22+
</organization>
23+
24+
<url>https://www.fugerit.org/</url>
25+
26+
<build>
27+
28+
</build>
29+
30+
<dependencies>
31+
32+
<dependency>
33+
<groupId>org.fugerit.java</groupId>
34+
<artifactId>fj-core</artifactId>
35+
<version>8.6.9</version>
36+
</dependency>
37+
38+
</dependencies>
39+
40+
</project>

0 commit comments

Comments
 (0)