Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Need to know "real" jar bundle location
Need to know "real" jar bundle location [message #93325] Mon, 30 July 2007 17:57 Go to next message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Hi,

I have a plugin that needs to know the location of other bundles in the plugins folder of Eclipse.
The problem is that jar bundles are unpacked to somewhere under configuration/org.eclipse.osgi/bundles.
Is there a public API that I can query to get the original bundle's jar location?

Cheers
/Eike
Re: Need to know "real" jar bundle location [message #93461 is a reply to message #93325] Tue, 31 July 2007 19:16 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
Something like this should do the trick

import org.eclipse.core.runtime.FileLocator;
....
public File getRootFile(Bundle bundle) throws IOException {
URL rootEntry = bundle.getEntry("/");
rootEntry = FileLocator.resolve(rootEntry);
if ("file".equals(rootEntry.getProtocol()))
return new File(rootEntry.getPath());
if ("jar".equals(rootEntry.getProtocol())) {
String path = rootEntry.getPath();
// strip off the file: and the !/
path = path.substring(5, path.length() - 2);
return new File(path);
}
throw new IOException("unknown protococol");
}

I opened a bug to request such a method be added to FileLocator. See
https://bugs.eclipse.org/bugs/show_bug.cgi?id=198447

HTH

Tom
Re: Need to know "real" jar bundle location [message #93493 is a reply to message #93461] Tue, 31 July 2007 19:41 Go to previous message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Tom,

Thank you for your answer but I knew how to resolve a bundles location.
The problem is that the Eclipse update core (or whoever) *unpacks* some
jar bundles.
I took the following approach:

private static File[] getSiteLocations()
{
try
{
ILocalSite localSite = SiteManager.getLocalSite();
IInstallConfiguration configuration =
localSite.getCurrentConfiguration();
IConfiguredSite[] configuredSites =
configuration.getConfiguredSites();
File[] siteLocations = new File[configuredSites.length];

for (int i = 0; i < configuredSites.length; i++)
{
ISite site = configuredSites[i].getSite();
URL url = site.getURL();
siteLocations[i] = new File(url.getFile());
}

return siteLocations;
}
catch (CoreException ex)
{
throw WrappedException.wrap(ex);
}
}

private static File getLocation(String versionedIdentifier, File[]
siteLocations)
{
for (File siteLocation : siteLocations)
{
File pluginsFolder = new File(siteLocation, "plugins");
File archive = new File(pluginsFolder, versionedIdentifier +
ICDOWeaver.JAR_SUFFIX);
if (archive.exists())
{
if (!archive.isFile())
{
return null;
}

return archive;
}

File folder = new File(pluginsFolder, versionedIdentifier);
if (folder.exists())
{
if (!folder.isDirectory())
{
return null;
}

return folder;
}
}

return null;
}

Cheers
/Eike


Tom Watson schrieb:
> Something like this should do the trick
>
> import org.eclipse.core.runtime.FileLocator;
> ....
> public File getRootFile(Bundle bundle) throws IOException {
> URL rootEntry = bundle.getEntry("/");
> rootEntry = FileLocator.resolve(rootEntry);
> if ("file".equals(rootEntry.getProtocol()))
> return new File(rootEntry.getPath());
> if ("jar".equals(rootEntry.getProtocol())) {
> String path = rootEntry.getPath();
> // strip off the file: and the !/
> path = path.substring(5, path.length() - 2);
> return new File(path);
> }
> throw new IOException("unknown protococol");
> }
>
> I opened a bug to request such a method be added to FileLocator. See
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=198447
>
> HTH
>
> Tom
Previous Topic:Binary compatible bundles
Next Topic:Configuration Admin
Goto Forum:
  


Current Time: Fri Sep 20 03:02:34 GMT 2024

Powered by FUDForum. Page generated in 0.03842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top