Search in sources :

Example 1 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class ChangeDetectorSelector method init.

@Override
public void init(InputConfiguration configuration) {
    this.configuration = configuration;
    this.program = this.configuration.getInputProgram();
    final String configurationPath = configuration.getProperty("configPath");
    final String pathToFolder = configuration.getProperty("folderPath");
    InputConfiguration inputConfiguration;
    try {
        inputConfiguration = new InputConfiguration(configurationPath);
        InputProgram inputProgram = InputConfiguration.initInputProgram(inputConfiguration);
        inputConfiguration.setInputProgram(inputProgram);
        this.pathToChangedVersionOfProgram = pathToFolder + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + (inputConfiguration.getProperty("targetModule") != null ? inputConfiguration.getProperty("targetModule") + DSpotUtils.shouldAddSeparator.apply(pathToFolder) : "");
        inputProgram.setProgramDir(this.pathToChangedVersionOfProgram);
        Initializer.initialize(inputConfiguration, inputProgram);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Example 2 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class MemoryClassLoaderFactory method createMemoryClassLoader.

/*
        Here: the factory has the same behavior than @see fr.inria.stamp.test.runner.TestRunnerFactory
            We will use the parent of the system classloader in special case
     */
public static MemoryClassLoader createMemoryClassLoader(CtType<?> testClass, InputConfiguration configuration) {
    final InputProgram program = configuration.getInputProgram();
    final String classesDirectory = program.getProgramDir() + "/" + program.getClassesDir();
    final String testClassesDirectory = program.getProgramDir() + "/" + program.getTestClassesDir();
    String classpath = AutomaticBuilderFactory.getAutomaticBuilder(configuration).buildClasspath(program.getProgramDir()) + PATH_SEPARATOR + "target/dspot/dependencies/";
    ClassLoader classLoader = null;
    if (testClass != null && TestRunnerFactory.containsSpecificAnnotation.test(testClass)) {
        classLoader = new URLClassLoader(Arrays.stream(classpath.split(":")).map(File::new).map(File::toURI).map(uri -> {
            try {
                return uri.toURL();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }).toArray(URL[]::new), ClassLoader.getSystemClassLoader().getParent());
    } else {
        classLoader = new URLClassLoader(Arrays.stream(classpath.split(":")).map(File::new).map(File::toURI).map(uri -> {
            try {
                return uri.toURL();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }).toArray(URL[]::new), ClassLoader.getSystemClassLoader());
    }
    final URL[] urls;
    try {
        urls = new URL[] { new File(classesDirectory).toURI().toURL(), new File(testClassesDirectory).toURI().toURL() };
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    if (configuration.getProperty("additionalClasspathElements") != null) {
        return new MemoryClassLoader(Stream.concat(Arrays.stream(configuration.getProperty("additionalClasspathElements").split(PATH_SEPARATOR)).map(configuration.getInputProgram().getProgramDir()::concat).map(File::new).map(File::toURI).map(uri -> {
            try {
                return uri.toURL();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }), Arrays.stream(urls)).toArray(URL[]::new), classLoader);
    } else {
        return new MemoryClassLoader(urls, classLoader);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) Arrays(java.util.Arrays) CtType(spoon.reflect.declaration.CtType) Stream(java.util.stream.Stream) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) PATH_SEPARATOR(fr.inria.diversify.utils.AmplificationHelper.PATH_SEPARATOR) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) AutomaticBuilderFactory(fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory) TestRunnerFactory(fr.inria.stamp.test.runner.TestRunnerFactory) File(java.io.File) MalformedURLException(java.net.MalformedURLException) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) URL(java.net.URL) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram)

Example 3 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class Utils method init.

public static void init(String pathToConfFile) {
    try {
        FileUtils.forceDelete(new File(inputConfiguration.getOutputDirectory()));
    } catch (Exception ignored) {
    }
    try {
        FileUtils.forceDelete(new File("target/dspot/tmp_test_sources/"));
    } catch (Exception ignored) {
    }
    if (pathToConfFile.equals(currentInputConfigurationLoaded)) {
        return;
    }
    try {
        AmplificationHelper.minimize = false;
        AutomaticBuilderFactory.reset();
        if (!new File("target/dspot/dependencies/compare").exists()) {
            DSpotUtils.copyPackageFromResources("fr/inria/diversify/compare/", "MethodsHandler", "ObjectLog", "Observation", "Utils");
        }
        currentInputConfigurationLoaded = pathToConfFile;
        inputConfiguration = new InputConfiguration(pathToConfFile);
        Initializer.initialize(inputConfiguration);
        inputProgram = inputConfiguration.getInputProgram();
        builder = AutomaticBuilderFactory.getAutomaticBuilder(inputConfiguration);
        String dependencies = builder.buildClasspath(inputProgram.getProgramDir());
        if (inputConfiguration.getProperty("additionalClasspathElements") != null) {
            dependencies += PATH_SEPARATOR + inputConfiguration.getInputProgram().getProgramDir() + inputConfiguration.getProperty("additionalClasspathElements");
        }
        compiler = DSpotCompiler.createDSpotCompiler(inputProgram, dependencies);
        inputProgram.setFactory(compiler.getLauncher().getFactory());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration)

Example 4 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class AutomaticBuilderFactoryTest method getAutomaticBuilder_whenConfDoesntContainBuilder.

@Test
public void getAutomaticBuilder_whenConfDoesntContainBuilder() throws Exception {
    this.configuration = JSAPOptions.parse(getArgsWithNoBuilder());
    InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
    InputProgram program = InputConfiguration.initInputProgram(inputConfiguration);
    inputConfiguration.setInputProgram(program);
    assertTrue(inputConfiguration.getProperty("automaticBuilderName") == null);
    AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(inputConfiguration);
    assertNotNull(builder);
    assertTrue(builder.getClass().equals(MavenAutomaticBuilder.class));
}
Also used : InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test)

Example 5 with InputConfiguration

use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.

the class AutomaticBuilderFactoryTest method getAutomaticBuilder_whenMaven.

@Test
public void getAutomaticBuilder_whenMaven() throws Exception {
    this.configuration = JSAPOptions.parse(getArgsWithMavenBuilder());
    InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
    InputProgram program = InputConfiguration.initInputProgram(inputConfiguration);
    inputConfiguration.setInputProgram(program);
    inputConfiguration.getProperties().setProperty("automaticBuilderName", configuration.automaticBuilderName);
    assertTrue(inputConfiguration.getProperty("automaticBuilderName").toUpperCase().contains("MAVEN"));
    AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(inputConfiguration);
    assertNotNull(builder);
    assertTrue(builder.getClass().equals(MavenAutomaticBuilder.class));
}
Also used : InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test)

Aggregations

InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)25 Test (org.junit.Test)14 InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)11 JacocoCoverageSelector (fr.inria.diversify.dspot.selector.JacocoCoverageSelector)6 File (java.io.File)6 TestDataMutator (fr.inria.diversify.dspot.amplifier.TestDataMutator)5 DSpot (fr.inria.diversify.dspot.DSpot)4 AbstractTest (fr.inria.AbstractTest)3 IOException (java.io.IOException)3 Launcher (spoon.Launcher)3 CtType (spoon.reflect.declaration.CtType)3 StatementAdd (fr.inria.diversify.dspot.amplifier.StatementAdd)2 TestListener (fr.inria.stamp.test.listener.TestListener)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 Before (org.junit.Before)2 AutomaticBuilder (fr.inria.diversify.automaticbuilder.AutomaticBuilder)1 AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 NumberLiteralAmplifier (fr.inria.diversify.dspot.amplifier.NumberLiteralAmplifier)1 StringLiteralAmplifier (fr.inria.diversify.dspot.amplifier.StringLiteralAmplifier)1