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

edu.illinois.nondex.plugin.AbstractNondexMojo Maven / Gradle / Ivy

There is a newer version: 2.1.7
Show newest version
/*
The MIT License (MIT)
Copyright (c) 2015 Alex Gyori
Copyright (c) 2015 Owolabi Legunsen
Copyright (c) 2015 Darko Marinov
Copyright (c) 2015 August Shi


Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package edu.illinois.nondex.plugin;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;

import edu.illinois.nondex.common.ConfigurationDefaults;
import edu.illinois.nondex.common.Logger;
import edu.illinois.nondex.common.Mode;
import edu.illinois.nondex.common.Utils;
import edu.illinois.nondex.instr.Instrumenter;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

@Execute(phase = LifecyclePhase.TEST_COMPILE)
public abstract class AbstractNondexMojo extends AbstractMojo {
    // NonDex Mojo specific properties
    /**
     * The seed that is used for randomization during shuffling.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_SEED, defaultValue = ConfigurationDefaults.DEFAULT_SEED_STR)
    protected int seed;

    /**
     * The degree/level of shuffling that should be carried out.
     * Section III.B in http://mir.cs.illinois.edu/~awshi2/publications/ICST2016.pdf)
     * The options are:
     * FULL: shuffle on each invocation of methods with nondeterministic specs
     * ID: does not shuffle during invocations on objects with same identity
     * EQ: does not shuffle during invocations on objects that are equal
     * ONE: only shuffle on the first invocation of an object
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_MODE, defaultValue = ConfigurationDefaults.DEFAULT_MODE_STR)
    protected Mode mode;

    /**
     * Regex filter used to whitelist the sources of non-determinism to explore.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_FILTER, defaultValue = ConfigurationDefaults.DEFAULT_FILTER)
    protected String filter;

    /**
     * Starting point of the range of invocations to use during the debug phase.
     * The minimum value is 0 and the maximum can be obtained from first running
     * the nondex phase. If start and end have the same value, then only the
     * invocation at that value is shuffled.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_START, defaultValue = ConfigurationDefaults.DEFAULT_START_STR)
    protected long start;

    /**
     * Ending point of the range of invocations to use during the debug phase.
     * The minimum value is 0 and the maximum can be obtained from first running
     * the nondex phase. If start and end have the same value, then only the
     * invocation at that value is shuffled.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_START, defaultValue = ConfigurationDefaults.DEFAULT_END_STR)
    protected long end;


    /**
     * The number of seeds to use for shuffle. NonDex will obtain other seeds
     * apart from the specified (or default) seed from the current run and
     * some internal factor.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_NUM_RUNS,
            defaultValue = ConfigurationDefaults.DEFAULT_NUM_RUNS_STR)
    protected int numRuns;

    /**
     * Set this to "true" to rerun multiple times with only the specified (or
     * default) seed. The number of reruns is equal to numRuns.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_RERUN,
            defaultValue = ConfigurationDefaults.DEFAULT_RERUN_STR)
    protected boolean rerun;

    /**
     * Unique ID for the current nondex execution.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_EXECUTION_ID,
            defaultValue = ConfigurationDefaults.PROPERTY_DEFAULT_EXECUTION_ID)
    protected String executionId;

    /**
     * Select which run to perform debugging on. Default is the latest.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_RUN_ID,
            defaultValue = ConfigurationDefaults.PROPERTY_DEFAULT_RUN_ID)
    protected String runId;

    /**
     * Same as the levels defined in java.util.logging.Level.
     */
    @Parameter(property = ConfigurationDefaults.PROPERTY_LOGGING_LEVEL,
            defaultValue = ConfigurationDefaults.DEFAULT_LOGGING_LEVEL)
    protected String loggingLevel;

    // Generic properties
    @Parameter(property = "project")
    protected MavenProject mavenProject;
    @Parameter(defaultValue = "${project.build.directory}")
    protected String projectBuildDir;
    @Parameter(defaultValue = "${basedir}")
    protected File baseDir;
    @Parameter(property = "goal", alias = "mojo")
    protected String goal;
    @Component
    protected MavenSession mavenSession;
    @Component
    protected BuildPluginManager pluginManager;

    protected Plugin surefire;
    protected String originalArgLine;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        Logger.getGlobal().setLoggineLevel(Level.parse(this.loggingLevel));
        Path rtJarPath;
        rtJarPath = Utils.getRtJarLocation();
        if (rtJarPath == null) {
            Logger.getGlobal().log(Level.SEVERE, "Cannot find the rt.jar!");
            throw new MojoExecutionException("Cannot find the rt.jar!");
        }

        try {
            File fileForJar = Paths.get(this.baseDir.getAbsolutePath(),
                    ConfigurationDefaults.DEFAULT_NONDEX_JAR_DIR).toFile();

            fileForJar.mkdirs();
            Instrumenter.instrument(rtJarPath.toString(), Paths.get(fileForJar.getAbsolutePath(),
                    ConfigurationDefaults.INSTRUMENTATION_JAR).toString());
        } catch (IOException exc) {
            exc.printStackTrace();
        } catch (NoSuchAlgorithmException exc) {
            exc.printStackTrace();
        }

        this.surefire = this.lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin");

        Properties localProperties = this.mavenProject.getProperties();
        this.originalArgLine = localProperties.getProperty("argLine", "");
    }

    private Plugin lookupPlugin(String paramString) {
        List localList = this.mavenProject.getBuildPlugins();
        Iterator localIterator = localList.iterator();
        while (localIterator.hasNext()) {
            Plugin localPlugin = localIterator.next();
            if (paramString.equalsIgnoreCase(localPlugin.getKey())) {
                return localPlugin;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy