ant: calling antcall from <script> throws a java.lang.NullPointerException - ant

In the ant 1.8.2 build system, I am having a javascript that rely on an <antcall/>. That causes me a java.lang.NullPointerException which points to antcall.
Script:
<project default="main">
<target name="main">
<script language="javascript"> <![CDATA[
task = project.createTask( 'macro' );
task.execute();
]]></script>
</target>
<macrodef name="macro">
<sequential>
<antcall target="antcall" />
</sequential>
</macrodef>
<target name="antcall">
<echo>[antcall] succeed</echo>
</target>
</project>
build.xml:11: java.lang.NullPointerException( #3 ... ). The stacktrace just talk about RhinoScriptEngine, not sure that is any helpful
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:153)
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:167)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.util.ReflectUtil.invoke(ReflectUtil.java:108)
at org.apache.tools.ant.util.ReflectWrapper.invoke(ReflectWrapper.java:81)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:103)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
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: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(DefaultExecutor.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)
My questions are:
- can someone reproduce that issue?
- Am I doing something obviously wrong?
- Any ant guru around to assist me :-)

I found a bug report in Groovy detailing a similar issue http://jira.codehaus.org/browse/GROOVY-1506 . The attached patch by Andreas Sahlbach fixed the groovy issue by assigning an owner to a newly created task.
So I have gone ahead and added:
task.setOwningTarget( self.getOwningTarget() );
That fixed the issue. I have put the original script and the fixed one in gist 3636007 so other people can play with.
Final script is below:
<project default="main">
<target name="main">
<script language="javascript"> <![CDATA[
task = project.createTask( 'macro' );
if( task.getOwningTarget() == null ) {
task.log( "Assigning an owner ..." );
task.setOwningTarget( self.getOwningTarget() );
task.log( "Task: " + task.getOwningTarget() );
}
try {
task.execute();
} catch(err) {
task.log( "Execution error: " + err.message );
}
]]></script>
</target>
<macrodef name="macro">
<sequential>
<antcall target="antcall" />
</sequential>
</macrodef>
<target name="antcall">
<echo>[antcall] succeed</echo>
</target>
</project>
The resulting execution is:
$ ant
Buildfile: /Users/amusso/ant/bug/build.xml
main:
[macro] Assigning an owner ...
[macro] Task: main
antcall:
[echo] [antcall] succeed
BUILD SUCCESSFUL
Total time: 0 seconds
\O/

Related

Ant: java.sql.SQLException: unable to open database file

I try to build my java project by Ant.
Windows 7 Professional (64 bit), Java 1.8.
I run my custom ant's target:
ant create-dist-win-lite -Denvironment=development
Here build.xml
<target name="create-dist-win-lite" description="Create WIN Lite dinstribute">
<ac:var name="var.distribute.os.family" value="${prop.distribute.os.family.win}" />
<ac:var name="var.distribute.version.type" value="${prop.distribute.version.lite}" />
<ac:runtarget target="create-dist-os" />
</target>
<target name="db:sqlite-exec-queries" depends="db:sqlite-set-variables,db:set-db-url">
<echo message="var.data.dir.name=${var.data.dir.name}" />
<echo message="var.db.driver=${var.db.driver}" />
<echo message="var.db.current.url=${var.db.current.url}" />
<echo message="var.db.lib.file.name=${var.db.lib.file.name}" />
<delete dir="${var.data.dir.name}" />
<mkdir dir="${var.data.dir.name}" />
<sql driver="${var.db.driver}" url="${var.db.current.url}" userid="${var.db.user}" password="${var.db.pwd}" classpath="${lib.dir.name}/${var.db.lib.file.name}" delimiter="${var.db.delimiter}">
<transaction src="${db.dir}/${var.db.type}/create-tables.sql" />
<transaction src="${db.dir}/${var.db.type}/insert-data.sql" />
</sql>
</target>
As result, success created empty sqlite db file in c:\dev\ca\dist\data\ca.db.
But the folder c:\dev\ca\dist\data is READ only.
But target not success finish. When execute target db:sqlite-exec-queries I get error in this line:
<sql driver="${var.db.driver}" url="${var.db.current.url}" userid="${var.db.user}" password="${var.db.pwd}" classpath="${lib.dir.name}/${var.db.lib.file.name}" delimiter="${var.db.delimiter}">
Here full ant log:
db:sqlite-exec-queries:
[echo] var.data.dir.name=dist/data
[echo] var.db.driver=org.sqlite.JDBC
[echo] var.db.current.url=jdbc:sqlite://c:\dev\ca\dist\data/ca.db
[echo] var.db.lib.file.name=sqlitejdbc-v056.jar
[delete] Deleting directory c:\dev\ca\dist\data
[mkdir] Created dir: c:\dev\ca\dist\data
[sql] Executing resource: c:\dev\ca\db\sqlite\create-tables.sql
[sql] Failed to execute: CREATE UNIQUE INDEX [AccountStatuses_Index] ON [AccountStatuses]( [CODE] ASC )
BUILD FAILED
c:\dev\ca\build.xml:1396: java.sql.SQLException: unable to open database file
at org.sqlite.DB.execute(DB.java:275)
at org.sqlite.Stmt.exec(Stmt.java:56)
at org.sqlite.Stmt.execute(Stmt.java:83)
at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:775)
at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:745)
at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:1055)
at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:985)
at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:653)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
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: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 net.sf.antcontrib.logic.RunTargetTask.execute(RunTargetTask.java:48)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
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)

