How to regenrate java classes from xjc ant while xsd's are up to date - ant

If xsd are up to date , then xjc are not generating the class.
I want classes always to be generated..
<target name="jaxbSource" description="Generate jaxb objects">
<echo message="Generate jaxb objects for CategoryAPIRequest..." />
<xjc source="2.0" schema="${basedir}/schemas/categoryAPI/CategoryAPIRequest.xsd" package="com.myrio.tm.company.categories.util.request"
destdir="${basedir}/src" binding="${basedir}/schemas/categoryAPI/binding.xml">
<produces dir="${basedir}/src" includes="**/*.java" />
<arg value="-extension" />
</xjc>
<echo message="Generate jaxb objects for CategoryAPIReturn..." />
<xjc source="2.0" schema="${basedir}/schemas/categoryAPI/CategoryAPIReturn.xsd" package="com.myrio.tm.company.categories.util.response"
destdir="${basedir}/src" binding="${basedir}/schemas/categoryAPI/binding.xml">
<produces dir="${basedir}/src" includes="**/*.java" />
<arg value="-extension" />
</xjc>
</target>
-- My Binding xml is :
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.1">
<jaxb:globalBindings>
<xjc:serializable/>
</jaxb:globalBindings>
</jaxb:bindings>

Related

Ant creates jar files in wrong destination

Below is my build.xml file for ant.
<?xml version="1.0" encoding="UTF-8"?>
<project name="Struts2ProductsDemo" default="jar">
<property name="src.dir" location="src" />
<property name="build.dir" location="L:\build" />
<property name="project.name" value="Struts2ProductsDemo" />
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/classes" />
</target>
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" />
</target>
<target name="jar" depends="compile">
<jar destfile="${build.jar}/jars/${project.name}.jar" basedir="${build.dir}/classes" />
</target>
The jar files are created in: C:\Users\San\EclipseWS\Struts2ProductsDemo\${build.jar}\jars\Struts2ProductsDemo.jar
I am expecting the jar to be here: ${build.jar}/jars/${project.name}.jar
Property build.jar is never set. You have to define it. For example, you may add this to your build:
<property name="build.jar" location="target"/>

Jacoco not excluding the class from the report using exclude function

I am using jacoco with Ant and with the build.xml given below. I want to exclude eQMIUtil class from util.3.5 jar. But I am getting all the methods while generating report. Is there any way I can get a solution for this. What does **<arg value= "2*3+4">** actually do?
<description>
Example Ant build file that demonstrates how a JaCoCo coverage report
can be itegrated into an existing build in three simple steps.
</description>
<!-- property name="src.dir" location="./src/main/java" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.report.dir" location="${result.dir}/site/jacoco" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" /-->
<property name="activity.src.dir" location="./src/MIActivities" />
<property name="modules.src.dir" location="./src/Modules" />
<property name="plugins.src.dir" location="./src/Plugins" />
<property name="classes.src.dir" location="F:/jacoco/test/classes" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.Activities.dir" location="F:/Tomcat/apache-tomcat6/webapps/MI35PCQA01P/Activities" />
<property name="result.report.dir" location="F:/Jacoco/test/target/site" />
<property name="result.exec.file1" location="F:/Jacoco/jacoco.exec" />
<property name="project.parent.build.directory" location="C:/MIWork/Jacoco/Coverage" />
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="F:/Jacoco/jacoco-0.7.5.201505241946/lib/jacocoant.jar" />
</taskdef>
<target name="clean">
<delete dir="${result.report.dir}" />
</target>
<target name="report" >
<jacoco:report>
<executiondata>
<file file="${result.exec.file1}"/>
</executiondata>
<structure name="Example Project">
<classfiles>
<fileset file="${classes.src.dir}/util-3.5.jar" >
<exclude name="**/*eQMIUtil*.class"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
</sourcefiles>
</structure>
<html destdir="${result.report.dir}"/>
</jacoco:report>
</target>
<target name="test" depends="report">
<!-- Step 2: Wrap test execution with the JaCoCo coverage task -->
<jacoco:coverage destfile="${result.exec.file}">
<java classname="org.jacoco.examples.parser.Main" fork="true">
<classpath path="${result.classes.dir}" />
<arg value="2 * 3 + 4"/>
<arg value="2 + 3 * 4"/>
<arg value="(2 + 3) * 4"/>
<arg value="2 * 2 * 2 * 2"/>
<arg value="1 + 2 + 3 + 4"/>
<arg value="2 * 3 + 2 * 5"/>
</java>
</jacoco:coverage>
</target>
<target name="finalreport" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
<target name="rebuild" depends="clean,report" />
Instead of nesting a <fileset> under <jacoco:report>, you can nest a <zipfileset> instead.
This...
<jacoco:report>
...
<structure name="Example Project">
<classfiles>
<fileset file="${classes.src.dir}/util-3.5.jar" >
<exclude name="**/*eQMIUtil*.class"/>
</fileset>
</classfiles>
...
</structure>
...
</jacoco:report>
...should become...
<jacoco:report>
...
<structure name="Example Project">
<classfiles>
<zipfileset src="${classes.src.dir}/util-3.5.jar">
<exclude name="**/*eQMIUtil*.class"/>
</zipfileset>
</classfiles>
...
</structure>
...
</jacoco:report>
<zipfileset> works because JAR files are also ZIP files.

