public static IProject getLiferayWorkspaceProject() {
    IProject[] projects = CoreUtil.getAllProjects();

    for (IProject project : projects) {
      if (isValidWorkspace(project)) {
        return project;
      }
    }
    return null;
  }
  public void checkValidProjectTypes() {
    IProject[] projects = CoreUtil.getAllProjects();
    boolean hasValidProjectTypes = false;

    boolean hasJsfFacet = false;

    for (IProject project : projects) {
      if (ProjectUtil.isLiferayProject(project)) {
        Set<IProjectFacetVersion> facets =
            ProjectUtil.getFacetedProject(project).getProjectFacets();

        if (validProjectTypes != null && facets != null) {
          String[] validTypes = validProjectTypes.split(",");

          for (String validProjectType : validTypes) {
            for (IProjectFacetVersion facet : facets) {
              String id = facet.getProjectFacet().getId();

              if (isJsfPortlet && id.equals("jst.jsf")) {
                hasJsfFacet = true;
              }

              if (id.startsWith("liferay.") && id.equals("liferay." + validProjectType)) {
                hasValidProjectTypes = true;
              }
            }
          }
        }
      }
    }

    if (isJsfPortlet) {
      hasValidProjectTypes = hasJsfFacet && hasValidProjectTypes;
    }

    if (!hasValidProjectTypes) {
      final Shell activeShell = Display.getDefault().getActiveShell();
      Boolean openNewLiferayProjectWizard =
          MessageDialog.openQuestion(
              activeShell,
              "New Element",
              "There are no suitable Liferay projects available for this new element.\nDo you want"
                  + " to open the \'New Liferay Project\' wizard now?");

      if (openNewLiferayProjectWizard) {
        Action[] actions = NewPluginProjectDropDownAction.getNewProjectActions();

        if (actions.length > 0) {
          actions[0].run();
          this.checkValidProjectTypes();
        }
      }
    }
  }
  public static boolean hasLiferayWorkspace() throws CoreException {
    IProject[] projects = CoreUtil.getAllProjects();

    int count = 0;

    for (IProject project : projects) {
      if (isValidWorkspace(project)) {
        ++count;
      }
    }

    if (count == 1) {
      return true;
    } else if (count > 1) {
      throw new CoreException(ProjectCore.createErrorStatus(multiWorkspaceError));
    }

    return false;
  }
示例#4
0
  public static IJavaProject[] getAllServiceProjects() {
    final List<IJavaProject> serviceProjects = new ArrayList<IJavaProject>();

    for (final IProject project : CoreUtil.getAllProjects()) {
      if (project.isAccessible()) {
        final IJavaProject jp = JavaCore.create(project);

        if (jp != null) {
          final List<IFile> serviceXmls =
              new SearchFilesVisitor().searchFiles(project, "service.xml");

          if (serviceXmls.size() > 0) {
            serviceProjects.add(jp);
          }
        }
      }
    }

    return serviceProjects.toArray(new IJavaProject[0]);
  }