/** 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); } }
/** * Write check configurations to an external file in standard Checkstyle format. * * @param file File to write too. * @param config List of check configurations to write out. * @throws CheckstylePluginException Error during export. */ public static void exportConfiguration(File file, ICheckConfiguration config) throws CheckstylePluginException { InputStream in = null; OutputStream out = null; try { // Just copy the checkstyle configuration in = config.getCheckstyleConfiguration().getCheckConfigFileStream(); out = new BufferedOutputStream(new FileOutputStream(file)); IOUtils.copy(in, out); } catch (Exception e) { CheckstylePluginException.rethrow(e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }