use of net.sourceforge.pmd.PMD in project pmd by pmd.
the class XPathRuleTest method getReportForTestString.
private static Report getReportForTestString(Rule r, String test) throws PMDException {
PMD p = new PMD();
RuleContext ctx = new RuleContext();
Report report = new Report();
ctx.setReport(report);
ctx.setSourceCodeFilename("n/a");
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(r);
p.getSourceCodeProcessor().processSourceCode(new StringReader(test), new RuleSets(rules), ctx);
return report;
}
use of net.sourceforge.pmd.PMD in project pmd by pmd.
the class RuleTst method runTestFromString.
public void runTestFromString(String code, Rule rule, Report report, LanguageVersion languageVersion, boolean isUseAuxClasspath) {
try {
PMD p = new PMD();
p.getConfiguration().setDefaultLanguageVersion(languageVersion);
p.getConfiguration().setIgnoreIncrementalAnalysis(true);
if (isUseAuxClasspath) {
// configure the "auxclasspath" option for unit testing
p.getConfiguration().prependClasspath(".");
}
RuleContext ctx = new RuleContext();
ctx.setReport(report);
ctx.setSourceCodeFilename("n/a");
ctx.setLanguageVersion(languageVersion);
ctx.setIgnoreExceptions(false);
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
p.getSourceCodeProcessor().processSourceCode(new StringReader(code), new RuleSets(rules), ctx);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of net.sourceforge.pmd.PMD in project pmd by pmd.
the class XPathJspRuleTest method testExpressionMatching.
/**
* Test matching a XPath expression against a JSP source.
* @throws PMDException
*/
@Test
public void testExpressionMatching() throws PMDException {
Rule rule = new XPathRule(XPATH_EXPRESSION);
rule.setMessage("Test");
rule.setLanguage(LanguageRegistry.getLanguage(JspLanguageModule.NAME));
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
RuleContext ctx = new RuleContext();
Report report = new Report();
ctx.setReport(report);
ctx.setSourceCodeFilename("n/a");
ctx.setLanguageVersion(LanguageRegistry.getLanguage(JspLanguageModule.NAME).getDefaultVersion());
PMD p = new PMD();
p.getSourceCodeProcessor().processSourceCode(new StringReader(MATCH), new RuleSets(rules), ctx);
assertEquals("One violation expected!", 1, report.size());
RuleViolation rv = report.iterator().next();
assertEquals(1, rv.getBeginLine());
}
use of net.sourceforge.pmd.PMD in project pmd by pmd.
the class XPathMetricFunctionTest method getViolations.
private Iterator<RuleViolation> getViolations(Rule rule, String code) throws PMDException {
PMD p = new PMD();
RuleContext ctx = new RuleContext();
Report report = new Report();
ctx.setReport(report);
ctx.setSourceCodeFilename("n/a");
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
p.getSourceCodeProcessor().processSourceCode(new StringReader(code), new RuleSets(rules), ctx);
return report.iterator();
}
Aggregations