Skip to content

Commit

Permalink
Merge pull request jbake-org#30 from ancho/update/jbake-2.6.5
Browse files Browse the repository at this point in the history
update jbake to 2.6.5
  • Loading branch information
jonbullock authored May 11, 2020
2 parents 33846f2 + 9192424 commit a7821ec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 84 deletions.
27 changes: 18 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@
<artifactId>maven-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -111,22 +115,27 @@
<dependency>
<groupId>org.jbake</groupId>
<artifactId>jbake-core</artifactId>
<version>2.6.4</version>
<version>2.6.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
Expand Down Expand Up @@ -233,12 +242,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version>
<version>2.9</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
126 changes: 53 additions & 73 deletions src/main/java/org/jbake/maven/GenerateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/jbake/maven/WatchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a7821ec

Please sign in to comment.