How to pass arg for exec task on if-condition? [duplicate] - if-statement

I've got an ant build script which I should modify. Specifically I should make a subversion checkout conditional: currently only the trunk gets checked out, the new version should checkout a given branch if needed.
<target name="do-svn-checkout" depends="init"
<property name="branch" value=""/>
<exec executable="svn">
<arg value="checkout"/>
<arg value="-r"/>
<arg value="HEAD"/>
<arg value="http://t01/java/trunk"/>
<arg value="zzz"/>
<arg value="--password"/>
<arg value="xxx"/>
<arg value="--username"/>
<arg value="yyy"/>
</exec>
</target>
The property branch will be set via the command line like for instance -Dbranch=mybranch.
If the property branch is empty, the trunk should be checked out, but if the property has any other value, the respective branch should be checked out, like http://t01/svn/hlfg/HLFG/java/branch/the-value-of-the-property. So depending on the property the respective arg-value of the svn call should be modified.
Is it possible to solve this with basic Ant or would I need to use an inline script?

When using Ant >= 1.9.3 it's a piece of cake with the new if/unless feature introduced with Ant 1.9.1
(but you should at least use Ant 1.9.3 because of bugs in Ant 1.9.1, see this answer for details)
Don't forget the namespaces to activate that feature, f.e. :
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<property name="foobar" value=" "/>
<echo if:blank="${foobar}">foobar blank !</echo>
<echo unless:blank="${foobar}">foobar not blank !</echo>
</project>
in your case something like :
<target name="do-svn-checkout" depends="init"
<property name="branch" value=""/>
<exec executable="svn">
<arg value="checkout"/>
<arg value="-r"/>
<arg value="HEAD"/>
<arg value="http://t01/java/trunk" if:blank="${branch}">
<arg value=".." unless:blank="${branch}">
<arg value="zzz"/>
<arg value="--password"/>
<arg value="xxx"/>
<arg value="--username"/>
<arg value="yyy"/>
</exec>
</target>

You could define a wrapper target which depends on two other targets - one of which does trunk checkout, the other of which does branch checkout - and each of which is conditional on existence of your optional branch property.
You could further abstract the exec call into a macrodef to which you pass the trunk or branch url.
For example:
<project name="test" default="do-svn-checkout">
<target name="do-svn-checkout" depends="do-svn-trunk-checkout, do-svn-branch-checkout"/>
<target name="do-svn-trunk-checkout" unless="branch">
<svn-checkout svn-url="http://t01/svn/java/trunk"/>
</target>
<target name="do-svn-branch-checkout" if="branch">
<svn-checkout svn-url="http://t01/svn/hlfg/HLFG/java/branch/${branch}"/>
</target>
<macrodef name="svn-checkout">
<attribute name="svn-url"/>
<sequential>
<echo message="svn-url=#{svn-url}"/>
</sequential>
</macrodef>
</project>
Output with no branch property defined:
do-svn-trunk-checkout:
[echo] svn-url=http://t01/svn/java/trunk
do-svn-branch-checkout:
do-svn-checkout:
Output with branch property defined:
do-svn-trunk-checkout:
do-svn-branch-checkout:
[echo] svn-url=http://t01/svn/hlfg/HLFG/java/branch/mybranch
do-svn-checkout:

Related

Can we convert a freestyle job in jenkins into a template

