Search in sources :

Example 1 with CheckstyleToolException

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

the class CheckerFactory method createChecker.

private CachedChecker createChecker(@NotNull final ConfigurationLocation location, @Nullable final Module module) {
    final ListPropertyResolver propertyResolver;
    try {
        final Map<String, String> properties = removeEmptyProperties(location.getProperties());
        propertyResolver = new ListPropertyResolver(addEclipseCsProperties(location, module, properties));
    } catch (IOException e) {
        LOG.info("CheckStyle properties could not be loaded: " + location.getLocation(), e);
        return blacklistAndShowMessage(location, module, "checkstyle.file-io-failed", location.getLocation());
    }
    final ClassLoader loaderOfCheckedCode = moduleClassPathBuilder().build(module);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Call to create new checker.");
        logProperties(propertyResolver);
        logClassLoaders(loaderOfCheckedCode);
    }
    final Object workerResult = executeWorker(location, module, propertyResolver, loaderOfCheckedCode);
    if (workerResult instanceof CheckstyleToolException) {
        return blacklistAndShowMessage(location, module, (CheckstyleToolException) workerResult);
    } else if (workerResult instanceof IOException) {
        LOG.info("CheckStyle configuration could not be loaded: " + location.getLocation(), (IOException) workerResult);
        return blacklistAndShowMessage(location, module, "checkstyle.file-not-found", location.getLocation());
    } else if (workerResult instanceof Throwable) {
        return blacklistAndShowException(location, module, (Throwable) workerResult);
    }
    return (CachedChecker) workerResult;
}
Also used : URLClassLoader(java.net.URLClassLoader) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) IOException(java.io.IOException)

Example 2 with CheckstyleToolException

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

the class CheckStyleToolWindowPanel method displayErrorResult.

/**
 * Clear the results and display notice to say an error occurred.
 *
 * @param error the error that occurred.
 */
public void displayErrorResult(final Throwable error) {
    // match some friendly error messages.
    String errorText = null;
    if (error instanceof CheckstyleToolException && error.getCause() != null) {
        for (final Map.Entry<Pattern, String> errorPatternEntry : CHECKSTYLE_ERROR_PATTERNS.entrySet()) {
            final Matcher errorMatcher = errorPatternEntry.getKey().matcher(error.getCause().getMessage());
            if (errorMatcher.find()) {
                final Object[] args = new Object[errorMatcher.groupCount()];
                for (int i = 0; i < errorMatcher.groupCount(); ++i) {
                    args[i] = errorMatcher.group(i + 1);
                }
                errorText = message(errorPatternEntry.getValue(), args);
            }
        }
    }
    if (errorText == null) {
        if (error instanceof CheckStylePluginParseException) {
            errorText = message("plugin.results.unparseable");
        } else {
            errorText = message("plugin.results.error");
        }
    }
    treeModel.clear();
    treeModel.setRootText(errorText);
    clearProgress();
}
Also used : Pattern(java.util.regex.Pattern) CheckStylePluginParseException(org.infernus.idea.checkstyle.exception.CheckStylePluginParseException) Matcher(java.util.regex.Matcher) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CheckstyleToolException

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

the class OpCreateChecker method execute.

@Override
@NotNull
public CheckStyleChecker execute(@NotNull final Project project) throws CheckstyleException {
    final Configuration csConfig = loadConfig(project);
    final Checker checker = new Checker();
    // for Checkstyle to load modules (checks)
    checker.setModuleClassLoader(getClass().getClassLoader());
    // for checks to load the classes and resources to be analyzed
    setClassLoader(checker, loaderOfCheckedCode);
    try {
        checker.configure(csConfig);
    } catch (Error e) {
        // e.g. java.lang.NoClassDefFoundError thrown by Checkstyle for pre-8.0 custom checks
        throw new CheckstyleToolException(e);
    }
    CheckerWithConfig cwc = new CheckerWithConfig(checker, csConfig);
    final TabWidthAndBaseDirProvider configs = configurations != null ? configurations : new Configurations(module, csConfig);
    return new CheckStyleChecker(cwc, configs.tabWidth(), configs.baseDir(), checkstyleProjectService.getCheckstyleInstance());
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) Checker(com.puppycrawl.tools.checkstyle.Checker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) CheckerWithConfig(org.infernus.idea.checkstyle.service.entities.CheckerWithConfig) CheckstyleToolException(org.infernus.idea.checkstyle.exception.CheckstyleToolException) TabWidthAndBaseDirProvider(org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider) Configurations(org.infernus.idea.checkstyle.service.Configurations) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CheckstyleToolException (org.infernus.idea.checkstyle.exception.CheckstyleToolException)3 Checker (com.puppycrawl.tools.checkstyle.Checker)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CheckStyleChecker (org.infernus.idea.checkstyle.checker.CheckStyleChecker)1 TabWidthAndBaseDirProvider (org.infernus.idea.checkstyle.csapi.TabWidthAndBaseDirProvider)1 CheckStylePluginParseException (org.infernus.idea.checkstyle.exception.CheckStylePluginParseException)1 Configurations (org.infernus.idea.checkstyle.service.Configurations)1 CheckerWithConfig (org.infernus.idea.checkstyle.service.entities.CheckerWithConfig)1 NotNull (org.jetbrains.annotations.NotNull)1