Search in sources :

Example 1 with CheckStylePluginException

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

the class PluginConfiguration method locationsAreEqual.

private boolean locationsAreEqual(final PluginConfiguration other) {
    Iterator<ConfigurationLocation> locationIterator = locations.iterator();
    Iterator<ConfigurationLocation> otherLocationIterator = other.locations.iterator();
    while (locationIterator.hasNext() && otherLocationIterator.hasNext()) {
        try {
            if (locationIterator.next().hasChangedFrom(otherLocationIterator.next())) {
                return false;
            }
        } catch (IOException e) {
            throw new CheckStylePluginException("Unable to test configuration properties for changes", e);
        }
    }
    return locations.size() == other.locations.size();
}
Also used : ConfigurationLocation(org.infernus.idea.checkstyle.model.ConfigurationLocation) IOException(java.io.IOException) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException)

Example 2 with CheckStylePluginException

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

the class VersionMixExceptionTest method readBaseVersion.

@NotNull
private static String readBaseVersion() {
    String result;
    try (InputStream is = VersionMixExceptionTest.class.getResourceAsStream(PROPS_FILE_NAME)) {
        Properties props = new Properties();
        props.load(is);
        result = props.getProperty("baseVersion");
    } catch (IOException e) {
        throw new CheckStylePluginException("internal error - Failed to read property file: " + PROPS_FILE_NAME, e);
    }
    Assert.assertNotNull(result);
    return result;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CheckStylePluginException

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

the class VersionListReader method readProperties.

@NotNull
private Properties readProperties(@NotNull final String propertyFile) {
    final Properties props = new Properties();
    InputStream is = null;
    try {
        is = getClass().getClassLoader().getResourceAsStream(propertyFile);
        if (is == null) {
            // in unit tests, it seems we need this:
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile);
        }
        if (is != null) {
            props.load(is);
        }
    } catch (IllegalArgumentException | IOException e) {
        throw new CheckStylePluginException("Internal error: Could not read internal configuration file '" + propertyFile + "'", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
    if (props.isEmpty()) {
        throw new CheckStylePluginException("Internal error: Could not read internal configuration file '" + propertyFile + "'");
    }
    return props;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CheckStylePluginException

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

the class CheckstyleClassLoader method buildClassLoader.

@NotNull
private ClassLoader buildClassLoader(@NotNull final String pClassPathFromProps, @NotNull final List<URL> pThirdPartyClassPath) {
    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 : pClassPathFromProps.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(pThirdPartyClassPath);
    // The plugin classloader is the new classloader's parent classloader.
    final ChildFirstURLClassLoader newClassLoader = new ChildFirstURLClassLoader(urls.toArray(new URL[urls.size()]), 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[urls.size()]), 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)

Example 5 with CheckStylePluginException

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

the class CsVersionInfo method readBaseVersion.

@NotNull
private static String readBaseVersion() {
    String result;
    try (InputStream is = CsVersionInfo.class.getResourceAsStream(PROPS_FILE_NAME)) {
        Properties props = new Properties();
        props.load(is);
        result = props.getProperty("baseVersion");
    } catch (IOException e) {
        throw new CheckStylePluginException("internal error - Failed to read property file: " + PROPS_FILE_NAME, e);
    }
    assertNotNull(result);
    return result;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) CheckStylePluginException(org.infernus.idea.checkstyle.exception.CheckStylePluginException) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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