package org.bndtools.utils.workspace;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;

import aQute.bnd.build.Project;

public class WorkspaceUtils {

    public static IProject findOpenProject(IWorkspaceRoot wsroot, Project model) {
        return findOpenProject(wsroot, model.getName());
    }

    public static IProject findOpenProject(IWorkspaceRoot wsroot, String name) {
        IProject project = wsroot.getProject(name);
        if (project == null || !project.exists() || !project.isOpen())
            return null;
        return project;
    }

    public static IProject findCnfProject() throws Exception {
        return findOpenProject(ResourcesPlugin.getWorkspace().getRoot(), "cnf");
    }

}

package org.bndtools.utils.workspace;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;

import aQute.bnd.build.Project;

public class WorkspaceUtils {

    public static IProject findOpenProject(IWorkspaceRoot wsroot, Project model) {
        return findOpenProject(wsroot, model.getName());
    }

    public static IProject findOpenProject(IWorkspaceRoot wsroot, String name) {
        IProject project = wsroot.getProject(name);
        if (checkProject(project, name)) {
            return project;
        }
        for (IProject p : wsroot.getProjects()) {
            if (checkProject(p, name)) {
                return p;
            }
        }
        return null;
    }

    public static IProject findCnfProject() throws Exception {
        return findOpenProject(ResourcesPlugin.getWorkspace().getRoot(), "cnf");
    }

    private static boolean checkProject(IProject project, String name) {
        if ((project != null) && project.exists() && project.isOpen()) {
            IPath path = project.getLocation();
            if ((path != null) && name.equals(path.lastSegment())) {
                return true;
            }
        }
        return false;
    }
}

Handle mapping bnd project name to renamed eclipse project
utils: Handle mapping bnd project name to renamed eclipse project

If you rename a project in eclipse, it does not change the folder name
just the project name in .project. This change deals with such a rename
when bndtools needs to find the eclipse project for a bnd project.

Signed-off-by: BJ Hargrave <3d26bb3930946e3370762d769a073cece444c2d8@bjhargrave.com>
