All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nocrala.tools.database.sentinel.maven.TakeSnapshotMojo Maven / Gradle / Ivy

package org.nocrala.tools.database.sentinel.maven;

import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.nocrala.tools.database.sentinel.plugin.TakeSnapshotOperation;
import org.nocrala.tools.database.sentinel.util.SUtil;

@Mojo(name = "take-snapshot", defaultPhase = LifecyclePhase.COMPILE) // Goal name set to "take-snapshot"
public class TakeSnapshotMojo extends AbstractMojo {

  private static final Logger log = LogManager.getLogger(TakeSnapshotMojo.class);

  // Parameters

  @Parameter()
  private String driverclass = null;

  @Parameter()
  private String url = null;

  @Parameter()
  private String username = null;

  @Parameter()
  private String password = null;

  @Parameter()
  private String catalog = null;

  @Parameter()
  private String schema = null;

  @Parameter()
  private String snapshotfile = null;

  // Project information

  @Parameter(defaultValue = "${project}", required = true, readonly = true)
  private MavenProject project;

  public void execute() throws MojoExecutionException {
    log.debug("init");
    validateParameters();
    try {
      new TakeSnapshotOperation(this.driverclass, this.url, this.username, this.password, this.catalog, this.schema,
          new File(this.project.getBasedir(), this.snapshotfile)).execute(new MojoFeedback(this));
    } catch (Exception e) {
      throw new MojoExecutionException(e.getMessage(), e.getCause());
    }
  }

  private void validateParameters() throws MojoExecutionException {
    if (SUtil.isEmpty(this.driverclass)) {
      throw new MojoExecutionException("Parameter 'driverclass' must be specified.");
    }
    if (SUtil.isEmpty(this.url)) {
      throw new MojoExecutionException("Parameter 'url' must be specified.");
    }
    if (SUtil.isEmpty(this.username)) {
      throw new MojoExecutionException("Parameter 'username' must be specified.");
    }
    if (SUtil.isEmpty(this.snapshotfile)) {
      throw new MojoExecutionException("Parameter 'snapshotfile' must be specified.");
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy