use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Storage method close.
public void close() {
try {
save();
} catch (IOException e) {
// $NON-NLS-1$
getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error saving on shutdown", e);
}
// close all the generations
List<Module> modules = moduleContainer.getModules();
for (Module module : modules) {
for (ModuleRevision revision : module.getRevisions().getModuleRevisions()) {
Generation generation = (Generation) revision.getRevisionInfo();
if (generation != null) {
generation.close();
}
}
}
for (ModuleRevision removalPending : moduleContainer.getRemovalPending()) {
Generation generation = (Generation) removalPending.getRevisionInfo();
if (generation != null) {
generation.close();
}
}
mruList.shutdown();
adaptor.shutdownResolverExecutor();
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Handler method findBundleEntry.
protected BundleEntry findBundleEntry(URL url, Module module) throws IOException {
ModuleRevision current = module.getCurrentRevision();
ModuleWiring wiring = current == null ? null : current.getWiring();
ModuleClassLoader classloader = (ModuleClassLoader) (current == null ? null : wiring.getClassLoader());
if (classloader == null)
throw new FileNotFoundException(url.getPath());
BundleEntry entry = classloader.getClasspathManager().findLocalEntry(url.getPath(), url.getPort());
if (entry == null) {
// this isn't strictly needed but is kept to maintain compatibility
entry = classloader.getClasspathManager().findLocalEntry(url.getPath());
}
if (entry == null) {
throw new FileNotFoundException(url.getPath());
}
return entry;
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class EquinoxBundle method adapt0.
@SuppressWarnings("unchecked")
private <A> A adapt0(Class<A> adapterType) {
if (AccessControlContext.class.equals(adapterType)) {
Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
ProtectionDomain domain = current.getDomain();
return (A) (domain == null ? null : new AccessControlContext(new ProtectionDomain[] { domain }));
}
if (BundleContext.class.equals(adapterType)) {
try {
return (A) getBundleContext();
} catch (SecurityException e) {
return null;
}
}
if (BundleRevision.class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
return (A) module.getCurrentRevision();
}
if (BundleRevisions.class.equals(adapterType)) {
return (A) module.getRevisions();
}
if (BundleStartLevel.class.equals(adapterType)) {
return (A) module;
}
if (BundleWiring.class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
ModuleRevision revision = module.getCurrentRevision();
if (revision == null) {
return null;
}
return (A) revision.getWiring();
}
if (BundleDTO.class.equals(adapterType)) {
// Unfortunately we need to lock here to make sure the BSN and version
// are consistent in case of updates
readLock();
try {
return (A) DTOBuilder.newBundleDTO(this);
} finally {
readUnlock();
}
}
if (BundleStartLevelDTO.class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
return (A) DTOBuilder.newBundleStartLevelDTO(this, module);
}
if (BundleRevisionDTO.class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
return (A) DTOBuilder.newBundleRevisionDTO(module.getCurrentRevision());
}
if (BundleRevisionDTO[].class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
// proper locking for us.
return (A) DTOBuilder.newArrayBundleRevisionDTO(module.getRevisions());
}
if (BundleWiringDTO.class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
readLock();
try {
return (A) DTOBuilder.newBundleWiringDTO(module.getCurrentRevision());
} finally {
readUnlock();
}
}
if (BundleWiringDTO[].class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
readLock();
try {
return (A) DTOBuilder.newArrayBundleWiringDTO(module.getRevisions());
} finally {
readUnlock();
}
}
if (ServiceReferenceDTO[].class.equals(adapterType)) {
if (module.getState().equals(State.UNINSTALLED)) {
return null;
}
BundleContextImpl current = getBundleContextImpl();
ServiceReference<?>[] references = (current == null) ? null : equinoxContainer.getServiceRegistry().getRegisteredServices(current);
return (A) DTOBuilder.newArrayServiceReferenceDTO(references);
}
if (getBundleId() == 0) {
if (Framework.class.equals(adapterType)) {
return (A) this;
}
if (FrameworkStartLevel.class.equals(adapterType)) {
return (A) module.getContainer().getFrameworkStartLevel();
}
if (FrameworkWiring.class.equals(adapterType)) {
return (A) module.getContainer().getFrameworkWiring();
}
if (FrameworkDTO.class.equals(adapterType)) {
BundleContextImpl current = getBundleContextImpl();
Map<String, String> configuration = equinoxContainer.getConfiguration().getConfiguration();
readLock();
try {
return (A) DTOBuilder.newFrameworkDTO(current, configuration);
} finally {
readUnlock();
}
}
if (FrameworkStartLevelDTO.class.equals(adapterType)) {
return (A) DTOBuilder.newFrameworkStartLevelDTO(module.getContainer().getFrameworkStartLevel());
}
if (FrameworkWiringDTO.class.equals(adapterType)) {
readLock();
try {
Set<BundleWiring> allWirings = new HashSet<>();
for (Module m : module.getContainer().getModules()) {
for (BundleRevision revision : m.getRevisions().getRevisions()) {
BundleWiring wiring = revision.getWiring();
if (wiring != null) {
allWirings.add(wiring);
}
}
}
for (ModuleRevision revision : module.getContainer().getRemovalPending()) {
BundleWiring wiring = revision.getWiring();
if (wiring != null) {
allWirings.add(wiring);
}
}
return (A) DTOBuilder.newFrameworkWiringDTO(allWirings);
} finally {
readUnlock();
}
}
}
// Equinox extras
if (Module.class.equals(adapterType)) {
return (A) module;
}
if (ProtectionDomain.class.equals(adapterType)) {
Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
return (A) current.getDomain();
}
return null;
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class FrameworkExtensionInstaller method startExtensionActivators.
public void startExtensionActivators(BundleContext context) {
// First start the hook registry activators
// TODO not sure we really need these anymore
HookRegistry hookRegistry = configuration.getHookRegistry();
List<ActivatorHookFactory> activatorHookFactories = hookRegistry.getActivatorHookFactories();
for (ActivatorHookFactory activatorFactory : activatorHookFactories) {
BundleActivator activator = activatorFactory.createActivator();
try {
startActivator(activator, context, null);
} catch (Exception e) {
configuration.getHookRegistry().getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, null, e);
}
}
// start the extension bundle activators. In Equinox we let
// framework extensions define Bundle-Activator headers.
ModuleWiring systemWiring = (ModuleWiring) context.getBundle().adapt(BundleWiring.class);
if (systemWiring != null) {
List<ModuleWire> extensionWires = systemWiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
for (ModuleWire extensionWire : extensionWires) {
ModuleRevision extensionRevision = extensionWire.getRequirer();
startExtensionActivator(extensionRevision, context);
}
}
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Storage method saveGenerations.
private void saveGenerations(DataOutputStream out) throws IOException {
List<Module> modules = moduleContainer.getModules();
List<Generation> generations = new ArrayList<>();
for (Module module : modules) {
ModuleRevision revision = module.getCurrentRevision();
if (revision != null) {
Generation generation = (Generation) revision.getRevisionInfo();
if (generation != null) {
generations.add(generation);
}
}
}
out.writeInt(VERSION);
out.writeUTF(runtimeVersion.toString());
out.writeInt(cachedHeaderKeys.size());
for (String headerKey : cachedHeaderKeys) {
out.writeUTF(headerKey);
}
out.writeInt(generations.size());
for (Generation generation : generations) {
BundleInfo bundleInfo = generation.getBundleInfo();
out.writeLong(bundleInfo.getBundleId());
out.writeUTF(bundleInfo.getLocation());
out.writeLong(bundleInfo.getNextGenerationId());
out.writeLong(generation.getGenerationId());
out.writeBoolean(generation.isDirectory());
out.writeBoolean(generation.isReference());
out.writeBoolean(generation.hasPackageInfo());
if (bundleInfo.getBundleId() == 0) {
// just write empty string for system bundle content in this case
// $NON-NLS-1$
out.writeUTF("");
} else {
if (generation.isReference()) {
// make reference installs relative to the install path
out.writeUTF(new FilePath(installPath).makeRelative(new FilePath(generation.getContent().getAbsolutePath())));
} else {
// make normal installs relative to the storage area
out.writeUTF(Storage.getBundleFilePath(bundleInfo.getBundleId(), generation.getGenerationId()));
}
}
out.writeLong(generation.getLastModified());
Dictionary<String, String> headers = generation.getHeaders();
for (String headerKey : cachedHeaderKeys) {
String value = headers.get(headerKey);
if (value != null) {
out.writeUTF(value);
} else {
out.writeUTF(NUL);
}
}
out.writeBoolean(generation.isMRJar());
}
saveStorageHookData(out, generations);
}
Aggregations