public BundleContext start()

in modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java [185:337]


    public BundleContext start() {
        try {
            if (injectedBundleContext == null) {

                Properties props = configureProperties();
                startFramework(props);

            } else {

                // Get bundle context from the running Eclipse instance
                bundleContext = injectedBundleContext;
            }
            
            // Determine the runtime classpath entries
            Set<URL> urls;
            urls = findBundleLocations();

            // Sort out which are bundles (and not already installed) and which are just
            // regular JARs
            for (URL url : urls) {
                File file = file(url);
               
                Manifest manifest = getCustomizedMF(file.getName());
                String bundleName = null;
                if (manifest == null) {
                    bundleName = bundleName(file);
                } else {
                    if (manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME) == null) {
                        manifest = null;
                    }
                }
                if (bundleName != null) {
                    bundleFiles.add(url);
                    bundleNames.add(bundleName);
                } else {
                    if (file.isFile()) {
                        jarFiles.put(url, manifest);
                    }
                }
            }

            // Get the already installed bundles
            for (Bundle bundle : bundleContext.getBundles()) {
                allBundles.put(bundle.getSymbolicName(), bundle);
            }

            // Install the launcher bundle if necessary
            String launcherBundleName = "org.apache.tuscany.sca.node.launcher.equinox";
            String launcherBundleLocation;
            launcherBundle = allBundles.get(launcherBundleName);
            if (launcherBundle == null) {
                launcherBundleLocation = thisBundleLocation();
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Installing launcher bundle: " + launcherBundleLocation);
                }
                fixupBundle(launcherBundleLocation);
                launcherBundle = bundleContext.installBundle(launcherBundleLocation);
                allBundles.put(launcherBundleName, launcherBundle);
                installedBundles.add(launcherBundle);
            } else {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Launcher bundle is already installed: " + string(launcherBundle, false));
                }
                // launcherBundleLocation = thisBundleLocation(launcherBundle);
            }

            // FIXME: SDO bundles dont have the correct dependencies
            setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");

            // Install the Tuscany bundles
            long start = currentTimeMillis();

            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Generating third-party library bundle.");
            }
            
            logger.info("Checking for manfiests customized by Tuscany in node-launcher-equinox/resources");
            
            long libraryStart = currentTimeMillis();
            
            Set<String> serviceProviders = new HashSet<String>();
            if (!aggregateThirdPartyJars) {
                for (Map.Entry<URL, Manifest> entry : jarFiles.entrySet()) {
                    URL jarFile = entry.getKey();
                    Manifest manifest = entry.getValue();
                    Bundle bundle = null;
                    if (manifest == null) {
                        bundle = installAsBundle(jarFile, null);
                    } else {
                        bundle = installAsBundle(Collections.singleton(jarFile), manifest);
                    }
                    isServiceProvider(bundle, serviceProviders);
                }
            } else {
                Bundle bundle = installAsBundle(jarFiles.keySet(), LAUNCHER_EQUINOX_LIBRARIES);
                isServiceProvider(bundle, serviceProviders);
            }
            
            installGatewayBundle(serviceProviders);
            
            if (logger.isLoggable(Level.FINE)) {
                logger
                    .fine("Third-party library bundle installed in " + (currentTimeMillis() - libraryStart) + " ms: ");
            }

            // Install all the other bundles that are not already installed
            for (URL bundleFile : bundleFiles) {
                fixupBundle(bundleFile.toString());
            }
            for (int i = 0, n = bundleFiles.size(); i < n; i++) {
                URL bundleFile = bundleFiles.get(i);
                String bundleName = bundleNames.get(i);
                if (bundleName.contains("org.eclipse.jdt.junit") || bundleName.contains("org.apache.tuscany.sca.base")) {
                    continue;
                }
                installBundle(bundleFile, bundleName);
            }

            long end = currentTimeMillis();
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Tuscany bundles are installed in " + (end - start) + " ms.");
            }

            // Start the extensiblity and launcher bundles
            String extensibilityBundleName = "org.apache.tuscany.sca.extensibility.equinox";
            Bundle extensibilityBundle = allBundles.get(extensibilityBundleName);
            if (extensibilityBundle != null) {
                if ((extensibilityBundle.getState() & Bundle.ACTIVE) == 0) {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.fine("Starting bundle: " + string(extensibilityBundle, false));
                    }
                    extensibilityBundle.start();
                } else if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Bundle is already started: " + string(extensibilityBundle, false));
                }
            }
            if ((launcherBundle.getState() & Bundle.ACTIVE) == 0) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.fine("Starting launcher bundle: " + string(launcherBundle, false));
                }
                launcherBundle.start();
            } else if (logger.isLoggable(Level.FINE)) {
                logger.fine("Bundle is already started: " + string(launcherBundle, false));
            }

            // Start all our bundles for now to help diagnose any class loading issues
            // startBundles( bundleContext );
            return bundleContext;

        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }