<commit_before>// (c) Copyright 2011 Odiago, Inc.

package com.odiago.maven.plugins.hbase;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.hadoop.conf.Configuration;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

/**
 * A maven goal that starts a mini HBase cluster in a new daemon thread.
 *
 * <p>A new daemon thread is created that starts a mini HBase cluster.  The main thread
 * blocks until the HBase cluster has full started.  The daemon thread with the
 * in-process HBase cluster will continue to run in the background until stopped by the
 * 'stop' goal of the plugin.</p>
 *
 * <p>The configuration of the started mini HBase cluster will be written to a
 * hbase-site.xml file in the test classpath ('${basedir}/target/test-classes' by
 * default).  The path to the generated configuration file may be customized with the
 * 'hbaseSiteFile' property</p>
 *
 * @goal start
 * @phase pre-integration-test
 * @requiresDependencyResolution test
 */
public class StartMojo extends AbstractMojo {
  /**
   * The file that will store the configuration required to connect to the started mini HBase
   * cluster.  This file will be generated by the goal.
   *
   * @parameter property="hbaseSiteFile" expression="${hbase.site.file}" default-value="${project.build.testOutputDirectory}/hbase-site.xml"
   * @required
   */
  private File mHBaseSiteFile;

  /**
   * If true, also start a mini MapReduce cluster.
   *
   * @parameter property="mapReduceEnabled" expression="${mapreduce.enabled}" default-value="false"
   */
  private boolean mIsMapReduceEnabled;

  /**
   * Extra Hadoop configuration properties to use.
   *
   * @parameter property="hadoopConfiguration"
   */
  private Properties mHadoopConfiguration;

  /**
   * A list of this plugin's dependency artifacts.
   *
   * @parameter default-value="${plugin.artifacts}"
   * @required
   * @readonly
   */
  private List<Artifact> mPluginDependencyArtifacts;


  /**
   * The maven project this plugin is running within.
   *
   * @parameter default-value="${project}"
   * @required
   * @readonly
   */
  private MavenProject mMavenProject;

  /**
   * Sets the file that we should write the HBase cluster configuration to.
   *
   * <p>Note: The property "hbaseSiteFile" defined in this mojo means this method must be
   * named setHbaseSiteFile instead of setHBaseSiteFile.</p>
   *
   * @param hbaseSiteFile The file we should write to.
   */
  public void setHbaseSiteFile(File hbaseSiteFile) {
    mHBaseSiteFile = hbaseSiteFile;
  }

  /**
   * Sets whether we should start a mini MapReduce cluster in addition to the HBase cluster.
   *
   * @param enabled Whether to start a mini MapReduce cluster.
   */
  public void setMapReduceEnabled(boolean enabled) {
    mIsMapReduceEnabled = enabled;
  }

  /**
   * Sets Hadoop configuration properties.
   *
   * @param properties Hadoop configuration properties to use in the mini cluster.
   */
  public void setHadoopConfiguration(Properties properties) {
    mHadoopConfiguration = properties;
  }