I have configured a freestyle Jenkins job to perform build, run some tests, perform code analysis and upload artifacts to Nexus. I will need to create more of such jobs in future and so I want to create a template so that its easy for anyone else to create those jobs in future. Is there a way to convert the freestyle job into template?
You can create generic mechanisms using Ant(In my case NAnt), and use them using a set of imported variables.
My config for web app looks like:
<?xml version="1.0" encoding="utf-8"?>
<webapps>
<add basedir="deploys\JobLocation" deploydir="C:\CIReference\Sites" appname="JobLocation" appid="5" appuri="http/*:8081" apppool.runtineversion="v4.0" />
</webapps>
The add tag has the basic configuration of the webapp
And the generic mechanism to deploy web application is like this
<?xml version="1.0" encoding="utf-8"?>
<project name="webdeploy" xmlns="http://nant.sf.net/release/0.92/nant.xsd">
<include buildfile="baseconfigs.xml" />
<include buildfile="external_tools.xml" />
<call target="baseConfigs" />
<property name="current.environment.path" value="${path::combine(nant.environmentsdir,environment)}"/>
<foreachxml file="${path::combine(current.environment.path,'webapps.xml')}" xpath="/webapps/add" property="basedir,deploydir,appname,appid,appuri,apppool.runtineversion">
<exec program="${appcmd.path}" failonerror="false">
<arg value="delete" />
<arg value="site" />
<arg value="/site.name: ${appname}" />
</exec>
<exec program="${appcmd.path}" failonerror="false">
<arg value="delete" />
<arg value="apppool" />
<arg value="/apppool.name: ${appname}" />
</exec>
<echo message="Deleting directory: ${path::combine(deploydir, appname)}" />
<delete dir="${path::combine(deploydir, appname)}" failonerror="false" />
<echo message="Coping directory to: ${path::combine(deploydir, appname)}" />
<copy todir="${path::combine(deploydir, appname)}" includeemptydirs="true" overwrite="true" verbose="true">
<fileset basedir="${path::combine(directory::get-current-directory(), basedir)}">
<include name="**\*.*" />
</fileset>
</copy>
<exec program="${appcmd.path}">
<arg value="add" />
<arg value="apppool" />
<arg value="/name: ${appname}" />
</exec>
<exec program="${appcmd.path}">
<arg value="set" />
<arg value="apppool" />
<arg value="/name: ${appname}" />
<arg value="/managedRuntimeVersion:${apppool.runtineversion}" />
</exec>
<exec program="${appcmd.path}">
<arg value="add" />
<arg value="site" />
<arg value="/name: ${appname}" />
<arg value="/id: ${appid}" />
<arg value="/bindings: ${appuri}" />
<arg value="/physicalPath: ${path::combine(deploydir, appname)}" />
</exec>
<exec program="${appcmd.path}" failonerror="false">
<arg value="set" />
<arg value="site" />
<arg value="${appname}" />
<arg value="/applicationPool:${appname}" />
</exec>
</foreachxml>
</project>
You can use this tool to create whatever mechanism do you need for your CI solution.
Order files...
baseconfigs.xml
<?xml version="1.0" encoding="utf-8"?>
<project>
<property name="nant.dir" value="" />
<property name="nant.environmentsdir" value="" />
<target name="baseConfigs">
<cd dir="..\..\" />
<property name="nant.dir" value="${path::combine(directory::get-current-directory(),'jenkins\NAnt')}" />
<property name="nant.environmentsdir" value="${path::combine(nant.dir,'environments')}" />
</target>
</project>
external_tools.xml
<?xml version="1.0" encoding="utf-8"?>
<project>
<property name="appcmd.path" value="c:\windows\System32\InetSrv\appcmd.exe" />
<property name="java_path" value="C:\Program Files (x86)\Jenkins\jre\bin"/>
<property name="liquibase_exe_path" value="C:\Program Files (x86)\Jenkins\tools\liquibase\"/>
<loadtasks assembly="C:\Program Files (x86)\Jenkins\tools\nant\nantcontrib\NAnt.Contrib.Tasks.dll" />
<loadtasks assembly="C:\Program Files (x86)\Jenkins\tools\nant\NAnt.GF.Custom.Tasks.dll" />
</project>

How to retrieve and use the setted value of a property in WSO2 ESB?

