Changed Sonar web.context, now ant task fails - ant

I had a working sonar/jenkins installation, where sonar was installed on localhost:9000 and jenkins was on localhost:8080. I then wanted to hide those services behind Apache and protect them behind Crowd-authenticated account access.
So first, I relocated Jenkins to localhost:8080/jenkins and proxied it. Which worked.
Then I relocated Sonar to localhost:9000/sonar and proxied it. Which also worked.
But now, when I try to execute the Sonar task from within the build script in Jenkins, I get the following error:
sonar:
[sonar:sonar] Apache Ant version 1.7.1 compiled on April 26 2010
[sonar:sonar] Sonar Ant Task version: 1.2
[sonar:sonar] Loaded from: file:/usr/share/ant/lib/sonar-ant-task-1.2.jar
[sonar:sonar] Sonar work directory: /var/lib/jenkins/jobs/buzzcartes/workspace/.sonar
[sonar:sonar] Sonar server: http://localhost:9000
BUILD FAILED
org.sonar.batch.bootstrapper.BootstrapException: http://localhost:9000/api/server /version
at org.sonar.batch.bootstrapper.Bootstrapper.getServerVersion(Bootstrapper.java:71)
at org.sonar.ant.SonarTask.checkSonarVersion(SonarTask.java:225)
at org.sonar.ant.SonarTask.execute(SonarTask.java:188)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.io.FileNotFoundException: http://localhost:9000/api/server/version
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
at java.net.URLConnection.getContent(URLConnection.java:748)
at org.sonar.batch.bootstrapper.Bootstrapper.remoteContent(Bootstrapper.java:123)
at org.sonar.batch.bootstrapper.Bootstrapper.getServerVersion(Bootstrapper.java:69)
... 18 more
I've updated the configuration in Jenkins to reflect the new location of http://localhost/sonar so I'm not sure where the http://localhost:9000/ is now coming from. I've looked in a variety of config files so far with no joy and Google isn't turning up any good answers so far. Any pointers would be most welcome.
Oh, my sonar task in build.xml looks like this:
<target name="sonar" depends="compile">
<!-- list of mandatory Sonar properties -->
<property name="sonar.sources" value="${basedir}/src" />
<!-- list of optional Sonar properties -->
<property name="sonar.projectName" value="buzzcartes" />
<property name="sonar.binaries" value="${basedir}/build" />
<property name="sonar.tests" value="${basedir}/test" />
<property name="sonar.libraries" value="${basedir}/lib" />
<sonar:sonar key="com.benjasoft:buzzcartes" version="0.1-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant" />
Thanks!

Try so set the sonar.host.url parameter
Maven
<sonar.host.url>http://wherever.sonar.com:9000</sonar.host.url>
Ant
<property name="sonar.host.url" value="http://wherever.sonar.com:9000" />
Strangely it is not documented here, but mentioned in the ant task guide.

Related

org.sonar.runner.impl.RunnerException: Unable to execute Sonar

