Prompt SONAR to analyse code - java

Actually in our project, we are planning to start developing code (with SONAR to analyze from beginning only) , So we are making use of sonar plugin in eclipse. We know how to analyze code by configuring project to SONARQUEBE and making use of maven build tool as well as using sonarrunner. Instead of building maven for every code changes and analysing , is there any way that prompts (as well as show error lines ) sonar to immediately analyze just after saving the java file ?
Help will be appreciated..... Thanks in advance

There is currently no way to tie an sonar analysis to a save action.
However, you do not need to run the maven based analysis. Assuming you use a recent version of SonarQube and SonarQube ide (4+ and 3.3), you can simply run the analysis using the shortcut (ALT-Ctrl-Q, by default).
Using incremental mode with SonarQube 4+, this is actually really fast, because it analyzes only the changed files as compared to the last successful SonarQube run.
Of course, you need make sure that your buildserver regularily runs your full SonarQube builds as well.

Related

Running sonarLint analysis for a directory? [duplicate]

I have installed the latest sonarLint plugins with Intellij 2016.1.2.
Analyze on the fly works fine. However, I can't find in the IntelliJ "Analyze" tab any "Analyze with SonarLint". In the SonarLint window>issues tab, I can only see scope "current file" or "opened files". I don't see any Project scope.
So my question is how to trigger the analysis on my whole project ?
Since SonarLint v2.8, it's possible to analyze all files in the project.
Open the SonarLint Tool Window, go to the Project files tab, and click in the "play" button.
There is also an action to which you can assign a shortcut.
More information here: https://www.sonarlint.org/intellij/howto.html
The easiest two ways to do project analyze:
Choose Analyze | Analyze with SonarLint
Press Ctrl + Shift + S
As #Duarte - SonarSource Team suggests Sonar-Lint has a different purpose. It is intended to use to analyze for code changes in current file(s). i.e. it cannot perform analysis which needs to compare 2 files. (ex: finding duplicates, coverage etc.)
For your purpose that best way to achieve is running SonarQube with preview mode.
Update:
As per this, the preview mode has been deprocated in v 6.6 and will be dropped in future.
they stated many times that their intent is to support only new issue being introduced running an on-fly analysis on files being changed.
If you wanna run a full analysis you should use the SonarQubeCommunity plugin or visit your remote Sonar Server.
If you wanna gather only coverage information within your IDE, use the Jacoco plugin.
However there is an open feature request to browse those issues directly in the SonarLint plugin: https://jira.sonarsource.com/browse/SLE-54
Yes, that screenshot is confusing, but that feature was previously available.
Since version 2.8 analysis of all files in the project is possible.

Gradle slows down computer during findbugs analysis of Java project

I'm using gradle 2.4 for a multi-project written in Java which has abount 15000 lines of code in 5 projects and i'm using Windows 7. I'm using the findbugs plugin in every sub-project.
The build itself is fast (enough) but while findbugs is running the reactivity of my PC is very bad. Most time the mouse hangs, opening websites takes a lot of time, music shutters, video hangs, etc.
If i reduce the priority of the corresponding java-process, everything is fine. For linux i found this https://askubuntu.com/questions/469709/gradle-compiling-slows-down-my-computer . I tried the suggested -PtaskThreads=x option, but that didn't help.
Is there a way to set the priority of the java-process which does the findbugs stuff to 'idle' or 'background' programmaticaly? Preferable with pure gradle options since i don't want to use some tools like CPULimit.

Unable to delete the persistit_tempvol file after Executing sonar Embedded Runner from Java

