Skip to content

Commit

Permalink
[fj-doc-maven-plugin] check if module exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Aug 21, 2024
1 parent f623315 commit 52c9dba
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
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] check if module exists

## [8.6.0] - 2024-08-21

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Mojo( name = "add" )
public class MojoAdd extends AbstractMojo {

@Parameter(property = "version", defaultValue = "8.5.2", required = true)
@Parameter(property = "version", defaultValue = "8.6.0", required = true)
protected String version;

@Parameter(property = "extensions", defaultValue = "base,freemarker", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.maxxq.maven.dependency.ModelIO;

import java.io.*;
Expand All @@ -18,8 +19,6 @@ public class BasicVenusFacade {

protected BasicVenusFacade() {}

protected static final String MODULE_PREFIX = "fj-doc-";

protected static final String GROUP_ID = "org.fugerit.java";

protected static final String KEY_VERSION = "fj-doc-version";
Expand Down Expand Up @@ -73,16 +72,18 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
fjDocBom.setScope( "import" );
addOrOverwrite( dm.getDependencies(), fjDocBom );
log.info( "start dependencies size : {}, version : {}", model.getDependencies().size(), context.getVersion() );
for ( String currentModule : Arrays.asList( extensionList ).stream().map(e -> {
if ( e.startsWith( MODULE_PREFIX ) ) {
return e;
for ( String currentModule : Arrays.asList( extensionList ) ) {
String moduleName = ModuleFacade.toModuleName( currentModule );
log.info( "Adding module : {}", moduleName );
if ( ModuleFacade.isModuleSupported( moduleName ) ) {
addCurrentModule( moduleName, model.getDependencies() );
context.getModules().add( currentModule );
} else {
return MODULE_PREFIX + e;
String message = String.format( "Module not supported : %s", moduleName );
log.warn( "{}, supported modules are : ", message );
ModuleFacade.getModules().forEach( log::warn );
throw new ConfigRuntimeException( message );
}
} ).collect(Collectors.toList()) ) {
log.info( "Adding module : {}", currentModule );
addCurrentModule( currentModule, model.getDependencies() );
context.getModules().add( currentModule );
}
log.info( "end dependencies size : {}", model.getDependencies().size() );
try (OutputStream pomStream = new FileOutputStream( pomFile ) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.fugerit.java.doc.project.facade;

import java.util.*;

public class ModuleFacade {

private ModuleFacade() {}

private static final String MODULE_PREFIX = "fj-doc-";

public static String toModuleName( String module ) {
if ( module.contains( MODULE_PREFIX ) ) {
return module;
} else {
return MODULE_PREFIX + module;
}
}

private static final Set<String> MODULES = new HashSet<>( Arrays.asList(
toModuleName( "base" ),
toModuleName( "base-json" ),
toModuleName( "base-yaml" ),
toModuleName( "freemarker" ),
toModuleName( "mod-fop" ),
toModuleName( "mod-poi" ),
toModuleName( "mod-opencsv" ),
toModuleName( "mod-openpdf-ext" ),
toModuleName( "mod-openrtf-ext" )
) );

public static boolean isModuleSupported( String moduleName ) {
return MODULES.contains( toModuleName( moduleName ) );
}

public static Collection<String> getModules() {
return Collections.unmodifiableCollection( MODULES );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.io.FileIO;
import org.fugerit.java.doc.maven.MojoAdd;
import org.fugerit.java.doc.project.facade.BasicVenusFacade;
Expand Down Expand Up @@ -39,10 +40,13 @@ public void testAddVenus() throws IOException {
log.info( "projectDir: {}, exists:{}", projectDir, projectDir.exists() );
Assert.assertTrue( projectDir.exists() );
String moduleList = "fj-doc-base,base-json,mod-fop,mod-opencsv,mod-poi";
boolean addFacade = false;
if ( count == 0 ) {
moduleList = "base,freemarker";
addFacade = true;
}
VenusContext context = new VenusContext( projectDir, this.getVersion(), moduleList );
context.setAddDocFacace( addFacade );
boolean result = AddVenusFacade.addVenusToMavenProject( context );
Assert.assertTrue( result );
count++;
Expand Down Expand Up @@ -75,6 +79,15 @@ public void testFail() {
Assert.assertFalse( result );
}

@Test
public void testFailNoModule() throws IOException {
for ( String currentConfig : Arrays.asList( "ko1-pom" ) ) {
File projectDir = this.initConfigWorker(currentConfig);
VenusContext context = new VenusContext( projectDir, this.getVersion(), "base,not-exists" );
Assert.assertThrows( ConfigRuntimeException.class, () -> AddVenusFacade.addVenusToMavenProject( context ) );
}
}

@Test
public void testAdditional() {
Assert.assertNotNull( new BasicVenusFacade() {} );
Expand Down
26 changes: 26 additions & 0 deletions fj-doc-maven-plugin/src/test/resources/ko1-pom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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>fjdocmavenpluginok1</artifactId>
<groupId>org.fugerit.java.test</groupId>
<version>1.0.0-SNAPSHOT</version>

<name>Fugerit Doc Maven Plugin Ok POM Test 1</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>

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

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

</project>

0 comments on commit 52c9dba

Please sign in to comment.