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 pattern in a replaceregexp task
regexp pattern='Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version="1. [\s\S]*'
To end up with this:
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 trouble is I keep getting this:
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
What should my regex be to get rid of the empty line?
Thanks.
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, which include \r
and \n
) but since you're dealing with a manifest file it would make more sense to use a proper manifest parser. Unfortunately the Ant <manifest>
task doesn't provide a way to remove attributes, but it's pretty straightforward with a <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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With