use of org.eclipse.osgi.framework.util.FilePath in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemCapabilitiesBug522125.
public void testSystemCapabilitiesBug522125() throws URISyntaxException, FileNotFoundException, IOException, BundleException, InterruptedException {
String frameworkLocation = OSGiTestsActivator.getContext().getProperty(EquinoxConfiguration.PROP_FRAMEWORK);
URI uri = new URI(frameworkLocation);
File f = new File(uri);
if (!f.isFile()) {
Assert.fail("Cannot test when framework location is a directory: " + f.getAbsolutePath());
}
File testDestination = OSGiTestsActivator.getContext().getDataFile(getName() + ".framework.jar");
BaseSecurityTest.copy(new FileInputStream(f), testDestination);
FilePath userDir = new FilePath(System.getProperty("user.dir"));
FilePath testPath = new FilePath(testDestination);
String relative = userDir.makeRelative(testPath);
System.out.println(relative);
URL relativeURL = new URL("file:" + relative);
relativeURL.openStream().close();
final ClassLoader osgiClassLoader = getClass().getClassLoader();
URLClassLoader cl = new URLClassLoader(new URL[] { relativeURL }) {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (name.startsWith("org.osgi.")) {
return osgiClassLoader.loadClass(name);
}
return super.loadClass(name, resolve);
}
};
ServiceLoader<FrameworkFactory> sLoader = ServiceLoader.load(FrameworkFactory.class, cl);
FrameworkFactory factory = sLoader.iterator().next();
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, String> configuration = new HashMap<String, String>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(EquinoxConfiguration.PROP_FRAMEWORK, relativeURL.toExternalForm());
Framework framework = factory.newFramework(configuration);
framework.init();
framework.stop();
framework.waitForStop(5000);
BundleRevision systemRevision1 = framework.adapt(BundleRevision.class);
int capCount1 = systemRevision1.getCapabilities(null).size();
framework = factory.newFramework(configuration);
framework.init();
framework.stop();
framework.waitForStop(5000);
BundleRevision systemRevision2 = framework.adapt(BundleRevision.class);
int capCount2 = systemRevision2.getCapabilities(null).size();
Assert.assertEquals("Wrong number of capabilities", capCount1, capCount2);
}
use of org.eclipse.osgi.framework.util.FilePath in project rt.equinox.framework by eclipse.
the class FilePathTest method testColonOnPath.
public void testColonOnPath() {
FilePath path = new FilePath("/c:b/a");
if (Platform.getOS().equals(Platform.OS_WIN32)) {
// Windows-specific testing
assertTrue("1.0", !path.isAbsolute());
assertEquals("2.0", "c:", path.getDevice());
String[] segments = path.getSegments();
assertEquals("3.0", 2, segments.length);
assertEquals("3.1", "b", segments[0]);
assertEquals("3.2", "a", segments[1]);
return;
}
// this runs on non-Windows platforms
assertTrue("1.0", path.isAbsolute());
assertNull("2.0", path.getDevice());
String[] segments = path.getSegments();
assertEquals("3.0", 2, segments.length);
assertEquals("3.1", "c:b", segments[0]);
assertEquals("3.2", "a", segments[1]);
}
use of org.eclipse.osgi.framework.util.FilePath 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