Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] How to wrap CPD as a rule #186

Closed
rsoesemann opened this issue Jan 11, 2017 · 2 comments
Closed

[core] How to wrap CPD as a rule #186

rsoesemann opened this issue Jan 11, 2017 · 2 comments
Labels
a:question Request for information that doesn't necessarily entail changes to the code base

Comments

@rsoesemann
Copy link
Member

rsoesemann commented Jan 11, 2017

This is more a discussion item that an issue, but I post it here to mention the experts (e.g. @adangel @jsotuyod ) to get some feedback.

I am the creator of the Apex language module and of ApexMetrics which wraps PMD and makes it available to the Code Climate platform for code analysis. PMD and CodeClimate are a perfect match as both work on a per file basis and know the concept of issues of a certain severity.

Besides PMD I am a heavy user of the Copy Paste Detector that is part of PMD. But only as a local standalone tool. I would like to create a CopyPasteRule instead and wonder if that is doable?

As nobody has done it in the last 10 years I fear its just not doable because of tthe way PMD works. I mean Visitor pattern, issues checked per file.

What do you think?

@adangel adangel added the a:question Request for information that doesn't necessarily entail changes to the code base label Jan 11, 2017
@jsotuyod jsotuyod changed the title [Question] How to wrap CDP as a rule [core] How to wrap CDP as a rule Jan 11, 2017
@jsotuyod
Copy link
Member

This one is tough.

There are 2 main differences on how PMD and CPD work that makes this hard:

  • CPD works on tokens, PMD on the AST. The AST is a higher level of abstraction, and the codebases for each are not fully shared (that's why you can support CPD without having PMD rules).
  • CPD checks token sequences even from different files. For PMD each file can be analyzed on it's own. Several parts of PMD take this for granted and make use of it. That's why we could build an analysis cache to speed up PMD, but not for CPD. This is also used when running multithreaded analysis on PMD.

There are ideas around to bridge this gap (see wiki) but they are early and will probably not do so fully. Having CPD as a PMD rule would require forcefully disabling the analysis cache, and is probably not much to be gained there.

What may be possible, is having a run option for running CPD as part of PMD, and have found violations redirected to a PMD report rather to the standard CPD one. To do so one would have to add required flags to CLI / Ant, and at the end of PMD.doPMD() call CPD.go(), retrieve the found matches, and manually adding them to the reporter.... possibly the RuleViolation interface will require some modification to fit CPD violations (which in turn may require updating renderers).

It's not the cleanest solution, but the only one I can see actually working.

On the other hand, you could simply add support for different renderers in CPD, just like PMD has (bonus points for reusing existing codebase), move the current rendering code to an XMLRenderer, and add your own Code Climate renderer, to be used just as you currently use PMD.

@jsotuyod jsotuyod changed the title [core] How to wrap CDP as a rule [core] How to wrap CPD as a rule Jan 14, 2017
@rsoesemann
Copy link
Member Author

Thanks @jsotuyod fro providing valuable feedback here. I guess your second idea is the solution. Make CDP run seperately and redirect / convert the ouput so CodeClimate can understand it.

@pmd pmd locked and limited conversation to collaborators Jan 15, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
a:question Request for information that doesn't necessarily entail changes to the code base
Projects
None yet
Development

No branches or pull requests

3 participants