Search in sources :

Example 6 with CheckStylePluginException

use of org.infernus.idea.checkstyle.exception.CheckStylePluginException in project checkstyle-idea by jshiell.

the class CheckstyleClassLoaderContainer method buildClassLoader.

@NotNull
private ClassLoader buildClassLoader(@NotNull final String classPathFromProps, @NotNull final List<URL> thirdPartyClasspath) {
    final String basePath = getBasePath();
    final File classesDir4UnitTesting = new File(basePath, "classes/java/csaccess");
    final boolean unitTesting = classesDir4UnitTesting.exists();
    List<URL> urls = new ArrayList<>();
    try {
        if (unitTesting) {
            urls.add(classesDir4UnitTesting.toURI().toURL());
        } else {
            urls.add(new File(basePath, "checkstyle/classes").toURI().toURL());
        }
        for (String jar : classPathFromProps.trim().split("\\s*;\\s*")) {
            if (unitTesting) {
                String testJarLocation = "tmp/gatherCheckstyleArtifacts" + jar.substring(jar.lastIndexOf('/'));
                urls.add(new File(basePath, testJarLocation).toURI().toURL());
            } else {
                urls.add(new File(basePath, jar).toURI().toURL());
            }
        }
    } catch (MalformedURLException e) {
        throw new CheckStylePluginException("internal error", e);
    }
    urls.addAll(thirdPartyClasspath);
    // The plugin classloader is the new classloader's parent classloader.
    final ChildFirstURLClassLoader newClassLoader = new ChildFirstURLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
    if (weAreDebuggingADifferentVersionOfIdea(newClassLoader)) {
        // if we're debugging from another version of IDEA then child-first will do nasty things to the IDEA classpath
        Notifications.showWarning(project, message("plugin.debugging"));
        return new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
    }
    return newClassLoader;
}
Also used : MalformedURLException(java.net.MalformedURLException) ChildFirstURLClassLoader(org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader) ChildFirstURLClassLoader(org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader) URLClassLoader(java.net.URLClassLoader) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) File(java.io.File) URL(java.net.URL) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CheckStylePluginException (org.infernus.idea.checkstyle.exception.CheckStylePluginException)6 NotNull (org.jetbrains.annotations.NotNull)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 ChildFirstURLClassLoader (org.infernus.idea.checkstyle.util.ChildFirstURLClassLoader)2 ConfigurationLocation (org.infernus.idea.checkstyle.model.ConfigurationLocation)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1