I am trying to integrate Sonar task in Ant build in Eclipse. SonarQube server is running successfully at the default port on localhost. On opening "http://localhost:9000/" in browser, SonarQube web interface is successfully opening.
Problem is when I am running Sonar task from Ant build file it is giving error "org.sonar.runner.impl.RunnerException: Unable to execute Sonar". That's it. No stacktrace is logged on console.
The sonar task in ANt build is defined as below:
<target name="sonar" depends="jcompile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="<PathToAntPlugin>/lib/sonar-ant-task-2.2.jar" />
</taskdef>
<property name="sonar.projectDescription" value="Example application using Ant and Jacoco" />
<property name="sonar.sources" value="${basedir}/src" />
<property name="sonar.host.url" value="http://localhost:9000"/>
<property name="sonar.surefire.reportsPath" value="${reports.junit.xml.dir}" />
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<property name="sonar.jacoco.antTargets" value="run-tests" />
<property name="sonar.projectKey" value="<PathToMyProject>" />
<property name="sonar.projectVersion" value="1.0" />
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
</target>
Other details:
SonarQube Server 4.5,
sonar-ant-task-2.2.jar,
JDK 1.6.0_21,
Eclipse Kepler
Is there any comptability issue between the jdk, eclipse, sonar server or sonar ant jar? Is there any way to find the detail logs in order to debug the issue?
Apart from above issue, I am having other issue. When I am installing SonarCube plugin in eclipse, in Windows ->Preferences SonarCube is not coming. However, in installed software list in Eclipse it is listed. I have tried to run eclipse with -clean option but no success. Please let me know what could be the problem?
When we are running the build file from eclipse it is not giving full stack trace on console in some cases. Try to run the build file from the command prompt.
For example:
Open command prompt window and go to eclipse ant bin directory path(In my system it is C:\eclipse\plugins\org.apache.ant_1.9.6.v201510161327\bin) and from here run your build file using ant command.
C:\eclipse\plugins\org.apache.ant_1.9.6.v201510161327\bin>ant -buildfile [path_of_build_file]\build-test.xml
I know I am late, but this is to help who visits this with same problem
For the missing preferences, the Installation FAQ of Sonar says to do a restart with -clean argument.

Worklight project throwing error while uploading files to mobileFirstServer

I am using ant script to deploy adapters and wlapp file over mobileFirstServer. I am using Java 7. Using the code below:
<target name="deploy-wlapp">
<taskdef resource="com/worklight/ant/deployers/antlib.xml">
<classpath>
<pathelement location="worklight-ant-deployer.jar"/>
</classpath>
</taskdef>
<wladm url="http://localhost:10080/worklightadmin" user="admin" password="admin" secure="false">
<deploy-app runtime="myTime" file="/Users/admin/Documents/workspace/myTime/bin/myTime-iOSnative- 1.0.wlapp"/>
</wladm>
</target>
<target name="deploy-adapter">
<taskdef resource="com/worklight/ant/deployers/antlib.xml">
<classpath>
<pathelement location="worklight-ant-deployer.jar"/>
</classpath>
</taskdef>
<wladm url="http://localhost:10080/worklightadmin" user="admin" password="admin" secure="false">
<deploy-adapter runtime="myTime" file="//Users/admin/Documents/workspace/myTime/bin/Requests.adapter"/>
</wladm>
</target>
I am getting the following error in terminal:
: com.ibm.worklight.admin.restclient.RESTException: Error accessing http://localhost:10080/worklightadmin/management-apis/1.0/runtimes/myTime/adapters?locale=en_US: HTTP/1.1 404 Not Found
FWLSE3002E: The resource is not found.
FWLSE3041E: No MBean found for MobileFirst project 'myTime'. Possibly the MobileFirst runtime web application for MobileFirst project 'myTime' is not running. If it is running, use JConsole to inspect the available MBeans. If it is not running, full error details are available in the log files of the server.
at com.ibm.worklight.admin.restclient.RESTClient.getResponse(RESTClient.java:1247)
at com.ibm.worklight.admin.restclient.RESTClient.getResponseWithTimeout(RESTClient.java:1324)
at com.ibm.worklight.admin.restclient.RESTClient.getPOSTResponse(RESTClient.java:1442)
at com.ibm.worklight.admin.restclient.RESTClient.getPOSTFileResponse(RESTClient.java:1464)
at com.ibm.worklight.admin.commands.DeployAdapter.getResponse(DeployAdapter.java:41)
at com.ibm.worklight.admin.restclient.ActionClient.execute(ActionClient.java:84)
at com.ibm.worklight.admin.ant.types.AbstractActionElement.executeCommand(AbstractActionElement.java:76)
at com.ibm.worklight.admin.ant.types.ActionElement.executeCommands(ActionElement.java:43)
at com.ibm.worklight.admin.ant.WladmTask.executeCommands(WladmTask.java:705)
at com.ibm.worklight.admin.ant.WladmTask.execute(WladmTask.java:459)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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)
In Eclipse the following error is shown:
ERROR ] FWLSE3002E: The resource is not found.
FWLSE3041E: No MBean found for MobileFirst project 'myTime'. Possibly the MobileFirst runtime web application for MobileFirst project 'myTime' is not running. If it is running, use JConsole to inspect the available MBeans. If it is not running, full error details are available in the log files of the server.
The same code is running fine for other projects.
It's clearly mentioned in the IBM Knowledgecenter you have to mention the <WorklightInstallDir>/WorklightServer/worklight-ant-deployer.jar
So you have to mention the WorklightServer install directory path (absolte path to the worklight-ant-deployer.jar File)
SO your taskdef should look like
<taskdef resource="com/worklight/ant/deployers/antlib.xml">
<classpath>
<pathelement location="C:\IBM\MobileFirst_Platform_Server\WorklightServer\worklight-ant-deployer.jar"/>
</classpath>
</taskdef>
The location is where your mobilefirst server is located. The jar file
alone wont do the trick. So try it out by giving the absolute path to the mobilefirst production server

