コード例 #1
0
  public void setupNewProject(IDataModel dataModel, IFacetedProjectWorkingCopy facetedProject) {
    ProjectUtil.setGenerateDD(dataModel, true);

    FacetDataModelMap map = (FacetDataModelMap) dataModel.getProperty(FACET_DM_MAP);
    IDataModel webFacetModel = map.getFacetDataModel(IJ2EEFacetConstants.DYNAMIC_WEB_FACET.getId());

    webFacetModel.setStringProperty(
        IWebFacetInstallDataModelProperties.CONFIG_FOLDER,
        IPluginFacetConstants.PORTLET_PLUGIN_SDK_CONFIG_FOLDER);
    webFacetModel.setStringProperty(
        IWebFacetInstallDataModelProperties.SOURCE_FOLDER,
        IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER);
    IDataModel javaFacetModel = map.getFacetDataModel(JavaFacet.FACET.getId());
    javaFacetModel.setStringProperty(
        IJavaFacetInstallDataModelProperties.SOURCE_FOLDER_NAME,
        IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER);
    javaFacetModel.setStringProperty(
        IJavaFacetInstallDataModelProperties.DEFAULT_OUTPUT_FOLDER_NAME,
        IPluginFacetConstants.PORTLET_PLUGIN_SDK_DEFAULT_OUTPUT_FOLDER);

    if (dataModel.isNestedModel(PLUGIN_FRAGMENT_DM)) {
      dataModel.removeNestedModel(PLUGIN_FRAGMENT_DM);
    }

    // need to allow portlet framework to do any additional configuration

    IPortletFramework portletFramework =
        (IPortletFramework) dataModel.getProperty(PORTLET_FRAMEWORK);

    portletFramework.configureNewProject(dataModel, facetedProject);
  }
  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();
      }
    }
  }