Search in sources :

Example 11 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method ensureBundlesActive.

private static void ensureBundlesActive(Bundle[] bundles) {
    for (int i = 0; i < bundles.length; i++) {
        if (bundles[i].getState() != Bundle.ACTIVE) {
            if (bundles[i].getState() == Bundle.INSTALLED) {
                // Log that the bundle is not resolved
                log.log(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, NLS.bind(Msg.ECLIPSE_STARTUP_ERROR_BUNDLE_NOT_RESOLVED, bundles[i].getLocation()), 0, null, null));
                continue;
            }
            // check that the startlevel allows the bundle to be active (111550)
            FrameworkStartLevel fwStartLevel = context.getBundle().adapt(FrameworkStartLevel.class);
            BundleStartLevel bundleStartLevel = bundles[i].adapt(BundleStartLevel.class);
            if (fwStartLevel != null && (bundleStartLevel.getStartLevel() <= fwStartLevel.getStartLevel())) {
                log.log(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, NLS.bind(Msg.ECLIPSE_STARTUP_ERROR_BUNDLE_NOT_ACTIVE, bundles[i]), 0, null, null));
            }
        }
    }
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel)

Example 12 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method uninstallBundles.

private static void uninstallBundles(Bundle[] curInitBundles, InitialBundle[] newInitBundles, List<Bundle> toRefresh) {
    for (int i = 0; i < curInitBundles.length; i++) {
        boolean found = false;
        for (int j = 0; j < newInitBundles.length; j++) {
            if (curInitBundles[i].getLocation().equalsIgnoreCase(newInitBundles[j].locationString)) {
                found = true;
                break;
            }
        }
        if (!found)
            try {
                curInitBundles[i].uninstall();
                toRefresh.add(curInitBundles[i]);
            } catch (BundleException e) {
                FrameworkLogEntry entry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, NLS.bind(Msg.ECLIPSE_STARTUP_FAILED_UNINSTALL, curInitBundles[i].getLocation()), 0, e, null);
                log.log(entry);
            }
    }
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 13 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method getInitialBundles.

private static InitialBundle[] getInitialBundles(String[] installEntries) {
    searchCandidates.clear();
    List<InitialBundle> result = new ArrayList<>(installEntries.length);
    int defaultStartLevel = Integer.parseInt(getProperty(PROP_BUNDLES_STARTLEVEL, DEFAULT_BUNDLES_STARTLEVEL));
    String syspath = getSysPath();
    // should canonicalize the syspath.
    try {
        syspath = new File(syspath).getCanonicalPath();
    } catch (IOException ioe) {
    // do nothing
    }
    Collection<ServiceReference<Location>> installLocRef;
    try {
        installLocRef = context.getServiceReferences(Location.class, Location.INSTALL_FILTER);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    Location installLocation = installLocRef == null ? null : context.getService(installLocRef.iterator().next());
    if (installLocation == null) {
        throw new IllegalStateException(Msg.EclipseStarter_InstallLocation);
    }
    for (int i = 0; i < installEntries.length; i++) {
        String name = installEntries[i];
        int level = defaultStartLevel;
        boolean start = false;
        int index = name.lastIndexOf('@');
        if (index >= 0) {
            // $NON-NLS-1$
            String[] attributes = getArrayFromList(name.substring(index + 1, name.length()), ":");
            for (int j = 0; j < attributes.length; j++) {
                String attribute = attributes[j];
                if (// $NON-NLS-1$
                attribute.equals("start"))
                    start = true;
                else {
                    try {
                        level = Integer.parseInt(attribute);
                    } catch (NumberFormatException e) {
                        // bug 188089
                        index = name.length();
                        continue;
                    }
                }
            }
            name = name.substring(0, index);
        }
        try {
            URL location = searchForBundle(name, syspath);
            if (location == null) {
                FrameworkLogEntry entry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, NLS.bind(Msg.ECLIPSE_STARTUP_BUNDLE_NOT_FOUND, installEntries[i]), 0, null, null);
                log.log(entry);
                // skip this entry
                continue;
            }
            location = makeRelative(installLocation.getURL(), location);
            String locationString = INITIAL_LOCATION + location.toExternalForm();
            result.add(new InitialBundle(locationString, location, level, start));
        } catch (IOException e) {
            log.log(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null));
        }
    }
    return result.toArray(new InitialBundle[result.size()]);
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) Location(org.eclipse.osgi.service.datalocation.Location)

Example 14 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method run.

/**
 * Runs the application for which the platform was started. The platform
 * must be running.
 * <p>
 * The given argument is passed to the application being run.  If it is <code>null</code>
 * then the command line arguments used in starting the platform, and not consumed
 * by the platform code, are passed to the application as a <code>String[]</code>.
 * </p>
 * @param argument the argument passed to the application. May be <code>null</code>
 * @return the result of running the application
 * @throws Exception if anything goes wrong
 */