SONAR - java.lang.IllegalStateException: Infinite loop in property interpolation of ${SQLSCRIPT}: SQLSCRIPT

I have very simple Sonar configuration with Ant task:
<target name="upload_to_sonar">
<property name="sonar.jdbc.url" value="jdbc:oracle:thin:#server:1521:sid"/>
<property name="sonar.host.url" value="http://sonar:80"/>
<property name="sonar.jdbc.username" value="SONAR"/>
<property name="sonar.jdbc.password" value="SONAR"/>
<property name="sonar.projectKey" value="test"/>
<property name="sonar.projectName" value="test"/>
<property name="sonar.projectVersion" value="trunk"/>
<property name="sonar.language" value="java"/>
<property name="sonar.sources" value="sources_for_sonar"/>
<property name="sonar.binaries" value="classes_for_sonar"/>
<taskdef name="sonar" classname="org.sonar.ant.SonarTask">
<classpath path="${EXTERNAL}/sonar-ant-task-2.0.jar" />
</taskdef>
<sonar/>
</target>
Those folders contain sources and classes in root level.
For some reason execution gives me following error no matter how I configure it:
Buildfile: D:\trunk\src\build.xml
upload_to_sonar:
[sonar:sonar] Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[sonar:sonar] Sonar Ant Task version: 2.0
[sonar:sonar] Loaded from: file:/D:/trunk/src/./sources/external/sonar-ant-task-
2.0.jar
[sonar:sonar] Sonar work directory: D:\trunk\src\.sonar
[sonar:sonar] Sonar server: http://sonar:80
BUILD FAILED
D:\trunk\src\build.xml:132: org.sonar.runner.RunnerException: java.lang.IllegalS
tateException: Infinite loop in property interpolation of ${SQLSCRIPT}: SQLSCRIP
T
at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:93)
at org.sonar.ant.SonarTask.execute(SonarTask.java:75)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
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.lang.IllegalStateException: Infinite loop in property interpolat
ion of ${SQLSCRIPT}: SQLSCRIPT
at org.apache.commons.lang.text.StrSubstitutor.checkCyclicSubstitution(S
trSubstitutor.java:701)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:645)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:656)
at org.apache.commons.lang.text.StrSubstitutor.substitute(StrSubstitutor
.java:563)
at org.apache.commons.lang.text.StrSubstitutor.replace(StrSubstitutor.ja
va:305)
at org.apache.commons.configuration.PropertyConverter.interpolate(Proper
tyConverter.java:958)
at org.apache.commons.configuration.AbstractConfiguration.interpolate(Ab
stractConfiguration.java:446)
at org.apache.commons.configuration.CompositeConfiguration.getList(Compo
siteConfiguration.java:312)
at org.apache.commons.configuration.AbstractConfiguration.getList(Abstra
ctConfiguration.java:1109)
at org.apache.commons.configuration.CompositeConfiguration.getStringArra
y(CompositeConfiguration.java:320)
at org.sonar.batch.Batch.convertToProperties(Batch.java:89)
at org.sonar.batch.Batch.create(Batch.java:78)
at org.sonar.runner.internal.batch.Launcher.executeBatch(Launcher.java:6
8)
at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.sonar.runner.Runner.delegateExecution(Runner.java:285)
... 19 more
Total time: 1 minute 12 seconds
SONAR server version is 3.2
Ant task version 2.0
Enabling verbosity don't give any additional details whatsoever
Created a ticket for community http://jira.codehaus.org/browse/SONARPLUGINS-2704

