private static IJavaProject[] getProjectSearchOrder(String projectName) {

    ArrayList<String> projectNames = new ArrayList<String>();
    projectNames.add(projectName);

    int nextProject = 0;
    while (nextProject < projectNames.size()) {
      String nextProjectName = projectNames.get(nextProject);
      IJavaProject jproject = getJavaProject(nextProjectName);

      if (jproject != null) {
        try {
          String[] childProjectNames = jproject.getRequiredProjectNames();
          for (int i = 0; i < childProjectNames.length; i++) {
            if (!projectNames.contains(childProjectNames[i])) {
              projectNames.add(childProjectNames[i]);
            }
          }
        } catch (JavaModelException e) {
          JavaPlugin.log(e);
        }
      }
      nextProject += 1;
    }

    ArrayList<IJavaProject> result = new ArrayList<IJavaProject>();
    for (int i = 0, size = projectNames.size(); i < size; i++) {
      String name = projectNames.get(i);
      IJavaProject project = getJavaProject(name);
      if (project != null) result.add(project);
    }

    return result.toArray(new IJavaProject[result.size()]);
  }
Esempio n. 2
0
 public static List<IJavaProject> getAllDependingJavaProjects(IJavaProject project) {
   List<IJavaProject> javaProjects = new ArrayList<IJavaProject>();
   IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
   if (model != null) {
     try {
       String[] names = project.getRequiredProjectNames();
       IJavaProject[] projects = model.getJavaProjects();
       for (int index = 0; index < projects.length; index++) {
         for (int offset = 0; offset < names.length; offset++) {
           String name = projects[index].getProject().getName();
           if (name.equals(names[offset])) {
             javaProjects.add(projects[index]);
           }
         }
       }
     } catch (JavaModelException exception) {
     }
   }
   return javaProjects;
 }