/** * Get an <code>CheckConfiguration</code> instance by its name. * * @param name Name of the requested instance. * @return The requested instance or <code>null</code> if the named instance could not be found. */ public static ICheckConfiguration getByName(String name) { for (ICheckConfiguration config : sConfigurations) { if (config.getName().equals(name)) { return config; } } return null; }
/** Load the check configurations from the persistent state storage. */ private static void loadFromPersistence() throws CheckstylePluginException { InputStream inStream = null; try { IPath configPath = CheckstylePlugin.getDefault().getStateLocation(); configPath = configPath.append(CHECKSTYLE_CONFIG_FILE); File configFile = configPath.toFile(); // // Make sure the files exists, it might not. // if (!configFile.exists()) { return; } else { inStream = new BufferedInputStream(new FileInputStream(configFile)); } SAXReader reader = new SAXReader(); Document document = reader.read(inStream); Element root = document.getRootElement(); String version = root.attributeValue(XMLTags.VERSION_TAG); if (!CURRENT_CONFIG_FILE_FORMAT_VERSION.equals(version)) { // the old (pre 4.0.0) configuration files aren't supported // anymore CheckstyleLog.log( null, "eclipse-cs version 3.x type configuration files are not supported anymore."); return; } String defaultConfigName = root.attributeValue(XMLTags.DEFAULT_CHECK_CONFIG_TAG); sConfigurations.addAll(getGlobalCheckConfigurations(root)); for (ICheckConfiguration config : sConfigurations) { if (config.getName().equals(defaultConfigName)) { sDefaultCheckConfig = config; } } } catch (IOException e) { CheckstylePluginException.rethrow(e, Messages.errorLoadingConfigFile); } catch (DocumentException e) { CheckstylePluginException.rethrow(e, Messages.errorLoadingConfigFile); } finally { IOUtils.closeQuietly(inStream); } }