Search in sources :

Example 1 with FilePath

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);
}
Also used : FilePath(org.eclipse.osgi.framework.util.FilePath) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URI(java.net.URI) FileInputStream(java.io.FileInputStream) URL(java.net.URL) FrameworkFactory(org.osgi.framework.launch.FrameworkFactory) URLClassLoader(java.net.URLClassLoader) BundleRevision(org.osgi.framework.wiring.BundleRevision) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Framework(org.osgi.framework.launch.Framework)

Example 2 with FilePath

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]);
}
Also used : FilePath(org.eclipse.osgi.framework.util.FilePath)

Example 3 with FilePath

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);
}
Also used : FilePath(org.eclipse.osgi.framework.util.FilePath) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Aggregations

FilePath (org.eclipse.osgi.framework.util.FilePath)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Module (org.eclipse.osgi.container.Module)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 Framework (org.osgi.framework.launch.Framework)1 FrameworkFactory (org.osgi.framework.launch.FrameworkFactory)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1