2015-12-03 3 views
0

J'essaie d'ajouter plusieurs conditions AND dans une cible Ant check pour définir une propriété. Je veux effectuer certaines actions en fonction de la propriété en cours de définition.Ant - plusieurs conditions pour générer une valeur de propriété

<target name="checkVal"> 
    <condition property="val.present"> 
     <and> 
      <available file="${srcDir}/somefile"/> 
      <matches pattern="MyClass.java" string="${pathString}"/> 
     </and> 
    </condition> 
    <fail message="Failing the condition."/> 
</target> 

<target name="doSomething" depends="checkVal" if="val.present"> 
    ... 
</target> 

L'intention est d'exécuter « doSomething » si la propriété val.present est définie par les 2 conditions dans le bloc <and>. Une condition vérifie si un fichier est disponible et une autre vérifie si une chaîne de chemin contient un fichier source particulier.

Je reçois le message d'échec toujours.

Les travaux suivants cependant:

<target name="checkVal"> 
    <available file="${srcDir}/somefile" property="val.present"/> 
</target> 

<target name="doSomething" depends="checkVal" if="val.present"> 
    ... 
</target> 

Quelqu'un pourrait-il me dire comment je peux obtenir ce correct?

Répondre

1

Cela a fonctionné après avoir remplacé la tâche matches par une tâche contains.

<target name="checkVal"> 
    <condition property="val.present"> 
     <and> 
      <available file="${srcDir}/somefile"/> 
      <contains substring="MyClass.java" string="${srcDir}"/> 
     </and> 
    </condition>  
</target>