I am pretty new in WSO2 ESB and I have the following problem trying to retrieve the value of a property and put into an XML document that I am generating.
So, I have the following situation, in my ESB flow I have defined this property named TRANSACTION and having register as value:
<property name="TRANSACTION" scope="default" type="STRING" value="register"/>
Then in my flow I am generating an XML document (it works fine), using a payloadFactory mediator, in this way:
<payloadFactory media-type="xml">
<format>
<register password="$14" username="$13" xmlns="http://ws.wso2.org/dataservice">
<location>
<wiews>$1</wiews>
<pid>$2</pid>
<name>$3</name>
<address>$4</address>
<country>$5</country>
<lat>$6</lat>
<lon>$7</lon>
</location>
<sampledoi>$8</sampledoi>
<sampleid>$9</sampleid>
<date>$10</date>
<method>$11</method>
<genus>$12</genus>
</register>
</format>
<args>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_wiews/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_pid/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_name/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_address/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_country/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_lat/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:hold_lon/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:sample_doi/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:sample_id/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:date/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:method/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:genus/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:username/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
<arg evaluator="xml" expression="$ctx:sampleData//ds:Sample/ds:password/text()" xmlns:ds="http://ws.wso2.org/dataservice"/>
</args>
</payloadFactory>
That genetes an XML document like this:
<?xml version="1.0" encoding="UTF-8" ?>
<register username="myUserName" password="myPswd">
<sampleid>CGN00001</sampleid>
<genus>Hordeum2</genus>
...................................
...................................
...................................
I want use the value of my TRANSACTION property to create the name of the first tag of my XML document, in this:
<register password="$14" username="$13" xmlns="http://ws.wso2.org
the register name have to be a $15 variable that use the TRANSACTION property value. I think that I can define it in some way into the ... list but I don't know how. At this time in this list I only have value retrieved from a DSS service output, in this case I think that I have to put the value of my TRANSACTION property, but how?
So, is it possible to something like this:
<$15 password="$14" username="$13" xmlns="http://ws.wso2.org
to dinamically insert the tag name?
As far as I know, you can't do that with payloadFactory but you can use a default name for your root node and just after payloadFactory mediator, add this javascript :
<script language="js"><![CDATA[
mc.getEnvelope().getBody().getFirstElement().setLocalName(mc.getProperty("TRANSACTION"));
]]></script>
An other solution would be to use XSLT

WSO2ESB: Property setting not accepting empty value

