Junit 4test result parsing not able to find <failure> tag - junit4

here is my Junit test result.xml
I am able to get hold of testsuite and testcase nodes. Now I need to check if test case is failed.
I am using an approach where I check if testcase node has any child and then check if that child is failure node. But when I try to get hold of child node and its type, it returns only the TEXT_NODE and displays failure message text. How do I check if child node is failure?
<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="com.Test" tests="47" failures="1" errors="0" skipped="0" time="0.425" timestamp="2017-05-25T10:04:14" hostname="localhost">
<properties>
<property name="device" value="Nexus_6_API_22(AVD) - 5.1.1" />
<property name="flavor" value="DEV" />
<property name="project" value="test" />
</properties>
<testcase name="test_1" classname="com.Test" time="0.053" />
<testcase name="test_2" classname="com.Test" time="0.081" />
<testcase name="test_3" classname="com.Test" time="0.0" />
<testcase name="test_4" classname="com.Test" time="0.001">
<failure>junit.framework.ComparisonFailure: expected:<512[]> but was:<512[fed_]>
at junit.framework.Assert.assertEquals(Assert.java:85)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
</failure>
</testcase>
</testsuite>

Well, I figured this out as below, posting for the benefit of others -
//Get a list of test cases with below code -
testCaseList = docElement.getElementsByTagName(TEST_CASE_TAG);
//Iterate through the list and set each item to testElement
// Get Test Case status
TestStatus testCaseStatus = TestStatus.FAILED;
if(testElement.hasChildNodes()) {
//Check if test failed ?
elems = getDirectChildsByTagName(testElement, TEST_FAILURE_TAG);
if(elems != null && elems.size()>0) {
logger.info("failed Tests :"+elems.size());
testCaseStatus = TtuTestStatus.FAILED;
}
//Check if test skipped ?
else {
elems = getDirectChildsByTagName(testElement, TEST_SKIPPED_TAG);
if(elems != null && elems.size()>0) {
logger.info("Skipped Tests :"+elems.size());
testCaseStatus = TtuTestStatus.SKIPPED;
}
}
}
else {
testCaseStatus = TtuTestStatus.PASSED;
}

Related

Stop task when there is an exception thrown in ItemProcessor

