<commit_before>package com.byclosure.maven.plugins.middleman;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractJRubyMojo extends AbstractMojo {

	/**
	 * @parameter default-value="${project.basedir}" expression="${bundler.working_dir}"
	 */
	protected String working_dir;

	/**
	 * @parameter default-value="https://s3.amazonaws.com/jruby.org/downloads/1.7.19/jruby-bin-1.7.19.tar.gz" expression="${bundler.jruby_download_location}"
	 */
	protected String jruby_download_location;

	/**
	 * @parameter default-value="${project.basedir}/vendor" expression="${bundler.vendor}"
	 */
	protected String vendor;

	/**
	 * @parameter default-value="${project.basedir}/vendor/jruby-1.7.19/bin" expression="${bundler.jruby_home}"
	 */
	protected String jruby_bin;

	/**
	 * @parameter default-value="${project.basedir}/vendor/gem_home" expression="${bundler.gem_home}"
	 */
	protected String gem_home;

	/**
	 * @parameter default-value="${project.basedir}/vendor/gem_home" expression="${bundler.gem_home}"
	 */
	protected String gem_path;

	/**
	 * @parameter default-value="${project.basedir}/vendor/bin" expression="${bundler.binstubs}"
	 */
	protected String binstubs;

	/**
	 * @parameter default-value="1.8.2" expression="${bundler.bundler_version}"
	 */
	protected String bundler_version;

	protected abstract void executeComand() throws IOException;

	@Override
	public void execute() throws MojoExecutionException {
		try {
			extractJRubyToVendor();
			ensureBundlerInstalled();
			executeComand();
		} catch (IOException e) {
			throw new MojoExecutionException(e.getMessage());
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}


	protected void extractJRubyToVendor() throws IOException, URISyntaxException, MojoExecutionException {
		final File vendorDir = new File(vendor);
		vendorDir.mkdirs();

		final File jrubyToDownload = new File(jruby_download_location);
		final File jrubydownloadedFile = new File(vendorDir, jrubyToDownload.getName());

		if (!jrubydownloadedFile.exists()) {

			System.out.println("Downloading: " + jruby_download_location);
			final URL jrubyUrl = new URL(jruby_download_location);

			final ReadableByteChannel rbc = Channels.newChannel(jrubyUrl.openStream());
			final FileOutputStream fos = new FileOutputStream(jrubydownloadedFile);
			fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

			Decompressor.decompress(jrubydownloadedFile.getPath(), vendorDir.getPath() + "/");<commit_msg>[EASYEASY-1984] change var name to be more explicit<commit_after>package com.byclosure.maven.plugins.middleman;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.HashMap;
import java.util.Map;

public abstract class AbstractJRubyMojo extends AbstractMojo {

	/**
	 * @parameter default-value="${project.basedir}" expression="${bundler.working_dir}"
	 */
	protected String working_dir;

	/**
	 * @parameter default-value="https://s3.amazonaws.com/jruby.org/downloads/1.7.19/jruby-bin-1.7.19.tar.gz" expression="${bundler.jruby_download_location}"
	 */
	protected String jruby_download_url;

	/**
	 * @parameter default-value="${project.basedir}/vendor" expression="${bundler.vendor}"
	 */
	protected String vendor;

	/**
	 * @parameter default-value="${project.basedir}/vendor/jruby-1.7.19/bin" expression="${bundler.jruby_home}"
	 */
	protected String jruby_bin;

	/**
	 * @parameter default-value="${project.basedir}/vendor/gem_home" expression="${bundler.gem_home}"
	 */
	protected String gem_home;

	/**
	 * @parameter default-value="${project.basedir}/vendor/gem_home" expression="${bundler.gem_home}"
	 */
	protected String gem_path;

	/**
	 * @parameter default-value="${project.basedir}/vendor/bin" expression="${bundler.binstubs}"
	 */
	protected String binstubs;

	/**
	 * @parameter default-value="1.8.2" expression="${bundler.bundler_version}"
	 */
	protected String bundler_version;

	protected abstract void executeComand() throws IOException;

	@Override
	public void execute() throws MojoExecutionException {
		try {
			extractJRubyToVendor();
			ensureBundlerInstalled();
			executeComand();
		} catch (IOException e) {
			throw new MojoExecutionException(e.getMessage());
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}


	protected void extractJRubyToVendor() throws IOException, URISyntaxException, MojoExecutionException {
		final File vendorDir = new File(vendor);
		vendorDir.mkdirs();

		final File jrubyToDownload = new File(jruby_download_url);
		final File jrubydownloadedFile = new File(vendorDir, jrubyToDownload.getName());

		if (!jrubydownloadedFile.exists()) {

			System.out.println("Downloading: " + jruby_download_url);
			final URL jrubyUrl = new URL(jruby_download_url);

			final ReadableByteChannel rbc = Channels.newChannel(jrubyUrl.openStream());
			final FileOutputStream fos = new FileOutputStream(jrubydownloadedFile);
			fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

			Decompressor.decompress(jrubydownloadedFile.getPath(), vendorDir.getPath() + "/");
{'fraction_non_alphanumeric': 0.132996632996633, 'fraction_numerical': 0.006397306397306397, 'mean_word_length': 5.422702702702702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662396', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1784, 'n_words': 323}