2
votes

I am new to SonarQube and trying to run the analytics on all the extensions in one go. I am able to run it successfully for extensions individually but when I run "ant sonar" with hybris, it gives me below exception:

[echo] - sonar.jdbc.url        : ${sonar.jdbc.url}
[echo] - sonar.projectName        : Superproject
[echo] - sonar.project.key        : superprojectkey
[echo] - sonar.project.version        : 1.0
[echo] - sonar.excludedExtensions        :
[echo] - sonar.language        : java
[echo] *************************************************
[echo]
r:sonar] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
r:sonar] Sonar Ant Task version: 2.1
r:sonar] Loaded from: file:/E:/hybris/bin/platform/resources/ant
r:sonar] INFO: Default locale: "en_IN", source code encoding: "UTF-8"
r:sonar] INFO: Work directory: E:\hybris\bin\platform\.sonar
r:sonar] ERROR: Sonar server 'http://localhost:9000' can not be reached


E:\\hybris\bin\platform\resources\ant\sonar.xml:84: org.sonar.runner.kevinsawicki.Ht
        at org.sonar.runner.kevinsawicki.HttpRequest.code(HttpRequest.java:1392)
        at org.sonar.runner.kevinsawicki.HttpRequest.ok(HttpRequest.java:1417)
        at org.sonar.runner.impl.ServerConnection.downloadString(ServerConnection.java:83)
        at org.sonar.runner.impl.ServerVersion.downloadVersion(ServerVersion.java:49)
        at org.sonar.runner.impl.ServerVersion.version(ServerVersion.java:40)
        at org.sonar.runner.impl.ServerVersion.is35Compatible(ServerVersion.java:64)
        at org.sonar.runner.impl.JarDownloader.download(JarDownloader.java:39)
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:59)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:57)
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:71)
        at org.sonar.runner.api.Runner.execute(Runner.java:89)
        at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)
        at org.sonar.ant.SonarTask.execute(SonarTask.java:48)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.apache.tools.ant.Main.runBuild(Main.java:851)
        at org.apache.tools.ant.Main.startAnt(Main.java:235)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.net.ConnectException: Connection refused: connect
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
        at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
        at org.sonar.runner.kevinsawicki.HttpRequest.code(HttpRequest.java:1390)
        ... 44 more

I know this is an configuration issue but I could not locate the file where the LOG is saying it is. Also, why is it requiring jdbc url?

Thanks.

3
What version is your SonarQube server?G. Ann - SonarSource Team
Hi G.Ann. it is 6.5AppleBud
Can you edit the question to include your Ant config & target?G. Ann - SonarSource Team
imho we also had no luck with the ant target of sonar for hybris -> luckily we have our own wrapper for the whole hybris "ant"-stuff to work with! - but in your case it just looks like you did not define the server properly... because it tries to connect to your localhost. About the JDBC url - hybris has some really old code "jalo" and therefore they are probably used 4.5LTS when they generated that, and at this time that property existed. right now, you just have to provide your sonar-url -> if you really want to do analysis on your code, i recommend to either use gradle or jenkinsrunnerSimon Schrottner
@SimonSchrottner, that is what I am not getting how to do. It says that the working directory is somewhere under hybris package structure but I could not find that so that I can provide the sonar server url.AppleBud

3 Answers

1
votes

i just write down the approach we are using within our projects - not exactly as we are wrapping ant with gradle but how we proceed and configure everything.

We are not using the ant sonar scanner but either, the gradle sonar scanner [1] or the jenkins sonar scanner [2], so in this case you could actually use the sonar scanner [3].

Configuring sonar properties:

you can easily put all your configurations in your project root in a file called sonar-project.properties.

sonar.host.url=<sonar url>
sonar.projectKey=<project key>
sonar.projectName=<project name>

# you could use here java as language, but if you also want to analyse JS and other languages remove it, and adapt the source path to add those too
sonar.language=java

sonar.sources=<path-to-extension>/src,\
    <path-to-extension>/hmc/src,\ 
    <path-to-extension>/web/src,\
sonar.tests=<path-to-extension>/testsrc

sonar.java.binaries=**/classes
sonar.java.libraries=**/*.jar
sonar.java.test.binaries=**/classes
sonar.java.test.libraries=**/*.jar
  1. this is just a simple basic configuration - so you need to define your test plugin and paths in here too.
  2. i added paths for web and hmc, if your extension is not using them remove them
  3. i just added one extensions, you could simply extend it with multiple ones
  4. every config you do, you can simply put into this sonar-project.properties, and you can even check it into your VCS, to share it with others. benefits are that this settings are connected with your source, so if you have a new extension you also adapt the sonar settings, and do not need to adapt any build etc.

Running the scanner

now you can simple use every runner you like by using those project properties. either jenkins, or gradle or local, you just need to ensure that the sonar-project.properties file is in the root of your project, and pointing to the right files.

Acknowledge

i know this is not the default hybris way, and it is not using the ant target of hybris, but i figured out, that this approach gives me much more flexibility than the default way!

[1] https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle?src=contextnavpagetreemode

[2] https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins

[3] https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

0
votes

are you sure that the Sonarqube server is launched? Maybe launch it manually and be sure that is is visible in your browser when accessing locallhost:9000/about . As the root problem is the sonarserver not being available i'd go for that...

0
votes

The Sonar Host URL is configured through a property called sonar.host.url

On the project I was working a while ago this property was set in hybris\config\local.properties

Related to the INFO: Work directory: E:\hybris\bin\platform.sonar logged, I think that the working directory can be set using the sonar.working.directory which ,if not set, is somehow computed to be the one you saw in logs (i.e hybris\bin\platform.sonar)