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.
Related
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)
I'm new to Arquillian and I have some problems with the remote testing.
I'm trying to remote test on Wildfly using Arquillian. My Wildfly instance can be reached on port 8180 but it's runing on a local virtual machine on internal port 8080. I have set a port forwarding with Vagrant and VirtualBox
When I run my test from eclipse I got the following error :
java.lang.IllegalStateException: Error launching test playeraudio.repository.player.PlayerRepositoryTestCase public void playeraudio.repository.player.PlayerRepositoryTestCase.should_find_all_players() throws java.lang.Exception
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:103)
at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:136)
at org.jboss.arquillian.junit.Arquillian$8.evaluate(Arquillian.java:363)
at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:245)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:259)
at org.jboss.arquillian.junit.Arquillian$7.evaluate(Arquillian.java:321)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:204)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: Error launching request at http://0.0.0.0:8080/test/ArquillianServletRunner?outputMode=serializedObject&className=playeraudio.repository.player.PlayerRepositoryTestCase&methodName=should_find_all_players. No result returned
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.executeWithRetry(ServletMethodExecutor.java:139)
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:99)
... 76 more
Any clue please ?
This is my arquillian.xml file:
<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="widlfly-remote" default="true">
<configuration>
<property name="chameleonTarget">wildfly:8.2.1.Final:remote</property>
<property name="allowConnectingToRunningServer">true</property>
<property name="managementAddress">127.0.0.1</property>
<property name="managementPort">10090</property>
<property name="username">admin</property>
<property name="password">manager</property>
<property name="outputToConsole">true</property>
</configuration>
</container>
<container qualifier=""></container>
<extension qualifier="transaction">
<property name="manager">java:jboss/UserTransaction</property>
</extension>
<extension qualifier="persistence">
<property name="defaultDataSource">java:jboss/datasources/MySQLDS</property>
</extension>
<extension qualifier="persistence-script">
<property name="scriptsToExecuteBeforeTest">SET REFERENTIAL_INTEGRITY FALSE</property>
</extension>
<extension qualifier="persistence-dbunit">
<property name="datatypeFactory">org.dbunit.ext.mssql.MsSqlDataTypeFactory</property>
</extension>
</arquillian>
I find the solution: we need to specifiy the port for the used protocol (i.e. Servlet 3.0) in arquillian.xml file :
<container qualifier="jboss" default="true">
<configuration>
<property name="chameleonTarget">wildfly:8.2.1.Final:remote</property>
</configuration>
<protocol type="Servlet 3.0">
<property name="host">localhost</property>
<property name="port">8180</property>
</protocol>
...
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
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/
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.