Skip to content

Commit

Permalink
final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Nov 10, 2024
1 parent 020d7d6 commit 246c26e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* <a href="https://maven.apache.org/doxia/references/">Doxia provided modules</a>.
*
* @author jdlee
* @since 0.1.2.1
*/
@Component(role = ParserModule.class, hint = AsciidoctorConverterDoxiaParser.ROLE_HINT)
public class AsciidoctorConverterDoxiaParserModule extends AbstractParserModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Asciidoctor conversion wrapper for maven-site integration.
* In addition to conversion, handles header metadata extraction.
*
* @author abelsromero
* @since 3.0.0
*/
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public SiteConversionConfiguration processAsciiDocConfig(MavenProject mavenProje
return new SiteConversionConfiguration(asciidocConfig, siteDir, options, gemsToRequire);
}

private Xpp3Dom getSiteConfig(MavenProject project) {
return project.getGoalConfiguration("org.apache.maven.plugins", "maven-site-plugin", "site", "site");
private Xpp3Dom getSiteConfig(MavenProject mavenProject) {
return mavenProject.getGoalConfiguration("org.apache.maven.plugins", "maven-site-plugin", "site", "site");
}

private File resolveProjectDir(MavenProject project, String path) {
private File resolveProjectDir(MavenProject mavenProject, String path) {
final File filePath = new File(path);
return !filePath.isAbsolute() ? new File(project.getBasedir(), filePath.toString()).getAbsoluteFile() : filePath;
return !filePath.isAbsolute() ? new File(mavenProject.getBasedir(), filePath.toString()).getAbsoluteFile() : filePath;
}

// The possible baseDir based on configuration are:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.asciidoctor.maven;

import javax.inject.Singleton;
import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -9,8 +10,13 @@
import org.asciidoctor.jruby.internal.JRubyRuntimeContext;
import org.jruby.Ruby;

import javax.inject.Singleton;

/**
* Creates an {@link Asciidoctor} instance taking into consideration the project's
* GEMs configuration.
*
* @author abelsromero
* @since 3.1.1
*/
@Singleton
public class AsciidoctorJFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,24 @@ public class AsciidoctorMojo extends AbstractMojo {
protected MavenProject project;

private final AsciidoctorJFactory asciidoctorJFactory;

private final AsciidoctorOptionsFactory asciidoctorOptionsFactory;

private final SourceDocumentFinder finder;

protected final ResourcesProcessor defaultResourcesProcessor;
protected final ResourcesProcessor resourcesProcessor;

@Inject
public AsciidoctorMojo(AsciidoctorJFactory asciidoctorJFactory, AsciidoctorOptionsFactory asciidoctorOptionsFactory, SourceDocumentFinder finder, ResourcesProcessor defaultResourcesProcessor) {
public AsciidoctorMojo(AsciidoctorJFactory asciidoctorJFactory,
AsciidoctorOptionsFactory asciidoctorOptionsFactory,
SourceDocumentFinder finder,
ResourcesProcessor resourcesProcessor) {
this.asciidoctorJFactory = asciidoctorJFactory;
this.asciidoctorOptionsFactory = asciidoctorOptionsFactory;
this.finder = finder;
this.defaultResourcesProcessor = defaultResourcesProcessor;
this.resourcesProcessor = resourcesProcessor;
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
processAllSources(defaultResourcesProcessor);
processAllSources(resourcesProcessor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
import static org.asciidoctor.maven.commons.StringUtils.isBlank;
import static org.asciidoctor.maven.commons.StringUtils.isNotBlank;

/**
* Creates an {@link OptionsBuilder} instance taking into consideration the project's
* configurations to be used or further customized.
* The instance also contains initialized {@link Attributes}.
*
* @author abelsromero
* @since 3.1.1
*/
@Singleton
public class AsciidoctorOptionsFactory {

Expand All @@ -24,7 +32,7 @@ public class AsciidoctorOptionsFactory {
* @param configuration AsciidoctorMojo containing conversion configuration.
* @param mavenProject Current {@link MavenProject} instance.
* @param log The mojo's {@link Log} reference.
* @return initialized attributesBuilder.
* @return initialized {@link Attributes}.
*/
private Attributes createAttributes(AsciidoctorMojo configuration, MavenProject mavenProject, Log log) {

Expand All @@ -50,11 +58,11 @@ private Attributes createAttributes(AsciidoctorMojo configuration, MavenProject
* Creates an OptionsBuilder instance with the options defined in the configuration.
*
* @param configuration AsciidoctorMojo containing conversion configuration.
* @param project Current {@link MavenProject} instance.
* @param mavenProject Current {@link MavenProject} instance.
* @param log The mojo's {@link Log} reference.
* @return initialized optionsBuilder.
*/
OptionsBuilder create(AsciidoctorMojo configuration, MavenProject project, Log log) {
OptionsBuilder create(AsciidoctorMojo configuration, MavenProject mavenProject, Log log) {

final OptionsBuilder optionsBuilder = Options.builder()
.backend(configuration.getBackend())
Expand Down Expand Up @@ -83,7 +91,7 @@ OptionsBuilder create(AsciidoctorMojo configuration, MavenProject project, Log l
if (!configuration.getTemplateDirs().isEmpty())
optionsBuilder.templateDirs(configuration.getTemplateDirs().toArray(new File[]{}));

final Attributes attributes = createAttributes(configuration, project, log);
final Attributes attributes = createAttributes(configuration, mavenProject, log);
return optionsBuilder.attributes(attributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
protected void doWork() {
long timeInMillis = TimeCounter.timed(() -> {
try {
processAllSources(defaultResourcesProcessor);
processAllSources(resourcesProcessor);
} catch (MojoExecutionException e) {
getLog().error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.io.IOException;

import jnr.ffi.annotations.In;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* - AsciiDoc documents: based on file extension.
* - Asciidoctor Docinfo files.
* - Internal files and folders: those not starting with underscore '_'.
*
* @since 3.0.0
*/
@Named
public class CopyResourcesProcessor implements ResourcesProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import org.asciidoctor.maven.AsciidoctorMojo;

/**
* @since 2.1.0
*/
public interface ResourcesProcessor {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* In that case, it only checks availability for the value provided as initial.
*
* @author abelsromero
* @since 2.0.0
*/
public class SourceDirectoryFinder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ class MojoMocker {
@SuppressWarnings("unchecked")
<T> T mock(Class<T> clazz, Map<String, String> mavenProperties, LogHandler logHandler) {

final AsciidoctorMojo mojo = (AsciidoctorMojo) clazz.getConstructors()[0].newInstance(new Object[]{null, null, null, null});
final AsciidoctorMojo mojo = (AsciidoctorMojo) clazz.getConstructors()[0].newInstance(new Object[]{
new AsciidoctorJFactory(),
new AsciidoctorOptionsFactory(),
new SourceDocumentFinder(),
new CopyResourcesProcessor()
});

parametersInitializer.initialize(mojo);
setVariableValueInObject(mojo, "log", new SystemStreamLog());
setVariableValueInObject(mojo, "project", mockMavenProject(mavenProperties));
setVariableValueInObject(mojo, "asciidoctorJFactory", new AsciidoctorJFactory());
setVariableValueInObject(mojo, "asciidoctorOptionsFactory", new AsciidoctorOptionsFactory());
setVariableValueInObject(mojo, "defaultResourcesProcessor", new CopyResourcesProcessor());
setVariableValueInObject(mojo, "finder", new SourceDocumentFinder());

if (logHandler != null)
setVariableValueInObject(mojo, "logHandler", logHandler);
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@
<version>4.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
Expand Down

0 comments on commit 246c26e

Please sign in to comment.