use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class BundleLocalizationImpl method getLocalization.
/**
* The getLocalization method gets a ResourceBundle object for the given
* locale and bundle.
*
* @return A <code>ResourceBundle</code> object for the given bundle and locale.
* If null is passed for the locale parameter, the default locale is used.
*/
public ResourceBundle getLocalization(Bundle bundle, String locale) {
Module m = ((EquinoxBundle) bundle).getModule();
ModuleRevision r = m.getCurrentRevision();
Generation g = (Generation) r.getRevisionInfo();
return g.getResourceBundle(locale);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class Storage method refreshStaleBundles.
private void refreshStaleBundles() throws BundleException {
Collection<Module> needsRefresh = new ArrayList<>(0);
// First uninstall any modules that had their content changed or deleted
for (Module module : moduleContainer.getModules()) {
if (module.getId() == Constants.SYSTEM_BUNDLE_ID)
continue;
ModuleRevision revision = module.getCurrentRevision();
Generation generation = (Generation) revision.getRevisionInfo();
if (needsDiscarding(generation)) {
needsRefresh.add(module);
moduleContainer.uninstall(module);
generation.delete();
}
}
// because the runtime version changed.
if (refreshMRBundles.get()) {
needsRefresh.addAll(refreshMRJarBundles());
}
// refresh the modules that got deleted or are Multi-Release bundles
if (!needsRefresh.isEmpty()) {
moduleContainer.refresh(needsRefresh);
}
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class Storage method install.
public Generation install(Module origin, String bundleLocation, URLConnection content) throws BundleException {
if (osgiLocation.isReadOnly()) {
// $NON-NLS-1$
throw new BundleException("The framework storage area is read only.", BundleException.INVALID_OPERATION);
}
URL sourceURL = content.getURL();
InputStream in;
try {
in = content.getInputStream();
} catch (Throwable e) {
// $NON-NLS-1$
throw new BundleException("Error reading bundle content.", e);
}
// Check if the bundle already exists at this location
// before doing the staging and generation creation.
// This is important since some installers seem to continually
// re-install bundles using the same location each startup
Module existingLocation = moduleContainer.getModule(bundleLocation);
if (existingLocation != null) {
// Another thread could win the location lock and install before this thread does.
try {
in.close();
} catch (IOException e) {
// ignore
}
if (origin != null) {
// Check that the existing location is visible from the origin module
Bundle bundle = origin.getBundle();
BundleContext context = bundle == null ? null : bundle.getBundleContext();
if (context != null && context.getBundle(existingLocation.getId()) == null) {
Bundle b = existingLocation.getBundle();
throw new BundleException(NLS.bind(Msg.ModuleContainer_NameCollisionWithLocation, new Object[] { b.getSymbolicName(), b.getVersion(), bundleLocation }), BundleException.REJECTED_BY_HOOK);
}
}
return (Generation) existingLocation.getCurrentRevision().getRevisionInfo();
}
boolean isReference = in instanceof ReferenceInputStream;
File staged = stageContent(in, sourceURL);
Generation generation = null;
try {
Long nextID = moduleDatabase.getAndIncrementNextId();
BundleInfo info = new BundleInfo(this, nextID, bundleLocation, 0);
generation = info.createGeneration();
File contentFile = getContentFile(staged, isReference, nextID, generation.getGenerationId());
generation.setContent(contentFile, isReference);
// Check that we can open the bundle file
generation.getBundleFile().open();
setStorageHooks(generation);
ModuleRevisionBuilder builder = getBuilder(generation);
builder.setId(nextID);
Module m = moduleContainer.install(origin, bundleLocation, builder, generation);
if (!nextID.equals(m.getId())) {
// this revision is already installed. delete the generation
generation.delete();
return (Generation) m.getCurrentRevision().getRevisionInfo();
}
return generation;
} catch (Throwable t) {
if (!isReference) {
try {
delete(staged);
} catch (IOException e) {
// tried our best
}
}
if (generation != null) {
generation.delete();
generation.getBundleInfo().delete();
}
if (t instanceof SecurityException) {
// if the cause is a bundle exception then throw that
if (t.getCause() instanceof BundleException) {
throw (BundleException) t.getCause();
}
throw (SecurityException) t;
}
if (t instanceof BundleException) {
throw (BundleException) t;
}
// $NON-NLS-1$
throw new BundleException("Error occurred installing a bundle.", t);
} finally {
if (generation != null) {
generation.getBundleInfo().unlockGeneration(generation);
}
}
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class BundleResourceHandler method openConnection.
/**
* Establishes a connection to the resource specified by <code>URL</code>.
* Since different protocols may have unique ways of connecting, it must be
* overridden by the subclass.
*
* @return java.net.URLConnection
* @param url java.net.URL
*
* @exception IOException thrown if an IO error occurs during connection establishment
*/
protected URLConnection openConnection(URL url) throws IOException {
if (// if the bundleEntry is not null then return quick
bundleEntry != null)
return (new BundleURLConnection(url, bundleEntry));
String host = url.getHost();
if (host == null) {
throw new IOException(NLS.bind(Msg.URL_NO_BUNDLE_ID, url.toExternalForm()));
}
long bundleID;
try {
bundleID = getBundleID(host);
} catch (NumberFormatException nfe) {
throw (MalformedURLException) new MalformedURLException(NLS.bind(Msg.URL_INVALID_BUNDLE_ID, host)).initCause(nfe);
}
Module module = getModule(bundleID);
if (module == null)
throw new IOException(NLS.bind(Msg.URL_NO_BUNDLE_FOUND, url.toExternalForm()));
// at URL construction.
if (!url.getAuthority().equals(SECURITY_CHECKED)) {
// No admin security check was made better check now.
checkAuthorization(module);
}
return (new BundleURLConnection(url, findBundleEntry(url, module)));
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class ClasspathManager method findLocalResources.
/**
* Finds the local resources by searching the ClasspathEntry objects of the classpath manager.
* @param resource the requested resource name.
* @return an enumeration of the the requested resources
*/
public Enumeration<URL> findLocalResources(String resource) {
Module m = generation.getRevision().getRevisions().getModule();
List<URL> resources = new ArrayList<>(6);
int classPathIndex = 0;
for (ClasspathEntry cpEntry : entries) {
if (cpEntry != null) {
URL url = cpEntry.findResource(resource, m, classPathIndex);
if (url != null) {
resources.add(url);
}
}
classPathIndex++;
}
// look in fragments
for (FragmentClasspath fragCP : getFragmentClasspaths()) {
for (ClasspathEntry cpEntry : fragCP.getEntries()) {
URL url = cpEntry.findResource(resource, m, classPathIndex);
if (url != null) {
resources.add(url);
}
classPathIndex++;
}
}
if (resources.size() > 0)
return Collections.enumeration(resources);
return EMPTY_ENUMERATION;
}
Aggregations