Skip to content

Commit ddbb807

Browse files
committed
check fj-core VersionCompare #466
1 parent 95ab077 commit ddbb807

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

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

Lines changed: 34 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,29 @@ 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+
private 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+
return dep.getVersion();
40+
}
41+
}
42+
return null;
43+
}
44+
2545
private static void addOrOverwrite( List<Dependency> deps, Dependency d ) {
2646
Iterator<Dependency> it = deps.iterator();
2747
while ( it.hasNext() ) {
@@ -159,6 +179,20 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
159179
modelIO.writeModelToStream( model, pomStream );
160180
}
161181
}
182+
// check fj-core
183+
String projectPomFjCoreVersion = versionToCheck( FJCoreMaven.FJ_CORE_GROUP_ID, FJCoreMaven.FJ_CORE_ARTIFACT_ID, model );
184+
Optional<String> fjCoreVersion = FJCoreMaven.getFJCoreVersion();
185+
if ( StringUtils.isNotEmpty( projectPomFjCoreVersion ) ) {
186+
// required version
187+
if ( VersionCompare.isGreaterThan( MIN_FJ_VERSION, projectPomFjCoreVersion ) ) {
188+
log.error( FJCORE_VERSION_LOG2, projectPomFjCoreVersion, MIN_FJ_VERSION );
189+
throw new ConfigRuntimeException( String.format( "minimum org.fugerit.java:fj-core version is : %s", MIN_FJ_VERSION ) );
190+
}
191+
// suggested version
192+
if ( fjCoreVersion.isPresent() && VersionCompare.isGreaterThan( fjCoreVersion.get(), projectPomFjCoreVersion ) ) {
193+
log.warn( FJCORE_VERSION_LOG1, projectPomFjCoreVersion, fjCoreVersion.get() );
194+
}
195+
}
162196
}
163197

164198
private static void handleSimpleModel( File pomFile, VenusContext context, List<String> moduleList ) throws IOException {

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,51 @@ void testAdditional() {
152152
BasicVenusFacade.checkDependencies( true, d );
153153
}
154154

155+
@Test
156+
void testMojoAddFjCoreVersion1() throws IOException, MojoExecutionException, MojoFailureException {
157+
for ( String currentConfig : Arrays.asList( "ok6-pom" ) ) {
158+
File projectDir = this.initConfigWorker( currentConfig );
159+
MojoAdd mojoAdd = new MojoAdd() {
160+
@Override
161+
public void execute() throws MojoExecutionException, MojoFailureException {
162+
this.version = VenusContext.VERSION_NA_VERIFY_PLUGIN;
163+
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";
164+
this.projectFolder = projectDir.getAbsolutePath();
165+
this.addDocFacade = true;
166+
this.force = true;
167+
this.excludeXmlApis = true;
168+
this.addVerifyPlugin = true;
169+
this.addJunit5 = true;
170+
this.addLombok = true;
171+
super.execute();
172+
}
173+
};
174+
mojoAdd.execute();
175+
Assertions.assertTrue( projectDir.exists() );
176+
}
177+
}
178+
179+
@Test
180+
void testMojoAddFjCoreVersion2() throws IOException, MojoExecutionException, MojoFailureException {
181+
for ( String currentConfig : Arrays.asList( "ko2-pom" ) ) {
182+
File projectDir = this.initConfigWorker( currentConfig );
183+
MojoAdd mojoAdd = new MojoAdd() {
184+
@Override
185+
public void execute() throws MojoExecutionException, MojoFailureException {
186+
this.version = VenusContext.VERSION_NA_VERIFY_PLUGIN;
187+
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";
188+
this.projectFolder = projectDir.getAbsolutePath();
189+
this.addDocFacade = true;
190+
this.force = true;
191+
this.excludeXmlApis = true;
192+
this.addVerifyPlugin = true;
193+
this.addJunit5 = true;
194+
this.addLombok = true;
195+
super.execute();
196+
}
197+
};
198+
Assertions.assertThrows( ConfigRuntimeException.class, () -> mojoAdd.execute() );
199+
}
200+
}
201+
155202
}
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.8</version>
36+
</dependency>
37+
38+
</dependencies>
39+
40+
</project>
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)