package org.eclipse.osgi.storage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.eclipse.osgi.container.Module;
import org.eclipse.osgi.container.ModuleCapability;
import org.eclipse.osgi.container.ModuleContainer;
import org.eclipse.osgi.container.ModuleContainerAdaptor;
import org.eclipse.osgi.container.ModuleDatabase;
import org.eclipse.osgi.container.ModuleRevision;
import org.eclipse.osgi.container.ModuleRevisionBuilder;
import org.eclipse.osgi.container.ModuleWire;
import org.eclipse.osgi.container.ModuleWiring;
import org.eclipse.osgi.container.builders.OSGiManifestBuilderFactory;
import org.eclipse.osgi.container.namespaces.EclipsePlatformNamespace;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.framework.util.FilePath;
import org.eclipse.osgi.framework.util.ObjectPool;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.debug.Debug;
import org.eclipse.osgi.internal.framework.EquinoxConfiguration;
import org.eclipse.osgi.internal.framework.EquinoxContainer;
import org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor;
import org.eclipse.osgi.internal.framework.FilterImpl;
import org.eclipse.osgi.internal.hookregistry.BundleFileWrapperFactoryHook;
import org.eclipse.osgi.internal.hookregistry.StorageHookFactory;
import org.eclipse.osgi.internal.hookregistry.StorageHookFactory.StorageHook;
import org.eclipse.osgi.internal.location.EquinoxLocations;
import org.eclipse.osgi.internal.location.LocationHelper;
import org.eclipse.osgi.internal.log.EquinoxLogServices;
import org.eclipse.osgi.internal.messages.Msg;
import org.eclipse.osgi.internal.permadmin.SecurityAdmin;
import org.eclipse.osgi.internal.url.URLStreamHandlerFactoryImpl;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.storage.BundleInfo.Generation;
import org.eclipse.osgi.storage.bundlefile.BundleEntry;
import org.eclipse.osgi.storage.bundlefile.BundleFile;
import org.eclipse.osgi.storage.bundlefile.BundleFileWrapper;
import org.eclipse.osgi.storage.bundlefile.BundleFileWrapperChain;
import org.eclipse.osgi.storage.bundlefile.DirBundleFile;
import org.eclipse.osgi.storage.bundlefile.MRUBundleFileList;
import org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile;
import org.eclipse.osgi.storage.bundlefile.ZipBundleFile;
import org.eclipse.osgi.storage.url.reference.Handler;
import org.eclipse.osgi.storage.url.reference.ReferenceInputStream;
import org.eclipse.osgi.storagemanager.ManagedOutputStream;
import org.eclipse.osgi.storagemanager.StorageManager;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
import org.osgi.framework.namespace.HostNamespace;
import org.osgi.framework.namespace.NativeNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
public class Storage {
public static class StorageException extends RuntimeException {
private static final long serialVersionUID = 1L;
public StorageException() {
super();
}
public StorageException(String message, Throwable cause) {
super(message, cause);
}
public StorageException(String message) {
super(message);
}
public StorageException(Throwable cause) {
super(cause);
}
}
public static final int VERSION = 5;
private static final int MR_JAR_VERSION = 4;
private static final int CACHED_SYSTEM_CAPS_VERION = 5;
private static final int LOWEST_VERSION_SUPPORTED = 3;
public static final String BUNDLE_DATA_DIR = "data";
public static final String BUNDLE_FILE_NAME = "bundleFile";
public static final String FRAMEWORK_INFO = "framework.info";
public static final String ECLIPSE_SYSTEMBUNDLE = "Eclipse-SystemBundle";
public static final String DELETE_FLAG = ".delete";
public static final String LIB_TEMP = "libtemp";
private static final String JAVASE = "JavaSE";
private static final String PROFILE_EXT = ".profile";
private static final String NUL = new String(new byte[] {0});
private static final String INITIAL_LOCATION = "initial@";
static final SecureAction secureAction = AccessController.doPrivileged(SecureAction.createSecureAction());
private final EquinoxContainer equinoxContainer;
private final String installPath;
private final Location osgiLocation;
private final File childRoot;
private final File parentRoot;
private final PermissionData permissionData;
private final SecurityAdmin securityAdmin;
private final EquinoxContainerAdaptor adaptor;
private final ModuleDatabase moduleDatabase;
private final ModuleContainer moduleContainer;
private final Object saveMonitor = new Object();
private long lastSavedTimestamp = -1;
private final MRUBundleFileList mruList;
private final FrameworkExtensionInstaller extensionInstaller;
private final List<String> = Arrays.asList(Constants.BUNDLE_SYMBOLICNAME, Constants.BUNDLE_ACTIVATIONPOLICY, "Service-Component");
private final boolean allowRestrictedProvides;
private final AtomicBoolean refreshMRBundles = new AtomicBoolean(false);
private final Version runtimeVersion;
private final String javaSpecVersion;
public static Storage createStorage(EquinoxContainer container) throws IOException, BundleException {
String[] cachedInfo = new String[3];
Storage storage = new Storage(container, cachedInfo);
storage.checkSystemBundle(cachedInfo);
storage.refreshStaleBundles();
storage.installExtensions();
storage.getModuleContainer().setInitialModuleStates();
return storage;
}
private Storage(EquinoxContainer container, String[] cachedInfo) throws IOException {
Version javaVersion = Version.valueOf("1.7");
String javaSpecVersionProp = System.getProperty(EquinoxConfiguration.PROP_JVM_SPEC_VERSION);
StringTokenizer st = new StringTokenizer(javaSpecVersionProp, " _-");
javaSpecVersionProp = st.nextToken();
try {
String[] vComps = javaSpecVersionProp.split("\\.");
int major = vComps.length > 0 ? Integer.parseInt(vComps[0]) : 0;
int minor = vComps.length > 1 ? Integer.parseInt(vComps[1]) : 0;
int micro = vComps.length > 2 ? Integer.parseInt(vComps[2]) : 0;
javaVersion = new Version(major, minor, micro);
} catch (IllegalArgumentException e) {
}
runtimeVersion = javaVersion;
javaSpecVersion = javaSpecVersionProp;
mruList = new MRUBundleFileList(getBundleFileLimit(container.getConfiguration()), container.getConfiguration().getDebug());
equinoxContainer = container;
extensionInstaller = new FrameworkExtensionInstaller(container.getConfiguration());
allowRestrictedProvides = Boolean.parseBoolean(container.getConfiguration().getConfiguration(EquinoxConfiguration.PROP_ALLOW_RESTRICTED_PROVIDES));
Location installLoc = container.getLocations().getInstallLocation();
URL installURL = installLoc.getURL();
installPath = installURL.getPath();
Location configLocation = container.getLocations().getConfigurationLocation();
Location parentConfigLocation = configLocation.getParentLocation();
Location osgiParentLocation = null;
if (parentConfigLocation != null) {
osgiParentLocation = parentConfigLocation.createLocation(null, parentConfigLocation.getDataArea(EquinoxContainer.NAME), true);
}
this.osgiLocation = configLocation.createLocation(osgiParentLocation, configLocation.getDataArea(EquinoxContainer.NAME), configLocation.isReadOnly());
this.childRoot = new File(osgiLocation.getURL().getPath());
if (Boolean.valueOf(container.getConfiguration().getConfiguration(EquinoxConfiguration.PROP_CLEAN)).booleanValue()) {
cleanOSGiStorage(osgiLocation, childRoot);
}
if (!this.osgiLocation.isReadOnly()) {
this.childRoot.mkdirs();
}
Location parent = this.osgiLocation.getParentLocation();
parentRoot = parent == null ? null : new File(parent.getURL().getPath());
if (container.getConfiguration().getConfiguration(Constants.FRAMEWORK_STORAGE) == null) {
container.getConfiguration().setConfiguration(Constants.FRAMEWORK_STORAGE, childRoot.getParentFile().getAbsolutePath());
}
InputStream info = getInfoInputStream();
DataInputStream data = info == null ? null : new DataInputStream(new BufferedInputStream(info));
try {
Map<Long, Generation> generations;
try {
generations = loadGenerations(data, cachedInfo);
} catch (IllegalArgumentException e) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.WARNING, "The persistent format for the framework data has changed. The framework will be reinitialized: " + e.getMessage(), null);
generations = new HashMap<>(0);
data = null;
cleanOSGiStorage(osgiLocation, childRoot);
}
this.permissionData = loadPermissionData(data);
this.securityAdmin = new SecurityAdmin(null, this.permissionData);
this.adaptor = new EquinoxContainerAdaptor(equinoxContainer, this, generations);
this.moduleDatabase = new ModuleDatabase(this.adaptor);
this.moduleContainer = new ModuleContainer(this.adaptor, this.moduleDatabase);
if (data != null) {
try {
moduleDatabase.load(data);
lastSavedTimestamp = moduleDatabase.getTimestamp();
} catch (IllegalArgumentException e) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.WARNING, "Incompatible version. Starting with empty framework.", e);
cleanOSGiStorage(osgiLocation, childRoot);
generations.clear();
}
}
} finally {
if (data != null) {
try {
data.close();
} catch (IOException e) {
}
}
}
}
public Version getRuntimeVersion() {
return runtimeVersion;
}
public MRUBundleFileList getMRUBundleFileList() {
return mruList;
}
private int getBundleFileLimit(EquinoxConfiguration configuration) {
int propValue = 100;
try {
String prop = configuration.getConfiguration(EquinoxConfiguration.PROP_FILE_LIMIT);
if (prop != null)
propValue = Integer.parseInt(prop);
} catch (NumberFormatException e) {
}
return propValue;
}
private void installExtensions() {
Module systemModule = moduleContainer.getModule(0);
ModuleRevision systemRevision = systemModule == null ? null : systemModule.getCurrentRevision();
ModuleWiring systemWiring = systemRevision == null ? null : systemRevision.getWiring();
if (systemWiring == null) {
return;
}
Collection<ModuleRevision> fragments = new ArrayList<>();
for (ModuleWire hostWire : systemWiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE)) {
fragments.add(hostWire.getRequirer());
}
try {
getExtensionInstaller().addExtensionContent(fragments, null);
} catch (BundleException e) {
getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, e.getMessage(), e);
}
}
private static PermissionData loadPermissionData(DataInputStream in) throws IOException {
PermissionData permData = new PermissionData();
if (in != null) {
permData.readPermissionData(in);
}
return permData;
}
private void refreshStaleBundles() throws BundleException {
Collection<Module> needsRefresh = new ArrayList<>(0);
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();
}
}
if (refreshMRBundles.get()) {
needsRefresh.addAll(refreshMRJarBundles());
}
if (!needsRefresh.isEmpty()) {
moduleContainer.refresh(needsRefresh);
}
}
private boolean needsDiscarding(Generation generation) {
for (StorageHook<?, ?> hook : generation.getStorageHooks()) {
try {
hook.validate();
} catch (IllegalStateException e) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.WARNING, "Error validating installed bundle.", e);
return true;
}
}
File content = generation.getContent();
if (getConfiguration().inCheckConfigurationMode()) {
if (generation.isDirectory()) {
content = new File(content, "META-INF/MANIFEST.MF");
}
return generation.getLastModified() != secureAction.lastModified(content);
}
if (!content.exists()) {
return true;
}
return false;
}
private void checkSystemBundle(String[] cachedInfo) {
Module systemModule = moduleContainer.getModule(0);
Generation newGeneration = null;
try {
if (systemModule == null) {
BundleInfo info = new BundleInfo(this, 0, Constants.SYSTEM_BUNDLE_LOCATION, 0);
newGeneration = info.createGeneration();
File contentFile = getSystemContent();
newGeneration.setContent(contentFile, false);
loadVMProfile(newGeneration);
String extraCapabilities = getSystemExtraCapabilities();
String extraExports = getSystemExtraPackages();
ModuleRevisionBuilder builder = getBuilder(newGeneration, extraCapabilities, extraExports);
systemModule = moduleContainer.install(null, Constants.SYSTEM_BUNDLE_LOCATION, builder, newGeneration);
moduleContainer.resolve(Collections.singletonList(systemModule), false);
} else {
ModuleRevision currentRevision = systemModule.getCurrentRevision();
Generation currentGeneration = currentRevision == null ? null : (Generation) currentRevision.getRevisionInfo();
if (currentGeneration == null) {
throw new IllegalStateException("No current revision for system bundle.");
}
try {
loadVMProfile(currentGeneration);
String extraCapabilities = getSystemExtraCapabilities();
String extraExports = getSystemExtraPackages();
File contentFile = currentGeneration.getContent();
if (systemNeedsUpdate(contentFile, currentRevision, currentGeneration, extraCapabilities, extraExports, cachedInfo)) {
newGeneration = currentGeneration.getBundleInfo().createGeneration();
newGeneration.setContent(contentFile, false);
ModuleRevisionBuilder newBuilder = getBuilder(newGeneration, extraCapabilities, extraExports);
moduleContainer.update(systemModule, newBuilder, newGeneration);
moduleContainer.refresh(Collections.singleton(systemModule));
} else {
if (currentRevision.getWiring() == null) {
moduleContainer.resolve(Collections.singleton(systemModule), true);
}
}
} catch (BundleException e) {
throw new IllegalStateException("Could not create a builder for the system bundle.", e);
}
}
ModuleRevision currentRevision = systemModule.getCurrentRevision();
List<ModuleCapability> nativeEnvironments = currentRevision.getModuleCapabilities(NativeNamespace.NATIVE_NAMESPACE);
Map<String, Object> configMap = equinoxContainer.getConfiguration().getInitialConfig();
for (ModuleCapability nativeEnvironment : nativeEnvironments) {
nativeEnvironment.setTransientAttrs(configMap);
}
Version frameworkVersion = null;
if (newGeneration != null) {
frameworkVersion = findFrameworkVersion();
} else {
String sVersion = cachedInfo[0];
frameworkVersion = sVersion == null ? findFrameworkVersion() : Version.parseVersion(sVersion);
}
if (frameworkVersion != null) {
this.equinoxContainer.getConfiguration().setConfiguration(Constants.FRAMEWORK_VERSION, frameworkVersion.toString());
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException("Error occurred while checking the system module.", e);
} finally {
if (newGeneration != null) {
newGeneration.getBundleInfo().unlockGeneration(newGeneration);
}
}
}
private Version findFrameworkVersion() {
Requirement osgiPackageReq = ModuleContainer.createRequirement(PackageNamespace.PACKAGE_NAMESPACE, Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)"), Collections.<String, String> emptyMap());
Collection<BundleCapability> osgiPackages = moduleContainer.getFrameworkWiring().findProviders(osgiPackageReq);
for (BundleCapability packageCapability : osgiPackages) {
if (packageCapability.getRevision().getBundle().getBundleId() == 0) {
Version v = (Version) packageCapability.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
if (v != null) {
return v;
}
}
}
return null;
}
private Collection<Module> refreshMRJarBundles() throws BundleException {
Collection<Module> mrJarBundles = new ArrayList<>();
for (Module m : moduleContainer.getModules()) {
Generation generation = (Generation) m.getCurrentRevision().getRevisionInfo();
if (Boolean.parseBoolean(generation.getRawHeaders().get(BundleInfo.MULTI_RELEASE_HEADER))) {
refresh(m);
mrJarBundles.add(m);
}
}
return mrJarBundles;
}
public void close() {
try {
save();
} catch (IOException e) {
getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error saving on shutdown", e);
}
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.shutdownExecutors();
}
private boolean systemNeedsUpdate(File systemContent, ModuleRevision currentRevision, Generation existing, String extraCapabilities, String extraExports, String[] cachedInfo) throws BundleException {
if (!extraCapabilities.equals(cachedInfo[1])) {
return true;
}
if (!extraExports.equals(cachedInfo[2])) {
return true;
}
if (systemContent == null) {
ModuleRevisionBuilder newBuilder = getBuilder(existing, extraCapabilities, extraExports);
return !currentRevision.getVersion().equals(newBuilder.getVersion());
}
if (existing.isDirectory()) {
systemContent = new File(systemContent, "META-INF/MANIFEST.MF");
}
return existing.getLastModified() != secureAction.lastModified(systemContent);
}
private void cleanOSGiStorage(Location location, File root) {
if (location.isReadOnly() || !StorageUtil.rm(root, getConfiguration().getDebug().DEBUG_STORAGE)) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "The -clean (osgi.clean) option was not successful. Unable to clean the storage area: " + root.getAbsolutePath(), null);
}
if (!location.isReadOnly()) {
root.mkdirs();
}
}
public ModuleDatabase getModuleDatabase() {
return moduleDatabase;
}
public ModuleContainerAdaptor getAdaptor() {
return adaptor;
}
public ModuleContainer getModuleContainer() {
return moduleContainer;
}
public EquinoxConfiguration getConfiguration() {
return equinoxContainer.getConfiguration();
}
public EquinoxLogServices getLogServices() {
return equinoxContainer.getLogServices();
}
public FrameworkExtensionInstaller getExtensionInstaller() {
return extensionInstaller;
}
public boolean isReadOnly() {
return osgiLocation.isReadOnly();
}
public URLConnection getContentConnection(Module module, String bundleLocation, final InputStream in) throws IOException {
List<StorageHookFactory<?, ?, ?>> storageHooks = getConfiguration().getHookRegistry().getStorageHookFactories();
for (StorageHookFactory<?, ?, ?> storageHook : storageHooks) {
URLConnection hookContent = storageHook.handleContentConnection(module, bundleLocation, in);
if (hookContent != null) {
return hookContent;
}
}
if (in != null) {
return new URLConnection(null) {
@Override
public void connect() throws IOException {
connected = true;
}
@Override
public InputStream getInputStream() throws IOException {
return (in);
}
};
}
if (module == null) {
if (bundleLocation == null) {
throw new IllegalArgumentException("Module and location cannot be null");
}
return getContentConnection(bundleLocation);
}
return getContentConnection(getUpdateLocation(module));
}
private String getUpdateLocation(final Module module) {
if (System.getSecurityManager() == null)
return getUpdateLocation0(module);
return AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return getUpdateLocation0(module);
}
});
}
String getUpdateLocation0(Module module) {
ModuleRevision current = module.getCurrentRevision();
Generation generation = (Generation) current.getRevisionInfo();
String updateLocation = generation.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
if (updateLocation == null) {
updateLocation = module.getLocation();
}
if (updateLocation.startsWith(INITIAL_LOCATION)) {
updateLocation = updateLocation.substring(INITIAL_LOCATION.length());
}
return updateLocation;
}
private URLConnection getContentConnection(final String spec) throws IOException {
if (System.getSecurityManager() == null) {
return LocationHelper.getConnection(createURL(spec));
}
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<URLConnection>() {
@Override
public URLConnection run() throws IOException {
return LocationHelper.getConnection(createURL(spec));
}
});
} catch (PrivilegedActionException e) {
if (e.getException() instanceof IOException)
throw (IOException) e.getException();
throw (RuntimeException) e.getException();
}
}
URL createURL(String spec) throws MalformedURLException {
if (spec.startsWith(URLStreamHandlerFactoryImpl.PROTOCOL_REFERENCE)) {
return new URL(null, spec, new Handler(equinoxContainer.getConfiguration().getConfiguration(EquinoxLocations.PROP_INSTALL_AREA)));
}
return new URL(spec);
}
public Generation install(Module origin, String bundleLocation, URLConnection content) throws BundleException {
if (osgiLocation.isReadOnly()) {
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) {
throw new BundleException("Error reading bundle content.", e);
}
Module existingLocation = moduleContainer.getModule(bundleLocation);
if (existingLocation != null) {
try {
in.close();
} catch (IOException e) {
}
if (origin != null) {
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);
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())) {
generation.delete();
return (Generation) m.getCurrentRevision().getRevisionInfo();
}
return generation;
} catch (Throwable t) {
if (!isReference) {
try {
delete(staged);
} catch (IOException e) {
}
}
if (generation != null) {
generation.delete();
generation.getBundleInfo().delete();
}
if (t instanceof SecurityException) {
if (t.getCause() instanceof BundleException) {
throw (BundleException) t.getCause();
}
throw (SecurityException) t;
}
if (t instanceof BundleException) {
throw (BundleException) t;
}
throw new BundleException("Error occurred installing a bundle.", t);
} finally {
if (generation != null) {
generation.getBundleInfo().unlockGeneration(generation);
}
}
}
private void setStorageHooks(Generation generation) throws BundleException {
if (generation.getBundleInfo().getBundleId() == 0) {
return;
}
List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<>(getConfiguration().getHookRegistry().getStorageHookFactories());
List<StorageHook<?, ?>> hooks = new ArrayList<>(factories.size());
for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) {
@SuppressWarnings("unchecked")
StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
if (hook != null) {
hooks.add(hook);
}
}
generation.setStorageHooks(Collections.unmodifiableList(hooks), true);
for (StorageHook<?, ?> hook : hooks) {
hook.initialize(generation.getHeaders());
}
}
public ModuleRevisionBuilder getBuilder(Generation generation) throws BundleException {
return getBuilder(generation, null, null);
}
public ModuleRevisionBuilder getBuilder(Generation generation, String extraCapabilities, String extraExports) throws BundleException {
Dictionary<String, String> headers = generation.getHeaders();
Map<String, String> mapHeaders;
if (headers instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, String> unchecked = (Map<String, String>) headers;
mapHeaders = unchecked;
} else {
mapHeaders = new HashMap<>();
for (Enumeration<String> eKeys = headers.keys(); eKeys.hasMoreElements();) {
String key = eKeys.nextElement();
mapHeaders.put(key, headers.get(key));
}
}
if (generation.getBundleInfo().getBundleId() != 0) {
ModuleRevisionBuilder builder = allowRestrictedProvides ? OSGiManifestBuilderFactory.createBuilder(mapHeaders, null, null, "") : OSGiManifestBuilderFactory.createBuilder(mapHeaders);
if ((builder.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
for (ModuleRevisionBuilder.GenericInfo reqInfo : builder.getRequirements()) {
if (HostNamespace.HOST_NAMESPACE.equals(reqInfo.getNamespace())) {
if (HostNamespace.EXTENSION_BOOTCLASSPATH.equals(reqInfo.getDirectives().get(HostNamespace.REQUIREMENT_EXTENSION_DIRECTIVE))) {
throw new BundleException("Boot classpath extensions are not supported.", BundleException.UNSUPPORTED_OPERATION, new UnsupportedOperationException());
}
}
}
}
return builder;
}
return OSGiManifestBuilderFactory.createBuilder(mapHeaders, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, extraExports, extraCapabilities);
}
private String () {
EquinoxConfiguration equinoxConfig = equinoxContainer.getConfiguration();
StringBuilder result = new StringBuilder();
String systemCapabilities = equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMCAPABILITIES);
if (systemCapabilities != null && systemCapabilities.trim().length() > 0) {
result.append(systemCapabilities).append(", ");
}
String extraSystemCapabilities = equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA);
if (extraSystemCapabilities != null && extraSystemCapabilities.trim().length() > 0) {
result.append(extraSystemCapabilities).append(", ");
}
result.append(EclipsePlatformNamespace.ECLIPSE_PLATFORM_NAMESPACE).append("; ");
result.append(EquinoxConfiguration.PROP_OSGI_OS).append("=").append(equinoxConfig.getOS()).append("; ");
result.append(EquinoxConfiguration.PROP_OSGI_WS).append("=").append(equinoxConfig.getWS()).append("; ");
result.append(EquinoxConfiguration.PROP_OSGI_ARCH).append("=").append(equinoxConfig.getOSArch()).append("; ");
result.append(EquinoxConfiguration.PROP_OSGI_NL).append("=").append(equinoxConfig.getNL());
String osName = equinoxConfig.getConfiguration(Constants.FRAMEWORK_OS_NAME);
osName = osName == null ? null : osName.toLowerCase();
String processor = equinoxConfig.getConfiguration(Constants.FRAMEWORK_PROCESSOR);
processor = processor == null ? null : processor.toLowerCase();
String osVersion = equinoxConfig.getConfiguration(Constants.FRAMEWORK_OS_VERSION);
osVersion = osVersion == null ? null : osVersion.toLowerCase();
String language = equinoxConfig.getConfiguration(Constants.FRAMEWORK_LANGUAGE);
language = language == null ? null : language.toLowerCase();
result.append(", ");
result.append(NativeNamespace.NATIVE_NAMESPACE).append("; ");
if (osName != null) {
osName = getAliasList(equinoxConfig.getAliasMapper().getOSNameAliases(osName));
result.append(NativeNamespace.CAPABILITY_OSNAME_ATTRIBUTE).append(":List<String>=").append(osName).append("; ");
}
if (processor != null) {
processor = getAliasList(equinoxConfig.getAliasMapper().getProcessorAliases(processor));
result.append(NativeNamespace.CAPABILITY_PROCESSOR_ATTRIBUTE).append(":List<String>=").append(processor).append("; ");
}
result.append(NativeNamespace.CAPABILITY_OSVERSION_ATTRIBUTE).append(":Version").append("=\"").append(osVersion).append("\"; ");
result.append(NativeNamespace.CAPABILITY_LANGUAGE_ATTRIBUTE).append("=\"").append(language).append('\"');
return result.toString();
}
String getAliasList(Collection<String> aliases) {
if (aliases.isEmpty()) {
return null;
}
StringBuilder builder = new StringBuilder();
builder.append('"');
for (String alias : aliases) {
builder.append(alias).append(',');
}
builder.setLength(builder.length() - 1);
builder.append('"');
return builder.toString();
}
private String () {
EquinoxConfiguration equinoxConfig = equinoxContainer.getConfiguration();
StringBuilder result = new StringBuilder();
String systemPackages = equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMPACKAGES);
if (systemPackages != null) {
result.append(systemPackages);
}
String extraSystemPackages = equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
if (extraSystemPackages != null && extraSystemPackages.trim().length() > 0) {
if (result.length() > 0) {
result.append(", ");
}
result.append(extraSystemPackages);
}
return result.toString();
}
private void refresh(Module module) throws BundleException {
ModuleRevision current = module.getCurrentRevision();
Generation currentGen = (Generation) current.getRevisionInfo();
File content = currentGen.getContent();
String spec = (currentGen.isReference() ? "reference:" : "") + content.toURI().toString();
URLConnection contentConn;
try {
contentConn = getContentConnection(spec);
} catch (IOException e) {
throw new BundleException("Error reading bundle content.", e);
}
update(module, contentConn);
}
public Generation update(Module module, URLConnection content) throws BundleException {
if (osgiLocation.isReadOnly()) {
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) {
throw new BundleException("Error reading bundle content.", e);
}
boolean isReference = in instanceof ReferenceInputStream;
File staged = stageContent(in, sourceURL);
ModuleRevision current = module.getCurrentRevision();
Generation currentGen = (Generation) current.getRevisionInfo();
BundleInfo bundleInfo = currentGen.getBundleInfo();
Generation newGen = bundleInfo.createGeneration();
try {
File contentFile = getContentFile(staged, isReference, bundleInfo.getBundleId(), newGen.getGenerationId());
newGen.setContent(contentFile, isReference);
newGen.getBundleFile().open();
setStorageHooks(newGen);
ModuleRevisionBuilder builder = getBuilder(newGen);
moduleContainer.update(module, builder, newGen);
} catch (Throwable t) {
if (!isReference) {
try {
delete(staged);
} catch (IOException e) {
}
}
newGen.delete();
if (t instanceof SecurityException) {
if (t.getCause() instanceof BundleException) {
throw (BundleException) t.getCause();
}
throw (SecurityException) t;
}
if (t instanceof BundleException) {
throw (BundleException) t;
}
throw new BundleException("Error occurred updating a bundle.", t);
} finally {
bundleInfo.unlockGeneration(newGen);
}
return newGen;
}
private File getContentFile(final File staged, final boolean isReference, final long bundleID, final long generationID) throws BundleException {
if (System.getSecurityManager() == null)
return getContentFile0(staged, isReference, bundleID, generationID);
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {
@Override
public File run() throws BundleException {
return getContentFile0(staged, isReference, bundleID, generationID);
}
});
} catch (PrivilegedActionException e) {
if (e.getException() instanceof BundleException)
throw (BundleException) e.getException();
throw (RuntimeException) e.getException();
}
}
File getContentFile0(File staged, boolean isReference, long bundleID, long generationID) throws BundleException {
File contentFile;
if (!isReference) {
File generationRoot = new File(childRoot, bundleID + "/" + generationID);
generationRoot.mkdirs();
if (!generationRoot.isDirectory()) {
throw new BundleException("Could not create generation directory: " + generationRoot.getAbsolutePath());
}
contentFile = new File(generationRoot, BUNDLE_FILE_NAME);
if (!StorageUtil.move(staged, contentFile, getConfiguration().getDebug().DEBUG_STORAGE)) {
throw new BundleException("Error while renaming bundle file to final location: " + contentFile);
}
} else {
contentFile = staged;
}
return contentFile;
}
private static String getBundleFilePath(long bundleID, long generationID) {
return bundleID + "/" + generationID + "/" + BUNDLE_FILE_NAME;
}
public File getFile(String path, boolean checkParent) throws StorageException {
return getFile(null, path, checkParent);
}
public File getFile(String base, String path, boolean checkParent) throws StorageException {
File childPath = getFile(childRoot, base, path);
if (checkParent && parentRoot != null) {
if (childPath.exists()) {
return childPath;
}
File parentPath = getFile(parentRoot, base, path);
if (parentPath.exists()) {
return parentPath;
}
}
return childPath;
}
private static File getFile(File root, String base, String path) {
if (base == null) {
return new File(root, path);
}
root = new File(root, base);
File result = new File(root, path);
try {
String resultCanonical = result.getCanonicalPath();
String rootCanonical = root.getCanonicalPath();
if (!resultCanonical.startsWith(rootCanonical + File.separator) && !resultCanonical.equals(rootCanonical)) {
throw new StorageException("Invalid path: " + path);
}
} catch (IOException e) {
throw new StorageException("Invalid path: " + path, e);
}
return result;
}
private File stageContent(final InputStream in, final URL sourceURL) throws BundleException {
if (System.getSecurityManager() == null)
return stageContent0(in, sourceURL);
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {
@Override
public File run() throws BundleException {
return stageContent0(in, sourceURL);
}
});
} catch (PrivilegedActionException e) {
if (e.getException() instanceof BundleException)
throw (BundleException) e.getException();
throw (RuntimeException) e.getException();
}
}
File stageContent0(InputStream in, URL sourceURL) throws BundleException {
File outFile = null;
try {
if (in instanceof ReferenceInputStream) {
return ((ReferenceInputStream) in).getReference();
}
outFile = File.createTempFile(BUNDLE_FILE_NAME, ".tmp", childRoot);
String protocol = sourceURL == null ? null : sourceURL.getProtocol();
if ("file".equals(protocol)) {
File inFile = new File(sourceURL.getPath());
inFile = LocationHelper.decodePath(inFile);
if (inFile.isDirectory()) {
outFile.delete();
StorageUtil.copyDir(inFile, outFile);
} else {
StorageUtil.readFile(in, outFile);
}
} else {
StorageUtil.readFile(in, outFile);
}
return outFile;
} catch (IOException e) {
if (outFile != null) {
outFile.delete();
}
throw new BundleException(Msg.BUNDLE_READ_EXCEPTION, BundleException.READ_ERROR, e);
}
}
public void setPermissions(File file) {
String commandProp = getConfiguration().getConfiguration(EquinoxConfiguration.PROP_SETPERMS_CMD);
if (commandProp == null)
commandProp = getConfiguration().getConfiguration(Constants.FRAMEWORK_EXECPERMISSION);
if (commandProp == null)
return;
String[] commandComponents = ManifestElement.getArrayFromList(commandProp, " ");
List<String> command = new ArrayList<>(commandComponents.length + 1);
boolean foundFullPath = false;
for (String commandComponent : commandComponents) {
if ("[fullpath]".equals(commandComponent) || "${abspath}".equals(commandComponent)) {
command.add(file.getAbsolutePath());
foundFullPath = true;
} else {
command.add(commandComponent);
}
}
if (!foundFullPath)
command.add(file.getAbsolutePath());
try {
Runtime.getRuntime().exec(command.toArray(new String[command.size()])).waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
public BundleFile createBundleFile(File content, Generation generation, boolean isDirectory, boolean isBase) {
BundleFile result;
try {
if (isDirectory) {
boolean strictPath = Boolean.parseBoolean(equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROPERTY_STRICT_BUNDLE_ENTRY_PATH, Boolean.FALSE.toString()));
result = new DirBundleFile(content, strictPath);
} else {
result = new ZipBundleFile(content, generation, mruList, getConfiguration().getDebug());
}
} catch (IOException e) {
throw new RuntimeException("Could not create bundle file.", e);
}
return wrapBundleFile(result, generation, isBase);
}
public BundleFile createNestedBundleFile(String nestedDir, BundleFile bundleFile, Generation generation) {
return createNestedBundleFile(nestedDir, bundleFile, generation, Collections.<String> emptyList());
}
public BundleFile createNestedBundleFile(String nestedDir, BundleFile bundleFile, Generation generation, Collection<String> filterPrefixes) {
return wrapBundleFile(new NestedDirBundleFile(bundleFile, nestedDir, filterPrefixes), generation, false);
}
public BundleFile wrapBundleFile(BundleFile bundleFile, Generation generation, boolean isBase) {
List<BundleFileWrapperFactoryHook> wrapperFactories = getConfiguration().getHookRegistry().getBundleFileWrapperFactoryHooks();
BundleFileWrapperChain wrapped = wrapperFactories.isEmpty() ? null : new BundleFileWrapperChain(bundleFile, null);
for (BundleFileWrapperFactoryHook wrapperFactory : wrapperFactories) {
BundleFileWrapper wrapperBundle = wrapperFactory.wrapBundleFile(bundleFile, generation, isBase);
if (wrapperBundle != null && wrapperBundle != bundleFile)
bundleFile = wrapped = new BundleFileWrapperChain(wrapperBundle, wrapped);
}
return bundleFile;
}
public void compact() {
if (!osgiLocation.isReadOnly()) {
compact(childRoot);
}
}
private void compact(File directory) {
if (getConfiguration().getDebug().DEBUG_STORAGE)
Debug.println("compact(" + directory.getPath() + ")");
String list[] = directory.list();
if (list == null)
return;
int len = list.length;
for (int i = 0; i < len; i++) {
if (BUNDLE_DATA_DIR.equals(list[i]))
continue;
File target = new File(directory, list[i]);
if (!target.isDirectory())
continue;
File delete = new File(target, DELETE_FLAG);
if (delete.exists()) {
if (!StorageUtil.rm(target, getConfiguration().getDebug().DEBUG_STORAGE) && !delete.exists()) {
try {
FileOutputStream out = new FileOutputStream(delete);
out.close();
} catch (IOException e) {
if (getConfiguration().getDebug().DEBUG_STORAGE)
Debug.println("Unable to write " + delete.getPath() + ": " + e.getMessage());
}
}
} else {
compact(target);
}
}
}
void delete(final File delete) throws IOException {
if (System.getSecurityManager() == null) {
delete0(delete);
} else {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws IOException {
delete0(delete);
return null;
}
});
} catch (PrivilegedActionException e) {
if (e.getException() instanceof IOException)
throw (IOException) e.getException();
throw (RuntimeException) e.getException();
}
}
}
void delete0(File delete) throws IOException {
if (!StorageUtil.rm(delete, getConfiguration().getDebug().DEBUG_STORAGE)) {
FileOutputStream out = new FileOutputStream(new File(delete, DELETE_FLAG));
out.close();
}
}
public void save() throws IOException {
if (isReadOnly()) {
return;
}
if (System.getSecurityManager() == null) {
save0();
} else {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws IOException {
save0();
return null;
}
});
} catch (PrivilegedActionException e) {
if (e.getException() instanceof IOException)
throw (IOException) e.getException();
throw (RuntimeException) e.getException();
}
}
}
void save0() throws IOException {
StorageManager childStorageManager = null;
ManagedOutputStream mos = null;
DataOutputStream out = null;
boolean success = false;
moduleDatabase.readLock();
try {
synchronized (this.saveMonitor) {
if (lastSavedTimestamp == moduleDatabase.getTimestamp())
return;
childStorageManager = getChildStorageManager();
mos = childStorageManager.getOutputStream(FRAMEWORK_INFO);
out = new DataOutputStream(new BufferedOutputStream(mos));
saveGenerations(out);
savePermissionData(out);
moduleDatabase.store(out, true);
lastSavedTimestamp = moduleDatabase.getTimestamp();
success = true;
}
} finally {
if (!success) {
if (mos != null) {
mos.abort();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (childStorageManager != null) {
childStorageManager.close();
}
moduleDatabase.readUnlock();
}
}
private void savePermissionData(DataOutputStream out) throws IOException {
permissionData.savePermissionData(out);
}
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());
Version curFrameworkVersion = findFrameworkVersion();
out.writeUTF(curFrameworkVersion == null ? Version.emptyVersion.toString() : curFrameworkVersion.toString());
saveLongString(out, getSystemExtraCapabilities());
saveLongString(out, getSystemExtraPackages());
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) {
out.writeUTF("");
} else {
if (generation.isReference()) {
out.writeUTF(new FilePath(installPath).makeRelative(new FilePath(generation.getContent().getAbsolutePath())));
} else {
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);
}
private void saveLongString(DataOutputStream out, String value) throws IOException {
if (value == null) {
out.writeInt(0);
} else {
byte[] data = value.getBytes("UTF-8");
out.writeInt(data.length);
out.write(data);
}
}
private String readLongString(DataInputStream in) throws IOException {
int length = in.readInt();
byte[] data = new byte[length];
in.readFully(data);
return new String(data, "UTF-8");
}
private void saveStorageHookData(DataOutputStream out, List<Generation> generations) throws IOException {
List<StorageHookFactory<?, ?, ?>> factories = getConfiguration().getHookRegistry().getStorageHookFactories();
out.writeInt(factories.size());
for (StorageHookFactory<?, ?, ?> factory : factories) {
out.writeUTF(factory.getKey());
out.writeInt(factory.getStorageVersion());
ByteArrayOutputStream tempBytes = new ByteArrayOutputStream();
DataOutputStream temp = new DataOutputStream(tempBytes);
try {
Object saveContext = factory.createSaveContext();
for (Generation generation : generations) {
if (generation.getBundleInfo().getBundleId() == 0) {
continue;
}
@SuppressWarnings({"rawtypes", "unchecked"})
StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass());
if (hook != null) {
hook.save(saveContext, temp);
}
}
} finally {
temp.close();
}
out.writeInt(tempBytes.size());
out.write(tempBytes.toByteArray());
}
}
private Map<Long, Generation> loadGenerations(DataInputStream in, String[] cachedInfo) throws IOException {
if (in == null) {
return new HashMap<>(0);
}
int version = in.readInt();
if (version > VERSION || version < LOWEST_VERSION_SUPPORTED) {
throw new IllegalArgumentException("Found persistent version \"" + version + "\" expecting \"" + VERSION + "\"");
}
Version savedRuntimeVersion = (version >= MR_JAR_VERSION) ? Version.parseVersion(in.readUTF()) : null;
if (savedRuntimeVersion == null || !savedRuntimeVersion.equals(runtimeVersion)) {
refreshMRBundles.set(true);
}
cachedInfo[0] = (version >= CACHED_SYSTEM_CAPS_VERION) ? in.readUTF() : null;
cachedInfo[1] = (version >= CACHED_SYSTEM_CAPS_VERION) ? readLongString(in) : null;
cachedInfo[2] = (version >= CACHED_SYSTEM_CAPS_VERION) ? readLongString(in) : null;
int numCachedHeaders = in.readInt();
List<String> storedCachedHeaderKeys = new ArrayList<>(numCachedHeaders);
for (int i = 0; i < numCachedHeaders; i++) {
storedCachedHeaderKeys.add(ObjectPool.intern(in.readUTF()));
}
int numInfos = in.readInt();
Map<Long, Generation> result = new HashMap<>(numInfos);
List<Generation> generations = new ArrayList<>(numInfos);
for (int i = 0; i < numInfos; i++) {
long infoId = in.readLong();
String infoLocation = ObjectPool.intern(in.readUTF());
long nextGenId = in.readLong();
long generationId = in.readLong();
boolean isDirectory = in.readBoolean();
boolean isReference = in.readBoolean();
boolean hasPackageInfo = in.readBoolean();
String contentPath = in.readUTF();
long lastModified = in.readLong();
Map<String, String> cachedHeaders = new HashMap<>(storedCachedHeaderKeys.size());
for (String headerKey : storedCachedHeaderKeys) {
String value = in.readUTF();
if (NUL.equals(value)) {
value = null;
} else {
value = ObjectPool.intern(value);
}
cachedHeaders.put(headerKey, value);
}
boolean isMRJar = (version >= MR_JAR_VERSION) ? in.readBoolean() : false;
File content;
if (infoId == 0) {
content = getSystemContent();
isDirectory = content != null ? content.isDirectory() : false;
} else {
content = new File(contentPath);
if (!content.isAbsolute()) {
if (isReference) {
content = new File(installPath, contentPath);
} else {
content = getFile(contentPath, true);
}
}
}
BundleInfo info = new BundleInfo(this, infoId, infoLocation, nextGenId);
Generation generation = info.restoreGeneration(generationId, content, isDirectory, isReference, hasPackageInfo, cachedHeaders, lastModified, isMRJar);
result.put(infoId, generation);
generations.add(generation);
}
loadStorageHookData(generations, in);
return result;
}
private void loadStorageHookData(List<Generation> generations, DataInputStream in) throws IOException {
List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<>(getConfiguration().getHookRegistry().getStorageHookFactories());
Map<Generation, List<StorageHook<?, ?>>> hookMap = new HashMap<>();
int numFactories = in.readInt();
for (int i = 0; i < numFactories; i++) {
String factoryName = in.readUTF();
int version = in.readInt();
StorageHookFactory<Object, Object, StorageHook<Object, Object>> factory = null;
for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) {
@SuppressWarnings("unchecked")
StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
if (next.getKey().equals(factoryName)) {
factory = next;
iFactories.remove();
break;
}
}
int dataSize = in.readInt();
byte[] bytes = new byte[dataSize];
in.readFully(bytes);
if (factory != null) {
DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes));
try {
if (factory.isCompatibleWith(version)) {
Object loadContext = factory.createLoadContext(version);
for (Generation generation : generations) {
if (generation.getBundleInfo().getBundleId() == 0) {
continue;
}
StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
if (hook != null) {
hook.load(loadContext, temp);
getHooks(hookMap, generation).add(hook);
}
}
} else {
for (Generation generation : generations) {
if (generation.getBundleInfo().getBundleId() == 0) {
continue;
}
StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
if (hook != null) {
hook.initialize(generation.getHeaders());
getHooks(hookMap, generation).add(hook);
}
}
}
} catch (BundleException e) {
throw new IOException(e);
} finally {
temp.close();
}
}
}
for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) {
@SuppressWarnings("unchecked")
StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
for (Generation generation : generations) {
if (generation.getBundleInfo().getBundleId() == 0) {
continue;
}
StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
if (hook != null) {
try {
hook.initialize(generation.getHeaders());
getHooks(hookMap, generation).add(hook);
} catch (BundleException e) {
throw new IOException(e);
}
}
}
}
for (Generation generation : generations) {
generation.setStorageHooks(Collections.unmodifiableList(getHooks(hookMap, generation)), false);
}
}
private static List<StorageHook<?, ?>> getHooks(Map<Generation, List<StorageHook<?, ?>>> hookMap, Generation generation) {
List<StorageHook<?, ?>> result = hookMap.get(generation);
if (result == null) {
result = new ArrayList<>();
hookMap.put(generation, result);
}
return result;
}
private File getSystemContent() {
String frameworkValue = equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROP_FRAMEWORK);
if (frameworkValue == null || !frameworkValue.startsWith("file:")) {
return null;
}
File result = new File(frameworkValue.substring(5)).getAbsoluteFile();
if (!result.exists()) {
throw new IllegalStateException("Configured framework location does not exist: " + result.getAbsolutePath());
}
return result;
}
@SuppressWarnings("deprecation")
private void loadVMProfile(Generation systemGeneration) {
EquinoxConfiguration equinoxConfig = equinoxContainer.getConfiguration();
Properties profileProps = findVMProfile(systemGeneration);
String systemExports = equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMPACKAGES);
if (systemExports == null) {
systemExports = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
if (systemExports != null)
equinoxConfig.setConfiguration(Constants.FRAMEWORK_SYSTEMPACKAGES, systemExports);
}
String type = equinoxConfig.getConfiguration(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE_BOOTDELEGATION);
String profileBootDelegation = profileProps.getProperty(Constants.FRAMEWORK_BOOTDELEGATION);
if (EquinoxConfiguration.PROP_OSGI_BOOTDELEGATION_OVERRIDE.equals(type)) {
if (profileBootDelegation == null)
equinoxConfig.clearConfiguration(Constants.FRAMEWORK_BOOTDELEGATION);
else
equinoxConfig.setConfiguration(Constants.FRAMEWORK_BOOTDELEGATION, profileBootDelegation);
} else if (EquinoxConfiguration.PROP_OSGI_BOOTDELEGATION_NONE.equals(type))
equinoxConfig.clearConfiguration(Constants.FRAMEWORK_BOOTDELEGATION);
if (equinoxConfig.getConfiguration(Constants.FRAMEWORK_EXECUTIONENVIRONMENT) == null) {
String ee = profileProps.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, profileProps.getProperty(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE_NAME));
if (ee != null)
equinoxConfig.setConfiguration(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee);
}
if (equinoxConfig.getConfiguration(Constants.FRAMEWORK_SYSTEMCAPABILITIES) == null) {
String systemCapabilities = profileProps.getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES);
if (systemCapabilities != null)
equinoxConfig.setConfiguration(Constants.FRAMEWORK_SYSTEMCAPABILITIES, systemCapabilities);
}
}
private Properties findVMProfile(Generation systemGeneration) {
Properties result = readConfiguredJavaProfile(systemGeneration);
String vmProfile = null;
try {
if (result != null) {
return result;
}
if (Version.valueOf("9").compareTo(runtimeVersion) <= 0) {
result = calculateVMProfile(runtimeVersion);
if (result != null) {
return result;
}
}
String embeddedProfileName = "-";
if (runtimeVersion != null && Version.valueOf("1.8").compareTo(runtimeVersion) <= 0) {
String javaHome = System.getProperty("java.home");
if (javaHome != null) {
File release = new File(javaHome, "release");
if (release.exists()) {
Properties releaseProps = new Properties();
try (InputStream releaseStream = new FileInputStream(release)) {
releaseProps.load(releaseStream);
String releaseName = releaseProps.getProperty("JAVA_PROFILE");
if (releaseName != null) {
releaseName = releaseName.replaceAll("^\\s*\"?|\"?\\s*$", "");
embeddedProfileName = "_" + releaseName + "-";
}
} catch (IOException e) {
}
}
}
}
result = new Properties();
vmProfile = JAVASE + embeddedProfileName + javaSpecVersion;
InputStream profileIn = null;
if (vmProfile != null) {
String javaProfile = vmProfile + PROFILE_EXT;
profileIn = findInSystemBundle(systemGeneration, javaProfile);
if (profileIn == null)
profileIn = getNextBestProfile(systemGeneration, JAVASE, runtimeVersion, embeddedProfileName);
}
if (profileIn == null)
profileIn = findInSystemBundle(systemGeneration, "JavaSE-1.7.profile");
if (profileIn != null) {
try {
result.load(new BufferedInputStream(profileIn));
} catch (IOException e) {
} finally {
try {
profileIn.close();
} catch (IOException ee) {
}
}
}
} finally {
if (result != null && result.getProperty(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE_NAME) == null) {
if (vmProfile != null) {
result.put(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE_NAME, vmProfile.replace('_', '/'));
} else {
result.put(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE_NAME, "JavaSE-1.7");
}
}
}
return result;
}
private Properties readConfiguredJavaProfile(Generation systemGeneration) {
String propJavaProfile = equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROP_OSGI_JAVA_PROFILE);
if (propJavaProfile != null) {
InputStream profileIn = null;
try {
profileIn = new URL(propJavaProfile).openStream();
} catch (IOException e) {
profileIn = findInSystemBundle(systemGeneration, propJavaProfile);
}
if (profileIn != null) {
Properties result = new Properties();
try {
result.load(new BufferedInputStream(profileIn));
} catch (IOException e) {
} finally {
try {
profileIn.close();
} catch (IOException e) {
}
}
return result;
}
}
return null;
}
@SuppressWarnings("deprecation")
private Properties calculateVMProfile(Version javaVersion) {
String systemPackages = calculateVMPackages();
if (systemPackages == null) {
return null;
}
String executionEnvs = calculateVMExecutionEnvs(javaVersion);
String eeCapabilities = calculateEECapabilities(javaVersion);
Properties result = new Properties();
result.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages);
result.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, executionEnvs);
result.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES, eeCapabilities);
return result;
}
private String calculateVMExecutionEnvs(Version javaVersion) {
StringBuilder result = new StringBuilder("OSGi/Minimum-1.0, OSGi/Minimum-1.1, OSGi/Minimum-1.2, JavaSE/compact1-1.8, JavaSE/compact2-1.8, JavaSE/compact3-1.8, JRE-1.1, J2SE-1.2, J2SE-1.3, J2SE-1.4, J2SE-1.5, JavaSE-1.6, JavaSE-1.7, JavaSE-1.8");
Version v = new Version(9, 0, 0);
while (v.compareTo(javaVersion) <= 0) {
result.append(',').append(' ').append(JAVASE).append('-').append(v.getMajor());
if (v.getMinor() > 0) {
result.append('.').append(v.getMinor());
}
if (v.getMajor() == javaVersion.getMajor()) {
v = new Version(v.getMajor(), v.getMinor() + 1, 0);
} else {
v = new Version(v.getMajor() + 1, 0, 0);
}
}
return result.toString();
}
private String calculateEECapabilities(Version javaVersion) {
Version v = new Version(9, 0, 0);
StringBuilder versionsBulder = new StringBuilder();
while (v.compareTo(javaVersion) <= 0) {
versionsBulder.append(',').append(' ').append(v.getMajor()).append('.').append(v.getMinor());
if (v.getMajor() == javaVersion.getMajor()) {
v = new Version(v.getMajor(), v.getMinor() + 1, 0);
} else {
v = new Version(v.getMajor() + 1, 0, 0);
}
}
String versionsList = versionsBulder.toString();
StringBuilder result = new StringBuilder("osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0, 1.1, 1.2\", osgi.ee; osgi.ee=\"JRE\"; version:List<Version>=\"1.0, 1.1\", osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8");
result.append(versionsList).append("\"");
result.append(",osgi.ee; osgi.ee=\"JavaSE/compact1\"; version:List<Version>=\"1.8");
result.append(versionsList).append("\"");
result.append(",osgi.ee; osgi.ee=\"JavaSE/compact2\"; version:List<Version>=\"1.8");
result.append(versionsList).append("\"");
result.append(",osgi.ee; osgi.ee=\"JavaSE/compact3\"; version:List<Version>=\"1.8");
result.append(versionsList).append("\"");
return result.toString();
}
@SuppressWarnings("unchecked")
private String calculateVMPackages() {
try {
List<String> packages = new ArrayList<>();
Class<?> moduleLayerClass = Class.forName("java.lang.ModuleLayer");
Method boot = moduleLayerClass.getMethod("boot");
Method modules = moduleLayerClass.getMethod("modules");
Class<?> moduleClass = Class.forName("java.lang.Module");
Method getDescriptor = moduleClass.getMethod("getDescriptor");
Class<?> moduleDescriptorClass = Class.forName("java.lang.module.ModuleDescriptor");
Method exports = moduleDescriptorClass.getMethod("exports");
Method isAutomatic = moduleDescriptorClass.getMethod("isAutomatic");
Method packagesMethod = moduleDescriptorClass.getMethod("packages");
Class<?> exportsClass = Class.forName("java.lang.module.ModuleDescriptor$Exports");
Method isQualified = exportsClass.getMethod("isQualified");
Method source = exportsClass.getMethod("source");
Object bootLayer = boot.invoke(null);
Set<?> bootModules = (Set<?>) modules.invoke(bootLayer);
for (Object m : bootModules) {
Object descriptor = getDescriptor.invoke(m);
if ((Boolean) isAutomatic.invoke(descriptor)) {
packages.addAll((Set<String>) packagesMethod.invoke(descriptor));
} else {
for (Object export : (Set<?>) exports.invoke(descriptor)) {
String pkg = (String) source.invoke(export);
if (!((Boolean) isQualified.invoke(export))) {
packages.add(pkg);
}
}
}
}
Collections.sort(packages);
StringBuilder result = new StringBuilder();
for (String pkg : packages) {
if (result.length() != 0) {
result.append(',').append(' ');
}
result.append(pkg);
}
return result.toString();
} catch (Exception e) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error determining system packages.", e);
return null;
}
}
private InputStream getNextBestProfile(Generation systemGeneration, String javaEdition, Version javaVersion, String embeddedProfileName) {
if (javaVersion == null || javaEdition != JAVASE)
return null;
InputStream bestProfile = findNextBestProfile(systemGeneration, javaEdition, javaVersion, embeddedProfileName);
if (bestProfile == null && !"-".equals(embeddedProfileName)) {
return getNextBestProfile(systemGeneration, javaEdition, javaVersion, "-");
}
return bestProfile;
}
private InputStream findNextBestProfile(Generation systemGeneration, String javaEdition, Version javaVersion, String embeddedProfileName) {
InputStream result = null;
int major = javaVersion.getMajor();
int minor = javaVersion.getMinor();
do {
String profileResourceName = javaEdition + embeddedProfileName + major + ((minor > 0) ? "." + minor : "") + PROFILE_EXT;
result = findInSystemBundle(systemGeneration, profileResourceName);
if (minor > 0) {
minor -= 1;
} else if (major > 9) {
major -= 1;
} else if (major <= 9 && major > 1) {
minor = 8;
major = 1;
} else {
return result;
}
} while (result == null && minor >= 0);
return result;
}
private InputStream findInSystemBundle(Generation systemGeneration, String entry) {
BundleFile systemContent = systemGeneration.getBundleFile();
BundleEntry systemEntry = systemContent != null ? systemContent.getEntry(entry) : null;
InputStream result = null;
if (systemEntry != null) {
try {
result = systemEntry.getInputStream();
} catch (IOException e) {
}
}
if (result == null) {
ClassLoader loader = getClass().getClassLoader();
result = loader == null ? ClassLoader.getSystemResourceAsStream(entry) : loader.getResourceAsStream(entry);
}
return result;
}
public static Enumeration<URL> findEntries(List<Generation> generations, String path, String filePattern, int options) {
List<BundleFile> bundleFiles = new ArrayList<>(generations.size());
for (Generation generation : generations)
bundleFiles.add(generation.getBundleFile());
List<String> pathList = listEntryPaths(bundleFiles, path, filePattern, options);
if (pathList.size() == 0)
return null;
final String[] pathArray = pathList.toArray(new String[pathList.size()]);
final Generation[] generationArray = generations.toArray(new Generation[generations.size()]);
return new Enumeration<URL>() {
private int curPathIndex = 0;
private int curDataIndex = 0;
private URL nextElement = null;
@Override
public boolean hasMoreElements() {
if (nextElement != null)
return true;
getNextElement();
return nextElement != null;
}
@Override
public URL nextElement() {
if (!hasMoreElements())
throw new NoSuchElementException();
URL result = nextElement;
getNextElement();
return result;
}
private void getNextElement() {
nextElement = null;
if (curPathIndex >= pathArray.length)
return;
while (nextElement == null && curPathIndex < pathArray.length) {
String curPath = pathArray[curPathIndex];
while (nextElement == null && curDataIndex < generationArray.length)
nextElement = generationArray[curDataIndex++].getEntry(curPath);
if (curDataIndex >= generationArray.length) {
curPathIndex++;
curDataIndex = 0;
}
}
}
};
}
public static List<String> listEntryPaths(List<BundleFile> bundleFiles, String path, String filePattern, int options) {
LinkedHashSet<String> pathList = new LinkedHashSet<>();
Filter patternFilter = null;
Hashtable<String, String> patternProps = null;
if (filePattern != null) {
if ((options & BundleWiring.FINDENTRIES_RECURSE) == 0 && filePattern.indexOf('*') == -1 && filePattern.indexOf('\\') == -1) {
if (path.length() == 0)
path = filePattern;
else
path += path.charAt(path.length() - 1) == '/' ? filePattern : '/' + filePattern;
for (BundleFile bundleFile : bundleFiles) {
if (bundleFile.getEntry(path) != null && !pathList.contains(path))
pathList.add(path);
}
return new ArrayList<>(pathList);
}
try {
patternFilter = FilterImpl.newInstance("(filename=" + sanitizeFilterInput(filePattern) + ")");
patternProps = new Hashtable<>(2);
} catch (InvalidSyntaxException e) {
return new ArrayList<>(pathList);
}
}
for (BundleFile bundleFile : bundleFiles) {
listEntryPaths(bundleFile, path, patternFilter, patternProps, options, pathList);
}
return new ArrayList<>(pathList);
}
public static String sanitizeFilterInput(String filePattern) throws InvalidSyntaxException {
StringBuilder buffer = null;
boolean foundEscape = false;
for (int i = 0; i < filePattern.length(); i++) {
char c = filePattern.charAt(i);
switch (c) {
case '\\' :
foundEscape = foundEscape ? false : true;
if (buffer != null)
buffer.append(c);
break;
case '(' :
case ')' :
if (!foundEscape) {
if (buffer == null) {
buffer = new StringBuilder(filePattern.length() + 16);
buffer.append(filePattern.substring(0, i));
}
buffer.append('\\');
} else {
foundEscape = false;
}
if (buffer != null)
buffer.append(c);
break;
default :
foundEscape = false;
if (buffer != null)
buffer.append(c);
break;
}
}
if (foundEscape)
throw new InvalidSyntaxException("Trailing escape characters must be escaped.", filePattern);
return buffer == null ? filePattern : buffer.toString();
}
private static LinkedHashSet<String> listEntryPaths(BundleFile bundleFile, String path, Filter patternFilter, Hashtable<String, String> patternProps, int options, LinkedHashSet<String> pathList) {
if (pathList == null)
pathList = new LinkedHashSet<>();
Enumeration<String> entryPaths;
if ((options & BundleWiring.FINDENTRIES_RECURSE) != 0)
entryPaths = bundleFile.getEntryPaths(path, true);
else
entryPaths = bundleFile.getEntryPaths(path);
if (entryPaths == null)
return pathList;
while (entryPaths.hasMoreElements()) {
String entry = entryPaths.nextElement();
int lastSlash = entry.lastIndexOf('/');
if (patternProps != null) {
int secondToLastSlash = entry.lastIndexOf('/', lastSlash - 1);
int fileStart;
int fileEnd = entry.length();
if (lastSlash < 0)
fileStart = 0;
else if (lastSlash != entry.length() - 1)
fileStart = lastSlash + 1;
else {
fileEnd = lastSlash;
if (secondToLastSlash < 0)
fileStart = 0;
else
fileStart = secondToLastSlash + 1;
}
String fileName = entry.substring(fileStart, fileEnd);
patternProps.put("filename", fileName);
}
if (!pathList.contains(entry) && (patternFilter == null || patternFilter.matchCase(patternProps)))
pathList.add(entry);
}
return pathList;
}
public String copyToTempLibrary(Generation generation, String absolutePath) {
File libTempDir = new File(childRoot, LIB_TEMP);
File realLib = new File(absolutePath);
String libName = realLib.getName();
File bundleTempDir = null;
File libTempFile = null;
Long bundleID = new Long(generation.getBundleInfo().getBundleId());
for (int i = 0; i < Integer.MAX_VALUE; i++) {
bundleTempDir = new File(libTempDir, bundleID.toString() + "_" + Integer.valueOf(i).toString());
libTempFile = new File(bundleTempDir, libName);
if (bundleTempDir.exists()) {
if (libTempFile.exists())
continue;
break;
}
break;
}
if (!bundleTempDir.isDirectory()) {
bundleTempDir.mkdirs();
bundleTempDir.deleteOnExit();
File deleteFlag = new File(libTempDir, DELETE_FLAG);
if (!deleteFlag.exists()) {
try {
FileOutputStream out = new FileOutputStream(deleteFlag);
out.close();
} catch (IOException e) {
}
}
}
try {
InputStream in = new FileInputStream(realLib);
StorageUtil.readFile(in, libTempFile);
setPermissions(libTempFile);
libTempFile.deleteOnExit();
return libTempFile.getAbsolutePath();
} catch (IOException e) {
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, e.getMessage(), e);
return null;
}
}
public SecurityAdmin getSecurityAdmin() {
return securityAdmin;
}
protected StorageManager getChildStorageManager() throws IOException {
String locking = getConfiguration().getConfiguration(LocationHelper.PROP_OSGI_LOCKING, LocationHelper.LOCKING_NIO);
StorageManager sManager = new StorageManager(childRoot, isReadOnly() ? LocationHelper.LOCKING_NONE : locking, isReadOnly());
try {
sManager.open(!isReadOnly());
} catch (IOException ex) {
if (getConfiguration().getDebug().DEBUG_STORAGE) {
Debug.println("Error reading framework.info: " + ex.getMessage());
Debug.printStackTrace(ex);
}
String message = NLS.bind(Msg.ECLIPSE_STARTUP_FILEMANAGER_OPEN_ERROR, ex.getMessage());
equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, message, ex);
getConfiguration().setProperty(EclipseStarter.PROP_EXITCODE, "15");
String errorDialog = "<title>" + Msg.ADAPTOR_STORAGE_INIT_FAILED_TITLE + "</title>" + NLS.bind(Msg.ADAPTOR_STORAGE_INIT_FAILED_MSG, childRoot) + "\n" + ex.getMessage();
getConfiguration().setProperty(EclipseStarter.PROP_EXITDATA, errorDialog);
throw ex;
}
return sManager;
}
private InputStream getInfoInputStream() throws IOException {
StorageManager storageManager = getChildStorageManager();
InputStream storageStream = null;
try {
storageStream = storageManager.getInputStream(FRAMEWORK_INFO);
} catch (IOException ex) {
if (getConfiguration().getDebug().DEBUG_STORAGE) {
Debug.println("Error reading framework.info: " + ex.getMessage());
Debug.printStackTrace(ex);
}
} finally {
storageManager.close();
}
if (storageStream == null && parentRoot != null) {
StorageManager parentStorageManager = null;
try {
parentStorageManager = new StorageManager(parentRoot, LocationHelper.LOCKING_NONE, true);
parentStorageManager.open(false);
storageStream = parentStorageManager.getInputStream(FRAMEWORK_INFO);
} catch (IOException e1) {
} finally {
if (parentStorageManager != null) {
parentStorageManager.close();
}
}
}
return storageStream;
}
}