TestNg/Selenium call by ant always return Cannot find class in the classpath

I'm pretty new with this setup. And having issue to call my project with TestNG by ant.
I can run the testng.xml without any problem in Eclipse but I alway receive Cannot find class in classpath by ant.
Build.xml
<project basedir="." default="runTest" name="Ant file for TestNG">
<property name="src" location="src" />
<property name="bin" location="bin" />
<property name="telus" location="C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\resources\suite\local" />
<property name="libs" location="lib" />
<path id="class.path">
<pathelement location="${libs}/testng-6.4.jar" />
<pathelement location="${libs}/selenium-java-client-driver.jar" />
<pathelement location="${libs}/selenium-server-standalone-2.39.0.jar" />
<pathelement location="${bin}"/>
<pathelement location="${telus}"/>
</path>
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="${libs}/testng-6.4.jar"/>
</classpath>
</taskdef>
<target name="runTest">
<echo message="mkdir"/>
<mkdir dir="testng_output"/><!-- Create the output directory. -->
<echo message= "TestNg Start"/>
<testng outputdir="testng_output" classpathref="class.path">
<xmlfileset dir="${telus}" includes="testng.xml"/>
<!-- <xmlfileset dir="." includes="TestNG2.xml"/> -->
</testng>
</target>
</project>
Testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Bolt harness QA" verbose="1">
<parameter name="test.env" value="qa" />
<parameter name="selenium.url" value="https://www.google.com" />
<!-- Valid values for browser: FF, IE, Chrome -->
<parameter name="selenium.browser" value="Chrome" />
<listeners>
<listener class-name="com.gdo.test.integration.listener.SoftAssertTestListener" />
</listeners>
<test name="Test_MS_Website" preserve-order="true">
<classes>
<class name="com.gdo.telus.SC006">
<methods>
<include name="Web_InvalidPassword" />
<exclude name="Web_LockedAccount" />
</methods>
</class>
</classes>
</test>
</suite>
My Class are at this path :
C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\java\com\gdo\telus
Thanks for your help.
Try my build.xml file, I did add the ReportNG plugin into this build.xml file to generate better looking reports instead of the default TestNG reports. You can just download the jar file for ReportNG and place it into your lib folder and it should still work fine:
<project name="Some Bullshit Goes Here" default="clean" basedir=".">
<!-- Initilization properties -->
<!-- <property name="lib.dir" value="${basedir}/lib"/> -->
<!-- using the ${basedir} allows you to use relative paths. It will use the working directory and add folders that you specify -->
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="hardcoded value can go here"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="bin.dir" value="${basedir}/bin"/>
<property name="output.dir" value="${basedir}/output"/>
<!-- I chose to hardcode the location where my jar library files will be, it will be used for compilation. Again you can set relative path if you wish.-->
<path id="assloadoflibs">
<fileset dir="/automated/tests/library">
<include name="*.jar"/>
</fileset>
<pathelement path="${basedir}/bin"/>
</path>
<!-- setting libraries -->
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/"/>
<fileset dir="/automated/tests/library" includes="*.jar"/>
</path>
<!-- Convert jar collection from a given reference into one list, storing the result into a given property, separated by colon -->
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<target name="loadTestNG" depends="setClassPath">
<!-- Creating task definition for TestNG task -->
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<!-- Creating build directory structure used by compile -->
<mkdir dir="${build.dir}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<!-- In compile target dependency is given over clean target followed by init,
this order makes sure that build directory gets created before compile takes place
This is how a clean complile is achieved.
-->
<target name="compile" depends="clean,init,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling..."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<target name="run" depends="compile">
<!-- testng classpath has been provided reference of jar files and compiled classes
this will generate report NG report.
-->
<testng classpath="${test.classpath}:${build.dir}" outputdir="${basedir}/output" haltonfailure="false" useDefaultListeners="true" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter" classpathref="reportnglibs">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
<!-- This value here will show the title of the report -->
<sysproperty key="org.uncommons.reportng.title" value="Example Test Report"/>
</testng>
</target>
</project>
Here is my TestNG.xml file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Example Test Suite">
<test name ="Example TestCase Name">
<classes>
<class name="packageName.JavaFilename"></class>
</classes>
</test>
</suite>
I've found my answer on this site. I need to use maven to call my solution.
http://rationaleemotions.wordpress.com/2012/05/14/continuous-integration-with-selenium/
but thanx anyway for your help