ANT error CreateProcess error=2

When I try to call simple JAR file via ANT. Whenever i execute I get the following error:
C:\temp\My\My_Ant.xml:20: Execute failed: java.io.IOException: Cannot run program "C:\PROGRA~1\Java\jre7\bin\java.exe -jar C:\temp\My\javatest.jar" (in directory "C:\temp\My"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:426)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:440)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:629)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:670)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:496)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
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:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
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.(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 24 more
The Java program is simply printing "hello world!"
I call the ANT in the following way:
C:\Tools\ANT\apache-ant-1.9.7\bin\ant -buildfile My_Ant.xml
Any idea why I am getting this? when I run this via command line I get the correct message.
C:\temp\My>C:\PROGRA~1\Java\jre7\bin\java.exe -jar JavaTest.jar
hello from Java
Edit:
Ant Script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Issue Management" default="startActivity" xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="javaPath" value="C:\PROGRA~1\Java\jre7\bin\java.exe"/>
<property name="AnalyzerPath" value="C:\temp\my"/>
<property name="Analyzer" value="javatest.jar"/>
<!--Setting the location of ANT Contrib starts
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="C:/Tools/ANT/apache-ant-1.8.2/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>-->
<tstamp>
<format property="current.time" pattern="yyyyMMdd_HHmmss" />
</tstamp>
<target name="startActivity">
<echo>Issue Management script started at ${current.time}</echo>
<exec executable="${javaPath} -jar ${AnalyzerPath}\${Analyzer}" resultproperty="BuildErrorCode" failonerror="true" dir="${AnalyzerPath}">
<arg value="--help"/>
</exec>
<echo>Issue Management script ended at ${current.time}</echo>
</target>
</project>
The executable parameter needs to be set to the name or path of just the executable; command arguments should be specified separately using nested <arg> elements, for example:
<exec executable="${javaPath}" resultproperty="BuildErrorCode"
failonerror="true" dir="${AnalyzerPath}">
<arg value="-jar" />
<arg value="${AnalyzerPath}\${Analyzer}" />
<arg value="--help" />
</exec>
When you specified the whole command line as the executable, it was treated as a single command with embedded spaces, and so was not found:
Cannot run program "C:\PROGRA~1\Java\jre7\bin\java.exe -jar C:\temp\My\javatest.jar"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception thrown while running JMockit tests through ant script

I am trying to run JMcokit tests using ant script. But I am getting exceptions. I have tried to include java agent using 'jvmargs' as mentioned in other posts, also tried to add jmockit jar before junit jar in the classpath, but its of no use.
If I add java agent argument in my eclipse, then I am able to run them through eclipse, but not through ant script.
The only way I am able to run them through ant script is by adding attach.dll in my java path. But that is not a feasible solution and need a work around.
Ant script:
<!-- Run the TestSuite -->
<junit fork="yes" description="Runs the Junit testcase." printsummary="yes"
haltonfailure="${halt.on.junit.failure}" showoutput="yes">
<sysproperty key="java.library.path" path="C:/Program Files/Java/jdk1.6.0_12/jre/bin/attach.dll"/>
<jvmarg value="-javaagent:${lib.dir}/jmockit.jar" />
<jvmarg value=" -Dcom.sun.management.jmxremote"/>
<!-- <classpath path="${lib.dir}/jmockit-0.999.8.jar" />
<classpath path="${lib.dir}/junit-4.7.jar" />-->
<classpath>
<pathelement location="${lib.dir}/jmockit-0.999.8.jar" />
<pathelement location="${lib.dir}/junit-4.7.jar" />
<pathelement location="${lib.dir}/activemq-all-5.5.1.jar" />
<pathelement location="${classes.dir}" />
<!--<fileset dir="${lib.dir}">
<include name="**/*.jar" />
<exclude name="**/jmockit-0.999.8.jar, **/junit-4.7.jar" />
</fileset>-->
</classpath>
<!-- <test name="com.quest.shareplex.hadoopconnector.junits.AllTests"
fork="no" todir="${junit.output.dir}"> <formatter type="xml" /> </test> -->
<batchtest fork="no" todir="${junit.output.dir}">
<formatter type="xml" />
<fileset dir="${connector.src}">
<include name="**/*Test.java" />
<exclude name="**/*HDFSUtilsTest*.java" />
</fileset>
</batchtest>
</junit>
Please let me know, if there is any other way to work it, or if I am doing something incorrectly.
I have tried all the ways that are mentioned on stack overflow:
-Tried to change java lib path
-Tried to change java class path
-Added java agent
But nothing is working.
Exception:
<error type="java.lang.reflect.InvocationTargetException">java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
</error>
<system-out><![CDATA[]]></system-out>
<system-err><![CDATA[java.lang.UnsatisfiedLinkError: no attach in java.library.path
java.lang.IllegalStateException: Unable to load Java agent; please add lib/tools.jar from your JDK to the classpath
at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:82)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:203)
at org.junit.runner.Runner.<clinit>(Runner.java:25)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:473)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1420)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:848)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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: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.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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: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.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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: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(DefaultExecutor.java:41)
at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
Thanks,
Mayank
It looks like your java is plain jre.
java.library.path java.lang.IllegalStateException: Unable to load Java
agent; please add lib/tools.jar from your JDK to the classpath
at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:82)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54
Jmockit needs JDK to work.
If you are on a Mac, this is happening because the forked JVM doesn't have tools.jar in the classpath. I encountered this today and blogged about it.

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

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