コード例 #1
0
  @Test
  public void testNewLiferayModuleProjectNewProperties() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();

    op.setProjectName("test-properties-in-portlet");

    op.setProjectTemplateName("portlet");
    op.setComponentName("Test");

    PropertyKey pk = op.getPropertyKeys().insert();

    pk.setName("property-test-key");
    pk.setValue("property-test-value");

    Status exStatus =
        NewLiferayModuleProjectOpMethods.execute(
            op, ProgressMonitorBridge.create(new NullProgressMonitor()));

    assertEquals("OK", exStatus.message());

    IProject modPorject = CoreUtil.getProject(op.getProjectName().content());
    modPorject.open(new NullProgressMonitor());

    SearchFilesVisitor sv = new SearchFilesVisitor();
    List<IFile> searchFiles = sv.searchFiles(modPorject, "TestPortlet.java");
    IFile componentClassFile = searchFiles.get(0);

    assertEquals(componentClassFile.exists(), true);

    String actual = CoreUtil.readStreamToString(componentClassFile.getContents());

    assertTrue(actual, actual.contains("\"property-test-key=property-test-value\""));
  }
コード例 #2
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();
  }
コード例 #3
0
  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;
  }
コード例 #4
0
  private final void refreshValidation() {
    final Status st = this.part.validation();

    if (st.severity() == Status.Severity.ERROR) {
      setMessage(st.message(), ERROR);
      setPageComplete(false);
    } else if (st.severity() == Status.Severity.WARNING) {
      setMessage(st.message(), WARNING);
      setPageComplete(true);
    } else {
      setMessage(null);
      setPageComplete(true);
    }
  }
コード例 #5
0
  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;
  }
コード例 #6
0
  @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();
  }
コード例 #7
0
  @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;
  }
コード例 #8
0
  @Override
  protected Object run(Presentation context) {
    final NewModuleFragmentOp op =
        context.part().getModelElement().nearest(NewModuleFragmentOp.class);

    final ElementList<OverrideFilePath> currentFiles = op.getOverrideFiles();

    final String projectName = op.getProjectName().content();

    final OSGiBundleFileSelectionDialog dialog =
        new OSGiBundleFileSelectionDialog(null, currentFiles, projectName);

    final String runtimeName = op.getLiferayRuntimeName().content();

    final IRuntime runtime = ServerUtil.getRuntime(runtimeName);

    final IPath temp = GradleCore.getDefault().getStateLocation();

    dialog.setTitle("Add files from OSGi bundle to override");

    final PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation());
    String currentOSGiBundle = op.getHostOsgiBundle().content();

    if (!currentOSGiBundle.endsWith("jar")) {
      currentOSGiBundle = currentOSGiBundle + ".jar";
    }

    ServerUtil.getModuleFileFrom70Server(runtime, currentOSGiBundle, temp);

    if (portalBundle != null) {
      try {
        File module =
            portalBundle.getOSGiBundlesDir().append("modules").append(currentOSGiBundle).toFile();

        if (!module.exists()) {
          module = GradleCore.getDefault().getStateLocation().append(currentOSGiBundle).toFile();
        }

        dialog.setInput(module);
      } catch (Exception e) {
      }
    }

    if (dialog.open() == Window.OK) {
      Object[] selected = dialog.getResult();

      for (int i = 0; i < selected.length; i++) {
        OverrideFilePath file = op.getOverrideFiles().insert();
        file.setValue(selected[i].toString());
      }
    }

    return Status.createOkStatus();
  }
コード例 #9
0
  @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;
  }
コード例 #10
0
 @Override
 public Status problem(Value<?> value) {
   return Status.createOkStatus();
 }
コード例 #11
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();
  }