Пример #1
0
  public static Object getRuntimeAdapter(
      org.eclipse.wst.common.project.facet.core.runtime.IRuntime facetRuntime,
      Class<?> adapterClass) {

    String runtimeId = facetRuntime.getProperty("id");

    for (org.eclipse.wst.server.core.IRuntime runtime : ServerCore.getRuntimes()) {
      if (runtime.getId().equals(runtimeId)) {

        if (IRuntime.class.equals(adapterClass)) {
          return runtime;
        }

        IRuntimeWorkingCopy runtimeWC = null;

        if (!runtime.isWorkingCopy()) {
          runtimeWC = runtime.createWorkingCopy();
        } else {
          runtimeWC = (IRuntimeWorkingCopy) runtime;
        }

        return (ILiferayRuntime) runtimeWC.loadAdapter(adapterClass, null);
      }
    }

    return null;
  }
  private Map<String, IRuntime> getServerRuntimes(IProjectFacetVersion facetVersion) {
    Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> runtimesSet;
    if (facetVersion == null) {
      runtimesSet = RuntimeManager.getRuntimes();
    } else {
      runtimesSet = RuntimeManager.getRuntimes(Collections.singleton(facetVersion));
    }

    Map<String, IRuntime> runtimesMap = new LinkedHashMap<>();
    for (org.eclipse.wst.common.project.facet.core.runtime.IRuntime r : runtimesSet) {
      IRuntime serverRuntime = FacetUtil.getRuntime(r);
      if (serverRuntime != null) {
        runtimesMap.put(r.getLocalizedName(), serverRuntime);
      }
    }
    return runtimesMap;
  }
  @Override
  public boolean performOk() {
    final String selectedRuntimeName = this.runtimeCombo.getText();

    if (!CoreUtil.isNullOrEmpty(selectedRuntimeName)) {
      final org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime =
          RuntimeManager.getRuntime(selectedRuntimeName);

      if (runtime != null) {
        final IFacetedProject fProject = ProjectUtil.getFacetedProject(getProject());

        final org.eclipse.wst.common.project.facet.core.runtime.IRuntime primaryRuntime =
            fProject.getPrimaryRuntime();

        if (!runtime.equals(primaryRuntime)) {
          Job job = new WorkspaceJob("Setting targeted runtime for project.") // $NON-NLS-1$
              {
                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                  IStatus retval = Status.OK_STATUS;

                  try {
                    fProject.setTargetedRuntimes(Collections.singleton(runtime), monitor);
                    fProject.setPrimaryRuntime(runtime, monitor);
                  } catch (Exception e) {
                    retval =
                        ProjectUIPlugin.createErrorStatus(
                            "Could not set targeted runtime", e); // $NON-NLS-1$
                  }

                  return retval;
                }
              };

          job.schedule();
        }
      } else {
        return false;
      }
    }

    return true;
  }
 /** @see IValidator#validate(Object, Object) */
 public Map<String, IStatus> validate(Object value, Object context) {
   final String deploymentType = value.toString();
   if (!ISeamFacetDataModelProperties.DEPLOY_AS_WAR.equals(deploymentType)) {
     Object runtimeName =
         model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
     if (runtimeName != null) {
       IRuntime rt = RuntimeManager.getRuntime(runtimeName.toString());
       if (!rt.supports(EJB_30) || !rt.supports(EAR_50)) {
         return SeamValidatorFactory.createErrormessage(
             propertyName,
             new Status(
                 IStatus.ERROR,
                 SeamCorePlugin.PLUGIN_ID,
                 NLS.bind(
                     SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_CANNOT_USE_SELECTED_DEPLOYMENT6,
                     new String[] {deploymentType.toUpperCase(), runtimeName.toString()})));
       }
     }
   }
   return SeamValidatorFactory.NO_ERRORS;
 }
  protected void installWARFacet(
      final String j2eeVersionText,
      final String warProjectName,
      final IRuntime runtime,
      final IProgressMonitor monitor) {
    IProject project = ProjectUtilities.getProject(warProjectName);
    if (project.exists()) return;

    IFacetedProjectWorkingCopy fpjwc = null;
    try {
      fpjwc = FacetedProjectFramework.createNewProject();

      fpjwc.setProjectName(warProjectName);

      if (runtime != null) {
        fpjwc.setTargetedRuntimes(Collections.singleton(runtime));
      }
      ArrayList<IProjectFacet> requiredFacets = new ArrayList<IProjectFacet>();
      requiredFacets.add(JavaFacetUtils.JAVA_FACET);
      requiredFacets.add(IJ2EEFacetConstants.DYNAMIC_WEB_FACET);
      final Collection<IProjectFacet> fixedFacets = requiredFacets;
      fpjwc.setFixedProjectFacets(new HashSet<IProjectFacet>(fixedFacets));
      // fpjwc.setFixedProjectFacets( Collections.singleton( JavaFacetUtils.JAVA_FACET) );
      fpjwc.setSelectedPreset(FacetedProjectFramework.DEFAULT_CONFIGURATION_PRESET_ID);

      if (j2eeVersionText != null) {
        final IProjectFacetVersion defaultWarFacetVersion =
            fpjwc.getProjectFacetVersion(IJ2EEFacetConstants.DYNAMIC_WEB_FACET);

        if (!defaultWarFacetVersion.getVersionString().equals(j2eeVersionText)) {
          String presetId = null;

          if (runtime != null) {
            for (IRuntimeComponent rc : runtime.getRuntimeComponents()) {
              presetId =
                  RuntimePresetMappingRegistry.INSTANCE.getPresetID(
                      rc.getRuntimeComponentType().getId(),
                      rc.getRuntimeComponentVersion().getVersionString(),
                      IJ2EEFacetConstants.DYNAMIC_WEB_FACET.getId(),
                      j2eeVersionText);

              if (presetId != null) {
                break;
              }
            }
          }

          final IProjectFacetVersion warFacetVersion =
              IJ2EEFacetConstants.DYNAMIC_WEB_FACET.getVersion(j2eeVersionText);

          // Note that the next call is necessary even if a preset is going to be selected
          // later since it allows the dynamic preset to adjust for the war facet version.
          ArrayList<IProjectFacetVersion> requiredFacetVersions =
              new ArrayList<IProjectFacetVersion>();
          requiredFacetVersions.add(JavaFacetUtils.JAVA_FACET.getVersion("1.5")); // $NON-NLS-1$
          requiredFacetVersions.add(warFacetVersion);
          final Collection<IProjectFacetVersion> fixedFacetVersions = requiredFacetVersions;
          fpjwc.setProjectFacets(new HashSet<IProjectFacetVersion>(fixedFacetVersions));

          // fpjwc.setProjectFacets( Collections.singleton( warFacetVersion ) );

          if (presetId != null) {
            fpjwc.setSelectedPreset(presetId);
          }
        }

        Set<IFacetedProject.Action> actions = fpjwc.getProjectFacetActions();
        for (IFacetedProject.Action action : actions) {
          Object actionConfig = action.getConfig();
          if (actionConfig instanceof JavaFacetInstallConfig) {
            JavaFacetInstallConfig c = (JavaFacetInstallConfig) actionConfig;
            c.setDefaultOutputFolder(
                new Path(
                    J2EEPlugin.getDefault()
                        .getJ2EEPreferences()
                        .getString(Keys.DYN_WEB_OUTPUT_FOLDER)));
          }
        }
      }
      try {
        fpjwc.commitChanges(null);
      } catch (CoreException e) {
        J2EEPlugin.logError(e);
      }
    } finally {
      if (fpjwc != null) {
        fpjwc.dispose();
      }
    }
  }
