Recently I've upgraded SonarQube from 3.5 to 4.5.4 (LTS) and now there are a few users complaining that there are some reports missing on their project dashboards. The reports/numbers missing widgets are: lines of code and complexity. Unit tests coverage displays nothing. Other widgets (like technical debt, issues, directory tangle index) display 0 which also is suspicious. The project is in Java using the Sonar way profile.
The user does:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install
mvn sonar:sonar -Dsonar.login=login -Dsonar.password=***** -Dcom.sun.jndi.ldap.connect.pool.prefsize=0 -Dcom.sun.jndi.ldap.connect.pool.timeout=3600000
The sonar:sonar step shows "0 files indexed".
The log is huge so I don't want to paste it here. I could not find anything helpful in it. What do I need to do to have all reports I used to have?
I have a test project where most of the missing data is displayed "out of the box".
Starting with version 4.3, SonarQube no longer runs automated tests. It expects Jenkins/CI system to run the tests, create the JUnit/PMD/Jacoco/Clover etc. reports, and then tell SonarQube where to find them. (In older versions of SonarQube, this behavior could be achieved by setting the "reuseReports" flag to true.)
If the build is not configured to generate the reports, it will need to be adjusted to do so.
Related
I have sonarqube and eclipse with plugin configured for a java project. When I run mvn sonar:sonar - I see results of the build in sonarqube console.
When I make analysis with Eclipse plugin - I see all issues locally in Eclipse, but not on server.
This is because eclipse plugin uses preview mode and sonarque db is not updated (which is good).
Now I would like that every eclipse sonar analysis would run in "analysis mode" - and sonarqube database get updated every time (don't ask why).
Do you know how to enable this behaviour?
thanks!
I don't ask why but anyway this is not possible.
I need to prepare a reporting system which will be displayed the code parts are used and not used by the application and in this particular case I'm going to use EMMA. However there will be no any test code next to project and emma will scan only the methods and give such a report like "20% are not using, %80 are in use" etc...
Is this possible?
If yes how should I configure ant without junit? (Please share sample ant code)
Do I need to make something additional to work with jenkins?
I will try to provide an answer after all even though you didn't tell what exactly you have and need.
Step 1. The first thing to do is to configure Hudson. First step I did was to download hudson war file and run it.
Step 2. What I did here was to start it via java command line and configure the plugins that I need. In your case the plugins are svn, git and android emulator. See below how to configure Hudson.
Configure Hudson Link 1
Configure Hudson Link 2
Next, I downloaded tomcat and I configured the web.xml file from webapps/hudson/web-inf to link to the hudson home just created earlier.
Now, once you managed to run hudson properly, you can start configuring hudson and next the jobs.
Step 3. Configuring Hudson. You start by configuring Hudson, by setting up the plugins you need, like Apache Ant, Android Emulator, etc.
Step 4. Configuring jobs. You have two type of jobs: normal and test.
See below a printscreen for the required configuration.
Common things for both jobs is the repository URL of your online URL, SVN, Git, etc.
A printscreen for a normal job can be seen at:
For the test job on the other hand you have to configure a bit more. You start by configuring the build environment. If you installed the Android Emulator plugin you should see options " Run an Android emulator during build". This has to be checked together with some other information. A small tutorial can be found here. I would say it is pretty similar.
Android on Hudson.
Once you achieved this, further on you configure ant. Here, you check the Ant version to be one that you set before in the general settings section and, as for the targets, I used the following option:
"clean-set-absolute-tested-path emma instrument nodeps verbose-output-file-for-emma install test fetch-test-report".
Now, in order to see the coverage reports, I used a plugin that allows you to publish the coverage reports as an HTML page and this option can be found at the post-build actions step. For a better understanding see the image:
Step 5. Configuring the xml files.
Now, once hudson is done, further on you start configuring the project in eclipse. You start by creating a test project for your app(I hope you know how to do that) and after that you create the files ant.properties, build.xml and project.properties.
At first, you create the build xml and the ant properties files for the library.
An example of a build xml for the library can be found at:
http://pastebin.com/WiD2Y6j4
Also, the ant.properties for the library can be found at:
http://pastebin.com/cpuGVDhL
Further on, you need the configuration for the test app. Build xml:
http://pastebin.com/yjC8TViT
Ant properties:
http://pastebin.com/5STqMV6b
Once you have committed your code and run the jobs you created before, you should be able to see the html report for your code, classes %, methods % and even what your logic tested. However, from my experience the latter(logic testing) has not proven to be quite an exact science.
Hope it helps. That's pretty much the configuration we use at my work. So far was successful.
There is a SonarQube for IntelliJ, which, even though a bit temperamental, allows you to download rule violations from Sonar and view them directly in IntelliJ (the downside being the analysis runs on the server, necessitating a sync; the upside being you get exactly what you'd get in Sonar), and there is the QAPlugin, which allows you to import Sonar's Checkstyle, PMD and Findbugs rules and run them locally, but it does not support SSLR/squid rules yet. Sonar, however, seems to be moving away from PMD & Co. towards SSLR.
Is there currently a way to import Sonar's SSLR-based rules in IntelliJ and to run them locally?
You should take a look at the official SonarQube IntelliJ plugin which allows you to run SonarQube analysis within IntelliJ - whatever the rules you've configured on your SonarQube instance (SonarQube rules, Checkstyle, PMD, Findbugs).
Up from version 2 the SonarQube Community Plugin allows you not only to download issues from Sonar and view them directly in IntelliJ, but also to run any local analysis script, the results are then shown in Intellij like any other inspection.
You don't need to import any rules, instead you just run a local analysis script using the sonar-runner or any build tool plugin like mvn sonar plugin:
/path/to/mvn sonar:sonar -DskipTests=true -Dsonar.language=java -Dsonar.analysis.mode=incremental -Dsonar.host.url=http://your.sonar.host -Dsonar.profile=your_squid_based_profile
this will create a sonar-report.json file:
Export results to /path/to/your/project/target/sonar/sonar-report.json
You can configure the plugin which script to execute and where to read the results. Also the plugin does not care if the issues comes from squid or any other rule set.
See also: https://github.com/sonar-intellij-plugin/sonar-intellij-plugin
Currently I'm looking at integrating some build processes into my source control (Git hooks specifically). I'm trying to write a pre-commit hook that checks for build errors in my Java project (a medium-large test development project) and fails to allow commits that contain errors in the build. This is turning out to be rather challenging.
The approach here uses a command-line Eclipse tool to build and output warnings and errors. This does technically work, but it's slow and may cause problems with the Eclipse IDE (I've already had heap allocation errors). I've also looked at solutions using ant but these approaches don't seem to be a simple one-line solution, and may still be slow.
My main question: what's the fastest (run-time compilation speed) way to build and validate a Java project, by command line? I'd like a solution that returns 0 with no errors and something else if errors are present, but I'm willing to look at other things.
Let's start with some basics:
pre-commit hooks run on the server and not the client. There is no working directory by default. You have to make sure that javac is available, and is the correct version.
Your pre-commit hook will freeze up the user's terminal until completion.
Now, how long will it take to checkout a fresh copy of your Java project, run Ant, wait for it to compile, and then process the output of the compile? a minute or two? 20 seconds? 10 seconds? Even 10 seconds will feel like forever as you wait for the Git push to complete. And, if other users want to commit code, they have to also wait.
A better, and easier approach is to use a Continuous Build Server like Jenkins. Jenkins is easy to setup. (It comes with its own application server built in) and has hundreds of plugins that you can use to help report the health of your project. If a compile cannot happen, Jenkins will email the culprit and whomever else you mention.
We have our Jenkins setup to do Ant builds, Maven builds, and use either Git or Subversion as our repository (depending upon the project). Jenkins builds the project, keeps the console log, and will fail the build if build.xml fails. At our place, this means I start pestering the developer to fix the problem or to undo their changes. At my last workplace, developers were given 10 minutes to fix the build, or I would undo their changes.
Not only can Jenkins let you know when a build fails, but has plugins that can report on the Java compiler warnings, Javadoc warnings, run Findbugs, PMD, find duplicate lines of code (via CPD that comes with PMD), and then report everything in a series of graphs. You can also mark builds as unstable (build completes, but is problematic) or simply fail the build based upon the number of issues found with these tools.
Jenkins can also run Unit tests, and again graph the results, then run coverage analysis with JaCoCo or Cobertura or Emma.
So, take a look at Jenkins. It's easy to setup and will do exactly what you want and more.
Ant. There isn't going to be a "one-line-solution". Write an ANT script that compiles the code, and fails if there are any errors. It's not easy, but it's the best option.
Out of the choices you mention, Ant is the best. But let's face it, writing XML sucks. My guess is that any build tool will fail and return an error code when compilation fails. My favorite is sbt, but there's a bit of a learning curve if you aren't into Scala (and even those in Scala like to complain about sbt). Another great option IMO is Gradle. You write your scripts in Groovy which is a dynamically-typed superset of Java.
Jenkins may be a something you could look at
The JUnit integration with eclipse is very nice. However, I would like a feature to be able to generate a quick report from the Unit Tests. It is possible to do so when running a headless build (and my nightly build is configured to do so), but sometimes I want to generate a report from the UI.
Is there anyway to do this? command line options maybe? an extra plugin? maybe the functionality is already there and I can't find it?
EDIT: I have a PDE build, as my project is an RCP application. Thus, running the tests from this build is not really straight-forward. I guess I could try to hack a smaller ANT script to do the test, but then probably I have to fight with the classpath to obtain what I want. I was hoping to find some extension to the already existing JUnit plugin that would provide the information on the tree view, but as an HTML document.
You can use ant and generate HTML report [I think you can use Ant in Eclipse]
I found these link but you can survey more:
Ant JUnitReport Task
JUnit Tutorial
JUint Report
I'm not sure if you want a "physical" report that you can distribution or just more information you can view in your IDE.
Either way I agree with SjB's advice on configuring Eclipse to run the ant script generating the report in your nightly build.
If it's not possible to run the nightly build locally, you can do some very simple build script hacking following the links in SjB's answer.
You also might want to check out the Ant JUnit Task Manual Page