Search in sources :

Example 1 with EquinoxBundle

use of org.eclipse.osgi.internal.framework.EquinoxBundle in project rt.equinox.framework by eclipse.

the class BundleLocalizationImpl method getLocalization.

/**
 * The getLocalization method gets a ResourceBundle object for the given
 * locale and bundle.
 *
 * @return A <code>ResourceBundle</code> object for the given bundle and locale.
 * If null is passed for the locale parameter, the default locale is used.
 */
public ResourceBundle getLocalization(Bundle bundle, String locale) {
    Module m = ((EquinoxBundle) bundle).getModule();
    ModuleRevision r = m.getCurrentRevision();
    Generation g = (Generation) r.getRevisionInfo();
    return g.getResourceBundle(locale);
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 2 with EquinoxBundle

use of org.eclipse.osgi.internal.framework.EquinoxBundle in project rt.equinox.framework by eclipse.

the class PolicyHandler method getPolicyImplementation.

private IBuddyPolicy getPolicyImplementation(Object[] policiesSnapshot, int policyOrder) {
    synchronized (policiesSnapshot) {
        if (policyOrder >= policiesSnapshot.length)
            return null;
        if (policiesSnapshot[policyOrder] instanceof String) {
            String buddyName = (String) policiesSnapshot[policyOrder];
            if (REGISTERED_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = new RegisteredPolicy(policedLoader);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (BOOT_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.BOOT);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (APP_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.APP);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (EXT_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = SystemPolicy.getInstance(SystemPolicy.EXT);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (DEPENDENT_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = new DependentPolicy(policedLoader);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (GLOBAL_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = new GlobalPolicy(packageAdmin);
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            if (PARENT_POLICY.equals(buddyName)) {
                policiesSnapshot[policyOrder] = new SystemPolicy(policedLoader.getParentClassLoader());
                return (IBuddyPolicy) policiesSnapshot[policyOrder];
            }
            // Not a valid buddy policy
            EquinoxBundle bundle = (EquinoxBundle) policedLoader.getModuleClassLoader().getBundle();
            // $NON-NLS-1$
            bundle.getModule().getContainer().getAdaptor().publishContainerEvent(ContainerEvent.ERROR, bundle.getModule(), new RuntimeException("Invalid buddy policy: " + buddyName));
            policiesSnapshot[policyOrder] = null;
        // //Buddy policy can be provided by service implementations
        // BundleContext fwkCtx = policedLoader.bundle.framework.systemBundle.context;
        // ServiceReference[] matchingBuddies = null;
        // try {
        // matchingBuddies = fwkCtx.getAllServiceReferences(IBuddyPolicy.class.getName(), "buddyName=" + buddyName);
        // } catch (InvalidSyntaxException e) {
        // //The filter is valid
        // }
        // if (matchingBuddies == null)
        // return new IBuddyPolicy() {
        // public Class loadClass(String name) {
        // return null;
        // }
        // 
        // public URL loadResource(String name) {
        // return null;
        // }
        // 
        // public Enumeration loadResources(String name) {
        // return null;
        // }
        // };
        // 
        // //The policies loaded through service are not cached
        // return ((IBuddyPolicy) fwkCtx.getService(matchingBuddies[0]));
        }
        return (IBuddyPolicy) policiesSnapshot[policyOrder];
    }
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle)

Example 3 with EquinoxBundle

use of org.eclipse.osgi.internal.framework.EquinoxBundle in project rt.equinox.framework by eclipse.

the class SecurityAdmin method checkPermission.

boolean checkPermission(Permission permission, BundlePermissions bundlePermissions) {
    // check permissions by location
    PermissionInfoCollection locationCollection;
    SecurityTable curCondAdminTable;
    PermissionInfoCollection curPermAdminDefaults;
    // save off the current state of the world while holding the lock
    synchronized (lock) {
        // get location the hard way to avoid permission check
        Bundle bundle = bundlePermissions.getBundle();
        locationCollection = bundle instanceof EquinoxBundle ? permAdminTable.getCollection(((EquinoxBundle) bundle).getModule().getLocation()) : null;
        curCondAdminTable = condAdminTable;
        curPermAdminDefaults = permAdminDefaults;
    }
    if (locationCollection != null)
        return locationCollection.implies(permission);
    // if conditional admin table is empty the fall back to defaults
    if (curCondAdminTable.isEmpty())
        return curPermAdminDefaults != null ? curPermAdminDefaults.implies(permission) : DEFAULT_DEFAULT.implies(permission);
    // check the condition table
    int result = curCondAdminTable.evaluate(bundlePermissions, permission);
    if ((result & SecurityTable.GRANTED) != 0)
        return true;
    if ((result & SecurityTable.DENIED) != 0)
        return false;
    if ((result & SecurityTable.POSTPONED) != 0)
        return true;
    return false;
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle)

Example 4 with EquinoxBundle

use of org.eclipse.osgi.internal.framework.EquinoxBundle in project xtext-eclipse by eclipse.

the class TargetPlatformUtil method setTargetPlatform.

/**
 * Sets the target platform for tests (to be used in tycho mainly)
 * @param context any class of the test bundle to be able to determine the test bundle
 * @since 2.14
 */
public static void setTargetPlatform(Class<?> context) throws Exception {
    if (isPdeLaunch()) {
        return;
    }
    Bundle currentBundle = FrameworkUtil.getBundle(context);
    ITargetPlatformService tpService = TargetPlatformService.getDefault();
    ITargetDefinition targetDef = tpService.newTarget();
    targetDef.setName("Tycho platform");
    Bundle[] bundles = FrameworkUtil.getBundle(Platform.class).getBundleContext().getBundles();
    List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
    Set<File> dirs = new HashSet<File>();
    for (Bundle bundle : bundles) {
        if (bundle.equals(currentBundle)) {
            // errors during our tests.
            continue;
        }
        EquinoxBundle bundleImpl = (EquinoxBundle) bundle;
        Generation generation = (Generation) bundleImpl.getModule().getCurrentRevision().getRevisionInfo();
        File file = generation.getBundleFile().getBaseFile();
        File folder = file.getParentFile();
        if ((file.isFile() || Platform.inDevelopmentMode()) && !dirs.contains(folder)) {
            dirs.add(folder);
            bundleContainers.add(tpService.newDirectoryLocation(folder.getAbsolutePath()));
        }
    }
    targetDef.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
    targetDef.setArch(Platform.getOSArch());
    targetDef.setOS(Platform.getOS());
    targetDef.setWS(Platform.getWS());
    targetDef.setNL(Platform.getNL());
    // targetDef.setJREContainer()
    tpService.saveTargetDefinition(targetDef);
    Job job = new LoadTargetDefinitionJob(targetDef);
    job.schedule();
    job.join();
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ITargetLocation(org.eclipse.pde.core.target.ITargetLocation) ITargetPlatformService(org.eclipse.pde.core.target.ITargetPlatformService) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ITargetDefinition(org.eclipse.pde.core.target.ITargetDefinition) LoadTargetDefinitionJob(org.eclipse.pde.core.target.LoadTargetDefinitionJob) Job(org.eclipse.core.runtime.jobs.Job) LoadTargetDefinitionJob(org.eclipse.pde.core.target.LoadTargetDefinitionJob) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with EquinoxBundle

use of org.eclipse.osgi.internal.framework.EquinoxBundle in project xtext-eclipse by eclipse.

the class TargetPlatformUtil method setTargetPlatform.

/**
 * Sets the target platform for tests (to be used in tycho mainly)
 * @param context any class of the test bundle to be able to determine the test bundle
 * @since 2.14
 */
public static void setTargetPlatform(Class<?> context) throws Exception {
    if (isPdeLaunch()) {
        return;
    }
    Bundle currentBundle = FrameworkUtil.getBundle(context);
    ITargetPlatformService tpService = TargetPlatformService.getDefault();
    ITargetDefinition targetDef = tpService.newTarget();
    targetDef.setName("Tycho platform");
    Bundle[] bundles = FrameworkUtil.getBundle(Platform.class).getBundleContext().getBundles();
    List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
    Set<File> dirs = new HashSet<File>();
    for (Bundle bundle : bundles) {
        if (bundle.equals(currentBundle)) {
            // errors during our tests.
            continue;
        }
        EquinoxBundle bundleImpl = (EquinoxBundle) bundle;
        Generation generation = (Generation) bundleImpl.getModule().getCurrentRevision().getRevisionInfo();
        File file = generation.getBundleFile().getBaseFile();
        File folder = file.getParentFile();
        if (!dirs.contains(folder)) {
            dirs.add(folder);
            bundleContainers.add(tpService.newDirectoryLocation(folder.getAbsolutePath()));
        }
    }
    targetDef.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
    targetDef.setArch(Platform.getOSArch());
    targetDef.setOS(Platform.getOS());
    targetDef.setWS(Platform.getWS());
    targetDef.setNL(Platform.getNL());
    // targetDef.setJREContainer()
    tpService.saveTargetDefinition(targetDef);
    Job job = new LoadTargetDefinitionJob(targetDef);
    job.schedule();
    job.join();
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ITargetLocation(org.eclipse.pde.core.target.ITargetLocation) ITargetPlatformService(org.eclipse.pde.core.target.ITargetPlatformService) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ITargetDefinition(org.eclipse.pde.core.target.ITargetDefinition) LoadTargetDefinitionJob(org.eclipse.pde.core.target.LoadTargetDefinitionJob) Job(org.eclipse.core.runtime.jobs.Job) LoadTargetDefinitionJob(org.eclipse.pde.core.target.LoadTargetDefinitionJob) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

EquinoxBundle (org.eclipse.osgi.internal.framework.EquinoxBundle)5 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Job (org.eclipse.core.runtime.jobs.Job)2 ITargetDefinition (org.eclipse.pde.core.target.ITargetDefinition)2 ITargetLocation (org.eclipse.pde.core.target.ITargetLocation)2 ITargetPlatformService (org.eclipse.pde.core.target.ITargetPlatformService)2 LoadTargetDefinitionJob (org.eclipse.pde.core.target.LoadTargetDefinitionJob)2 Bundle (org.osgi.framework.Bundle)2 Module (org.eclipse.osgi.container.Module)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1