I have a set of project's on which I need to execute Sonar. Once I execute sonar task and it publishes the result it deletes all the files in the directory .sonartemp except the file persistit_tempvol. This file is locked by Java SE runtime and I am unable to delete this.
The reason I want to delete this file is once it starts executing another project it creates the same file for that project and the data from previous persistit_tempvol is still in Java Heap. So after I run few projects I actually go OutOfMemory.
I tried increaing the Heap memory, but the number of projects are very high ~100. I don't want to go one by one and execute them. I want to keep doing it in the loop.
I am running sonarrunner 2.4, windows 7, Java 8, sonar ant task 2.3, Sonar Qube 5.1
Here's how I am executing the sonar runner:
EmbeddedRunner.create().addProperties(properties)
.unmask("org.apache.tools.ant").unmask("org.sonar.ant")
.execute();
The properties is the property file of sonar.
I guess I cannot delete this file from sonar as it's locked by by my JVM. Is there a way I can delete this file?
I guess you don't really need to pass Ant objects as extension so I suggest you give a try to ForkedRunner instead of EmbeddedRunner. This would allow you to start with a clean JVM for each analysis.
FYI we are currently working on improving the embedded mode to support running several consecutive analysis without any resource leak (SQ Runner 2.5 + SQ server 5.2).
ForkedRunner.create().addProperties(properties).execute();
That's all I had to do and it is working fine now. Thanks :)

New Sonar IntelliJ plugin incremental analysis and detection not working

I’d like to ask for help. I installed the plugin and successfully added the SonarQube server. I upgraded to version 4.1.2. I use IntelliJ IDEA 13.0.2.
I also successfully associated the project and inspection warnings appeared. But when I fix the issue the status is not updated.
How to synchronize ?
I also run inspection by name ‘SonarQube issues’.
Nevertheless after running the inspection the warnings are also there, where the code was fixed. It seems to me the synchronization somehow fails.
Any idea, what todo, please?
What I had done in my situation.
Installed SonarQube 4.4.
Installed IntelliJ 13.1.4b (the same history was with 13.0.4).
Configured SonarQube intelliJ plugin (not community provided one but plugin from SonarSource). All instructions are under the link on Wiki.
Attached to Sonar project. Every step just as SonarSource recommends.
This gave me mapping from Sonar onto source code. But it does not update when I simply fix the issue. But if I fix issues I then re-post project onto Sonar through mvn sonar:sonar and this gives me updated picture next time I run inspection through sonarqube plugin.
But this is not 100% what is wanted. But definitely better than nothing. Also I have imported Sonar rules through QAPlug - this is far less useful. But notable faster.
Overall this configuration allows me to make what is needed but I'd like to receive real incremental processing without publishing local changes onto Sonar server.
Give a try to the SonarQube IntelliJ Community Plugin, it is made for fixing issues detected by jenkins on the local dev machine. Different then the official plugin you will need to do more configuration by yourself, but it gives you also the freedom to specify your local analysis script like you need.
What you need to do:
configure the plugin
setup sonar server
setup local analysis script
Afterwards you can run SonarQube (new issues) inspection, this will run the script and show the results in the Intellij. If you are fixing issues, you can just rerun the inspection from inside the inspections results tool window. This will rerun the script and show new results.
see also: https://github.com/sonar-intellij-plugin/sonar-intellij-plugin

Creating a program that will run before and after compilation in Eclipse

I am currently working on a small program that should comment out some code used for testing.
I want it to auto run before the compiler while compiling the release version and another program that will comment the code back in after compilation was over.
The program works the only thing I am missing is to add it to the build process.
Thanks to all helpers!
In Eclipse, right-click a project, choose Properties → Builders and click New. You can add an Ant script or a command line that Eclipse will trigger when building the project. You can also control the order of builders in the same dialog.
However, I agree with JB Nizet – there are many advantages to having Ant or Maven build your project.
Don't use Eclipse to build the release version of your app. Use Ant, Maven, or any other build tool that is much more flexible than Eclipse, doesn't need a GUI, can be scripted and used by a continuous integration server.
All of these tools should easily be used to include your pre-compilation and post-compilation tasks in the build process.
That said, you could just use a public static final boolean constant FOR_TEST, and include all your testing code in
if (TestUtil.FOR_TEST) {
}
You would then have just a single place to change in the code to have all the test code removed from the compiled version. No need for a complex Java program to do that.
Or you could let all the testing code in the released version, and activate it when testing using a system property, for example. This wouldn't even need any precompilation/postcompilation phase, and would probably have a negligible cost.

Categories

Resources