protected void installAndAddModuletoWAR( String j2eeVersionText, String warProjectName, IRuntime runtime, IProject moduleProject, String moduleURI, IProgressMonitor monitor) { installWARFacet(j2eeVersionText, warProjectName, runtime, monitor); final IVirtualComponent c = ComponentCore.createComponent(moduleProject); final IProject warProject = ProjectUtilities.getProject(warProjectName); final IVirtualComponent warComp = ComponentCore.createComponent(warProject); if (UIContextDetermination.getCurrentContext() == UIContextDetermination.HEADLESS_CONTEXT) { boolean isValidating = RendererFactory.getDefaultRendererFactory().isValidating(); try { if (isValidating) { RendererFactory.getDefaultRendererFactory().setValidating(false); } addToWar(warComp, c, moduleURI); } finally { RendererFactory.getDefaultRendererFactory().setValidating(isValidating); } } else { addToWar(warComp, c, moduleURI); } }
/** * Create a folder relative to the project based on aProjectRelativePathString. * * @param aProjectRelativePath * @return * @throws CoreException * @since 1.0.0 */ public IFolder createFolder(IPath aProjectRelativePath) throws CoreException { if (aProjectRelativePath != null && !aProjectRelativePath.isEmpty()) { IFolder folder = getWorkspace().getRoot().getFolder(getProjectPath().append(aProjectRelativePath)); if (!folder.exists()) { ProjectUtilities.ensureContainerNotReadOnly(folder); folder.create(true, true, null); } return folder; } return null; }
/** * Add the nature id to the project. * * @param proj * @param natureId * @throws CoreException * @since 1.0.0 */ protected static void addNatureToProject(IProject proj, String natureId) throws CoreException { ProjectUtilities.addNatureToProject(proj, natureId); }
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(); } } }
private Collection getWSServiceRefsFromSelection() { IStructuredSelection initSel = getInitialSelection(); if (initSel != null && initSel.size() == 1) { Object obj = initSel.getFirstElement(); ServiceRef serviceRef = null; if (obj instanceof ServiceRef) { // Client ServiceRef serviceRef = (ServiceRef) obj; serviceRefName_ = serviceRef.getServiceRefName(); project_ = ProjectUtilities.getProject(serviceRef); } else if (obj instanceof WebServiceNavigatorGroupType) { WebServiceNavigatorGroupType wsngt = (WebServiceNavigatorGroupType) obj; serviceRef = wsngt.getServiceRef(); serviceRefName_ = serviceRef.getServiceRefName(); project_ = ProjectUtilities.getProject(serviceRef); } else if (obj instanceof IFile) { Resource res = WorkbenchResourceHelperBase.getResource((IFile) obj, true); Collection serviceRefs = null; if (res instanceof WebServicesResource) { // webservicesclient.xml for J2EE 1.3 WebServicesResource wsRes = (WebServicesResource) res; serviceRefs = wsRes.getWebServicesClient().getServiceRefs(); if (!serviceRefs.isEmpty()) { ServiceRef ref = (ServiceRef) ((List) serviceRefs).get(0); serviceRefName_ = ref.getServiceRefName(); project_ = ProjectUtilities.getProject(ref); return serviceRefs; } return null; } else { if (res instanceof WebAppResource) { // web.xml for J2EE 1.4 WebAppResource webAppRes = (WebAppResource) res; serviceRefs = webAppRes.getWebApp().getServiceRefs(); } else if (res instanceof EJBResource) { EJBResource ejbRes = (EJBResource) res; serviceRefs = webServicesManager_.getServiceRefs(ejbRes.getEJBJar()); } else if (res instanceof ApplicationClientResource) { ApplicationClientResource appClientRes = (ApplicationClientResource) res; serviceRefs = webServicesManager_.getServiceRefs( appClientRes .getApplicationClient()); // appClientRes.getApplicationClient().getServiceRefs(); } if (serviceRefs != null && serviceRefs.size() > 0) { ServiceRef ref = (ServiceRef) ((List) serviceRefs).get(0); serviceRefName_ = ref.getServiceRefName(); project_ = ProjectUtilities.getProject(ref); } return serviceRefs; } } // This section is for obtaining all the serviceRefs from the project, given that the initial // selection // was from the J2EE view (ServiceRef or WebServiceNavigatorGroupType), it will select the // right serviceRef if (project_ == null) { project_ = getProject(); } if (project_ == null) { return null; } if (J2EEUtils.isWebComponent(project_)) { WebArtifactEdit webEdit = null; try { IVirtualComponent vc = ComponentCore.createComponent(project_); webEdit = WebArtifactEdit.getWebArtifactEditForRead(vc); if (webEdit != null) { WebApp webApp = (WebApp) webEdit.getDeploymentDescriptorRoot(); if (webApp != null) { return webServicesManager_.getServiceRefs(webApp); } } } finally { if (webEdit != null) webEdit.dispose(); } } else if (J2EEUtils.isEJBComponent(project_)) { IVirtualComponent vc = ComponentCore.createComponent(project_); EJBJar ejbJar = EJBArtifactEditUtilities.getEJBJar(vc); if (ejbJar != null) { return webServicesManager_.getServiceRefs(ejbJar); } } else if (J2EEUtils.isAppClientComponent(project_)) { IVirtualComponent vc = ComponentCore.createComponent(project_); AppClientArtifactEdit appEdit = null; try { appEdit = AppClientArtifactEdit.getAppClientArtifactEditForRead(vc); if (appEdit != null) { ApplicationClient appClient = appEdit.getApplicationClient(); if (appClient != null) { return webServicesManager_.getServiceRefs(appClient); } } } finally { if (appEdit != null) { appEdit.dispose(); } } } } return null; }