private static String getBundlePath()

in plugins/org.apache.karaf.eik.felix/src/main/java/org/apache/karaf/eik/felix/FelixLaunchConfiguration.java [129:196]


    private static String getBundlePath(String bundleName, String packageName) throws CoreException {
        final IPluginModelBase model = PluginRegistry.findModel(bundleName);
        if (model != null) {
            final IResource resource = model.getUnderlyingResource();

            if (!isWorkspaceModel(model)) {
                return model.getInstallLocation();
            }

            final IProject project = resource.getProject();
            if (project.hasNature(JavaCore.NATURE_ID)) {
                final IJavaProject jProject = JavaCore.create(project);
                final IClasspathEntry[] entries = jProject.getRawClasspath();

                for (int i = 0; i < entries.length; i++) {
                    final int kind = entries[i].getEntryKind();
                    if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) {
                        final IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]);

                        for (int j = 0; j < roots.length; j++) {
                            if (roots[j].getPackageFragment(packageName).exists()) {
                                // if source folder, find the output folder
                                if (kind == IClasspathEntry.CPE_SOURCE) {
                                    IPath path = entries[i].getOutputLocation();
                                    if (path == null) {
                                        path = jProject.getOutputLocation();
                                    }

                                    path = path.removeFirstSegments(1);

                                    return project.getLocation().append(path).toOSString();
                                }
                                // else if is a library jar, then get the
                                // location of the jar itself
                                final IResource jar = roots[j].getResource();
                                if (jar != null) {
                                    return jar.getLocation().toOSString();
                                }
                            }
                        }
                    }
                }
            }
        }

        final Bundle bundle = Platform.getBundle(bundleName);
        if (bundle != null) {
            try {
                URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$
                url = FileLocator.toFileURL(url);
                String path = url.getFile();
                if (path.startsWith("file:")) { //$NON-NLS-1$
                    path = path.substring(5);
                }

                path = new File(path).getAbsolutePath();

                if (path.endsWith("!")) { //$NON-NLS-1$
                    path = path.substring(0, path.length() - 1);
                }

                return path;
            } catch (IOException e) {
            }
        }

        return null;
    }