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

[doc] How to configure "-cache <path>" #1394

Closed
xyf0921 opened this Issue Oct 16, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@xyf0921

xyf0921 commented Oct 16, 2018

Affects PMD Version: 6.8.0

Rule:

Description:

I want to use the incremental analysis of the PMD. I looked up the document and it says use -cache to specify a location for the analysis cache file to use.But when I use the '-cache' argument within CLI, I just can't set the right parameter. It seems like I have trouble in generating the cache file at the first running , I do it like "-cache /path" which '/path' is the directory where I want to store the cache file. But I got the Error says"Could not load analysis cache from file. /***/*** (Is a directory)" . Then I set the path as an empty file like '.../cache' , and I got "Cache file a is malformed, will not be used for current analysis" . It seems like I can't generate the cache file at the first time . This may be an simple question but I am new for PMD and I didn't find the right way to do this on Internet. So I would be appreciated if you can help me with this.
Thanks a lot.

Code Sample demonstrating the issue:


Running PMD through: [CLI]

@jsotuyod

This comment has been minimized.

Member

jsotuyod commented Oct 16, 2018

@xyf0921 the -cache param, as you figured out, should point to a file, not a directory. If the file doesn't exist, it should create it just fine. If the file exists however, even if empty, it will attempt to load it, triggering the malformed error you saw; but it should rewrite it at the end of analysis, so following executions should use it without the message.

The way I see it:

  1. we should improve the docs and error messages to make it clear you should provide a path to a file.
  2. we should not say an empty file is malformed, but treat it as non-existing

On your end, could you please confirm that the cache has been created when a file was provided, and that following executions can use it?

@jsotuyod jsotuyod self-assigned this Oct 16, 2018

@xyf0921

This comment has been minimized.

xyf0921 commented Oct 17, 2018

@jsotuyod
Thanks. It seems like I wrongly configured the java environment before which makes PMD terminated. And now it can work well. As you say , when I provide an existed file , no matter the file is empty or not , it triggers the malformed error , but can rewrite the file at the end of analysis , and following executions can use it.

@adangel

This comment has been minimized.

Member

adangel commented Oct 17, 2018

Hi @xyf0921 , thanks for testing! Could you also check, whether an error is displayed, if the file doesn't exist yet? That is the most common case for the first run.

-cache existingfile.cache -> This is ok, if the file is valid, if it is empty or malformed, we log an error and ignore the contents. At the end, we have overridden whatever was in this file before.

-cache nonexistingfile.cache -> This should be ok and should we should not log a warning/error if the file doesn't exist. At the end, we should have created the file.

I think, you've already checked the first case. If the second case is, like I've described it, then we don't have a bug here.

The only thing left would be improving the documentation here: https://pmd.github.io/pmd-6.8.0/pmd_userdocs_incremental_analysis.html and https://pmd.github.io/pmd-6.8.0/pmd_userdocs_cli_reference.html#options

@xyf0921

This comment has been minimized.

xyf0921 commented Oct 17, 2018

Hi @adangel , I just tested the second case . It logs "Analysis cache invalidated, rulesets changed." and "Analysis cache invalidated, execution classpath changed." , but don't have malformed error anymore. And the cache file can be created after analysis.

@adangel

This comment has been minimized.

Member

adangel commented Oct 17, 2018

Thanks for checking.

I guess, we should log out instead of "Analysis cache invalided..." just something like "Creating new analysis cache file..." (and do this only once, not for both rulesets and classpath changes).

And update the documentation to clearly state, that this is a file, that and when it is being created, when it is being invalidated (malformed, ruleset and/or classpath changes).

@xyf0921

This comment has been minimized.

xyf0921 commented Oct 17, 2018

That's great! Thanks. @adangel

@adangel adangel changed the title from [java]How to configure "-cache <path>" to [java] How to configure "-cache <path>" Oct 17, 2018

@oowekyala oowekyala added the has:pr label Oct 22, 2018

@oowekyala oowekyala added this to the 6.9.0 milestone Oct 22, 2018

@adangel adangel changed the title from [java] How to configure "-cache <path>" to [doc] How to configure "-cache <path>" Oct 23, 2018

adangel added a commit to apache/maven-pmd-plugin that referenced this issue Oct 30, 2018

[MPMD-275] Upgrade to PMD 6.9.0 - adjust integration test
The log output for analysis cache has been changed.
See pmd/pmd#1394
and pmd/pmd#1403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment