Compute property arithmetically - jenkins

In short I am not able to make a computation based on a property within my build file.
Let's say I have:
<property name="basedir" value="${project.basedir}" /> <--Current value 73
How can I know the previous 3 builds (72,71 and 70) OR how can I compute these values(based on the basedir property)?
I have tried (ignore the addition):
<property name="basedir" value="${project.basedir}+1" /> <--But it concats the value: 73+1
<property name="basedir" value="${project.basedir+1}" /> <--But it is just wrong: build_${env.BUILD_NUMBER+1}
Scenario: Remove old releases (keep some releases in case of a rollback)
P.S: The duplicate link is invalid because this is a deployment via PHING not ANT

You could use an adhoc-task for this:
<?xml version="1.0"?>
<project default="main" phingVersion="2.11.0">
<property name="basedir" value = "73"/>
<adhoc-task name="increment"><![CDATA[
class increment extends Task {
private $value;
function setvalue($value) {
$this->value = $value;
}
function setProperty($property) {
$this->property = $property;
}
function main() {
$this->project->setProperty($this->property, ((int) $this->value + 1));
}
}
]]></adhoc-task>
<target name="main">
<echo>${basedir}</echo>
<increment value="${basedir}" property="basedir"/>
<echo>${basedir}</echo>
</target>
</project>

Related

How to map an attribute of Type Object in ORIKA

I have a class OrderEntryData and inside I have an attribute which is a list of configurationInfoData (List< ConfigurationInfoData >) and inside this ConfigurationInfoData an attribute of Type Object (Object value).
This value will be sometime a date , a string or a customClass.
I am using Orika for the webServices and I am trying to settle the OrderEntryDTO class.
File : customcommerceWebServices-beans.xml
<bean class="de.hybris.platform.commercewebservicescommons.dto.order.ConfigurationInfoWsDTO">
<property name="label" type="java.lang.String" />
<property name="value" type="java.lang.Object" />
</bean>
<bean class="de.hybris.platform.commercewebservicescommons.dto.order.OrderEntryWsDTO">
<property name="configurationInfos" type="java.util.List<de.hybris.platform.commercewebservicescommons.dto.order.ConfigurationInfoWsDTO>" />
<property name="orderCode" type="java.lang.String" />
</bean>
I am testing with an Object which is an instance of AddressData.
Cause the Mapping/Conversion of the address object is working well
AddressData -> AddressDTO
the problem is (I think) Orika does not recognize the instance of the object (Object source) or the destination class (Object Target).
In the response I should have a AddressWsDTO but I get :
"de.hybris.platform.cmssmarteditwebservices.dto.AbstractPageWsDTO#54330c75"
I tried to implement a converter cause I was thinking maybe Orika don't Know how to convert an object to an AddressData (not working).
#WsDTOMapping
public class ScalpAddressConverter extends BidirectionalConverter<AddressData, Object> {
#Override
public Object convertTo(AddressData addressData, Type<Object> type, MappingContext mappingContext) {
return (Object) addressData;
}
#Override
public AddressData convertFrom(Object o, Type<AddressData> type, MappingContext mappingContext) {
return (AddressData) o;
}
}

using groovy script in ANT task to call another ant task and passing groovy variables to ANT target properties

I would like to know how to pass groovy script variables(here: compName, compPath) to the ant target (here : build.application)
I would like to make the values of compName and compPath available to all ant targets in this build.xml
<target name="xmlreader" description="Clean deployment directory">
<groovy>
import javax.xml.xpath.*
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
def ant = new AntBuilder()
File buildfile = new File("d:/Users/sk/workspace/build.xml")
fileContent = buildfile.getText()
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(buildfile);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("BuildConfig/Applications/ApplicationConfig");
NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength() ; i++) {
String compName = (String)nl.item(i).getElementsByTagName("Name").item(0).getChildNodes().item(0).getNodeValue();
String compPath = (String)nl.item(i).getElementsByTagName("SVN_Path").item(0).getChildNodes().item(0).getNodeValue();
ant.echo "${compName}"
ant.echo "${compPath}"
ant.ant( antfile: 'build.xml' ){
target(name: 'build.application')
}
}
</groovy>
</target>
To answer your direct question, the ant task accepts property children to set properties in the new project used by the target you're calling:
ant.ant( antfile: 'build.xml', target: 'build.application') {
property(name:'compName', value:compName)
property(name:'compPath', value:compPath)
}
But you could also consider xmltask, whose "call" function can achieve the same thing without all the Groovy code.
<xmltask source="d:/Users/sk/workspace/build.xml">
<call path="BuildConfig/Applications/ApplicationConfig" target="build.application">
<param name="compName" path="Name" />
<param name="compPath" path="SVN_Path" />
</call>
</xmltask>

iOS8 CoreData "use of unimplemented initializer"