  /**
   * Starts a mini HBase cluster in a new thread.
   *
   * <p>This method is called by the maven plugin framework to run the goal.</p>
   *
   * @throws MojoExecutionException If there is a fatal error during this goal's execution.
   */
  @Override
  public void execute() throws MojoExecutionException {
    System.setProperty("java.class.path", getClassPath());
    getLog().info("Set java.class.path to: " + System.getProperty("java.class.path"));

    // Set any extra hadoop options.
    Configuration conf = new Configuration();
    if (null != mHadoopConfiguration) {
      for (Map.Entry<Object, Object> property : mHadoopConfiguration.entrySet()) {
        String confKey = property.getKey().toString();
        String confValue = property.getValue().toString();
        getLog().info("Setting hadoop conf property '" + confKey + "' to '" + confValue + "'");
        conf.set(confKey, confValue);
      }
    }

    // Start the cluster.
    try {
      MiniHBaseClusterSingleton.INSTANCE.startAndWaitUntilReady(
          getLog(), mIsMapReduceEnabled, conf);
    } catch (IOException e) {
      throw new MojoExecutionException("Unable to start HBase cluster.", e);
    }

    // Create an hbase conf file to write.
    File parentDir = mHBaseSiteFile.getParentFile();
    if (null != parentDir && !parentDir.exists() && !parentDir.mkdirs()) {
      throw new MojoExecutionException(
          "Unable to create hbase conf file: " + mHBaseSiteFile.getPath());<commit_msg>WIBI-346. hbase-maven-plugin should have a <skip> param.<commit_after>// (c) Copyright 2011 Odiago, Inc.

package com.odiago.maven.plugins.hbase;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.hadoop.conf.Configuration;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

/**
 * A maven goal that starts a mini HBase cluster in a new daemon thread.
 *
 * <p>A new daemon thread is created that starts a mini HBase cluster.  The main thread
 * blocks until the HBase cluster has full started.  The daemon thread with the
 * in-process HBase cluster will continue to run in the background until stopped by the
 * 'stop' goal of the plugin.</p>
 *
 * <p>The configuration of the started mini HBase cluster will be written to a
 * hbase-site.xml file in the test classpath ('${basedir}/target/test-classes' by
 * default).  The path to the generated configuration file may be customized with the
 * 'hbaseSiteFile' property</p>
 *
 * @goal start
 * @phase pre-integration-test
 * @requiresDependencyResolution test
 */
public class StartMojo extends AbstractMojo {
  /**
   * If true, this goal should be a no-op.
   *
   * @parameter property="skip" default-value="false"
   */
  private boolean mSkip;

  /**
   * The file that will store the configuration required to connect to the started mini HBase
   * cluster.  This file will be generated by the goal.
   *
   * @parameter property="hbaseSiteFile" expression="${hbase.site.file}" default-value="${project.build.testOutputDirectory}/hbase-site.xml"
   * @required
   */
  private File mHBaseSiteFile;

  /**
   * If true, also start a mini MapReduce cluster.
   *
   * @parameter property="mapReduceEnabled" expression="${mapreduce.enabled}" default-value="false"
   */
  private boolean mIsMapReduceEnabled;

  /**
   * Extra Hadoop configuration properties to use.
   *
   * @parameter property="hadoopConfiguration"
   */
  private Properties mHadoopConfiguration;

  /**
   * A list of this plugin's dependency artifacts.
   *
   * @parameter default-value="${plugin.artifacts}"
   * @required
   * @readonly
   */
  private List<Artifact> mPluginDependencyArtifacts;


  /**
   * The maven project this plugin is running within.
   *
   * @parameter default-value="${project}"
   * @required
   * @readonly
   */
  private MavenProject mMavenProject;

  /**
   * Sets whether this goal should be a no-op.
   *
   * @param skip If true, this goal should do nothing.
   */
  public void setSkip(boolean skip) {
    mSkip = skip;
  }

  /**
   * Sets the file that we should write the HBase cluster configuration to.
   *
   * <p>Note: The property "hbaseSiteFile" defined in this mojo means this method must be
   * named setHbaseSiteFile instead of setHBaseSiteFile.</p>
   *
   * @param hbaseSiteFile The file we should write to.
   */
  public void setHbaseSiteFile(File hbaseSiteFile) {
    mHBaseSiteFile = hbaseSiteFile;
  }

  /**
   * Sets whether we should start a mini MapReduce cluster in addition to the HBase cluster.
   *
   * @param enabled Whether to start a mini MapReduce cluster.
   */
  public void setMapReduceEnabled(boolean enabled) {
    mIsMapReduceEnabled = enabled;
  }

  /**
   * Sets Hadoop configuration properties.
   *
   * @param properties Hadoop configuration properties to use in the mini cluster.
   */
  public void setHadoopConfiguration(Properties properties) {
    mHadoopConfiguration = properties;
  }

  /**
   * Starts a mini HBase cluster in a new thread.
   *
   * <p>This method is called by the maven plugin framework to run the goal.</p>
   *
   * @throws MojoExecutionException If there is a fatal error during this goal's execution.
   */
  @Override
  public void execute() throws MojoExecutionException {
    if (mSkip) {
      getLog().info("Not starting an HBase cluster because skip=true.");
      return;
    }

    System.setProperty("java.class.path", getClassPath());
    getLog().info("Set java.class.path to: " + System.getProperty("java.class.path"));

    // Set any extra hadoop options.
    Configuration conf = new Configuration();
    if (null != mHadoopConfiguration) {
      for (Map.Entry<Object, Object> property : mHadoopConfiguration.entrySet()) {
        String confKey = property.getKey().toString();
        String confValue = property.getValue().toString();
        getLog().info("Setting hadoop conf property '" + confKey + "' to '" + confValue + "'");
        conf.set(confKey, confValue);
      }
    }

    // Start the cluster.
    try {
      MiniHBaseClusterSingleton.INSTANCE.startAndWaitUntilReady(
          getLog(), mIsMapReduceEnabled, conf);
    } catch (IOException e) {
      throw new MojoExecutionException("Unable to start HBase cluster.", e);
    }

    // Create an hbase conf file to write.
    File parentDir = mHBaseSiteFile.getParentFile();
    if (null != parentDir && !parentDir.exists() && !parentDir.mkdirs()) {
      throw new MojoExecutionException(
          "Unable to create hbase conf file: " + mHBaseSiteFile.getPath());
{'fraction_non_alphanumeric': 0.10226393188854489, 'fraction_numerical': 0.0010642414860681114, 'mean_word_length': 3.476829796448679, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6200491', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2928, 'n_words': 952}