sonar-maven3-plugin Javascript not respecting -Dsonar.source - maven

I have a project that contains javascript files in src/main/webapp/js. In order to analyze these, I am executing the following:
mvn install org.codehaus.sonar:sonar-maven-plugin:3.5:sonar -Dsonar.branch=js -Dsonar.language=js -Dsonar.sources=src/main/webapp/js -Dsonar.login=sonar -Dsonar.password=sonar
I have also attempting this with: -Dsonar.importSources=true
When I execute this, I get a build success. However, when I look at the js project I created, it contains no data. When I look at the logs, I see this which leads me to believe that the sonar.sources property is not being read.
[INFO] [17:38:42.273] Base dir: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace
[INFO] [17:38:42.273] Working dir: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/sonar
[INFO] [17:38:42.273] Source dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/src/main/java, /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/generated-sources/wsimport
[INFO] [17:38:42.273] Test dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/src/test/java
[INFO] [17:38:42.273] Binary dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/classes
[INFO] [17:38:42.273] Source encoding: UTF-8, default locale: en_US
Can anyone suggest a solution for this?

For now, it is not possible to use properties such as "sonar.sources" when the analysis is triggered with Maven. See http://docs.codehaus.org/display/SONAR/Analysis+Parameters. But it should be soon. See http://jira.codehaus.org/browse/SONAR-4536.
So, you can work with Maven profiles to override source directories.

A work-around have been found in this post :
Empty metrics in sonar for web and javascript projects
It is a bit messy with the maven profiles, but I tried it, it does the job...

Related

Get the list of resource files copied using maven in a text file or xml

Is there clean way to get the list of resource file names copied by the maven build from the project resources directory in a text file / xml . This file could be placed in the root of output resources folder.
For e.g
when maven say,
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # sample-project ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 100 resources
I need these 100 resource names in an text file in the result jar file.
Thanks in advance
This is not supported by the plugin, so there's no out-of-the-box solution.
You'll need to write your own plugin to do this... just checkout the current maven-resource-plugin and modify it as needed. Looking at the code, I think (but I'm not 100% sure) that you just need to add a bit of code in ResourcesMojo to capture the list of files that will be copied.
There are a few (maybe cheaper) alternatives such as using an ANT task to execute a plain ls/dir and put the output of that in a file.

SonarQube: Source is not present in module base directory

We have been executing sonar analysis successfully with SQ-4.5.4 version with no issues. Suddenly since couple days our sonar analysis build is failing with below error message:
It is not indexing any source file even though it has found them. We have made no changes in our pom.xml or project structure. I am not sure why it is adding "build/sonar" to base directory path that I have mentioned in pom.xml for project base directory. I tried giving relative path too but still issue is reproducible.
[INFO] [14:03:23.298] Base dir: /opt/customer/ci_workspace/sonar/10.1.0/TN/build/sonar
[INFO] [14:03:23.302] Source encoding: ISO-8859-1, default locale: en_US
[INFO] [14:03:23.304] Index files
[WARN] [14:03:24.008] File '/opt/customer/ci_workspace/sonar/10.1.0/TN/access/Application/src/com/panther/ph/access/persistence/cocobase/AccessBP.java' is ignored. It is not located in module basedir '/opt/customer/ci_workspace/sonar/10.1.0/TN/build/sonar'.
I have mentioned below property in my pom.xml
"/opt/customer/ci_workspace/sonar/10.1.0/TN
../../access/Application/src"
The base directory is where your POM is located and your analysis launched.
The problem is that in the POM, you are referring to a source folder that is not located in a sub-folder of the base directory. This is not supported in SonarQube - and this is actually not a standard structure for source code.
#Fabrice: The issue was someone had made some changes in repository which made our sonar-maven-plugin degrade to 2.0 version from 2.6 due to which it has failed.
#Everyone: If you are facing similar issue please check your sonar-maven-plugin is at least 2.6 version.

Jenkins "POM_VERSION" variable does not reset from build to build

