2017-12-20 5 views
0

내 요구 사항은 매우 간단합니다. 예외를 내부적으로 처리하고 예외를 throw하지 않는 ANT 태스크가 있으며 콘솔에 사용자 정의 메시지 [예외 사항이 아닙니다]가 표시됩니다. 샘플은 "지정된 이름의 작업 공간이 없습니다"라는 테스트와 함께 아래에 표시됩니다. 이러한 메시지는 "성공적인 구축"에서 떨어져있는 경우 여기ANT 스크립트의 조건부 태스크 실행

enter image description here

내 요구 사항입니다, 나는 그것이 더 나아가되지 않도록 내 ANT 스크립트가 실패 있는지 확인해야합니다. 하지만 콘솔에 쓰여진 사용자 지정 메시지를 어떻게 읽어야할지 모르겠으므로 그렇게 할 수 없습니다.

'기록'작업을 시도했지만이 로그가 콘솔이 아닌 파일에만 기록 되었기 때문에 실패했습니다. 이유를 모르겠습니다. 그러나 파일로 작성 되었더라도 각 텍스트 행을 읽고 특정 텍스트의 존재 여부를 알아야합니다.

이전에 실행 된 콘솔에서 물건을 읽는 간단한 방법이 있습니까?

<target name="build"> 
    <record name="test.txt" action="start" append="true" loglevel="verbose" /> 
    <echo>Welcome to Apache Ant! Building the project in Cordys Middleware</echo> 
    <property environment="env"/> 
    <property name="bop.install.dir" value="${env.CORDYS_HOME}"/> 
    <exec executable="${bop.install.dir}/components/cws/scripts/linux/CWSPackage.sh" failonerror="true" resultproperty="output">   
     <env key="CLASSPATH" value="/opt/Cordys/Oracle_Jar/ojdbc6.jar"/> 
     <arg value="${ORG_NAME}"/> 
     <arg value="${WORKSPACE_NAME}"/> 
     <arg value="${PROJECT_NAME}"/>  
    </exec> 
    <echo>Finishing the build</echo> 
    <record name="test.txt" action="stop"/> 
    <echo>${output}</echo> 
    <fail>Something wrong here.</fail> <!-- I want to throw this error conditionally --> 
</target> 

답변

1

은 무엇 당신이 찾고있는 것은 exec 작업의 outputproperty 속성입니다.

당신은 같은 것을 수행 할 수 있습니다

<exec executable="${my.executable}" outputproperty="exec.output"> 
    <arg value="${my.arg}" /> 
</exec> 

<fail message="Invalid output from exec task"> 
    <condition> 
     <contains string="${exec.output}" substring="The workspace with the specified string does not exist." /> 
    </condition> 
</fail> 

여러 조건 (부울 복잡성의 수준이 허용됩니다) :

<fail message="Invalid output from exec task"> 
    <condition> 
     <and> 
      <not> 
       <contains string="${exec.output}" substring="SUCCESS" /> 
      </not> 
      <or> 
       <contains string="${exec.output}" substring="ERROR" /> 
       <contains string="${exec.output}" substring="FAILED" /> 
      <or> 
     </and> 
    </condition> 
</fail> 

정규식 :

<fail message="Invalid output from exec task"> 
    <condition> 
     <matches string="${exec.output}" pattern="The .* does not exist." /> 
    </condition> 
</fail> 
+0

사용중인 Ant의 버전은 무엇입니까? 나는 이것을 실행 시키려고했으나 "실패는 중첩 된"요소를 포함하고 있지 않다 "는 오류로 실패했습니다." 나는 ANT의 1.10.xxx 버전을 사용해 보았는데 여전히 같은 문제에 직면하고 있습니까? 내가 여기서해야 할 다른 것이 있습니까? –

+1

@KiranJoshi 죄송합니다. ''블록에 포장하는 것을 잊었습니다. 한번 더 시도해보십시오. 당신의 다른 대답에 관해서는, ant-contrib의 사용을 피하는 것이 좋습니다. – CAustin

+0

outputproperty = "$ {exec.output}"캡처되지 않습니다. 오스틴 : ( $ {exec.output}을 보여 주며 분명히 이것 때문에 실패했습니다 .... –

0
<!-- * This is an ANT script to build the project in development environment. 
     Steps involved in this are 
      * Building the project 
      * Publishing the project 
      * Creating the package for the project 
--> 

<!-- 
    Sample command to execute this 
    ant build -DORG_NAME=businessservices3 -DWORKSPACE_NAME=ConfigurationManagement -DPROJECT_NAME='ConfigurationManagement' 
--> 
<project name="Building Project" default="build"> 
    <property file="${PROJECT}" /> 
    <target name="build"> 
     <echo>Welcome to Apache Ant! Building the project in Cordys Middleware</echo> 
     <property environment="env"/> 
     <property name="bop.install.dir" value="${env.CORDYS_HOME}"/> 

     <exec executable="${bop.install.dir}/components/cws/scripts/linux/CWSPackage.sh" outputproperty="exec.output">  
      <env key="CLASSPATH" value="/opt/Cordys/Oracle_Jar/ojdbc6.jar"/> 
      <arg value="${ORG_NAME}"/> 
      <arg value="${WORKSPACE_NAME}"/> 
      <arg value="${PROJECT_NAME}"/>  
     </exec> 
     <fail message="Build not successful for the project ${PROJECT_NAME}"> 
      <condition> 
       <not> 
        <contains string="${exec.output}" substring="Operation completed successful" /> 
       </not> 
      </condition> 
     </fail> 

    </target> 
</project> 

이것은 mu 이후에 나를 위해 일했습니다. 흔적과 오류 방법의 ch. 오스틴에게 감사드립니다. 이것은 ANT가 작동하고 있음에도 불구하고 귀하의 답변을 수락 할 것입니다.

관련 문제