Possibillity to store data between multiple analysises

Lets say we have multiple Files that need to be analysed: Foo.java and Bar.java.
Is it possible to store parsed informations about either of the files between runs.

My approaches would be:
Given the Check-Class gets instantiated once for each file.
Write informations to a temporary file and read it from other instances. Like a shared storage.
The only problem right now that I can think of is. When do I know when the last file is analysed.
In the end an error should be raised if no information is written to said file. But that requires the knowledge of how many files are still left to analyse.

Given the Check-Class gets instantiated per run (once per analysisrun).
Is it possible to store data within that Check-Class?
Again I believe its hard to determine when the analysis is done.

Any ideas or solutions?

Hey there.

I’m not the right person to answer this question, but I think it will help whoever is that right person if you answer the question “Why do you want to do this?”

Hello @LeslieM98,

What you tries to achieve is not easy to do with the existing APIs.

As far as I know, it’s the same instance of a rule which is used during the entirety of a simple project analysis. However, I’m not sure it’s the same for multi-modules java projects. Consequently, storing information directly in the rule might be OK for most of the cases, but not all of them. This needs to be tested while implementing.

Storing data on a dedicated place could be simpler… But then you need to know when the analysis is done to trigger collection of data, which is not a mechanism that the java Analyzer is providing through its public API. I however believe that when writing a custom plugin for SonarQube, you can define some ordering. This might solve the issue (having a plugin executed after the java analysis).

Now, regarding WHAT you are storing, here you need to be careful. If you store nodes of the AST, keep in mind that because each node is linked to its parent, you will store the entire compilation unit (file). There is a pretty high chance of exploding in term of memory.

Hope this helps,