2011-05-06 37 views
2

我試圖在Ant構建文件中進行標記替換,但前提是標記位於具有特定內容的行中。從文件Ant中的條件標記替換

樣品樣機片段:

<script type="text/javascript" src="scripts/someFolder/someFile1.js"></script> 
<script type="text/javascript" src="scripts/otherFolder/fileName.js"></script> 
<script type="text/javascript" src="scripts/aFolder/file3.js"></script> 
<script type="text/javascript" src="scripts/someFolder/aFile.js"></script> 
<script type="text/javascript" src="scripts/someFolder/subfolder/anotherFile.js"></script> 
<body> 
<p>Stuff</p> 

在這個例子中,我想追加一個時間戳任何文件從「somefolder」未來的js文件的? 我已經試過東西沿着這些路線(實際正則表達式是不同的):

<copy file="xyz.jsp" tofile="${staging}/jsp/Links-test.jsp"> 
    <filterchain> 
     <linecontainsregexp> 
      <regexp pattern="someFolder" /> 
     </linecontainsregexp> 
      <replacestring from=".js" to=".js?blahblah" />    
    </filterchain> 
</copy> 

但只是導致文件只被修改的行。我需要設置哪個標記以保留所有文件內容?我需要整個文件,只需要一些條件替換。

回答

0

您可以將多個過濾鏈放在一起。您的過濾器鏈將過濾掉包含正則表達式的行。你需要的是第二個過濾器鏈重新添加在

完全未經測試:

<copy file="xyz.jsp" tofile="${staging}/jsp/Links-test.jsp"> 
    <filterchain> 
     <linecontainsregexp> 
      <regexp pattern="someFolder" /> 
     </linecontainsregexp> 
      <replacestring from=".js" to=".js?blahblah" />    
    </filterchain> 
    <filterchain> 
     <linecontainsregexp negate="true"> 
      <regexp pattern="someFolder" /> 
     </linecontainsregexp> 
    </filterchain>    
</copy>