Ejemplo n.º 1
0
  @Override
  public Status validate() {
    final Value<String> packagePath = context().find(ServiceBuilder.class).getPackagePath();
    String packPathVal = packagePath.getContent();

    if (packPathVal == null) {
      return Status.createErrorStatus(Msgs.packagePathNotEmpty);
    }

    // Use standard java conventions to validate the package name
    IStatus javaStatus =
        JavaConventions.validatePackageName(
            packPathVal, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5);

    if (javaStatus.getSeverity() == IStatus.ERROR) {
      return Status.createErrorStatus(
          J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage());
    }

    if (javaStatus.getSeverity() == IStatus.WARNING) {
      return Status.createWarningStatus(
          J2EECommonMessages.ERR_JAVA_PACKAGE_NAME_WARNING + javaStatus.getMessage());
    }

    return Status.createOkStatus();
  }
  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 final Status execute(final UpgradeLiferayProjectsOp op, final ProgressMonitor pm) {
    Status retval = Status.createOkStatus();

    final IProgressMonitor monitor = ProgressMonitorBridge.create(pm);

    monitor.beginTask(
        "Upgrading Liferay plugin projects (this process may take several minutes)", 30);

    final ElementList<NamedItem> projectItems = op.getSelectedProjects();
    final ElementList<NamedItem> upgradeActions = op.getSelectedActions();
    final String runtimeName = op.getRuntimeName().content();
    final List<String> projectItemNames = new ArrayList<String>();
    final List<String> projectActionItems = new ArrayList<String>();

    for (NamedItem projectItem : projectItems) {
      projectItemNames.add(projectItem.getName().content());
    }

    for (NamedItem upgradeAction : upgradeActions) {
      projectActionItems.add(upgradeAction.getName().content());
    }

    Status[] upgradeStatuses =
        performUpgrade(projectItemNames, projectActionItems, runtimeName, monitor);

    for (Status s : upgradeStatuses) {
      if (!s.ok()) {
        retval =
            Status.createErrorStatus(
                "Some upgrade actions failed, please see Eclipse error log for more details");
      }
    }

    return retval;
  }
  @Override
  protected Status compute() {
    Status retval = Status.createOkStatus();

    String serverName = op().getBundleName().content();

    if (CoreUtil.empty(serverName)) {
      retval = Status.createErrorStatus("The Server Name is empty. Please input one.");

      return retval;
    }

    if (ServerPlugin.isNameInUse(null, serverName)) {
      retval =
          Status.createErrorStatus(
              "The Server Name \""
                  + serverName
                  + "\"+ is already in use. Specify a different name.");

      return retval;
    }

    return retval;
  }
  @Override
  protected Status compute() {
    if (!this.versionCompatibilityService.compatible() && !context(Property.class).empty()) {
      final String message;

      final Version version = this.versionCompatibilityService.version();
      final String versioned = this.versionCompatibilityService.versioned();

      if (version == null) {
        message = versionConstraintTargetNotFoundMessage.text();
      } else {
        message = notCompatibleWithVersionMessage.format(version.toString(), versioned);
      }

      return Status.createErrorStatus(message);
    }

    return Status.createOkStatus();
  }
  @Override
  protected Status compute() {
    Status retval = Status.createOkStatus();

    final JavaPackageName packageName = op().getPackageName().content(true);

    if (packageName != null) {
      int packageNameStatus =
          JavaConventions.validatePackageName(
                  packageName.toString(), CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7)
              .getSeverity();

      if (packageNameStatus == IStatus.ERROR) {
        retval = Status.createErrorStatus("Invalid package name");
      }
    }

    return retval;
  }
Ejemplo n.º 7
0
  protected final Status validateExtensions(final Path path) {
    if (this.fileExtensionsService != null) {
      final String fileName = path.lastSegment();

      if (fileName != null) {
        final List<String> extensions = this.fileExtensionsService.extensions();
        final int count = (extensions == null ? 0 : extensions.size());

        if (count > 0) {
          final String trimmedFileName = fileName.trim();
          final int lastdot = trimmedFileName.lastIndexOf('.');
          final String extension;

          if (lastdot == -1) {
            extension = "";
          } else {
            extension = trimmedFileName.substring(lastdot + 1);
          }

          boolean match = false;

          if (extension != null && extension.length() != 0) {
            for (String ext : extensions) {
              if (extension.equalsIgnoreCase(ext)) {
                match = true;
                break;
              }
            }
          }

          if (!match) {
            final String message;

            if (count == 1) {
              message = invalidFileExtensionOne.format(trimmedFileName, extensions.get(0));
            } else if (count == 2) {
              message =
                  invalidFileExtensionTwo.format(
                      trimmedFileName, extensions.get(0), extensions.get(1));
            } else {
              final StringBuilder buf = new StringBuilder();

              for (String ext : extensions) {
                if (buf.length() != 0) {
                  buf.append(", ");
                }

                buf.append(ext);
              }

              message = invalidFileExtensionMultiple.format(trimmedFileName, buf.toString());
            }

            return Status.createErrorStatus(message);
          }
        }
      }
    }

    return Status.createOkStatus();
  }