ant > map property names into a new set of properties

I'd like to "map" a bunch of ant properties, based on a prefix (sounds simple enough).
I have a solution, but it's not elegant (having to write out to a properties file, then read it back in!)
Question: Is there a quicker/more generic/simpler/out-of-the-box/straight-forward way of doing the below "load-propertyset" within ANT? (... than the example I've provided below)
(Roughly analogous to the Groovy > ConfigSlurper > Special Environment Configuration behaviour.)
For example:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Config">
<!-- Section 1. (These will be loaded from a property file...) -->
<property name="a.yyy" value="foo" />
<property name="a.zzz" value="cat" />
<property name="b.xxx" value="bar" />
<property name="b.zzz" value="dog" />
<macrodef name="load-propertyset">
<attribute name="prefix" />
<attribute name="outfile" default="123" />
<attribute name="propset" default="123" />
<sequential>
<propertyset id="#{propset}">
<propertyref prefix="#{prefix}" />
<globmapper from="#{prefix}.*" to="*" />
</propertyset>
<echo level="debug">Created propertyset - '#{propset}' from prefix='#{prefix}'</echo>
<tempfile property="#{outfile}" suffix=".properties" deleteonexit="true" />
<echo level="debug">Writing propset to temp file - '${#{outfile}}'</echo>
<echoproperties destfile="${#{outfile}}">
<propertyset refid="#{propset}"/>
</echoproperties>
<echo level="debug">Reading props from temp file - '${#{outfile}}'</echo>
<property file="${#{outfile}}" />
<delete file="${#{outfile}}" />
</sequential>
</macrodef>
<load-propertyset prefix="a" />
<load-propertyset prefix="b" />
<echo>>>> Using variables xxx=${xxx} yyy=${yyy} zzz=${zzz}</echo>
</project>
I'm sure I'm missing something simple, for instance:
Can I reference properties within a propertyset? (e.g. ${myprops.yyy} ?)
I'd like to avoid something like ${${filter}.hostname}.
The third-party Ant-Contrib has an <antcallback> task that takes the <antcall> task and adds the ability to return properties to the caller:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Config" default="run">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- Section 1. (These will be loaded from a property file...) -->
<property name="a.yyy" value="foo" />
<property name="a.zzz" value="cat" />
<property name="b.xxx" value="bar" />
<property name="b.zzz" value="dog" />
<macrodef name="load-propertyset">
<attribute name="prefix" />
<attribute name="return" />
<sequential>
<antcallback target="-empty-target" return="#{return}">
<propertyset>
<propertyref prefix="#{prefix}" />
<globmapper from="#{prefix}.*" to="*" />
</propertyset>
</antcallback>
</sequential>
</macrodef>
<target name="-empty-target"/>
<target name="run">
<property name="properties-to-return" value="xxx,yyy,zzz"/>
<load-propertyset prefix="a" return="${properties-to-return}"/>
<load-propertyset prefix="b" return="${properties-to-return}"/>
<echo>>>> Using variables xxx=${xxx} yyy=${yyy} zzz=${zzz}</echo>
</target>
</project>
The properties-to-return concept is a bit of a maintenance burden. Luckily, <antcallback> doesn't fail when asked to return a property that wasn't set. Only the properties-to-return property needs to be modified when you want a new mapped property.

Ant task to convert WSDL to POJO with the use of XJC gives an Error package name

I have an Ant task that takes a wsdl file and should auto generate POJO's (client side Java) , so I can start programming my client side JAX-WS web services.
However I'm getting an error "[ERROR] The package name .... used for this schema is not a valid package name"
This error only occurs when my wsdl file has more than 1 schema import in it such as
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
Below is the entire wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:CMSLINK="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" xmlns:REQ="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" xmlns:RESP="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" name="ProcessCustomerInquiryService">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ProcessCustomerInquiryRequest">
<wsdl:part name="requestData" element="REQ:ProcessCustomerInquiryRequest"/>
</wsdl:message>
<wsdl:message name="ProcessCustomerInquiryResponse">
<wsdl:part name="responseData" element="RESP:ProcessCustomerInquiryResponse"/>
</wsdl:message>
<wsdl:portType name="ESB_ProcessCustomerInquiryService">
<wsdl:operation name="ReqResp">
<wsdl:input name="processRequest" message="CMSLINK:ProcessCustomerInquiryRequest"/>
<wsdl:output name="processResponse" message="CMSLINK:ProcessCustomerInquiryResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProcessCustomerInquiryServiceSoapBinding" type="CMSLINK:ESB_ProcessCustomerInquiryService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ReqResp">
<wsdlsoap:operation soapAction="process"/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProcessCustomerInquiryService">
<wsdl:port name="ProcessCustomerInquiry" binding="CMSLINK:ProcessCustomerInquiryServiceSoapBinding">
<wsdlsoap:address location="http://tsesbd01.tms.toyota.com:51180/v2/MF_CMSLINK_ProcessCustomerInquiryDistributed.msgflow"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The XJC Ant task
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
If I remove the extra schema import either response.xsd or request.xsd, and also only include 1 "-p" package namespace argument for the ANT task, than the ANT runs without error, however my wsdl file contains multiple schema imports.
EDIT
I changed the value of "-p" arguement to adhere to package conventions, although my previous approach was based on JXC bug forum.
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
I have even tried the above ant task,with
-p <arg value="${wsdl.mapping.package.request }"/>
<arg value="${wsdl.mapping.package.response}"/>
by putting both package names on 1 line separated by space, this is according to JXC doc , explaining you can have "zero or more package namespaces separated by space". I require XJC to be able to handle more than 1 schema import.
The -p option specifies a single Java package that should be used for all generated classes regardless of namespace. If you want each namespace URI to map to its own package then you can't use -p, you instead need to use a binding customization file
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
<bindings schemaLocation="ProcessCustomerInquiryResponse.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.response"/>
</schemaBindings>
</bindings>
<bindings schemaLocation="ProcessCustomerInquiryRequest.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.request"/>
</schemaBindings>
</bindings>
</bindings>
and pass it to xjc using the -b option
<arg value="-b"/>
<arg file="bindings.xjb"/>
I think the problem is your Ant script. There are two problems:
The value of the package property must be a java package. Eg: <property name="wsdl.mapping.package" value="com.mycompany.xml.generated"/>
You should only specify the one package not two.
Good luck!
Also, here's a link for a package per schema approach.
-Muel

Resources