Package ch.hortis.sonar.mvn

Source Code of ch.hortis.sonar.mvn.DBMojo

package ch.hortis.sonar.mvn;

import java.io.File;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

import ch.hortis.sonar.db.DatabaseEmbedder;

/**
* Sonar embedded database runner plugin
*
* @goal run
*/
public class DBMojo extends AbstractMojo {

  /**
   * DBHome
   *
   * @parameter expression="${sonar.db.home}" default-value="./derby" alias="sonar.db.home"
   */
  private File dbHome;

  public void execute() throws MojoExecutionException {
    final DatabaseEmbedder embedder = new DatabaseEmbedder( dbHome );
    try {
      embedder.start();
      getLog().info("Embedded database started, press ctrl C to stop the process");
      Runtime.getRuntime().addShutdownHook( new Thread() {
        public void run() {
          try {
            embedder.stop();
            getLog().info("Embedded database stopped");
          } catch ( Exception e ) {
            System.err.println("Error during embedded database shutdown");
            e.printStackTrace( System.err );
          }
        }
      });
    } catch ( Exception e ) {
      throw new MojoExecutionException("Error during embedded database startup", e);
    }
    try {
      Thread.currentThread().join();
    } catch ( InterruptedException e ) {
      throw new MojoExecutionException("Interrupted exception", e);
    }
  }
 
}
TOP

Related Classes of ch.hortis.sonar.mvn.DBMojo

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.