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(); } } }
/** * Return the resource locator for this item provider's resources. * <!-- begin-user-doc --> * <!-- * end-user-doc --> */ @Override public ResourceLocator getResourceLocator() { return J2EEPlugin.getDefault(); }