diff --git a/pom.xml b/pom.xml index 18a0974e..66b3d9e8 100644 --- a/pom.xml +++ b/pom.xml @@ -76,8 +76,12 @@ maven-plugin-api - commons-lang - commons-lang + org.apache.commons + commons-lang3 + + + commons-configuration + commons-configuration org.apache.maven @@ -111,7 +115,7 @@ org.jbake jbake-core - 2.6.4 + 2.6.5 org.apache.maven @@ -119,14 +123,19 @@ 3.3.9 - commons-lang - commons-lang - 2.6 + org.apache.commons + commons-lang3 + 3.10 + + + commons-configuration + commons-configuration + 1.10 commons-io commons-io - 2.4 + 2.6 org.apache.maven.plugin-testing @@ -233,12 +242,12 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 2.8.1 + 2.9 org.apache.maven.plugins maven-plugin-plugin - 3.4 + 3.6.0 org.apache.maven.plugins diff --git a/src/main/java/org/jbake/maven/GenerateMojo.java b/src/main/java/org/jbake/maven/GenerateMojo.java index c9ee76d5..499b82cf 100644 --- a/src/main/java/org/jbake/maven/GenerateMojo.java +++ b/src/main/java/org/jbake/maven/GenerateMojo.java @@ -16,8 +16,6 @@ * limitations under the License. */ -import com.orientechnologies.orient.core.Orient; - import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.MapConfiguration; import org.apache.maven.plugin.AbstractMojo; @@ -28,9 +26,9 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.jbake.app.Oven; -import org.jbake.app.configuration.ConfigUtil; import org.jbake.app.configuration.DefaultJBakeConfiguration; import org.jbake.app.configuration.JBakeConfiguration; +import org.jbake.app.configuration.JBakeConfigurationFactory; import java.io.File; @@ -39,81 +37,63 @@ */ @Mojo(name = "generate", requiresProject = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) public class GenerateMojo extends AbstractMojo { - @Parameter(defaultValue="${project}") - protected MavenProject project; - - /** - * Location of the Output Directory. - */ - @Parameter(property = "jbake.outputDirectory", - defaultValue = "${project.build.directory}/${project.build.finalName}", - required = true) - protected File outputDirectory; - - /** - * Location of the Output Directory. - */ - @Parameter(property = "jbake.inputDirectory", defaultValue = "${project.basedir}/src/main/jbake", - required = true) - protected File inputDirectory; - - /** - * Breaks the build when {@code true} and errors occur during baking in JBake oven. - */ - @Parameter(property = "jbake.failOnError", defaultValue = "true") - protected boolean failOnError; - - /** - * Set if cache is present or clear - */ - @Parameter(property = "jbake.isClearCache", defaultValue = "false", required = true) - protected boolean isClearCache; - - public final void execute() throws MojoExecutionException, MojoFailureException { - try { - executeInternal(); - } finally { - closeQuietly(); + @Parameter(defaultValue = "${project}") + protected MavenProject project; + + /** + * Location of the Output Directory. + */ + @Parameter(property = "jbake.outputDirectory", + defaultValue = "${project.build.directory}/${project.build.finalName}", + required = true) + protected File outputDirectory; + + /** + * Location of the Output Directory. + */ + @Parameter(property = "jbake.inputDirectory", defaultValue = "${project.basedir}/src/main/jbake", + required = true) + protected File inputDirectory; + + /** + * Breaks the build when {@code true} and errors occur during baking in JBake oven. + */ + @Parameter(property = "jbake.failOnError", defaultValue = "true") + protected boolean failOnError; + + /** + * Set if cache is present or clear + */ + @Parameter(property = "jbake.isClearCache", defaultValue = "false", required = true) + protected boolean isClearCache; + + public final void execute() throws MojoExecutionException { + executeInternal(); } - } - protected final void closeQuietly() { - try { - Orient.instance().shutdown(); - } catch (Exception e) { - getLog().warn("Oops", e); + protected void executeInternal() throws MojoExecutionException { + reRender(); } - } - protected void executeInternal() throws MojoExecutionException, MojoFailureException { - reRender(); - } - - protected void reRender() throws MojoExecutionException, MojoFailureException { - try { - // TODO: Smells bad. A lot - Orient.instance().startup(); - - // TODO: At some point, reuse Oven - Oven oven = new Oven(createConfiguration()); - - oven.bake(); - if (failOnError && !oven.getErrors().isEmpty()) { - throw new MojoFailureException("Baked with " + oven.getErrors().size() + " errors. Check output above for details!"); - } - } catch (Exception e) { - getLog().info("Oops", e); - - throw new MojoExecutionException("Failure when running: ", e); + protected void reRender() throws MojoExecutionException { + try { + // TODO: At some point, reuse Oven + Oven oven = new Oven(createConfiguration()); + oven.bake(); + if (failOnError && !oven.getErrors().isEmpty()) { + throw new MojoFailureException("Baked with " + oven.getErrors().size() + " errors. Check output above for details!"); + } + } catch (Exception e) { + getLog().info("Oops", e); + + throw new MojoExecutionException("Failure when running: ", e); + } } - } - protected JBakeConfiguration createConfiguration() throws ConfigurationException { - DefaultJBakeConfiguration jBakeConfiguration = (DefaultJBakeConfiguration) new ConfigUtil().loadConfig(inputDirectory); - jBakeConfiguration.getCompositeConfiguration().addConfiguration(new MapConfiguration(this.project.getProperties())); - jBakeConfiguration.setDestinationFolder(outputDirectory); - jBakeConfiguration.setClearCache(isClearCache); - return jBakeConfiguration; - } + protected JBakeConfiguration createConfiguration() throws ConfigurationException { + DefaultJBakeConfiguration jBakeConfiguration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(inputDirectory, outputDirectory, isClearCache); + jBakeConfiguration.getCompositeConfiguration().addConfiguration(new MapConfiguration(this.project.getProperties())); + return jBakeConfiguration; + } } diff --git a/src/main/java/org/jbake/maven/WatchMojo.java b/src/main/java/org/jbake/maven/WatchMojo.java index 6402af07..5c47575b 100644 --- a/src/main/java/org/jbake/maven/WatchMojo.java +++ b/src/main/java/org/jbake/maven/WatchMojo.java @@ -33,10 +33,10 @@ @Mojo(name = "watch", requiresDirectInvocation = true, requiresProject = false) public class WatchMojo extends GenerateMojo { - public void executeInternal() throws MojoExecutionException, MojoFailureException { + public void executeInternal() throws MojoExecutionException { reRender(); - Long lastProcessed = Long.valueOf(System.currentTimeMillis()); + Long lastProcessed = System.currentTimeMillis(); getLog().info( "Now listening for changes on path " + inputDirectory.getPath());