[core] IDEAJRenderer: How to use setReportProperties in PMD Configuration? #3026
-
I am trying to figure out how to get variable , className or method name in RuleViolation result. try {
ClassLoader classLoader = this.getClass().getClassLoader();
InputStream resourceAsStream = classLoader.getResourceAsStream("xml/ruleSet.xml");
String ruleSetFilePath = "";
if (resourceAsStream != null) {
File file = stream2file(resourceAsStream);
ruleSetFilePath = file.getPath();
}
pmdConfiguration.setReportFormat("ideaj");
Properties properties = new Properties();
properties.setProperty(IDEAJRenderer.FILE_NAME.name(),"");
properties.setProperty("sourcePath","");
properties.setProperty("classAndMethodName","");
pmdConfiguration.setReportProperties(properties);
pmdConfiguration.setRuleSets(ruleSetFilePath);
pmdConfiguration.setThreads(4);
} catch (IOException e) {
e.printStackTrace();
}
SourceCodeProcessor sourceCodeProcessor = new SourceCodeProcessor(pmdConfiguration);
RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.getRulesetFactory(pmdConfiguration, new
ResourceLoader());
RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(pmdConfiguration.getRuleSets(), ruleSetFactory);
PmdReviewService pmdReviewService = new PmdReviewService(sourceCodeProcessor, ruleSets); What to set in setReportProperties which will fetch me those values? There is no documentation in this regard. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @Nagendra080389 , thanks for bringing this to our attention. I actually don't know, what to set there. But after digging, I think, I understand what this IDEAJRenderer is used for: For integrating PMD into IntelliJ IDEA, there are several ways:
Executing PMD at CLI with this renderer shows, which values you need to set: $ pwd
/home/andreas/PMD/pmd-it/issue-2117
$ mkdir src
$ echo 'public class Bar {}' > src/Bar.java
$ echo 'public class Foo {}' > src/Foo.java
$ tree
.
└── src
├── Bar.java
└── Foo.java
1 directory, 2 files
$ # running PMD for a single file
$ $PMD_PATH/bin/run.sh pmd -no-cache -d src/Foo.java -R rulesets/java/quickstart.xml -f ideaj -P fileName=src/Foo.java -P sourcePath=/home/andreas/PMD/pmd-it/issue-2117/src -P classAndMethodName=Foo
All classes, interfaces, enums and annotations must belong to a named package
at Foo(src/Foo.java:1)
$ # running PMD for a whole directory
$ $PMD_PATH/bin/run.sh pmd -no-cache -d src -R rulesets/java/quickstart.xml -f ideaj -P fileName=src/Foo.java -P sourcePath=/home/andreas/PMD/pmd-it/issue-2117/src -P classAndMethodName=.method
All classes, interfaces, enums and annotations must belong to a named package
at Bar.method(Bar.java:1)
All classes, interfaces, enums and annotations must belong to a named package
at Foo.method(Foo.java:1) So, there are obviously 2 cases:
But let's take a step back: The question is then: Do you really need the IDEAJ renderer or would a different renderer be better / more useful? What is the goal, you want to achieve? |
Beta Was this translation helpful? Give feedback.
-
I am trying to integrate pmd (apex language) with sonar qube, and was wondering when pmd throws complexity rule violations ( for eg: n path etc) it actually gives start line and end line for whole method or class, this make sonar qube difficult to highlight specific method. So i was wondering if ideajrenderer would give specific method name so that i can create a specific text range out of it and highlight only specific method name or class name. |
Beta Was this translation helpful? Give feedback.
-
I'm closing this, the ideaj renderer doesn't provide the information. This sounds more like improving CyclomaticComplexity or CognitiveComplexity for reporting the method with the highest complexity rather than the whole class. |
Beta Was this translation helpful? Give feedback.
I'm closing this, the ideaj renderer doesn't provide the information.
This sounds more like improving CyclomaticComplexity or CognitiveComplexity for reporting the method with the highest complexity rather than the whole class.