2012-11-20 30 views
4

我有以下的文本文件:如何删除使用Ant replaceregexp一条线,而不是留下一个空行

 
    Manifest-Version: 3.0.0 
    Ant-Version: Apache Ant 1.7.1 
    Created-By: 10.0-b19 (Sun Microsystems Inc.) 
    Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version="1. 
    1.0" 
    Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref 
    Bundle-Version: 3.0.0.20121120 
    Bundle-Localization: plugin 
    Bundle-Name: %plugin.name 
    Bundle-Vendor: %plugin.providername 

而且我尝试使用以下方式在replaceregexp任务

 
    regexp pattern='Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version="1. 
    [\s\S]*' 

要这样结束了:

 
    Manifest-Version: 3.0.0 
    Ant-Version: Apache Ant 1.7.1 
    Created-By: 10.0-b19 (Sun Microsystems Inc.) 
    1.0" 
    Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref 
    Bundle-Version: 3.0.0.20121120 
    Bundle-Localization: plugin 
    Bundle-Name: %plugin.name 
    Bundle-Vendor: %plugin.providername 

麻烦的是我不断收到这样的:

 
    Manifest-Version: 3.0.0 
    Ant-Version: Apache Ant 1.7.1 
    Created-By: 10.0-b19 (Sun Microsystems Inc.) 

    1.0" 
    Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref 
    Bundle-Version: 3.0.0.20121120 
    Bundle-Localization: plugin 
    Bundle-Name: %plugin.name 
    Bundle-Vendor: %plugin.providername 

我的正则表达式应该是摆脱空行吗?

谢谢。

+0

这会给你一个无效的清单 - “1.0”是前一行的延续,因为清单规范需要很长的行来打包。理想情况下,你应该使用适当的清单文件分析器,但不幸的是, Ant' manifest'任务似乎不支持_removing_属性,只是添加或修改它们。 –

+0

谢谢。我意识到清单将是无效的,我打算删除1.0“以及我发现如何摆脱空行:-)我只是不需要对该捆绑的依赖。 – Drew

回答

3

像这样的东西应该工作:

Require-Bundle: org\.eclipse\.linuxtools\.cdt\.libhover;bundle-version="1\.\s*1.0"\s* 

(使用\s*匹配零个或多个空白字符,其中包括\r\n),但因为你正在处理一个清单文件会更有意义使用适当的清单解析器。不幸的是,蚂蚁<manifest>任务不提供一种方式来删除属性,但它是一个<script>任务非常简单:

<property name="manifest.file" location="path/to/manifest.txt" /> 

<script language="javascript"><![CDATA[ 
    importPackage(java.io); 
    importPackage(java.util.jar); 

    // read the manifest 
    manifestFile = new File(project.getProperty('manifest.file')); 
    manifest = new Manifest(); 
    is = new FileInputStream(manifestFile); 
    manifest.read(is); 
    is.close(); 

    // remove the offending attribute 
    manifest.getMainAttributes().remove(new Attributes.Name('Require-Bundle')); 

    // write back to the original file 
    os = new FileOutputStream(manifestFile); 
    manifest.write(os); 
    os.close(); 
]]></script> 
+0

非常感谢伊恩,您的快速反应和我的技术更正。你解决了我的问题,我学到了新东西。 – Drew

0
<replaceregexp file="manifest.mf" match='Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version=\"[^\"]+\"[\r\n]*' replace="" flags="m"/> 

这对我的作品。

+1

它也适用于我。感谢您的回答,Gábor。 – Drew

相关问题