<commit_before>package de.saumya.mojo.rspec;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.sonatype.aether.RepositorySystemSession;

import de.saumya.mojo.ruby.gems.GemException;
import de.saumya.mojo.ruby.script.Script;
import de.saumya.mojo.ruby.script.ScriptException;
import de.saumya.mojo.runit.AbstractTestMojo;
import de.saumya.mojo.runit.JRubyRun.Mode;
import de.saumya.mojo.runit.JRubyRun.Result;

/**
 * executes the jruby command.
 * 
 * @goal test
 * @phase test
 * @requiresDependencyResolution test
 */
public class RSpecMojo extends AbstractTestMojo {

    /**
     * The project base directory
     * 
     * @parameter expression="${basedir}"
     * @required
     * @readonly
     */
    protected File                  basedir;

    /**
     * The classpath elements of the project being tested.
     * 
     * @parameter expression="${project.testClasspathElements}"
     * @required
     * @readonly
     */
    protected List<String>          classpathElements;

    /** @parameter default-value="${skipSpecs}" */
    protected boolean               skipSpecs = false;

    /**
     * The directory containing the RSpec source files
     * 
     * @parameter expression="spec"
     */
    protected String                specSourceDirectory;

    /**
     * The directory where the RSpec report will be written to
     * 
     * @parameter expression="target"
     * @required
     */
    protected File                  outputDirectory;

    /**
     * The name of the RSpec report (optional, defaults to "rspec-report.html")
     * 
     * @parameter expression="rspec-report.html"
     */
    protected String                reportName;

    /**
     * List of system properties to set for the tests.
     * 
     * @parameter
     */
    protected Properties            systemProperties;

    /**
     * rspec version used when there is no pom. default is latest version.
     * 
     * @parameter default-value="${rspec.version}"
     */
    private String                  rspecVersion;

    /**
     * @parameter default-value="${repositorySystemSession}"
     * @readonly
     */
    private RepositorySystemSession repoSession;

    private ScriptFactory           rspecScriptFactory;

    private String                  reportPath;

