use of com.puppycrawl.tools.checkstyle.PropertiesExpander in project checkstyle by checkstyle.
the class ChainedPropertyUtilTest method testPropertyChaining.
@Test
public void testPropertyChaining() throws Exception {
final File propertiesFile = new File(getPath("InputChainedPropertyUtil.properties"));
final Properties properties = loadProperties(propertiesFile);
final Properties resolvedProperties = ChainedPropertyUtil.getResolvedProperties(properties);
final PropertiesExpander expander = new PropertiesExpander(resolvedProperties);
final String message = "Unexpected property resolution.";
assertWithMessage(message).that(expander.resolve("basedir")).isEqualTo("/home");
assertWithMessage(message).that(expander.resolve("checkstyle.dir")).isEqualTo("/home/checkstyle");
assertWithMessage(message).that(expander.resolve("config.dir")).isEqualTo("/home/checkstyle/configs");
assertWithMessage(message).that(expander.resolve("checkstyle.suppressions.file")).isEqualTo("/home/checkstyle/configs/suppressions.xml");
assertWithMessage(message).that(expander.resolve("checkstyle.dir")).isEqualTo("/home/checkstyle");
assertWithMessage(message).that(expander.resolve("str")).isEqualTo("value");
}
use of com.puppycrawl.tools.checkstyle.PropertiesExpander in project mapstruct by mapstruct.
the class CompilingExtension method assertCheckstyleRules.
private void assertCheckstyleRules() throws Exception {
if (sourceOutputDir != null) {
Properties properties = new Properties();
properties.put("checkstyle.cache.file", classOutputDir + "/checkstyle.cache");
final Checker checker = new Checker();
checker.setModuleClassLoader(Checker.class.getClassLoader());
checker.configure(ConfigurationLoader.loadConfiguration(new InputSource(getClass().getClassLoader().getResourceAsStream("checkstyle-for-generated-sources.xml")), new PropertiesExpander(properties), ConfigurationLoader.IgnoredModulesOptions.OMIT));
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
checker.addListener(new DefaultLogger(NullOutputStream.NULL_OUTPUT_STREAM, AutomaticBean.OutputStreamOptions.CLOSE, errorStream, AutomaticBean.OutputStreamOptions.CLOSE));
int errors = checker.process(findGeneratedFiles(new File(sourceOutputDir)));
if (errors > 0) {
String errorLog = errorStream.toString("UTF-8");
assertThat(true).describedAs("Expected checkstyle compliant output, but got errors:\n" + errorLog).isEqualTo(false);
}
}
}
use of com.puppycrawl.tools.checkstyle.PropertiesExpander in project checkstyle by checkstyle.
the class XdocsPagesTest method isValidCheckstyleXml.
private static boolean isValidCheckstyleXml(String fileName, String code, String unserializedSource) throws IOException, CheckstyleException {
// can't process non-existent examples, or out of context snippets
if (!code.contains("com.mycompany") && !code.contains("checkstyle-packages") && !code.contains("MethodLimit") && !code.contains("<suppress ") && !code.contains("<suppress-xpath ") && !code.contains("<import-control ") && !unserializedSource.startsWith("<property ") && !unserializedSource.startsWith("<taskdef ")) {
// validate checkstyle structure and contents
try {
final Properties properties = new Properties();
properties.setProperty("checkstyle.header.file", new File("config/java.header").getCanonicalPath());
final PropertiesExpander expander = new PropertiesExpander(properties);
final Configuration config = ConfigurationLoader.loadConfiguration(new InputSource(new StringReader(code)), expander, IgnoredModulesOptions.EXECUTE);
final Checker checker = new Checker();
try {
final ClassLoader moduleClassLoader = Checker.class.getClassLoader();
checker.setModuleClassLoader(moduleClassLoader);
checker.configure(config);
} finally {
checker.destroy();
}
} catch (CheckstyleException ex) {
throw new CheckstyleException(fileName + " has invalid Checkstyle xml (" + ex.getMessage() + "): " + unserializedSource, ex);
}
}
return true;
}
use of com.puppycrawl.tools.checkstyle.PropertiesExpander in project checkstyle by checkstyle.
the class CommonUtilTest method testGetUriByFilenameFindsRelativeResourceOnClasspathPrefix.
@Test
public void testGetUriByFilenameFindsRelativeResourceOnClasspathPrefix() throws Exception {
final String filename = CommonUtil.CLASSPATH_URL_PROTOCOL + getPackageLocation() + "/InputCommonUtilTest_empty_checks.xml";
final URI uri = CommonUtil.getUriByFilename(filename);
final Properties properties = System.getProperties();
final Configuration config = ConfigurationLoader.loadConfiguration(uri.toString(), new PropertiesExpander(properties));
assertWithMessage("Unexpected config name!").that(config.getName()).isEqualTo("Checker");
}
use of com.puppycrawl.tools.checkstyle.PropertiesExpander in project checkstyle by checkstyle.
the class CommonUtilTest method testGetUriByFilenameFindsAbsoluteResourceOnClasspath.
@Test
public void testGetUriByFilenameFindsAbsoluteResourceOnClasspath() throws Exception {
final String filename = "/" + getPackageLocation() + "/InputCommonUtilTest_empty_checks.xml";
final URI uri = CommonUtil.getUriByFilename(filename);
final Properties properties = System.getProperties();
final Configuration config = ConfigurationLoader.loadConfiguration(uri.toString(), new PropertiesExpander(properties));
assertWithMessage("Unexpected config name!").that(config.getName()).isEqualTo("Checker");
}
Aggregations