Package br.com.ingenieux.mojo.jbake

Source Code of br.com.ingenieux.mojo.jbake.GenerateMojo

package br.com.ingenieux.mojo.jbake;

/*
* Copyright 2013 ingenieux Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.orientechnologies.orient.core.Orient;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.jbake.app.Oven;

import java.io.File;

/**
* Runs jbake on a folder
*/
@Mojo(name = "generate", requiresProject = false)
public class GenerateMojo extends AbstractMojo {

  /**
   * 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;

  /**
   * Set if cache is present or clear
   */
  @Parameter(property = "jbake.isClearCache", defaultValue = "false", required = true)
  protected boolean isClearCache;

  public final void execute() throws MojoExecutionException {
    try {
      executeInternal();
    } finally {
      closeQuietly();
    }
  }

  protected final void closeQuietly() {
    try {
      Orient.instance().shutdown();
    } catch (Exception e) {
      getLog().warn("Oops", e);
    }
  }

  protected void executeInternal() throws MojoExecutionException {
    reRender();
  }

  protected void reRender() throws MojoExecutionException {
    try {
      // TODO: At some point, reuse Oven
      Oven oven = new Oven(inputDirectory, outputDirectory, isClearCache);

      oven.setupPaths();

      oven.bake();
    } catch (Exception e) {
      getLog().info("Oops", e);

      throw new MojoExecutionException("Failure when running: ", e);
    }
  }
}
TOP

Related Classes of br.com.ingenieux.mojo.jbake.GenerateMojo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.