How to change the Path variable in ant exec task?

I tried setting the Path variable in ant exec task using this link. But its not working somehow. I am trying to add THRIFT_HOME which is set to basedir currently and I have the thrift.exe file in the basedir.
Also, when I change executable attribute value to thrift.exe, the thrift compiler works properly but the basedir is not added to the Path.
<exec executable="thrift">
<env key="Path" value="${env.Path};${THRIFT_HOME}" />
</exec>
I also tried using the setx command as:
<exec executable="setx">
<arg value="Path"/>
<arg value="%Path%;${THRIFT_HOME}"/>
</exec>
but it still does not work.
Any help would be appreciated!
how about this:
<property environment="env"/>
<!-- to see if you can access it -->
<echo message="${env.Path}" />
<exec executable="thrift">
<env key="Path" value="${env.Path};${THRIFT_HOME}" />
</exec>
I've found a hint here: http://www.factsandpeople.com/facts-mainmenu-5/23-other-software-technologies/125-using-environment-variables-in-ant-environment-variables-are-not-evaluated
I am currently using on Windows 7 and the problem was with spaces in the folder name. That's a big problem when working on Windows.
I tried placing the thrift executable at /d/thrift/ and it worked and assigning THRIFT_HOME = /d/thrift. Then I tried /d/thrift demo/ and there is the problem.
D:\noknok_fido_to_ostp\noknok_fido_to_ostp_workspace\Demo\build.xml:33: Execute failed: java.io.IOException: Cannot run program "thrift-0.9.0.exe": CreateProces
s error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:631)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:672)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:498)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
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.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 23 more
Another problem is that /d/thrift doesn't work in Eclipse Ant plugin build. I tried it using command prompt and the build was successful.
This teaches a new lesson: Always build from command prompt!
Thanks to all who answered for this question.
And what about searchpath attribute ?
searchpath: When this attribute is true, then system path environment variables will be searched when resolving the location of the executable. since Ant 1.6.3
So I think something like this:
<exec executable="thrift" searchpath="true">
<env key="Path" value="${env.Path};${THRIFT_HOME}" />
</exec>
should work.
I found it works by quote the value of variable
<exec executable="setx">
<arg line="Path "${env.Path};c:\test Path"" />
<arg line="/m" />
</exec>
https://stackoverflow.com/a/23777929/3659861

ClassNotFoundException on a JUNIT ant script

I have written few test scripts using JUnit 4 and Selenium.
I have added the jar files for JUnit and Selenium to eclipse and if I run my tests through eclipse IDE everything is working as expected.
I am now trying to run these tests through the ant script below:
<project name="JUnit" default="test">
<property name="src" value="./src" />
<property name="classes" value="./classes" />
<property name="test.class.name" value="AllTests" />
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="C:/Program Files/eclipse 3.5/plugins/org.junit4_4.5.0.v20090824/junit.jar" />
<pathelement location="C:/selenium/selenium-server-standalone-2.0b2.jar" />
<pathelement location="C:/Program Files/eclipse 3.5/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar" />
</path>
<target name="test">
<junit fork="yes" haltonfailure="yes">
<test name="${test.class.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
</project>
The problem is that when I run this ant script I am getting the following Exception:
[junit] java.lang.ClassNotFoundException: AllTests
[junit] at java.net.URLClassLoader$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Unknown Source)
I have added all the jar files that I see in eclipse .classpath file so a bit confused of which files I am missing.
Found the problem, stupid one but I guess it was lack of concentration...
My .class files are in the ./bin folder and the ant script was pointing to ./classes.
I copied it from an old ant script I've been using and didn't take notice of the properties configured.

Resources