How to add date while creating a folder Nant - nant

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.

Related

How can I use a variable inside an attribute's value?

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>

Struggling to use Cordova barcodescanner plugin

I'm trying to create an application with Cordova (developing in eclipse, using JBoss Hybrid Mobile Tools + CordovaSim).
I have inspired the code snippet that's giving me problems on this example.
The error I get is:
!JavaScript ERROR: TypeError: 'undefined' is not an object (evaluating 'cordova.plugins.barcodeScanner') on line 6 for http://localhost:54726/js/QRScan.js
QRScan.js only contains the following code (so basically as in the example):
var scanBut = document.getElementById('QRScanButton');
scanBut.onclick = quickScan();
function quickScan(){
cordova.plugins.barcodeScanner.scan(
function (result) {
var s = "Result: " + result.text + "<br/>" +
"Format: " + result.format + "<br/>" +
"Cancelled: " + result.cancelled;
resultDiv.innerHTML = s;
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
And I made sure my index.html contains the following line at the appropriate spot:
<script type="text/javascript" src="cordova.js"></script>
Finally my xml file should be configured correctly, I imported the correct plugin, the file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"
id="csam.test" version="1.0.0">
<name>csam test</name>
<description>
A sample Apache Cordova application that responds to the
deviceready
event.
</description>
<author href="http://www.eclipse.org/thym" email="thym-dev#eclipse.org">
Eclipse.org -
Thym
</author>
<content src="index.html" />
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="BarcodeScanner">
<param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
<param name="ios-package" value="CDVBarcodeScanner" />
<param name="wp-package" value="BarcodeScanner" />
<param name="id" value="cordova-plugin-barcodescanner" />
</feature>
<engine name="android" version="4.0.1" />
</widget>
Plugins must wait for the deviceready event for use. Here is the piece of code from the demo which waits for deviceready added back in.
document.addEventListener("deviceready", init, false);
function init() {
document.querySelector("#startScan").addEventListener("touchend", startScan, false);
var scanBut = document.getElementById('QRScanButton');
scanBut.onclick = quickScan();
}

Getting an error when running ANT command on build.xml

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!

OpenJPA orphan removal not working

I am trying out a master child test case with a OneToMany unidirectional relationship.
I have a scenario where I want to update the master by removing some entries from the children list. When I do a merge, I want these child entries to be automatically deleted.
I have tried in vain to get this working. I tried orphanremoval too, but that too didn't help. There were some suggestions to add equals and hashcode, which didn't work either.
Any hint or help in this regard is highly appreciated. Thank you.
I am using JPA2.0 with OpenJPA 2.1.0
Here is my code.
//Parent class
public class Account {
private String accountId;
private String accountNumber;
private List<SubAccount> subAccounts;
//followed by getters/setters
}
//Child class
public class SubAccount {
private String subAccountId;
private String subAccountNumber;
//followed by getters/setters
}
My orm.xml is as follows.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<entity-mappings version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<entity name="Account" class="test.data.Account">
<table name="ACCOUNT" />
<sequence-generator name="AccountSeq"
sequence-name="ACCOUNT_TEST_SEQ" />
<attributes>
<id name="accountId">
<column name="ACCOUNT_ID" />
<generated-value strategy="SEQUENCE" generator="AccountSeq" />
</id>
<basic name="accountNumber">
<column name="ACCOUNT_NO" />
</basic>
<one-to-many name="subAccounts" fetch="EAGER"
target-entity="test.data.SubAccount" orphan-removal="true" >
<join-column name="ACCOUNT_ID" referenced-column-name="ACCOUNT_ID" nullable="false" updatable="true"/>
<cascade>
<cascade-all />
</cascade>
</one-to-many>
</attributes>
</entity>
<entity name="SubAccount" class="test.data.SubAccount">
<table name="SUBACCOUNT" />
<sequence-generator name="SubAccountSeq"
sequence-name="SUBACCOUNT_TEST_SEQ" />
<attributes>
<id name="subAccountPK">
<column name="SUBACCOUNT_ID" />
<generated-value strategy="SEQUENCE" generator="AccountSeq" />
</id>
<basic name="subAccountNumber">
<column name="SUBACCOUNT_NO" />
</basic>
</attributes>
</entity>
</entity-mappings>
And this is what I am trying to do.
Account acc = (Account)entityMgr.find(Account.class, "1100")
acc.getSubAccounts().remove(0);
entityMgr.merge(acc)
I expect the subaccount to be deleted.
OpenJPA overrides the orphan-removal behavior if the cascade type is set to cascade-all or cascade-remove.
Instead of cascade-all, I had to configure cascade-type with cascade-persist, cascade-merge, cascade-refresh and cascade-detach.

if condition in nant

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!