2011-03-10 7 views
2

"D : \ ApEx_Schema \ Functions \ new.sql @@ \ main \ ONEVIEW_Integration \ 3"문자열이 있다고 말하십시오. diff 변수에 다음을 반입해야합니다. - 파일 ================문자열에서 단어를 선택하는 개미 작업

은 Pls는 어떤 ANT 작업

를 사용하는 데 도움이 (문자열의 마지막 문자 인) 및 버전 - 파일 경로 을 - 이름 ======================== 아래와 같은 데이터가 포함 된 txt 파일을 읽으려고합니다. -

.\ApEx_Schema\Functions\[email protected]@\main\ONEVIEW_Integration\3 

.\ApEx_Schema\Functions\[email protected]@\main\ONEVIEW_Integration\3 

.\ApEx_Schema\Indexes\[email protected]@\main\ONEVIEW_Integration\2 

그리고 파일 이름, 경로 세부 정보 및 버전을 수집하고 SQL 작업을 사용하여 DB에서이를 업데이트하려고합니다. 내 build.xml이 원하는대로 출력을 제공하지 않지만. 제안 및 의견 !!!

내 Build.xml 파일은 다음과 같습니다. - ============== 시작 ==================== =====

<description> 
    obiee copy files build file 
</description> 

<replace file="D:\buildFRIDAY\database.txt" token=".\" value="D:\"/> 
<loadfile property="src" srcFile="D:\buildFRIDAY\database.txt"/> 

<path id="antclasspath"> 
    <fileset dir="D:\OraHome_1\oracledi\drivers">  
    <include name="ojdbc14.jar"/>  
    </fileset> 
</path> 

<for list="${src}" param="detls" delimiter="${line.separator}"> 
<sequential> 
     <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> 
     <propertyregex property="path" input="@{detls}" 
         regexp="(.*)\\.*@@" select="\1" /> 
     <propertyregex property="file" input="@{detls}" 
         regexp=".*\\(.*)@@" select="\1" /> 
     <propertyregex property="version" input="@{detls}" 
         regexp=".*\\(.*)" select="\1" /> 

     <echo> 
     Input: @{detls} 
     Path: ${path} 
     File: ${file} 
     Version: ${version} 
     </echo> 

     <if> 
       <matches string="@{detls}" pattern=".sql" /> 
     <then> 

     </then> 
     </if> 

     <if> 
       <matches string="@{detls}" pattern="[0-9]" /> 
    <then> 
      <sql  
       driver="oracle.jdbc.driver.OracleDriver" 
       url="jdbc:oracle:thin:@172.16.88.68:1521:rdev" 
       userid="rapid"  
       password="rapid"  
       print="yes"  
       classpathref="antclasspath">  

       Insert into ROLTA_PATCH_FILE_APP_TAB (PATCH_NO,FILE_NAME,FILE_PATH,FILE_VERSION,APPLIED_DATE,STATUS) values ('3.2.12',"@{detls}",'D:\ApEx_Schema\Functions\Functions.sql','3',to_date('11-MAR-11','DD-MON-RR'),'Y'); 

       Insert into ROLTA_PATCH_TAB (PATCH_NO,PATCH_NAME,APPL_NAME,APPLIED_DATE) values ('3.2.12','2.1.11','@{detls}',to_date('11-MAR-11','DD-MON-RR')); 
      </sql> 
     </then> 
     </if> 
    </sequential> 
</for> 

=============== END ===========

답변

2

이것은 개미가 잘하는 것이 아닙니다. 가 아마 가장 간단한 솔루션을 사용하는 것입니다 ant-contribpropertyregex task :

작업의 개미의 contrib 수집의 항아리의 보류를 받고 포함
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/> 

<property name="candidate" 
      value="D:\ApEx_Schema\Functions\[email protected]@\main\ONEVIEW_Integration\3" /> 

<propertyregex property="path" input="${candidate}" 
       regexp="(.*)\\.*@@" select="\1" /> 
<propertyregex property="file" input="${candidate}" 
       regexp=".*\\(.*)@@" select="\1" /> 
<propertyregex property="version" input="${candidate}" 
       regexp=".*\\(.*)" select="\1" /> 

<echo> 
Input: ${candidate} 
Path: ${path} 
File: ${file} 
Version: ${version} 
</echo> 

.

A - 상당히 고약한 - 대안은 scriptdef task을 사용하는 것입니다.

<scriptdef name="get_elements" language="javascript"> 
    <attribute name="candidate" /> 
    <attribute name="path-property" /> 
    <attribute name="file-property" /> 
    <attribute name="version-property" /> 
    <![CDATA[ 
     filesep = project.getProperty("file.separator"); 
     candidate = attributes.get("candidate"); 
     path = candidate.substring(0, candidate.indexOf("@@")); 
     file = path.substring(path.lastIndexOf(filesep) + 1); 
     path = path.substring(0, path.lastIndexOf(filesep)); 
     version = candidate.substring(candidate.lastIndexOf(filesep) + 1); 

     project.setProperty(attributes.get("path-property"), path); 
     project.setProperty(attributes.get("file-property"), file); 
     project.setProperty(attributes.get("version-property"), version); 
    ]]> 
</scriptdef> 

<property name="candidate" 
      location="D:\ApEx_Schema\Functions\[email protected]@\main\ONEVIEW_Integration\3" 
      relative="yes" /> 
<get_elements candidate="${candidate}" 
       path-property="path" 
       file-property="file" 
       version-property="version" /> 
<echo> 
Input: ${candidate} 
Path: ${path} 
File: ${file} 
Version: ${version} 
</echo> 

(참고 :. Windows에서 경우 경로 분리 치료를 조정해야 할 수도 있으므로, 유닉스 OS에서이 테스트)

업데이트 : 구현에

일부 노트.

당신은 네임 스페이스해야 할 과제 '에 대한'

<ac:for list="${src}" param="detls" delimiter="${line.separator}" 
     xmlns:ac="antlib:net.sf.antcontrib"> 
    ... 
</ac:for> 

당신이 그 각각에 override="yes"를 설정해야합니다 (당신이 반복하고 당신이 할) 속성을 변경 propertyregex를 원하는 경우 . for, 안쪽 당신은 예를 들어, 표지판에서 탈출해야합니다

<propertyregex property="path" 
       input="@{detls}" 
       regexp="(.*)\\.*\@\@" select="\1" 
       override="yes"/> 

propertyregex 사용 ${path}보다는 @{path}에 의해 설정된 속성을 참조하십시오.

+0

고마워요 :) :) 작품! – Ajitesh

+0

마틴 그것은 하나의 문자열을 위해 일했는데, u pls 파일에 여러 문자열에 대한 도움을 제안 할 수 ... 감사합니다 – Ajitesh

+0

@Ajitesh - 업데이트, hth. –

1

기여한 작업 "propertyregex"또는 javascript가 필요하지 않은 대안.

<property name="candidate" value="D:\ApEx_Schema\Functions\[email protected]@\main\ONEVIEW_Integration\3" /> 

<pathconvert property="path"> 
    <path location="${candidate}" /> 
    <regexpmapper from="(.*)\\.*@@" to="\1" /> 
</pathconvert> 

<pathconvert property="file"> 
    <path location="${candidate}" /> 
    <regexpmapper from=".*\\(.*)@@" to="\1" /> 
</pathconvert> 

<pathconvert property="version"> 
    <path location="${candidate}" /> 
    <regexpmapper from=".*\\(.*)" to="\1" /> 
</pathconvert> 

<echo> 
Input: ${candidate} 
Path: ${path} 
File: ${file} 
Version: ${version} 
</echo> 
관련 문제