public static Object run(Object argument) throws Exception {
    if (!running)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_NOT_RUNNING);
    // if we are just initializing, do not run the application just return.
    if (initialize)
        return Integer.valueOf(0);
    try {
        if (appLauncher == null) {
            // $NON-NLS-1$
            boolean launchDefault = Boolean.valueOf(getProperty(PROP_APPLICATION_LAUNCHDEFAULT, "true")).booleanValue();
            // create the ApplicationLauncher and register it as a service
            appLauncher = new EclipseAppLauncher(context, Boolean.valueOf(getProperty(PROP_ALLOW_APPRELAUNCH)).booleanValue(), launchDefault, log, equinoxConfig);
            appLauncherRegistration = context.registerService(ApplicationLauncher.class.getName(), appLauncher, null);
            // will return only after the application has stopped.
            return appLauncher.start(argument);
        }
        return appLauncher.reStart(argument);
    } catch (Exception e) {
        if (log != null && context != null) {
            // context can be null if OSGi failed to launch (bug 151413)
            ResolutionReport report = context.getBundle().adapt(Module.class).getContainer().resolve(null, false);
            for (Resource unresolved : report.getEntries().keySet()) {
                String bsn = ((ModuleRevision) unresolved).getSymbolicName();
                FrameworkLogEntry logEntry = new FrameworkLogEntry(bsn != null ? bsn : EquinoxContainer.NAME, FrameworkLogEntry.WARNING, 0, Msg.Module_ResolveError + report.getResolutionReportMessage(unresolved), 1, null, null);
                log.log(logEntry);
            }
        }
        throw e;
    }
}
Also used : Resource(org.osgi.resource.Resource) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Module(org.eclipse.osgi.container.Module)

Example 15 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class HookRegistry method initialize.

/**
 * Initializes the hook configurators.  The following steps are used to initialize the hook configurators. <p>
 * 1. Get a list of hook configurators from all hook configurators properties files on the classpath,
 *    add this list to the overall list of hook configurators, remove duplicates. <p>
 * 2. Get a list of hook configurators from the (&quot;osgi.hook.configurators.include&quot;) system property
 *    and add this list to the overall list of hook configurators, remove duplicates. <p>
 * 3. Get a list of hook configurators from the (&quot;osgi.hook.configurators.exclude&quot;) system property
 *    and remove this list from the overall list of hook configurators. <p>
 * 4. Load each hook configurator class, create a new instance, then call the {@link HookConfigurator#addHooks(HookRegistry)} method <p>
 * 5. Set this HookRegistry object to read only to prevent any other hooks from being added. <p>
 */
public void initialize() {
    List<String> configurators = new ArrayList<>(5);
    // optimistic that no errors will occur
    List<FrameworkLogEntry> errors = new ArrayList<>(0);
    mergeFileHookConfigurators(configurators, errors);
    mergePropertyHookConfigurators(configurators);
    synchronized (this) {
        addClassLoaderHook(new DevClassLoadingHook(container.getConfiguration()));
        addClassLoaderHook(new EclipseLazyStarter(container));
        addClassLoaderHook(new WeavingHookConfigurator(container));
        configurators.add(SignedBundleHook.class.getName());
        loadConfigurators(configurators, errors);
        // set to read-only
        initialized = true;
    }
    for (FrameworkLogEntry error : errors) {
        container.getLogServices().getFrameworkLog().log(error);
    }
}
Also used : SignedBundleHook(org.eclipse.osgi.internal.signedcontent.SignedBundleHook) DevClassLoadingHook(org.eclipse.osgi.internal.hooks.DevClassLoadingHook) WeavingHookConfigurator(org.eclipse.osgi.internal.weaving.WeavingHookConfigurator) EclipseLazyStarter(org.eclipse.osgi.internal.hooks.EclipseLazyStarter) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Aggregations

FrameworkLogEntry (org.eclipse.osgi.framework.log.FrameworkLogEntry)16 Logger (org.eclipse.equinox.log.Logger)2 FrameworkLog (org.eclipse.osgi.framework.log.FrameworkLog)2 WeavingHookConfigurator (org.eclipse.osgi.internal.weaving.WeavingHookConfigurator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Module (org.eclipse.osgi.container.Module)1 DevClassLoadingHook (org.eclipse.osgi.internal.hooks.DevClassLoadingHook)1 EclipseLazyStarter (org.eclipse.osgi.internal.hooks.EclipseLazyStarter)1 SignedBundleHook (org.eclipse.osgi.internal.signedcontent.SignedBundleHook)1 Equinox (org.eclipse.osgi.launch.Equinox)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 Location (org.eclipse.osgi.service.datalocation.Location)1 EnvironmentInfo (org.eclipse.osgi.service.environment.EnvironmentInfo)1 Framework (org.osgi.framework.launch.Framework)1 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1 Resource (org.osgi.resource.Resource)1