public static final Status execute(final NewLiferayPluginProjectOp op, final ProgressMonitor pm) {
    final IProgressMonitor monitor = ProgressMonitorBridge.create(pm);

    monitor.beginTask(
        "Creating Liferay plugin project (this process may take several minutes)",
        100); //$NON-NLS-1$

    Status retval = null;

    try {
      final NewLiferayProjectProvider<NewLiferayPluginProjectOp> projectProvider =
          op.getProjectProvider().content(true);

      // IDE-1306  If the user types too quickly all the model changes may not have propagated
      final Path projectLocation = op.getLocation().content();
      updateLocation(op, projectLocation);

      final IStatus status = projectProvider.createNewProject(op, monitor);

      if (status.isOK()) {
        updateProjectPrefs(op);

        removeSampleCodeAndFiles(op);
      }

      retval = StatusBridge.create(status);
    } catch (Exception e) {
      final String msg = "Error creating Liferay plugin project."; // $NON-NLS-1$
      ProjectCore.logError(msg, e);

      return Status.createErrorStatus(msg + " Please see Eclipse error log for more details.", e);
    }

    return retval;
  }
  public static String getFrameworkName(NewLiferayPluginProjectOp op) {
    final IPortletFramework portletFramework = op.getPortletFramework().content();

    String frameworkName = portletFramework.getShortName();

    if (portletFramework.isRequiresAdvanced()) {
      frameworkName = op.getPortletFrameworkAdvanced().content().getShortName();
    }

    return frameworkName;
  }
  public static Set<String> getPossibleProfileIds(
      NewLiferayPluginProjectOp op, boolean includeNewProfiles) {
    final String activeProfilesValue = op.getActiveProfilesValue().content();

    final Path currentLocation = op.getLocation().content();

    final File param = currentLocation != null ? currentLocation.toFile() : null;

    final List<String> systemProfileIds =
        op.getProjectProvider().content().getData("profileIds", String.class, param);

    final ElementList<NewLiferayProfile> newLiferayProfiles = op.getNewLiferayProfiles();

    final Set<String> possibleProfileIds = new HashSet<String>();

    if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) {
      final String[] vals = activeProfilesValue.split(",");

      if (!CoreUtil.isNullOrEmpty(vals)) {
        for (String val : vals) {
          if (!possibleProfileIds.contains(val) && !val.contains(StringPool.SPACE)) {
            possibleProfileIds.add(val);
          }
        }
      }
    }

    if (!CoreUtil.isNullOrEmpty(systemProfileIds)) {
      for (Object systemProfileId : systemProfileIds) {
        if (systemProfileId != null) {
          final String val = systemProfileId.toString();

          if (!possibleProfileIds.contains(val) && !val.contains(StringPool.SPACE)) {
            possibleProfileIds.add(val);
          }
        }
      }
    }

    if (includeNewProfiles) {
      for (NewLiferayProfile newLiferayProfile : newLiferayProfiles) {
        final String newId = newLiferayProfile.getId().content();

        if ((!CoreUtil.isNullOrEmpty(newId))
            && (!possibleProfileIds.contains(newId))
            && (!newId.contains(StringPool.SPACE))) {
          possibleProfileIds.add(newId);
        }
      }
    }

    return possibleProfileIds;
  }
  public static boolean canUseCustomLocation(NewLiferayPluginProjectOp op) {
    boolean retval = false;

    if (op.getProjectProvider().content(true).getShortName().equals("maven")) {
      retval = true;
    }

    return retval;
  }
  private static IStatus removeSampleCodeAndFiles(NewLiferayPluginProjectOp op) {
    IStatus status = org.eclipse.core.runtime.Status.OK_STATUS;

    final boolean includeSampleCode = op.getIncludeSampleCode().content();

    if (!includeSampleCode) {
      final IProject project = CoreUtil.getLiferayProject(op.getFinalProjectName().content());

      if (project != null && project.exists()) {
        ProjectCore.operate(project, RemoveSampleElementsOperation.class);

        // delete sample files: view.jsp, main.css, main.js
        try {
          final IWebProject webproject = LiferayCore.create(IWebProject.class, project);

          if (webproject != null) {
            final IFolder docroot = webproject.getDefaultDocrootFolder();

            final IFile[] sampleFiles = {
              docroot.getFile("view.jsp"),
              docroot.getFile("css/main.css"),
              docroot.getFile("js/main.js")
            };

            for (IFile file : sampleFiles) {
              if (file != null && file.exists()) {
                file.delete(true, new NullProgressMonitor());

                if (file.getParent().members().length == 0) {
                  CoreUtil.deleteResource(file.getParent());
                }
              }
            }
          }
        } catch (CoreException e) {
          ProjectCore.logError("Error deleting sample files.", e);
        }
      }
    }

    return status;
  }
  private static void updateProjectPrefs(final NewLiferayPluginProjectOp op) {
    try {
      final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ProjectCore.PLUGIN_ID);

      prefs.put(
          ProjectCore.PREF_DEFAULT_PLUGIN_PROJECT_BUILD_TYPE_OPTION,
          op.getProjectProvider().text());
      prefs.putBoolean(ProjectCore.PREF_INCLUDE_SAMPLE_CODE, op.getIncludeSampleCode().content());
      prefs.putBoolean(ProjectCore.PREF_CREATE_NEW_PORLET, op.getCreateNewPortlet().content());

      if ("maven".equalsIgnoreCase(op.getProjectProvider().text())) {
        prefs.put(ProjectCore.PREF_DEFAULT_PLUGIN_PROJECT_MAVEN_GROUPID, op.getGroupId().content());
      }

      prefs.flush();
    } catch (Exception e) {
      final String msg = "Error updating default project build type."; // $NON-NLS-1$
      ProjectCore.logError(msg, e);
    }
  }
  public static String getMavenParentPomVersion(
      NewLiferayPluginProjectOp op, String projectName, IPath path) {
    String retval = null;

    final File parentProjectDir = path.toFile();
    final IStatus locationStatus =
        op.getProjectProvider().content().validateProjectLocation(projectName, path);

    if (locationStatus.isOK() && parentProjectDir.exists() && parentProjectDir.list().length > 0) {
      List<String> version =
          op.getProjectProvider()
              .content()
              .getData("parentVersion", String.class, parentProjectDir);

      if (!version.isEmpty()) {
        retval = version.get(0);
      }
    }

    return retval;
  }
  public static String getProjectNameWithSuffix(final NewLiferayPluginProjectOp op) {
    final String projectName = op.getProjectName().content();

    String suffix = null;

    if (projectName != null) {
      if ("ant".equals(op.getProjectProvider().content(true).getShortName())) // $NON-NLS-1$
      {
        suffix = getPluginTypeSuffix(op.getPluginType().content(true));

        if (suffix != null) {
          // check if project name already contains suffix
          if (projectName.endsWith(suffix)) {
            suffix = null;
          }
        }
      }
    }

    return (projectName == null ? StringPool.EMPTY : projectName)
        + (suffix == null ? StringPool.EMPTY : suffix);
  }
  public static boolean supportsWebTypePlugin(NewLiferayPluginProjectOp op) {
    boolean retval = false;

    if (op.getProjectProvider().content(true).getShortName().equals("maven")) {
      retval = true;
    } else {
      SDK sdk = null;

      try {
        sdk = SDKUtil.getWorkspaceSDK();
      } catch (CoreException e) {
      }

      if (sdk == null) {
        final Path sdkLocation = op.getSdkLocation().content();

        if (sdkLocation != null) {
          sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
        }
      }

      if (sdk != null) {
        final Version version = new Version(sdk.getVersion());

        final boolean greaterThan700 =
            CoreUtil.compareVersions(version, ILiferayConstants.V700) >= 0;

        if (greaterThan700) {
          retval = true;
        }
      } else {
        retval = true;
      }
    }

    return retval;
  }
  public static void updateActiveProfilesValue(
      final NewLiferayPluginProjectOp op, final ElementList<Profile> profiles) {
    final StringBuilder sb = new StringBuilder();

    if (profiles.size() > 0) {
      for (Profile profile : profiles) {
        if (!profile.getId().empty()) {
          sb.append(profile.getId().content());
          sb.append(',');
        }
      }
    }

    // remove trailing ','
    op.setActiveProfilesValue(sb.toString().replaceAll("(.*),$", "$1"));
  }
  public static void updateLocation(final NewLiferayPluginProjectOp op, final Path baseLocation) {
    final String projectName = getProjectNameWithSuffix(op);

    if (baseLocation == null) {
      return;
    }

    final String lastSegment = baseLocation.lastSegment();

    if (baseLocation != null && baseLocation.segmentCount() > 0) {
      if (lastSegment.equals(projectName)) {
        return;
      }
    }

    final Path newLocation = baseLocation.append(projectName);

    op.setLocation(newLocation);
  }