简体   繁体   中英

How to get the Bundle-SymbolicName from an IProject?

I'm writing a wizard for an eclipse project and want to include another plugin as Require-Bundle in the Manifest.MF .

I have the IProject I want to include, can I access its Bundle-SymbolicName without parsing the Manifest.MF ? Or are there other ways to avoid manual parsing?

An IProject may not represent a plug-in and doesn't have any direct API to get a plug-in id.

You can use the normal Java Manifest class to look at the MANIFEST.MF using something like:

IProject project = ...

IFile manifestResource = project.getFile(new Path("META-INF/MANIFEST.MF"));
if (manifestResource.exists()) {
    try (InputStream stream = manifestResource.getContents()) {
        Manifest manifest = new Manifest();
        manifest.read(stream);

        String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
    } catch (CoreException | IOException ex) {
       ...
    }
}

This code is adapted from code used by Eclipse PDE to look for the plug-in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM