How to delete a line using Ant replaceregexp but not leave a blank line

I have the following text file:

  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

And I'm trying to use the following template in a replaceregexp task

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

To get this done:

  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

The problem is that I keep getting the following:

     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.2012 112 120 Bundle-Localization: plugin Bundle-Name:% plugin.name Bundle-Vendor:% plugin.providername 

What should my regex be to get rid of an empty string?

Thanks.

+4
source share
2 answers

Something like this should work:

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

(using \s* to match zero or more whitespace characters that include \r and \n ), but since you are dealing with a manifest file, it makes sense to use the correct manifest manifest. Unfortunately, the Ant <manifest> task does not provide a way to remove attributes, but it is pretty simple with the <script> task:

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

This works for me.

0
source

Source: https://habr.com/ru/post/1447339/


All Articles