Пример #6
0
 public static IRuntime getRuntime(
     org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime) {
   return ServerCore.findRuntime(runtime.getProperty("id"));
 }
  private void initTargetRuntime() {
    if (_ifpwc == null) {
      _settingsGroup
          .getTargetRuntimesList()
          .setSelection(new StructuredSelection(SwitchYardSettingsGroup.NULL_RUNTIME));
      _settingsGroup.getTargetRuntimesList().getControl().setEnabled(false);
      return;
    } else {
      _ifpwc = SharedWorkingCopyManager.getWorkingCopy(_ifp);
    }
    final IRuntime runtime = _ifpwc.getPrimaryRuntime();
    if (runtime == null) {
      _settingsGroup
          .getTargetRuntimesList()
          .setSelection(new StructuredSelection(SwitchYardSettingsGroup.NULL_RUNTIME));
    } else {
      for (IRuntimeComponent component : runtime.getRuntimeComponents()) {
        if (SWITCHYARD_RUNTIME_ID.equals(component.getRuntimeComponentType().getId())
            || FSW_RUNTIME_ID.equals(component.getRuntimeComponentType().getId())) {
          _settingsGroup
              .getTargetRuntimesList()
              .setSelection(new StructuredSelection(component), true);
        }
      }
    }
    _settingsGroup
        .getTargetRuntimesList()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (selection.isEmpty()
                    || selection.getFirstElement() == SwitchYardSettingsGroup.NULL_RUNTIME) {
                  final IRuntime primaryRuntime = _ifpwc.getPrimaryRuntime();
                  if (primaryRuntime != null && !_configuredRuntimes.contains(primaryRuntime)) {
                    _ifpwc.removeTargetedRuntime(primaryRuntime);
                  } else if (primaryRuntime != null
                      && selection.getFirstElement() == SwitchYardSettingsGroup.NULL_RUNTIME) {
                    _ifpwc.removeTargetedRuntime(primaryRuntime);
                  }
                  _settingsGroup
                      .getIntegrationVersionsList()
                      .setSelection(new StructuredSelection(""));
                  _switchYardProject.setIntegrationVersion(null);
                  _settingsGroup.getKieVersionsList().setSelection(new StructuredSelection(""));
                  _switchYardProject.setKieVersion(null);
                } else {
                  final IRuntimeComponent component =
                      (IRuntimeComponent) selection.getFirstElement();
                  final IRuntime runtime = component.getRuntime();
                  if (!_ifpwc.isTargeted(
                      runtime)) { // if it's already targeted, we don't need to add it
                    _ifpwc.addTargetedRuntime(runtime);
                  }
                  _ifpwc.setPrimaryRuntime(runtime);

                  if (component != null) {
                    ArtifactVersion intVersion = _settingsGroup.getIntegVersion(component);
                    if (intVersion != null) {
                      _settingsGroup
                          .getIntegrationVersionsList()
                          .setSelection(new StructuredSelection(intVersion));
                    } else {
                      _settingsGroup
                          .getIntegrationVersionsList()
                          .setSelection(new StructuredSelection(""));
                    }
                    ArtifactVersion kieVersion = _settingsGroup.getKieVersion(component);
                    if (kieVersion != null) {
                      _settingsGroup
                          .getKieVersionsList()
                          .setSelection(new StructuredSelection(kieVersion));
                    } else {
                      _settingsGroup.getKieVersionsList().setSelection(new StructuredSelection(""));
                    }
                  }
                }
              }
            });
  }