I get the following error trying to run my application
fatal error: use of unimplemented initializer 'init(entity:insertIntoManagedObjectContext:)' for class 'rcresttest.CatalogItem'
I can bypass this error by changing the Entity's class in the data model to something else, but then I will get a swift_dynamicCastClassUnconditional: when trying to downcast.
Is this a bug in beta6 or am I doing something wrong?
CatalogItem.swift
import CoreData
#objc(CatalogItem)
class CatalogItem : NSManagedObject {
#NSManaged var id : String
#NSManaged var slug : String
#NSManaged var catalogItemId : String
init(entity: NSEntityDescription!, context: NSManagedObjectContext!, catalogResultsDict : NSDictionary) {
super.init(entity: entity, insertIntoManagedObjectContext: context)
id = catalogResultsDict["Id"] as String
slug = catalogResultsDict["Slug"] as String
catalogItemId = catalogResultsDict["CatalogItemId"] as String
}
}
and the data model
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6220.8" systemVersion="13E28" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="CatalogItem" representedClassName="CatalogItem" syncable="YES">
<attribute name="catalogItemId" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="id" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="slug" optional="YES" attributeType="String" syncable="YES"/>
</entity>
<elements>
<element name="CatalogItem" positionX="-45" positionY="0" width="128" height="90"/>
</elements>
</model>
Edit:
After changing the name of the datamodel class to have the module prefix The error message appears after trying to cast.
2014-08-20 10:49:15.335 rcresttest[63516:4194127] CoreData: warning: Unable to load class named 'rcresttest.CatalogItem' for entity 'CatalogItem'. Class not found, using default NSManagedObject instead.
This is a problem with the designated initializer. Just add convenience in front of your init and call init(entity:insertIntoManagedObjectContext:) on self instead super.

accessing ant properties in groovy taskdef gives Null Pointer Exception

I am trying to execute following code but I am getting null pointer exception.
<property name="from" value="from"/>
<property name="to" value="to"/>
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="G:\Tibco_Training\groovy-binary-1.8.5\groovy-all-1.6.5.jar" />
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<groovy>
class MoveDir extends org.apache.tools.ant.Task {
//def from = 'from'
//def to = 'to'
public void execute() {
new File(properties.from).eachFileMatch ~/.*/, { file ->
file.renameTo(new File(properties.to , file.getName()))
println "Moving file: $file.name from: " + from + " to: " + to }
}
}
project.addTaskDefinition('movedir', MoveDir)
</groovy>
<movedir />
If I don't use ant properties in groovy then the code works fine, but when I use ant properties for specifying directories, then it give null pointer exception. Am I passing wrong values or wrong syntax is the cause.
Wrong syntax, you have to use properties.'to' and properties.'from'

ant not executing .exe file

my searchversion.exe file is not running in the script..why is that so?
<project name="nightly_build" default="main" basedir="checkout">
<target name="init">
<property file="initial.properties"/>
<property file="C:/Work/lastestbuild.properties"/>
<tstamp>
<format property="suffix" pattern="yyyyMMddHHmmss"/>
</tstamp>
</target>
<target name="main" depends="init">
<sequential>
<exec executable="C:/Work/Searchversion.exe"/>
...
</sequential>
</target>
</project>
Searchversion.exe will generate latestbuild.properties file. I do not have any arguments for Searchversion.exe.
Here is the code for searchversion.exe:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Search
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "sslist.exe";
p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net /mobile";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
string procOutput = p.StandardOutput.ReadToEnd();
string procError = p.StandardError.ReadToEnd();
TextWriter outputlog = new StreamWriter("C:\\Work\\listofsnapshot.txt");
outputlog.Write(procOutput);
outputlog.Close();
string greatestVersionNumber = "";
using (StreamReader sr = new StreamReader("C:\\Work\\listofsnapshot.txt"))
{
while (sr.Peek() >= 0)
{
var line = sr.ReadLine();
var versionNumber = line.Replace(#"6.70_Extensions/6.70.102/ANT_SASE_RELEASE_", "");
if(versionNumber.Length != line.Length)
greatestVersionNumber = versionNumber;
}
}
Console.WriteLine(greatestVersionNumber);
TextWriter latest = new StreamWriter("C:\\Work\\latestbuild.properties");
latest.Write("Version_Number=" + greatestVersionNumber);
latest.Close();
}
}
}
sslist.exe gets a list of snapshots found in my version control software, and i will get the greatest version number and save it as a text (latestbuild.properties)
Two things in your script look odd.
I don't think you need the <sequential> task in the <main> target.
The depends attribute of you <main> target will cause the <init> target to run before Searchversion.exe. So, perhaps it is getting run, just too late.
Assuming #2 is the cause of your problem you should restructure your script to look like this:
<project name="nightly_build" default="main" basedir="checkout">
<target name="init">
<exec executable="C:/Work/Searchversion.exe"/>
<property file="initial.properties"/>
<property file="C:/Work/lastestbuild.properties"/>
<tstamp>
<format property="suffix" pattern="yyyyMMddHHmmss"/>
</tstamp>
</target>
<target name="main" depends="init">
...
</target>
</project>

Resources