Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Juan Martín Sotuyo Dodero
@jsotuyod
so it makes sense to close it wherever it's being consumed
Mike Moran
@mhmoran
newbie here... my dev box doesn't have bundle .. is it the one that comes from ruby ?
Juan Martín Sotuyo Dodero
@jsotuyod
yeap, gem install bundler should install it
bare in mind, that is only needed to build the docs / site; not the actual PMD binary
you can probably just skip those tasks / choose a different maven target
Mike Moran
@mhmoran
thanks
so not building implies not having the documentation locally, does that imply I can find it elsewhere ?
Juan Martín Sotuyo Dodero
@jsotuyod
Mike Moran
@mhmoran
thanks
so what is the distinction between target and src rulesets
Juan Martín Sotuyo Dodero
@jsotuyod
I'm sorry… what do you mean by src and target rulesets?
Mike Moran
@mhmoran

I've been tasked with code reviews on java and javascript .. scanning for ecmascript I see 17 versions .. not quite evenly split between
./pmd-javascript/target/ and
./pmd-javascript/src/

So I'm trying to figure out which one I should be using .. .

Juan Martín Sotuyo Dodero
@jsotuyod
oh, that's just how Maven works. When maven builds the project it puts all artifacts and intermediates under target/
under src are the originals
you probably care about neither
Mike Moran
@mhmoran
suggestion on which target I should be using ?
Juan Martín Sotuyo Dodero
@jsotuyod
the pmd bundle you ship (under pmd-dist/target you'll find a zip for the bin, which is also available from the web)
already contains all rulesets, and you can reference them directly by name
ie: -R rulesets/java/quickstart.xml
it will load it from the internal resources
if you just want to run PMD against some sources, you don't actually need to build it manually
https://pmd.github.io/ -> under quickstart you can see how to download and use the PMD binary for each OS
extra details on Command line arguments can be found here: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_cli_reference.html
and information on how to tailor a set of rules for your particular needs and likes is detailed here: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_making_rulesets.html
as for the complete catalogue of available rules, you can check the Java rules here: https://pmd.github.io/pmd-6.17.0/pmd_rules_java.html
Juan Martín Sotuyo Dodero
@jsotuyod
building from source is only needed if you intend to contribute to PMD or have an organizational rule that requires doing so :)
Mike Moran
@mhmoran
Just struggling to get it all working ..
Juan Martín Sotuyo Dodero
@jsotuyod
don't worry, we are here to help
Mike Moran
@mhmoran
so can I simply point the -R argument to a directory or a zip file ?
Mike Moran
@mhmoran
/usr/local/src/pmd.github.io/pmd-dist/target/classes/scripts/run.sh: line 73: cd: /usr/local/src/pmd.github.io/pmd-dist/target/classes/scripts/../lib: No such file or directory
Error: Could not find or load main class net.sourceforge.pmd.PMD
Caused by: java.lang.ClassNotFoundException: net.sourceforge.pmd.PMD
Clément Fournier
@oowekyala
@mhmoran That script expects a directory structure that matches that of the distribution archive. Here it's just in a temporary location where maven copies resources before packaging them, so the structure doesn't match. If you really want to build a distribution locally, use mvn package or mvn install from the project root directory and then use the zip in pmd-dist/target/pmd-bin-<version>.zip (but not the stuff in target/classes directly). But really the easiest way to install PMD is to not fiddle with the sources and to download a prebuilt archive from here, and to install it somewhere by just unzipping it.
Andreas Dangel
@adangel
@mhmoran Maybe we should clarify first, what your goals are: Dou you want to use PMD in order to analyze a project (then you can just you the released binaries and don't bother about building it yourself) or do you want to develop/change/contribute to PMD?
Or both?
Mike Moran
@mhmoran
just analyze other peoples projects. I'm working with a company in the compliance space and they offer code reviews.. so trying to build out an infrastructure to be able to do reviews quickly on C/C++, C#, Java, JS, Perl, PHP and Python
Juan Martín Sotuyo Dodero
@jsotuyod
@mhmoran then you should just download a binary distribution of PMD and run it directly
follow the quickstart from the web
and once you get that running, you can dive into more advanced usage
extra details on Command line arguments can be found here: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_cli_reference.html
and information on how to tailor a set of rules for your particular needs and likes is detailed here: https://pmd.github.io/pmd-6.17.0/pmd_userdocs_making_rulesets.html
as for the complete catalogue of available rules, you can check the Java rules here: https://pmd.github.io/pmd-6.17.0/pmd_rules_java.html
and Javascript here: https://pmd.github.io/pmd-6.17.0/pmd_rules_ecmascript.html
Alexis SEGURA
@alexisgra
Hello, I was wondering if it was possible to retrieve java code metrics (cf: https://pmd.github.io/pmd-6.17.0/pmd_java_metrics_index.html) via the CLI in the 6.17 or previous version ? Or am I required to create my own rules using the metric framework ? Thank you ! :)
Ullrich Hafner
@uhafner
We discussed that topic a couple of weeks ago (in May actually, is there a way to link to previous posts in Gitter?). It is not possible yet. One of my students will start working on that topic in his thesis. The general idea is to have a tool that uses PMD to extract those metrics into a file which then can be read by other tools. These metrics then can be consumed by Jenkins warnings plugin to present those metrics along with the PMD warnings.
Alexis SEGURA
@alexisgra
Ok thanks I found the previous discussion. So I implemented a custom rule that calls the Metrics framework. Thank you and have a good continuation on your project ! :)
Saladoc
@Saladoc
Hey I'm trying to work on pmd/pmd#659. I figured that in order to properly support it I'd need to port the rule over to its own class instead of using the old XPath version. Is there any good place to read up on the whole AST implementation or should I continue piecing together how it works from other tests and the trial, error and debugger?
Andreas Dangel
@adangel
Hi, thanks for working on PMD. I'd suggest to use the designer (https://pmd.github.io/latest/pmd_userdocs_extending_designer_reference.html) to have a look a the AST structure and the available attributes. In your IDE, you can use autocomplete to navigate the nodes (like findChildrenOfType(...) and findDescendantsOfType(...). See also https://pmd.github.io/latest/pmd_userdocs_extending_writing_pmd_rules.html
Andi Pabst
@andipabst
Hi, I added a pull request for calculating the Class Fan Out Metric in PMD (pmd/pmd#20769). This is the number of classes used by a certain class. Now I would also like to add the opposite, the Fan In (which classes are using the considered class). But I think this can not be computed by looking at only one class at a time, like the other metrics. Could you please point me in a direction on how this could be implemented? Thank you very much!
Andreas Dangel
@adangel
Hi, I'm afraid that's not possible with PMD 6. What we would need here is something like a "multifile analysis". You can currently write a rule, that visits every file and you can collect and share data via RuleContext#setAttribute(String, Object). But we are missing a final call at the end of the analysis of all files, where you could analyse the collected data and report violations based on this. It might be part of PMD 7, but that's not sure yet.
Saladoc
@Saladoc
While reading through some code to find the best way on how to iterate over a node's children I stumbled on https://github.com/pmd/pmd/blob/591cfc0a51febd8aa9869277f5c16914798c97e1/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java#L118 which seems like a legacy to do task or something? Maybe someone who is more familiar than the code will want to make sure that task is reflected somewhere more suitable.
Andi Pabst
@andipabst
@adangel Oh, thats unfortunate! But thank you for your help!
Clément Fournier
@oowekyala
@Saladoc this TODO was added recently (in pmd/pmd#2021)
It's scheduled for 7.0.0 since this is an API breaking change (eg would break the designer), and requires all supported language implementations to be aligned on the convention