Search in sources :

Example 6 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SecurityManagerTests method testEnableSecurityManager03.

public void testEnableSecurityManager03() throws BundleException {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testEnableSecurityManager03");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception on init()", e);
    }
    // $NON-NLS-1$
    assertNotNull("SecurityManager is null", System.getSecurityManager());
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    // try installing a bundle to tests bug
    // $NON-NLS-1$
    String locationSecurityA = installer.getBundleLocation("security.a");
    // set the security for the bundle
    ConditionalPermissionAdmin ca = (ConditionalPermissionAdmin) systemContext.getService(systemContext.getServiceReference(ConditionalPermissionAdmin.class.getName()));
    ConditionalPermissionUpdate update = ca.newConditionalPermissionUpdate();
    List rows = update.getConditionalPermissionInfos();
    rows.add(ca.newConditionalPermissionInfo(null, null, new PermissionInfo[] { hostFragmentPermission, importPackagePermission }, ConditionalPermissionInfo.ALLOW));
    // $NON-NLS-1$
    assertTrue("Cannot commit rows", update.commit());
    Bundle securityA = systemContext.installBundle(locationSecurityA);
    equinox.start();
    PackageAdmin pa = (PackageAdmin) systemContext.getService(systemContext.getServiceReference(PackageAdmin.class.getName()));
    try {
        assertTrue(pa.resolveBundles(new Bundle[] { securityA }));
        ExportedPackage[] eps = pa.getExportedPackages(securityA);
        // $NON-NLS-1$
        assertNull("Found unexpected exports", eps);
        RequiredBundle[] rbs = pa.getRequiredBundles(securityA.getSymbolicName());
        // $NON-NLS-1$
        assertNull("Found unexpected required bundle", rbs);
        // grant export permission
        update = ca.newConditionalPermissionUpdate();
        rows = update.getConditionalPermissionInfos();
        rows.clear();
        rows.add(ca.newConditionalPermissionInfo(null, null, new PermissionInfo[] { hostFragmentProvidePermission, allPackagePermission }, ConditionalPermissionInfo.ALLOW));
        // $NON-NLS-1$
        assertTrue("Cannot commit rows", update.commit());
        securityA.uninstall();
        securityA = systemContext.installBundle(locationSecurityA);
        assertTrue(pa.resolveBundles(new Bundle[] { securityA }));
        eps = pa.getExportedPackages(securityA);
        // $NON-NLS-1$
        assertNotNull("Did not find expected exports", eps);
        // $NON-NLS-1$
        assertEquals("Wrong number of exports found", 1, eps.length);
        rbs = pa.getRequiredBundles(securityA.getSymbolicName());
        // $NON-NLS-1$
        assertNotNull("Did not find required bundle", eps);
        // $NON-NLS-1$
        assertEquals("Wrong number of required bundles found", 1, rbs.length);
    } finally {
        // put the framework back to the RESOLVED state
        equinox.stop();
        try {
            equinox.waitForStop(10000);
        } catch (InterruptedException e) {
            // $NON-NLS-1$
            fail("Unexpected interrupted exception", e);
        }
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
    // $NON-NLS-1$
    assertNull("SecurityManager is not null", System.getSecurityManager());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) File(java.io.File)

Example 7 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testSchemes.

public void testSchemes() throws Exception {
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "http://example.com/a");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "ftp://example.com/c/d");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "platform:/base/e/f");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        checkSlashes(locations);
        checkLocation(locations.get(Location.USER_FILTER), true, true, "http");
        checkLocation(locations.get(Location.INSTANCE_FILTER), true, true, "ftp");
        checkLocation(locations.get(Location.CONFIGURATION_FILTER), true, true, "platform");
        checkLocation(locations.get(Location.INSTALL_FILTER), true, true, "file");
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 8 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testSlashes.

public void testSlashes() throws BundleException, InvalidSyntaxException {
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, prefix + "/a");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, prefix + "/c/d");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, prefix + "/e/f");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        checkSlashes(getLocations(equinox));
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox)

Example 9 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testUserDir.

public void testUserDir() throws Exception {
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@user.dir");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@user.dir");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@user.dir");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        checkLocation(locations.get(Location.USER_FILTER), true, true, "file");
        checkLocation(locations.get(Location.INSTANCE_FILTER), true, true, "file");
        checkLocation(locations.get(Location.CONFIGURATION_FILTER), true, true, "file");
        checkLocation(locations.get(Location.INSTALL_FILTER), true, true, "file");
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 10 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testNone.

public void testNone() throws Exception {
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@none");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@none");
    // TODO framework does not handle no config area well
    // fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@none");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        assertNull("User location should be null", locations.get(Location.USER_FILTER));
        assertNull("Instance location should be null", locations.get(Location.INSTANCE_FILTER));
    // TODO assertNull("Configuration location should be null", locations.get(Location.CONFIGURATION_FILTER));
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

Equinox (org.eclipse.osgi.launch.Equinox)105 File (java.io.File)88 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)58 BundleException (org.osgi.framework.BundleException)52 BundleContext (org.osgi.framework.BundleContext)51 Bundle (org.osgi.framework.Bundle)43 IOException (java.io.IOException)18 FileNotFoundException (java.io.FileNotFoundException)11 URL (java.net.URL)10 Location (org.eclipse.osgi.service.datalocation.Location)10 Properties (java.util.Properties)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 FrameworkEvent (org.osgi.framework.FrameworkEvent)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)8 BundleWiring (org.osgi.framework.wiring.BundleWiring)8 ArrayList (java.util.ArrayList)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileOutputStream (java.io.FileOutputStream)5