Actually I'm trying to get an empty value when I set a Property in a sequence in WSO2 ESB with an empty string. I have tried many things but always get the result "null" or "\"\"" instead of "" when I get the property, here is my code:
<property value=""""
name="arq.general.DestinationSystem" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns2="http://org.apache.synapse/xsd"/>
<property name="arq.general.ParentInstanceID" scope="default"
type="STRING" value=""/>
<property expression="get-property('NonExistentProperty')"
name="arq.functional.User"
scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ns2="http://org.apache.synapse/xsd"/>
Please could you help?
Cheers,
Tony
++ the payload Factory:
<payloadFactory media-type="xml">
<format>
<MensajeAuditoria xmlns="">
<Timestamp>$1</Timestamp>
<TrackingID>$2</TrackingID>
<SourceApplication>$3</SourceApplication>
<OperationName>$4</OperationName>
<ParentInstanceID>$5</ParentInstanceID>
<InstanceID>$6</InstanceID>
<ServiceID>$7</ServiceID>
<FunctionalID>$8</FunctionalID>
<AdapterType>$9</AdapterType>
<AdapterPoint>$10</AdapterPoint>
<HostName>$11</HostName>
<User>$12</User>
</MensajeAuditoria>
</format>
<args>
<arg evaluator="xml" expression="get-property('SYSTEM_TIME')"/>
<arg evaluator="xml" expression="get-property('arq.general.TrackingID')"/>
<arg evaluator="xml" expression="get-property('arq.general.SourceApplication')"/>
<arg evaluator="xml" expression="get-property('arq.functional.OperationName')"/>
<arg evaluator="xml" expression="get-property('arq.general.ParentInstanceID')"/>
<arg evaluator="xml" expression="get-property('arq.general.InstanceID')"/>
<arg evaluator="xml" expression="get-property('arq.general.ServiceID')"/>
<arg evaluator="xml" expression="get-property('arq.functional.FunctionalID')"/>
<arg evaluator="xml" expression="get-property('arq.general.AdapterType')"/>
<arg evaluator="xml" expression="$func:AdapterPoint"/>
<arg evaluator="xml" expression="get-property('SERVER_IP')"/>
<arg evaluator="xml" expression="get-property('arq.functional.User')"/>
</args>
</payloadFactory>
</else>
</filter>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
Adding the factory result:
{
"MensajeAuditoria": {
"Timestamp": 1492777451830,
"TrackingID": "76b9858d-8421-4d7e-d2af-e8e411382e2e",
"SourceApplication": "API Manager",
"OperationName": null,
"ParentInstanceID": null,
"InstanceID": "76b9858d-8421-4d7e-d2af-e8e411382e2e",
"ServiceID": "PRX_PROY1_AEX_AltaCliente",
"FunctionalID": null,
"AdapterType": "AEXP",
"AdapterPoint": "PreActRequest",
"HostName": "172.16.3.97",
"User": null,
}}
I have achieved a work-around using JavaScript but it should be possible to set it in the property mediator, or may be with enrich.
<script language="js"><![CDATA[var payload = mc.getPayloadJSON();
if(payload.MensajeAuditoria.ParentInstanceID== null){
payload.MensajeAuditoria.ParentInstanceID="";
}
mc.setPayloadJSON(payload);
mc.setProperty("MyProperty","");]]></script>
If you get an XML solution, please let me know.
Thanks.
An other solution is to use "string" xpath function :
<property name="arq.general.ParentInstanceID" expression="string('')"/>
I have tried your payloadFactory and it turns out it works like a charm on 4.8.1 but it fails on 5.0.0. This is most likely a change in the JSON message builder that they use in the ESB. The problem is not on your empty property but in the automatic translation from XML to JSON that happens when you set the messageType property.
What you can do to solve this though is the make the payload mediator create json straight away as follows:
<payloadFactory media-type="json">
<format>
{"MensajeAuditoria":{
"Timestamp":$1,
"TrackingID":"$2"
...
}
}
</format>
<args>
<arg evaluator="xml" expression="get-property('SYSTEM_TIME')"/>
<arg evaluator="xml" expression="get-property('arq.general.TrackingID')"/>
...
</args>
</payloadFactory>
</else>
</filter>
This way you are in control of the quotes, and it will never put null there unless you actually want it there.
Hope this helps solve your problem
Good thing would be to use enrich mediator to map the json field to xml field if there is a vale for the incoming field.
Sample
<filter regex="true" source="boolean(get-property('START_DATE'))">
<then>
<enrich description="Add startDate tag">
<source clone="true" type="inline">
<org:startDate xmlns:org="urn:example.com/service/org"/>
</source>
<target action="child" xpath="//*[local-name()=get-property('RequestType')]"/>
</enrich>
<enrich description="populate startDate">
<source clone="true" property="START_DATE" type="property"/>
<target
xmlns:org="urn:example.com/servi`enter code here`ce/org" xpath="//org:startDate"/>
</enrich>
</then>
<else/>
</filter>

Trying to add CSS to Docbook using Saxon

I am trying to add a CSS file to my Docbook HTML output. Most examples say:
xsltproc --stringparam html.stylesheet corpstyle.css chunk.xsl myfile.xml
Ours is a Saxon based toolkit... So accordingly, I changed the build file to:
<java jar="${DocBook}/saxon/saxon.jar" fork="true" dir="${gen.dir}/html-multi">
<arg line="com.icl.saxon.StyleSheet"/>
<arg line="${basedir}/book.xml "/>
<arg line="${DocBook}/html/chunk.xsl "/>
<arg line="html.stylesheet=mycss.css"/>
</java>
When running ant, this results in:
Bad param=value on the command line.
How do I set this up?
That seems more like an Ant problem, try
<java jar="${DocBook}/saxon/saxon.jar" fork="true" dir="${gen.dir}/html-multi">
<arg line="${basedir}/book.xml "/>
<arg line="${DocBook}/html/chunk.xsl "/>
<arg line="html.stylesheet=mycss.css"/>
</java>
as it seems the main class is taken from the jar argument.

Maximum number of arguments for qdbusxml2cpp

I am extending a DBus interface on a linux build machine using Qt. The existing interface works fine and I need to add another parameter
The XML generation method generation is:
<method name="get_card_info">
<arg type="b" name="success" direction="out" />
<arg type="s" name="version" direction="out" />
<arg type="s" name="serial" direction="out" />
<arg type="s" name="BeginDate" direction="out" />
<arg type="s" name="ExpirationDate" direction="out" />
<arg type="s" name="RenewalDate" direction="out" />
<arg type="s" name="ZipCode" direction="out" />
<arg type="s" name="ZipCodeExtension" direction="out" />
<!-- <arg type="u" name="cardStatus" direction="out" /> -->
</method>
The code works fine until I uncomment the commented out line, at which point qdbusxml2cpp reports:
interface_dbus_p.h:39:103: error: wrong number of template arguments (9, should be 8)
This is even if I comment out all calls to this function; indeed this is before the linking code even gets compiled; this is all from the qdbusxml2cpp call.
The XML will compile if I change this to six, seven or eight items, but if I increase it to nine it crashes.
I've changed no other configuration files except the XML code.
What's wrong? Is there a limit of eight parameters?
Found it; yes there is a limit, thanks to QDBusPendingReply
"The QDBusPendingReply is a template class with up to 8 template parameters. Those parameters are the types that will be used to extract the contents of the reply's data."
So no more than 8 parameters for me :(