I am designing a Spring Batch, which reads multiple csv files. I have used partitioning to read each file in chunk and process it to decrypt a certain column in the csv. Before decrypting if i encounter any validation error , i throw custom exception.
Now what i want is if the processing finds any validation error in the first line, the other lines should not be processed, and the job should end.
How can i achieve this? I tried to implement ProcessorListener too but it has no StepExecution object so that i can call SetTerminateOnly() or ExitStatus=Failed
Also note that i have multiple thread accessing the file in different lines.I want to kill all threads in the event of the first encountered error.
Thanks in advance
So, I identified that running multiple asynchronous concurrent threads (Spring Batch partitioning) was the real issue. Though one of the thread threw an Exception, the other threads were parallely running, and finished executing till the end.
Ath the end, the Job FAILED overall and there was no output processed, but it consumed time to process rest of the data.
Well,the solution to it is as simple as it gets. We just need stop the Job while encountering an error during processing.
The Custom Processor
public class MultiThreadedFlatFileItemProcessor implements ItemProcessor<BinFileVO, BinFileVO>,JobExecutionListener{
private JobExecution jobExecution;
private RSADecrypter decrypter;
public RSADecrypter getDecrypter() {
return decrypter;
}
public void setDecrypter(RSADecrypter decrypter) {
this.decrypter = decrypter;
}
#Override
/**
This method is used process the encrypted data
#param item
* */
public BinFileVO process(BinFileVO item) throws JobException {
if(null!=item.getEncryptedText() && !item.getEncryptedText().isEmpty()){
String decrypted = decrypter.getDecryptedText(item.getEncryptedText());
if(null!=decrypted && !decrypted.isEmpty()){
if(decrypted.matches("[0-9]+")){
if(decrypted.length() >= 12 && decrypted.length() <= 19){
item.setEncryptedText(decrypted);
}else{
this.jobExecution.stop();
throw new JobException(PropertyLoader.getValue(ApplicationConstants.DECRYPTED_CARD_NO_LENGTH_INVALID),item.getLineNumber());
}
}
}else{
this.jobExecution.stop();
throw new JobException(PropertyLoader.getValue(ApplicationConstants.EMPTY_ENCRYPTED_DATA),item.getLineNumber());
}
return item;
}
#Override
public void beforeJob(JobExecution jobExecution) {
this.jobExecution=jobExecution;
}
#Override
public void afterJob(JobExecution jobExecution) {
}
}
The Job xml config
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
.....>
<!-- JobRepository and JobLauncher are configuration/setup classes -->
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<!-- Job Details -->
<job id="simpleMultiThreadsReaderJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step" >
<partition step="step1" partitioner="partitioner">
<handler grid-size="5" task-executor="taskExecutor"/>
</partition>
</step>
<listeners>
<listener ref="decryptingItemProcessor"/>
</listeners>
</job>
<step id="step1" xmlns="http://www.springframework.org/schema/batch">
<tasklet>
<chunk reader="itemReader" writer="itemWriter" processor="decryptingItemProcessor" commit-interval="500"/>
<listeners>
<listener ref="customItemProcessorListener" />
</listeners>
</tasklet>
</step>
<!-- Processor Details -->
<bean id="decryptingItemProcessor" class="com.test.batch.io.MultiThreadedFlatFileItemProcessor">
<property name="decrypter" ref="rsaDecrypter" />
</bean>
<!-- RSA Decrypter class -->
<bean id="rsaDecrypter" class="test.batch.secure.rsa.client.RSADecrypter"/>
<!-- Partitioner Details -->
<bean class="org.springframework.batch.core.scope.StepScope" />
<bean id="partitioner" class="com.test.batch.partition.FlatFilePartitioner" scope="step">
<property name="resource" ref="inputFile"/>
</bean>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10"/>
</bean>
<!-- Step will need a transaction manager -->
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
........
.................
</beans>
Here are the logs
2016-09-01 06:32:40 INFO SimpleJobRepository:273 - Parent JobExecution is stopped, so passing message on to StepExecution
2016-09-01 06:32:43 INFO ThreadStepInterruptionPolicy:60 - Step interrupted through StepExecution
2016-09-01 06:32:43 INFO AbstractStep:216 - Encountered interruption executing step: Job interrupted status detected.
; org.springframework.batch.core.JobInterruptedException
2016-09-01 06:32:45 ERROR CustomJobListener:163 - exception :At line No. 1 : The decrypted card number is less than 12 or greater than 19 in length
2016-09-01 06:32:45 ERROR CustomJobListener:163 - exception :Job interrupted status detected.
2016-09-01 06:32:45 INFO SimpleJobLauncher:135 - Job: [FlowJob: [name=simpleMultiThreadsReaderJob]] completed with the following parameters: [{outputFile=/usr/local/pos/bulktokenization/csv/outputs/cc_output_EDWError_08162016.csv, partitionFile=/usr/local/pos/bulktokenization/csv/partitions/, inputFile=C:\usr\local\pos\bulktokenization\csv\inputs\cc_input_EDWError_08162016.csv, fileName=cc_input_EDWError_08162016}] and the following status: [FAILED]
2016-09-01 06:32:45 INFO BatchLauncher:122 - Exit Status : FAILED
2016-09-01 06:32:45 INFO BatchLauncher:123 - Time Taken : 8969
If we throw Custom Exception in Processor, Spring Batch will terminate and mark the job failed unless you setup 'skipable' exception. You have not mentioned where you perform validate step, are you doing in Processor or Reader? Let me know because it is where Spring Batch decides.
In my project, if I want to stop the job and throw Custom Exception, we put validation logic in a Tasklet or Processor and throw exception as below
private AccountInfoEntity getAccountInfo(Long partnerId) {
if(partnerId != null){
.....
return ....;
} else {
throw new ReportsException("XXXXX");
}
}

Alfresco API to run faceted search

I'm using Alfresco community 5.x version and I'm wondering if There are REST or any other remote alfresco apis to be able to run Faceted search.
I've seen some Restful apis to administer/manage some aspects of Faceted search viz : http://docs.alfresco.com/community5.0/references/RESTful-Facet.html
However no public APIs to run a faceted search.
I did notice that alfresco share fires the following against the core alfresco service to run its faceted search; but could not find any notes/docs related to that -
http://alfresco.mycompany.com/alfresco/s/slingshot/search
?facetFields={http://www.alfresco.org/model/content/1.0}creator,
{http://www.alfresco.org/model/content/1.0}content.mimetype,
{http://www.alfresco.org/model/content/1.0}created,
{http://www.alfresco.org/model/content/1.0}content.size,
{http://www.alfresco.org/model/content/1.0}modifier,
{http://www.alfresco.org/model/content/1.0}modified
&filters=
&term=wal
&tag=
&startIndex=0
&sort=
&site=
&rootNode=alfresco://company/home
&repo=false
&query=
&pageSize=25
&maxResults=0
&noCache=1455504682131
&spellcheck=true&
We have API based integration with Alfresco in our custom internal applications and don't use Alfresco Share.
I'm not sure if I should be using the above url or not.
Any suggestions on this?
Thanks!
Alfresco Version: 5.0.d
You can use the default search webscript:
webscripts\org\alfresco\slingshot\search\search.get.js
If you look at the code:
var params =
{
siteId: args.site,
containerId: args.container,
repo: (args.repo !== null) ? (args.repo == "true") : false,
term: args.term,
tag: args.tag,
query: args.query,
rootNode: args.rootNode,
sort: args.sort,
maxResults: (args.maxResults !== null) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS,
pageSize: (args.pageSize !== null) ? parseInt(args.pageSize, 10) : DEFAULT_PAGE_SIZE,
startIndex: (args.startIndex !== null) ? parseInt(args.startIndex, 10) : 0,
facetFields: args.facetFields,
filters: args.filters,
spell: (args.spellcheck !== null) ? (args.spellcheck == "true") : false
};
So if you present the right arguments with the facets to look for, then Alfresco will return the right faceted results.
I finally figured out how to implement and integrate the faceted search into a custom UI. the same also works with share.
create model in model manager (no hyphens)
Indexing attribute:
String: list of values whole match
Date, Number: enhanced search
For each type define the layout design - w/o this you wont be able to change type in share at least.
In share/search manager create filters/facets for fields you're interested in
Add a custom *context.xml to define a bean with your custom FacetQueryProvider implementation. inject that into the facet.solrFacetHelper bean
The custom FacetQueryProvider e.g. DollarAmountDisplayHandler basically provides facet queries based on the dollar amount buckets bean in the *context.xml, those will then be passed to solr.
Jar up the FacetQueryProvider implementation and copy to tomcat/lib directory.
Custom-solr-facets-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="facet.dateFacetFields" class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="sourceSet">
<set>
<value>#{http://www.alfresco.org/model/content/1.0}created</value>
<value>#{http://www.alfresco.org/model/content/1.0}modified</value>
<value>#{http://www.mycomp.com/model/hono/1.0}invoiceDate</value>
</set>
</property>
</bean>
<bean id="facet.dollarAmountBuckets" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="[0 TO 1000]" value="$0-$1K" />
<entry key="[1000 TO 10000]" value="$1K-$10K" />
<entry key="[10000 TO 100000]" value="$10K-$100K" />
<entry key="[100000 TO MAX]" value="Above.$100K" />
</map>
</property>
</bean>
<bean id="facet.dollarAmountDisplayHandler" class="com.mycomp.edm.alfresco.extensions.search.solr.facets.handlers.DollarAmountDisplayHandler" parent="baseFacetLabelDisplayHandler" >
<constructor-arg index="0">
<set>
<value>#{http://www.mycomp.com/model/hono/1.0}invoiceAmount</value>
</set>
</constructor-arg>
<constructor-arg index="1">
<ref bean="facet.dollarAmountBuckets" />
</constructor-arg>
</bean>
<bean id="facet.solrFacetHelper" class="org.alfresco.repo.search.impl.solr.facet.SolrFacetHelper" >
<constructor-arg>
<list>
<ref bean="facet.contentSizeBucketsDisplayHandler" />
<ref bean="facet.dateBucketsDisplayHandler" />
<ref bean="facet.dollarAmountDisplayHandler" />
</list>
</constructor-arg>
<property name="specialFacetIds">
<set>
<value>SITE</value>
<value>TAG</value>
<value>ANCESTOR</value>
<value>PARENT</value>
<value>ASPECT</value>
<value>TYPE</value>
<value>OWNER</value>
</set>
</property>
</bean>
</beans>
The model:
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="hon:hono">
<description>hono model</description>
<author>amit</author>
<imports>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
</imports>
<namespaces>
<namespace uri="http://www.mycomp.com/model/hono/1.0" prefix="hon"/>
</namespaces>
<data-types/>
<constraints/>
<types>
<type name="hon:invoice">
<title>Invoice</title>
<description>invoice model</description>
<parent>cm:content</parent>
<properties>
<property name="hon:invoiceNumber">
<title>Invoice Number</title>
<type>d:int</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>TRUE</tokenised>
<facetable>true</facetable>
</index>
</property>
<property name="hon:invoiceAmount">
<title>Invoice Amount</title>
<type>d:int</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>TRUE</tokenised>
<facetable>true</facetable>
</index>
</property>
<property name="hon:invoiceDate">
<title>Invoice Date</title>
<type>d:date</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>TRUE</tokenised>
<facetable>true</facetable>
</index>
</property>
<property name="hon:organizationName">
<title>Organization Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>FALSE</tokenised>
<facetable>true</facetable>
</index>
</property>
<property name="hon:customerName">
<title>Customer Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>FALSE</tokenised>
<facetable>true</facetable>
</index>
</property>
</properties>
<associations/>
<overrides/>
<mandatory-aspects/>
</type>
</types>
<aspects/>
</model>
Facet Query Provider
package com.mycomp.edm.alfresco.extensions.search.solr.facets.handlers;
import org.alfresco.repo.search.impl.solr.facet.FacetQueryProvider;
import org.alfresco.repo.search.impl.solr.facet.SolrFacetConfigException;
import org.alfresco.repo.search.impl.solr.facet.handler.AbstractFacetLabelDisplayHandler;
import org.alfresco.repo.search.impl.solr.facet.handler.FacetLabel;
import org.springframework.extensions.surf.util.ParameterCheck;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by Amit on 2/24/16.
*/
public class DollarAmountDisplayHandler extends AbstractFacetLabelDisplayHandler implements FacetQueryProvider {
private static final Pattern SIZE_RANGE_PATTERN = Pattern.compile("(\\[\\d+\\sTO\\s(\\d+|MAX)\\])");
private final Map<String, FacetLabel> facetLabelMap;
private final Map<String, List<String>> facetQueriesMap;
public DollarAmountDisplayHandler(Set<String> facetQueryFields, LinkedHashMap<String, String> dollarValueBucketMap)
{
System.out.println("instantiating bean DollarAmountDisplayHandler");
ParameterCheck.mandatory("facetQueryFields", facetQueryFields);
ParameterCheck.mandatory("dollarValueBucketMap", dollarValueBucketMap);
this.supportedFieldFacets = Collections.unmodifiableSet(facetQueryFields);
facetLabelMap = new HashMap<>(dollarValueBucketMap.size());
Map<String, List<String>> facetQueries = new LinkedHashMap<>(facetQueryFields.size());
for (String facetQueryField : facetQueryFields)
{
List<String> queries = new ArrayList<>();
int index = 0;
for (Map.Entry<String, String> bucket : dollarValueBucketMap.entrySet())
{
String sizeRange = bucket.getKey().trim();
Matcher matcher = SIZE_RANGE_PATTERN.matcher(sizeRange);
if (!matcher.find())
{
throw new SolrFacetConfigException(
"Invalid dollar value range. Example of a valid size range is: [0 TO 1000]");
}
// build the facet query. e.g. {http://www.mycomp.com/model/hono/1.0}invoiceAmount:[0 TO 1000]
String facetQuery = facetQueryField + ':' + sizeRange;
queries.add(facetQuery);
// indexOf('[') => 1
String sizeRangeQuery = sizeRange.substring(1, sizeRange.length() - 1);
sizeRangeQuery = sizeRangeQuery.replaceFirst("\\sTO\\s", "\"..\"");
facetLabelMap.put(facetQuery, new FacetLabel(sizeRangeQuery, bucket.getValue(), index++));
}
facetQueries.put(facetQueryField, queries);
}
this.facetQueriesMap = Collections.unmodifiableMap(facetQueries);
System.out.println("Bean DollarAmountDisplayHandler instantiated");
}
#Override
public FacetLabel getDisplayLabel(String value)
{
FacetLabel facetLabel = facetLabelMap.get(value);
return (facetLabel == null) ? new FacetLabel(value, value, -1) : facetLabel;
}
#Override
public Map<String, List<String>> getFacetQueries()
{
return this.facetQueriesMap;
}
}

how to delete a scenario in atg through API methods

I have created a scenario by creating a myScenario.sdl in my local config folder /atg/registry/data/scenarios/myScenario.sdl
myScenario.sdl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE process SYSTEM "dynamosystemresource:/atg/dtds/pdl/pdl_1.0.dtd">
<process author="admin" creation-time="1413804041263" enabled="false" last-modified-by="admin" modification-time="1413804191188">
<segment migrate-subjects="true">
<segment-name>ItemAddedToOrder</segment-name>
<!--================================-->
<!--== Item added to order Quantity with fraction is defined -->
<!--================================-->
<event id="1">
<event-name>atg.commerce.order.ItemAddedToOrder</event-name>
<filter construct="event-property-filter" operator="isNotNull">
<event-property construct="event-property">
<property-name>quantityWithFraction</property-name>
</event-property>
</filter>
</event>
<!--================================-->
<!--== Log a message message: Quantity With Fraction is Defines logTriggeringEvent: true -->
<!--================================-->
<action id="2">
<action-name>Log a message</action-name>
<action-param name="message">
<constant>Quantity With Fraction is Defines</constant>
</action-param>
<action-param name="logTriggeringEvent">
<constant type="java.lang.Boolean">true</constant>
</action-param>
</action>
</segment>
</process>
And enabled the scenario:
Registry scenarioRegistry = scenarioManager.getScenarioRegistry();
byte[] data = (byte[]) scenarioRegistry.getItem(pScenarioPath);
String xml = null;
if (data != null) {
xml = new String(data, "UTF-8");
} else {
Assert.fail("No scenario is existed to enable/disable");
}
String updatedXml;
if (scenarioState && xml != null) {
updatedXml = xml.replaceAll("enabled=\"false\"", "enabled=\"true\"");
} else {
updatedXml = xml.replaceAll("enabled=\"true\"", "enabled=\"false\"");
}
scenarioRegistry.putItem(pScenarioPath, updatedXml.getBytes("UTF-8"));
Now with this above written code, I can both disable or enable the scenario by changing the state as false and true respectively. But I want to delete the scenario(please remember, my requirement is DELETE not DISABLE SCENARIO). I know using scenarioManager.updateScenario() deleted the scenario. Is my understanding right?
One more thing, I know I can delete the scenario directly from ACC. But I need to code via code not manually from ACC.
Please share your thoughts!
Did you try scenarioRegistry.removeItem(path);

Openejb with JPA - able to retrieve but cannot insert into database

I am using openejb as my standalone container to run my unit testcases, in all the test in all the tests i was able to retrieve the values but not able to insert or update. Even if i try entitymanager.merge(obj), it is selecting the value correctly but it is not updating it.
I am new to this , so please help me with this error
thanks in advance
my persistence.xml file
<persistence-unit name="test"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/OracleDS</jta-data-source>
.....entity classes.....
<properties>
<property name="eclipselink.target-server" value="JBoss" />
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.parameters" value="true" />
</properties>
</persistence-unit>
my dao method
tp.setname("van");
tp.settype("vehicle");
//entityManager.getTransaction().begin();
entityManager.merge(tp);
//entityManager.getTransaction().commit();
Do the followings for
Persist new entity:
Transport tp = new Transport();
tp.setname("van");
tp.settype("vehicle");
entityManager.getTransaction().begin();
entityManager.persist(tp);
entityManager.getTransaction().commit();
Update existing entity:
Query qry = entityManager.createQuery("Select t from
Transport t where t.type ='vechicle'");
List list = qry.getResultList();
//assume result return single entity
Transport tp = list.get(0);
tp.setInspectionDone(new Date()) ;
entityManager.getTransaction().begin();
entityManager.merge(tp);
entityManager.getTransaction().commit();
I think you need to ad #Transactional annotation in your class or method

Return value when internally calling target with phing/phingcall

I am calling a target by means of phingcall command.
I want to pass back a status variable from the called target or at least change the existing value from the calling target.
Goal: I want to branch in my main target controlling logic if the sub target fails which I indicate with a property.
The code below does not work. Any idea how to make it work or an altertive approach for my goal?
Thanks,
Juergen
<target name="main">
<echo>target a</echo>
<echo>${bOk}</echo>
<exec command="echo 1" outputProperty="bOk" />
<echo>bOk is 1: ${bOk}</echo>
<phingcall inheritRefs="true" target="sub">
</phingcall>
<echo>bOk should now be 0: ${bOk}</echo>
</target>
<target name="sub">
<echo>target b</echo>
<echo>bOk is 1: ${bOk}</echo>
<exec command="echo 0" outputProperty="bOk" />
<echo>bOk now is 0: ${bOk}</echo>
</target>
The problem here is that
<echo>bOk should now be 0: ${bOk}</echo>
echos
bOk should now be 0: 1
Even with the great help of #phing IRC I couldn't solve the problem.
I decided to write a custom task to account for data passing between targets:
<?php
require_once "phing/Task.php";
class rvGlobalTask extends Task {
private static $bOk = 1;
private $sMode = null;
private $bValue = null;
private $outputProperty = null;
public function setSMode( $sMode ) {
$this->sMode = $sMode;
}
public function setBValue( $bValue ) {
$this->bValue = $bValue;
}
public function setOutputProperty( $outputProperty ) {
$this->outputProperty = $outputProperty;
}
public function main() {
if ( $this->sMode == "set" ) {
rvGlobalTask::$bOk = $this->bValue;
} else {
$this->project->setProperty(
$this->outputProperty,
rvGlobalTask::$bOk
);
}
}
}
?>
This works fine for my problem. Perhaps someone else finds this useful as well.
Here's how you use an ExecTask to capture output.
<?xml version="1.0" encoding="UTF-8"?>
<project name="example" default="check-composer">
<!-- set a property to contain the output -->
<property name="whichComposer" value="" />
<!-- check if composer (getcomposer.org) is installed globally -->
<target name="check-composer">
<!-- put the output of "which" in our property -->
<exec command="which composer" outputProperty="whichComposer" />
<!-- act on what we found out -->
<if>
<contains string="${whichComposer}" substring="composer" />
<then>
<echo>Composer installed at ${whichComposer}</echo>
</then>
<else>
<echo message="better install composer. ${whichComposer}"/>
</else>
</if>
</target>
</project>