    private File specSourceDirectory() {
        return new File(launchDirectory(), this.specSourceDirectory);
    }

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        if (this.skipTests || this.skipSpecs) {
            getLog().info("Skipping RSpec tests");
            return;
        }
        else {
            super.execute();
        }
    }

    @Override
    public void executeWithGems() throws MojoExecutionException,
            ScriptException, IOException, GemException {
        final File specSourceDirectory = specSourceDirectory();
        if (!specSourceDirectory.exists() && this.args == null) {
            getLog().info("Skipping RSpec tests since " + specSourceDirectory
                    + " is missing");
            return;
        }
        getLog().info("Running RSpec tests from " + specSourceDirectory);

        if (this.project.getBasedir() == null) {

            this.rspecVersion = this.gemsInstaller.installGem("rspec",
                                                              this.rspecVersion,
                                                              this.repoSession,
                                                              this.localRepository)
                    .getVersion();

        }

        this.reportPath = new File(this.outputDirectory, this.reportName).getAbsolutePath();

        initScriptFactory(getRSpecScriptFactory(), this.reportPath);

        try {
            this.rspecScriptFactory.emit();
        }
        catch (final Exception e) {
            getLog().error("error emitting .rb", e);
        }

        super.executeWithGems();
    }

    protected Result runIt(de.saumya.mojo.ruby.script.ScriptFactory factory,
            Mode mode, String version) throws IOException, ScriptException,
            MojoExecutionException {
        
        Script script = factory.newScript(this.rspecScriptFactory.getScriptFile());
        script.addArgs(this.args);
        script.executeIn(launchDirectory());

        final File reportFile;
        if (mode != Mode.DEFAULT) {
            reportFile = new File(reportPath.replace(".html", "-" + version
                    + mode.name() + ".html"));
        }
        else if (this.jrubyVersion.equals(version)) {
            reportFile = new File(reportPath);
        }
        else {
            reportFile = new File(reportPath.replace(".html", "-" + version
                    + ".html"));
        }
        new File(reportPath).renameTo(reportFile);

        Result result = new Result();
        Reader in = null;<commit_msg>added initial value for result.message, as guard for NPE<commit_after>package de.saumya.mojo.rspec;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.sonatype.aether.RepositorySystemSession;

import de.saumya.mojo.ruby.gems.GemException;
import de.saumya.mojo.ruby.script.Script;
import de.saumya.mojo.ruby.script.ScriptException;
import de.saumya.mojo.runit.AbstractTestMojo;
import de.saumya.mojo.runit.JRubyRun.Mode;
import de.saumya.mojo.runit.JRubyRun.Result;

/**
 * executes the jruby command.
 * 
 * @goal test
 * @phase test
 * @requiresDependencyResolution test
 */
public class RSpecMojo extends AbstractTestMojo {

    /**
     * The project base directory
     * 
     * @parameter expression="${basedir}"
     * @required
     * @readonly
     */
    protected File                  basedir;

    /**
     * The classpath elements of the project being tested.
     * 
     * @parameter expression="${project.testClasspathElements}"
     * @required
     * @readonly
     */
    protected List<String>          classpathElements;

    /** @parameter default-value="${skipSpecs}" */
    protected boolean               skipSpecs = false;

    /**
     * The directory containing the RSpec source files
     * 
     * @parameter expression="spec"
     */
    protected String                specSourceDirectory;

    /**
     * The directory where the RSpec report will be written to
     * 
     * @parameter expression="target"
     * @required
     */
    protected File                  outputDirectory;

    /**
     * The name of the RSpec report (optional, defaults to "rspec-report.html")
     * 
     * @parameter expression="rspec-report.html"
     */
    protected String                reportName;

    /**
     * List of system properties to set for the tests.
     * 
     * @parameter
     */
    protected Properties            systemProperties;

    /**
     * rspec version used when there is no pom. default is latest version.
     * 
     * @parameter default-value="${rspec.version}"
     */
    private String                  rspecVersion;

    /**
     * @parameter default-value="${repositorySystemSession}"
     * @readonly
     */
    private RepositorySystemSession repoSession;

    private ScriptFactory           rspecScriptFactory;

    private String                  reportPath;

    private File specSourceDirectory() {
        return new File(launchDirectory(), this.specSourceDirectory);
    }

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        if (this.skipTests || this.skipSpecs) {
            getLog().info("Skipping RSpec tests");
            return;
        }
        else {
            super.execute();
        }
    }

    @Override
    public void executeWithGems() throws MojoExecutionException,
            ScriptException, IOException, GemException {
        final File specSourceDirectory = specSourceDirectory();
        if (!specSourceDirectory.exists() && this.args == null) {
            getLog().info("Skipping RSpec tests since " + specSourceDirectory
                    + " is missing");
            return;
        }
        getLog().info("Running RSpec tests from " + specSourceDirectory);

        if (this.project.getBasedir() == null) {

            this.rspecVersion = this.gemsInstaller.installGem("rspec",
                                                              this.rspecVersion,
                                                              this.repoSession,
                                                              this.localRepository)
                    .getVersion();

        }

        this.reportPath = new File(this.outputDirectory, this.reportName).getAbsolutePath();

        initScriptFactory(getRSpecScriptFactory(), this.reportPath);

        try {
            this.rspecScriptFactory.emit();
        }
        catch (final Exception e) {
            getLog().error("error emitting .rb", e);
        }

        super.executeWithGems();
    }

    protected Result runIt(de.saumya.mojo.ruby.script.ScriptFactory factory,
            Mode mode, String version) throws IOException, ScriptException,
            MojoExecutionException {
        
        Script script = factory.newScript(this.rspecScriptFactory.getScriptFile());
        script.addArgs(this.args);
        script.executeIn(launchDirectory());

        final File reportFile;
        if (mode != Mode.DEFAULT) {
            reportFile = new File(reportPath.replace(".html", "-" + version
                    + mode.name() + ".html"));
        }
        else if (this.jrubyVersion.equals(version)) {
            reportFile = new File(reportPath);
        }
        else {
            reportFile = new File(reportPath.replace(".html", "-" + version
                    + ".html"));
        }
        new File(reportPath).renameTo(reportFile);

        Result result = new Result();
		result.message = "";
        Reader in = null;
{'fraction_non_alphanumeric': 0.10089728904161893, 'fraction_numerical': 0.0, 'mean_word_length': 2.022792844777842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2497723', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2646, 'n_words': 606}