Following Jenkins documentation jenkins docs
I can use the POM_VERSION environment variable to take the current version from the pom file.
But for some reason the POM_VERSION environment variable is not being refreshed from build to build. for example:
I changed the version number manually but the build number that exported was the last from the previous build.
From my python script:
print 'Current version is ' + os.environ['POM_VERSION']
which gives the following log Current version is 0.1.5 which is clearly wrong because i changed it. you can further see it in my maven versions goal output:
[INFO]
[INFO] --- versions-maven-plugin:2.1:set (default-cli) # ep-reporter ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /var/lib/jenkins/jobs/exchange-planner- reporter/workspace
[INFO] Processing com.exelate:ep-reporter
[INFO] Updating project com.company:ep-reporter
[INFO] from version 0.1.8 to 0.1.6
Props: {project.version=0.1.6, project.artifactId=ep-reporter, project.groupId=com.company}
note that it went from 0.1.5 because i have a script that advances it. but maven clearly states that its changing it from 0.1.8 to 0.1.6 which is not what POM_VERSION says
Thanks.
That environment variable is set at the time Jenkins first reads your POM file. You are clearly changing it during the build.
If you are changing it during the build, you know what you are changing to, and you should use the same mechanism to display it later.
I had the same problem and I resolved it by setting "Check-out Strategy" option to "Always checkout a fresh copy" in Source Code Management section.

Maven - dynamic pom file?

I'm using the Maven plugin was6-maven-plugin to deploy to websphere. When installing an application, there's a configuration value named "updateExisting" that should be false if I am installing a new application, and true if I am updating an existing application. I don't like having to manually toggle this value if I am fresh-installing/updating the application.
The way I see it, I can either add an uninstallApp goal to always uninstall the application before installing it, but this seems a rather silly way to do it.
I've noticed that this plugin also has a goal wsListApps that outputs all applications installed on the server. The output looks like this:
[INFO] [wsadmin] WASX7209I: Connected to process "server1" on node 1234Node02 using SOAP connector; The type of process is: UnManagedProcess
[INFO] [wsadmin] DefaultApplication
[INFO] [wsadmin] IBMUTC
[INFO] [wsadmin] MyApplicationEAR
[INFO] [wsadmin] ivtApp
[INFO] [wsadmin] query
Is it possible for Maven to scan this output for the string "MyApplicationEAR" and set "updateExisting" to "true" if it is found, and leave it "false" otherwise?
What you need is to be able to update a maven property during the life-cycle, before the phase binded with your was6-maven-plugin. (and using this property as a value for <updateExisting>)
Unfortunately, maven properties are static and cannot be changed at runtime. So at first sight it's impossible to do.
But, there is a plugin : properties-maven-plugin you can use to define new properties at runtime. The value of the property can be defined by a groovy script. Now the question is more about how can you write a groovy script telling if your app is already there or not.
Honestly, I don't know if it's a good idea to use it. I think running the uninstall goal everytime with failOnError set to false is probably the simplest way (and so probably the best, but maybe I am missing something ?)

Feeding emma coverage to sonar

I'm trying to feed sonar with emma results for a multimodule project
mvn sonar:sonar -Dsonar.dynamicAnalysis='true' -Dsonar.core.codeCoveragePlugin=emma -Dsonar.emma.reportPath=target
For each module I get:
instrumentation path processed in 1798 ms
[146 class(es) instrumented, 19 resource(s) copied]
metadata merged into [<module>/target/coverage.em] {in 152 ms}
and later:
[INFO] [12:24:32.514] Sensor EmmaSensor...
[INFO] [12:24:32.514] Parse reports: <module>/target
[WARN] [12:24:32.514] No coverage (*.ec) file found in <module>/target
[INFO] [12:24:35.123] Sensor EmmaSensor done: 2609 ms
So I get 0% coverage in sonar
Why is it trying to find .ec files instead of .em files?
Sonar version is: 3.5.1
Thanks
It would be nice if you mentioned the Sonar version you use.
However I think that the parameter sonar.dynamicAnalysis should have the value of 'reuseReports' and not 'true'
Also make sure that the em files are existing under the target folder
For more information see http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project
and
http://docs.codehaus.org/display/SONAR/Emma+Plugin

Resources