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");
    }

}

@@ -176,16 +176,55 @@
 sPlugin;
+%0Aimport org.eclipse.core.runtime.IPath;
 %0A%0Aimport
@@ -577,67 +577,171 @@
 if (
-project == null %7C%7C !project.exists() %7C%7C !project.isOpen())%0A
+checkProject(project, name)) %7B%0A            return project;%0A        %7D%0A        for (IProject p : wsroot.getProjects()) %7B%0A            if (checkProject(p, name)) %7B%0A   
     
@@ -752,20 +752,42 @@
     
+ 
 return 
-null;
+p;%0A            %7D%0A        %7D
 %0A   
@@ -794,31 +794,28 @@
      return 
-project
+null
 ;%0A    %7D%0A%0A   
@@ -962,10 +962,354 @@
 %0A    %7D%0A%0A
+    private static boolean checkProject(IProject project, String name) %7B%0A        if ((project != null) && project.exists() && project.isOpen()) %7B%0A            IPath path = project.getLocation();%0A            if ((path != null) && name.equals(path.lastSegment())) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A
 %7D%0A

Handle mapping bnd project name to renamed eclipse project