2011-03-10 10 views
2

說我有串 - 「d:\ ApEx_Schema \功能\ new.sql @@ \主\ ONEVIEW_Integration \ 3」 我需要獲取以下內容差異變量 - 文件命名 - 文件路徑 - 和版本(這是字符串的最後一個字符)Ant任務來接的話從一個字符串

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任務更新數據庫中的相同內容。 儘管我的build.xml沒有根據需要提供輸出。 任何建議和意見!

我的Build.xml文件看起來像 - ============== START ====================== =====

<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擅長的東西。 也許最簡單的辦法就是使用ant-contribpropertyregex task

<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> 

這涉及到越來越任務的螞蟻的contrib收集罐子的保持。

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> 

(注:測試此在UNIX操作系統,所以你可能需要,如果調整路徑分隔符的處理在Windows上)

更新:

您的實現的一些注意事項。

您可能需要的命名空間「的」任務:

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

如果你想propertyregex更改屬性(你做你正在迭代),你需要在每個那些設置 override="yes" 。 裏面一個for你需要躲避的跡象,例如:

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

要引用由propertyregex使用${path}而非@{path}設置屬性。

+0

謝謝馬丁:)它的工作原理! – Ajitesh 2011-03-10 11:12:24

+0

馬丁它爲單個字符串工作,你可以建議幫助多個字符串在一個文件中...謝謝 – Ajitesh 2011-03-10 12:59:06

+0

@Ajitesh - 更新,hth。 – 2011-03-10 14:03:33

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> 
相關問題