I have a Eclipse Plugin and I need to call ant inside of that plugin to make some stuffs, like run junit test and get the coverage of that test (using jacoco plugin for this purpose)...
My build.xml
<project name="Calculadora" default="rebuild" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
<property name="src" location="./src"/>
<property name="bin.dir" location="./bin"/>
<property name="bin.report.dir" location="${bin.dir}/report"/>
<property name="bin.exec.file" location="${bin.dir}/jacoco.exec"/>
<property name="junit.out.dir" location="${bin.report.dir}/junit/xml"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="/tmp/jacocoant4002041518230825590.jar"/>
</taskdef>
<path id="classpath">
<pathelement location="${bin.dir}"/>
<pathelement location="${src}"/>
<pathelement location="/usr/lib/eclipse/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
</path>
<target name="clean">
<mkdir dir="${bin.report.dir}"/>
<mkdir dir="${junit.out.dir}"/>
</target>
<target name="test" depends="clean">
<jacoco:coverage destfile="${bin.exec.file}">
<junit fork="true" forkmode="once">
<classpath refid="classpath"/>
<formatter type="xml" usefile="true"/>
<test name="functions.test.ReadFile" todir="${junit.out.dir}"/>
</junit>
</jacoco:coverage>
</target>
<target name="report" depends="test">
<jacoco:report>
<executiondata>
<file file="${bin.exec.file}"/>
</executiondata>
<structure name="">
<classfiles>
<fileset dir="${bin.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src}"/>
</sourcefiles>
</structure>
<xml destfile="${bin.report.dir}/report.xml"/>
</jacoco:report>
<junitreport todir="${junit.out.dir}">
<fileset dir="${junit.out.dir}">
<include name="TEST-*.xml"/>
</fileset>
</junitreport>
</target>
<target name="rebuild" depends="clean,test,report"/>
</project>
The code to call Ant in Java:
// Creates a new Project object
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
p.executeTarget(p.getDefaultTarget());
But when I run my plugin i get this error:
build.xml:34: java.lang.ClassNotFoundException:
org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.createMirror(JUnitTask.java:708)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.setupJUnitDelegate(JUnitTask.java:745)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:755)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at org.jacoco.ant.CoverageTask.execute(CoverageTask.java:95) at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
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:616) 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:1360)
at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
Caused by: java.lang.ClassNotFoundException:
org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl at
org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1386)
at
org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1336)
at
org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:52)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.createMirror(JUnitTask.java:701)
... 19 more
What's happening? What I am doing wrong?
Thanks in advance
Related
How can I use a variable inside an attribute's value?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.data.mapper.SomeMapper">
<sql id="fields">
<![CDATA[
${alias}some_seq AS `${prefix}someSeq`,
...
]]>
</sql>
<sql id="fieldsAssociative">
<include refid="com.example.demo.data.mapper.SomeMapper.fields">
<property name="alias" value="#{alias}"/> <!-- Can I do this? -->
<property name="prefix" value="#{prefix}"/> <!-- Or this? -->
</include>
,
<include refid="com.example.demo.data.mapper.OtherMapper.fields">
<property name="alias" value="#{alias}2o"/>m
<property name="prefix" value="#{prefix}.otgher."/>
</include>
</sql>
</mapper>
How to add current date while creating a folder in nant?
I have <mkdir dir="${Test.Dir}" /> and as a result I need to get the folder created with name
"TestDir-04-04-2022".
Any advise? Thanks.
In my case I only found solution to use embeded C# code with custom function. Possible solutions:
Variant 1:
<?xml version="1.0" encoding="utf-8"?>
<project name="Deployment" default="Deploy">
<script language="C#" prefix="datetime">
<code>
<![CDATA[
[Function("now-formatted")]
public static string GetNowAsString(string format) {
return DateTime.Now.ToString(format);
}
]]>
</code>
</script>
<target name="DateTimeTest">
<property name="Test.Dir" value="${'TestDir-' + datetime::now-formatted('dd-MM-yyyy')}" />
<echo message="${Test.Dir}" />
<mkdir dir="${Test.Dir}" />
</target>
</project>
Variant 2:
<?xml version="1.0" encoding="utf-8"?>
<project name="Deployment" default="Deploy">
<script language="C#" prefix="datetime">
<code>
<![CDATA[
[Function("format")]
public static string GetNowAsString(DateTime datetime, string format) {
return datetime.ToString(format);
}
]]>
</code>
</script>
<target name="DateTimeTest">
<property name="Test.Dir" value="${'TestDir-' + datetime::format(datetime::now(), 'dd-mm-yyyy')}" />
<echo message="${Test.Dir}" />
<mkdir dir="${Test.Dir}" />
</target>
</project>
Note: datetime::now - is standard nant function.
Output:
DateTimeTest:
[echo] TestDir-08-23-2022
[mkdir] Creating directory 'C:\Test\TestDir-08-23-2022'.
BUILD SUCCEEDED
Total time: 0.2 seconds.
Testng by itself works and I can get results generating. I'm trying to use XSLT reports to make things prettier but I'm not having any luck. Here is how eclipse is setup: http://i.imgur.com/A6XRbKt.jpg
BUILD.XML FILE:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="TestNG" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="E:\Selenium Main\TestNG\lib"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<!--target name="start-selenium-server">
<java jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="sivaprasad">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
<!--
<testng classpath="${test.classpath}:${test.dest}" groups="fast">
<classfileset dir="${test.dest}" includes="example1/*.class"/>
</testng>
-->
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${ws.home}/XSLT_Reports/output/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt>
</target>
<!-- ****************** targets not used ****************** -->
</project>
ERROR MESSAGE:
E:\Selenium Main\TestNG>ant makexsltreports
Buildfile: E:\Selenium Main\TestNG\build.xml
makexsltreports:
[xslt] Processing E:\Selenium Main\TestNG\test-output\testng-results.xml to E:\Selenium Main\TestNG\XSLT_Reports\output\index.html
[xslt] Loading stylesheet E:\Selenium Main\TestNG\src\xslt\testng-results.xsl
[xslt] E:\Selenium Main\TestNG\src\xslt\testng-results.xsl:34:71: Fatal Error! Error reported by XML parser Cause: org.xml.sax.SAXParseException; systemId: file:/E:/Selenium%20Main/TestNG/src/xslt/testng-results.xsl; lineNumber: 34; columnNumber
: 71; Attribute name "data-pjax-transient" associated with an element type "meta" must be followed by the ' = ' character.
[xslt] : Fatal Error! org.xml.sax.SAXParseException; systemId: file:/E:/Selenium%20Main/TestNG/src/xslt/testng-results.xsl; lineNumber: 34; columnNumber: 71; Attribute name "data-pjax-transient" associated with an element type "meta" must be fol
lowed by the ' = ' character. Cause: org.xml.sax.SAXParseException; systemId: file:/E:/Selenium%20Main/TestNG/src/xslt/testng-results.xsl; lineNumber: 34; columnNumber: 71; Attribute name "data-pjax-transient" associated with an element type "meta" m
ust be followed by the ' = ' character.
[xslt] Failed to process E:\Selenium Main\TestNG\test-output\testng-results.xml
BUILD FAILED
E:\Selenium Main\TestNG\build.xml:100: Fatal error during transformation using E:\Selenium Main\TestNG\src\xslt\testng-results.xsl: org.xml.sax.SAXParseException; systemId: file:/E:/Selenium%20Main/TestNG/src/xslt/testng-results.xsl; lineNumber: 34;
columnNumber: 71; Attribute name "data-pjax-transient" associated with an element type "meta" must be followed by the ' = ' character.
Total time: 1 second
E:\Selenium Main\TestNG>
Thank you
Alright, I fixed the issue. testng-results.xsl was the problem it looks like. I replaced the file with another copy found on the internet and it works now!
Hi all i'm try to deploy a esb project into jboss server 5.1ga
But i got this error
**My Enviroment is
Jboss 5.1 ga,
Jboss Developer Studio 5.0**
Jboss esb 4.11
Riftsaw 2.3.0
17:58:49,155 ERROR [AbstractKernelController] Error installing to Parse: name=vfszip:/D:/jboss-5.1.0.GA/server/default/deploy/Save_Event2.esb/ state=Not Installed mode=Manual requiredState=Parse
org.jboss.deployment.DeploymentException: Key properties cannot be empty
at org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser.getDependenciesFromDeploymentXml(EsbConfigParser.java:265)
at org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser.parse(EsbConfigParser.java:170)
at org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser.parse(EsbConfigParser.java:83)
at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parseAndInit(AbstractVFSParsingDeployer.java:256)
at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parse(AbstractVFSParsingDeployer.java:239)
at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.createMetaData(AbstractParsingDeployerWithOutput.java:355)
at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.createMetaData(AbstractParsingDeployerWithOutput.java:322)
at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.createMetaData(AbstractParsingDeployerWithOutput.java:294)
at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.deploy(AbstractParsingDeployerWithOutput.java:234)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
at org.jboss.Main.boot(Main.java:221)
at org.jboss.Main$1.run(Main.java:556)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.management.MalformedObjectNameException: Key properties cannot be empty
at javax.management.ObjectName.construct(Unknown Source)
at javax.management.ObjectName.<init>(Unknown Source)
at org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser.getDependenciesFromDeploymentXml(EsbConfigParser.java:247)
... 38 more
That is error I Got and i'm trying to pass bpel result to esb and back to bpes .
---My deployment.xml-----------------
<?xml version="1.0"?>
<jbossesb-deployment>
<depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_ esb_reply</depends>
<depends>quickstart_helloworld_Request_esb</depends>
<depends>quickstart_helloworld_Request_gw</depends>
</jbossesb-deployment>
--My jbm-queue-service.xml-----------
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb_reply"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
----My jboss-esb.xml-----------
<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb
xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
parameterReloadSecs="5">
<providers>
<jms-provider name="JBossMQ" connection-factory="ConnectionFactory">
<jms-bus busid="quickstartGwChannel">
<jms-message-filter dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_gw" />
</jms-bus>
<jms-bus busid="quickstartEsbChannel">
<jms-message-filter dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_esb" />
</jms-bus>
<jms-bus busid="quickstartEsbReplyChannel">
<jms-message-filter dest-type="QUEUE"
dest-name="queue/quickstart_helloworld_Request_esb_reply" />
</jms-bus>
</jms-provider>
<jbr-provider name="JBR-Http-1" protocol="http" host="localhost">
<jbr-bus busid="Http-1" port="8088" />
</jbr-provider>
</providers>
<services>
<service category="FirstServiceESB" name="SimpleListener"
description="Hello World">
<listeners>
<jms-listener name="JMS-Gateway" busidref="quickstartGwChannel"
is-gateway="true" />
<jms-listener name="helloWorld" busidref="quickstartEsbChannel" />
<jbr-listener name="Http-Gateway" busidref="Http-1"
is-gateway="true" />
</listeners>
<actions mep="RequestResponse">
<action name="action1"
class="MyJMSListenerAction"
process="displayMessage" />
<!--
<action name="action2" class="org.jboss.soa.esb.actions.SystemPrintln">
<property name="printfull" value="false" />
</action>
The next action is for Continuous Integration testing
<action name="testStore" class="org.jboss.soa.esb.actions.TestMessageStore" />
-->
</actions>
</service>
</services>
</jbossesb>
Any help Appreciated.
Best Regards,
Pradeep.
If you look at the stacktrace of the error you can see that the error is a MalformedObjectNameException coming from EsbConfigParser:
org.jboss.soa.esb.listeners.deployers.mc.EsbConfigParser.getDependenciesFromDeploymentXml(EsbConfigParser.java:247)
The method name where the error is thrown is
getDependenciesFromDeploymentXml
So it looks like the problem is in the deployment xml.
Now we can confirm this by looking at the source code of the class (https://www.java2s.com/Open-Source/Java/JBoss/jbossesb-4.7/org/jboss/soa/esb/listeners/deployers/mc/EsbConfigParser.java.htm) and see that it is doing this:
Iterator depends = MetaData.getChildrenByTagName(jboss, "depends");
if (depends != null)
{
while (depends.hasNext())
{
Element depend = (Element) depends.next();
dependencies.add(new ObjectName(MetaData.getElementContent(depend)));
}
}
And then if we look at your deployment.xml above there is indeed an element that looks invalid:
<depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_ esb_reply</depends>
"quickstart_helloworld_Request_ esb_reply" should not have a space between "Request_" and "esb_reply".
Change it to "quickstart_helloworld_Request_esb_reply".
I am trying to figure out how to write a simple if condition in nant
that will evaluate to true when both x & y properties are true.
<project default="all">
<property name="x" value="True" />
<property name="y" value="True" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${x}" />
<echo message="x AND y are True" if="${x} AND ${y}" />
<echo message="x AND y are True" if="${x} && ${y}" />
</target>
</project>
I cannot figure out the syntax for the x AND y echo message - I tried both AND and '&&' and that doesn't seem to work.(i keep getting error messages like : String was not recognized as a valid Boolean.)
You want to use if="${x and y}", where both x and y are in the same pair of brackets:
<project default="all">
<property name="x" value="true" />
<property name="y" value="true" />
<target name="all">
<echo message="x is True" if="${x}" />
<echo message="y is True" if="${y}" />
<echo message="x AND y are True" if="${x and y}" />
</target>
</project>
Hope that helps!