Search in sources :

Example 1 with PATH_SEPARATOR

use of fr.inria.diversify.utils.AmplificationHelper.PATH_SEPARATOR 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)

Aggregations

AutomaticBuilderFactory (fr.inria.diversify.automaticbuilder.AutomaticBuilderFactory)1 PATH_SEPARATOR (fr.inria.diversify.utils.AmplificationHelper.PATH_SEPARATOR)1 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)1 InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)1 TestRunnerFactory (fr.inria.stamp.test.runner.TestRunnerFactory)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Arrays (java.util.Arrays)1 Stream (java.util.stream.Stream)1 CtType (spoon.reflect.declaration.CtType)1