/** * Returns the module configurations in a specified file. * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @return the check configurations * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver) throws CheckstyleException { return loadConfiguration(config, overridePropsResolver, IgnoredModulesOptions.EXECUTE); }
/** * Returns the module configurations in a specified file. * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @param threadModeSettings the thread mode configuration * @return the check configurations * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver, ThreadModeSettings threadModeSettings) throws CheckstyleException { return loadConfiguration(config, overridePropsResolver, IgnoredModulesOptions.EXECUTE, threadModeSettings); }
/** * Returns the module configurations in a specified file. * * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @param ignoredModulesOptions {@code OMIT} if modules with severity * 'ignore' should be omitted, {@code EXECUTE} otherwise * @return the check configurations * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver, IgnoredModulesOptions ignoredModulesOptions) throws CheckstyleException { return loadConfiguration(config, overridePropsResolver, ignoredModulesOptions, ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE); }
/** * Returns the module configurations from a specified input source. * Note that if the source does wrap an open byte or character * stream, clients are required to close that stream by themselves * * @param configSource the input stream to the Checkstyle configuration * @param overridePropsResolver overriding properties * @param ignoredModulesOptions {@code OMIT} if modules with severity * 'ignore' should be omitted, {@code EXECUTE} otherwise * @return the check configurations * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver, IgnoredModulesOptions ignoredModulesOptions) throws CheckstyleException { return loadConfiguration(configSource, overridePropsResolver, ignoredModulesOptions, ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE); }
/** * Returns the module configurations in a specified file. * * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @param omitIgnoredModules {@code true} if modules with severity * 'ignore' should be omitted, {@code false} otherwise * @return the check configurations * @throws CheckstyleException if an error occurs * @deprecated in order to fulfill demands of BooleanParameter IDEA check. * @noinspection BooleanParameter */ @Deprecated public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver, boolean omitIgnoredModules) throws CheckstyleException { return loadConfiguration(config, overridePropsResolver, omitIgnoredModules, ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE); }
/** * Returns the module configurations from a specified input source. * Note that if the source does wrap an open byte or character * stream, clients are required to close that stream by themselves * * @param configSource the input stream to the Checkstyle configuration * @param overridePropsResolver overriding properties * @param omitIgnoredModules {@code true} if modules with severity * 'ignore' should be omitted, {@code false} otherwise * @return the check configurations * @throws CheckstyleException if an error occurs * @deprecated in order to fulfill demands of BooleanParameter IDEA check. * @noinspection BooleanParameter */ @Deprecated public static Configuration loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver, boolean omitIgnoredModules) throws CheckstyleException { return loadConfiguration(configSource, overridePropsResolver, omitIgnoredModules, ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE); }
public static Configuration loadConfiguration(String path, Properties props) throws CheckstyleException { return ConfigurationLoader.loadConfiguration(path, new PropertiesExpander(props)); }
@Test public void testExternalEntityFromUri() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final File file = new File( getPath("subdir/InputConfigurationLoaderExternalEntitySubDir.xml")); final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( file.toURI().toString(), new PropertiesExpander(props)); final Properties atts = new Properties(); atts.setProperty("tabWidth", "4"); atts.setProperty("basedir", "basedir"); verifyConfigNode(config, "Checker", 2, atts); }
private Configuration loadConfiguration( String name, Properties props) throws Exception { final String fName = getPath(name); return ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(props)); }
@Test public void testResourceLoadConfiguration() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); // load config that's only found in the classpath final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderChecks.xml"), new PropertiesExpander(props)); //verify the root, and property substitution final Properties attributes = new Properties(); attributes.setProperty("tabWidth", "4"); attributes.setProperty("basedir", "basedir"); verifyConfigNode(config, "Checker", 3, attributes); }
@Test public void testConfigWithIgnoreUsingInputSource() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new InputSource( new File(getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")) .toURI().toString()), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testResourceLoadConfigurationWithSingleThreadConfiguration() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final PropertiesExpander propertiesExpander = new PropertiesExpander(props); final String configPath = getPath("InputConfigurationLoaderChecks.xml"); final ThreadModeSettings singleThreadModeSettings = ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE; final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( configPath, propertiesExpander, singleThreadModeSettings); final Properties attributes = new Properties(); attributes.setProperty("tabWidth", "4"); attributes.setProperty("basedir", "basedir"); verifyConfigNode(config, "Checker", 3, attributes); }
@Test public void testLoadConfigurationDeprecated() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( Files.newInputStream(Paths.get( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"))), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testConfigCheckerWithIgnore() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderCheckerIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children.length); }
@Test public void testConstructors() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final String fName = getPath("InputConfigurationLoaderChecks.xml"); final Configuration configuration = ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(props), ConfigurationLoader.IgnoredModulesOptions.OMIT); assertEquals("Name is not expected", "Checker", configuration.getName()); final DefaultConfiguration configuration1 = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( new InputSource(Files.newInputStream(Paths.get( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")))), new PropertiesExpander(new Properties()), ConfigurationLoader.IgnoredModulesOptions.EXECUTE); final Configuration[] children = configuration1.getChildren(); assertEquals("Unexpected children size", 1, children[0].getChildren().length); }
@Test public void testLoadConfigurationFromClassPath() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testConfigWithIgnore() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
@Test public void testResourceLoadConfigurationWithMultiThreadConfiguration() throws Exception { final Properties props = new Properties(); props.setProperty("checkstyle.basedir", "basedir"); final PropertiesExpander propertiesExpander = new PropertiesExpander(props); final String configPath = getPath("InputConfigurationLoaderChecks.xml"); final ThreadModeSettings multiThreadModeSettings = new ThreadModeSettings(4, 2); try { ConfigurationLoader.loadConfiguration( configPath, propertiesExpander, multiThreadModeSettings); fail("An exception is expected"); } catch (IllegalArgumentException ex) { assertEquals("Invalid exception message", "Multi thread mode for Checker module is not implemented", ex.getMessage()); } }
@Test public void testLoadConfigurationWrongUrl() { try { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( ";InputConfigurationLoaderModuleIgnoreSeverity.xml", new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); fail("Exception is expected"); } catch (CheckstyleException ex) { assertEquals("Invalid exception message", "Unable to find: ;InputConfigurationLoaderModuleIgnoreSeverity.xml", ex.getMessage()); } }
@Test public void testMissingPropertyNameInMethodWithBooleanParameter() throws Exception { try { final String fName = getPath("InputConfigurationLoaderMissingPropertyName.xml"); ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(new Properties()), false); fail("missing property name"); } catch (CheckstyleException ex) { assertTrue("Invalid exception message: " + ex.getMessage(), ex.getMessage().contains("\"name\"")); assertTrue("Invalid exception message: " + ex.getMessage(), ex.getMessage().contains("\"property\"")); assertTrue("Invalid exception message: " + ex.getMessage(), ex.getMessage().endsWith(":8:41")); } }