public IProjectFacetVersion getWebFacetVersion(IProject project) { IFile webXml; String customWebXml = getCustomWebXml(project); if (customWebXml == null) { webXml = project.getFolder(getWarSourceDirectory()).getFile(WEB_XML); } else { webXml = project.getFile(customWebXml); } if (webXml.isAccessible()) { try { InputStream is = webXml.getContents(); try { JavaEEQuickPeek jqp = new JavaEEQuickPeek(is); switch (jqp.getVersion()) { case J2EEVersionConstants.WEB_2_2_ID: return WebFacetUtils.WEB_22; case J2EEVersionConstants.WEB_2_3_ID: return WebFacetUtils.WEB_23; case J2EEVersionConstants.WEB_2_4_ID: return WebFacetUtils.WEB_24; case J2EEVersionConstants.WEB_2_5_ID: return WebFacetUtils.WEB_FACET.getVersion("2.5"); // MNGECLIPSE-1978 case WEB_3_0_ID: // JavaEEQuickPeek will return this value only if WTP version >= 3.2 return WebFacetUtils.WEB_FACET.getVersion("3.0"); // only exists in WTP version >= 3.2 } } finally { is.close(); } } catch (IOException ex) { // expected } catch (CoreException ex) { // expected } } // MNGECLIPSE-1978 If no web.xml found and the project depends on some java EE 6 jar and WTP >= // 3.2, then set web facet to 3.0 if (WTPProjectsUtil.isJavaEE6Available() && WTPProjectsUtil.hasInClassPath(project, "javax.servlet.annotation.WebServlet")) { return WebFacetUtils.WEB_FACET.getVersion("3.0"); } // MNGECLIPSE-984 web.xml is optional for 2.5 Web Projects return WTPProjectsUtil.DEFAULT_WEB_FACET; // We don't want to prevent the project creation when the java compiler level is < 5, we coud // try that instead : // IProjectFacetVersion javaFv = // JavaFacetUtils.compilerLevelToFacet(JavaFacetUtils.getCompilerLevel(project)); // return (JavaFacetUtils.JAVA_50.compareTo(javaFv) > // 0)?WebFacetUtils.WEB_24:WebFacetUtils.WEB_25; }
/** * @param dependencyMavenProjectFacade * @param monitor * @return * @throws CoreException */ protected IProject preConfigureDependencyProject( IMavenProjectFacade dependencyMavenProjectFacade, IProgressMonitor monitor) throws CoreException { IProject dependency = dependencyMavenProjectFacade.getProject(); MavenProject mavenDependency = dependencyMavenProjectFacade.getMavenProject(monitor); String depPackaging = dependencyMavenProjectFacade.getPackaging(); // jee dependency has not been configured yet - i.e. it has no JEE facet- if (JEEPackaging.isJEEPackaging(depPackaging) && !WTPProjectsUtil.isJavaEEProject(dependency)) { IProjectConfiguratorDelegate delegate = ProjectConfiguratorDelegateFactory.getProjectConfiguratorDelegate( dependencyMavenProjectFacade.getPackaging()); if (delegate != null) { // Lets install the proper facets try { delegate.configureProject(dependency, mavenDependency, monitor); } catch (MarkedException ex) { // Markers already have been created for this exception, no more to do. return dependency; } } } else { // XXX Probably should create a UtilProjectConfiguratorDelegate configureWtpUtil(dependency, mavenDependency, monitor); } return dependency; }
protected void configureWtpUtil( IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { // Adding utility facet on JEE projects is not allowed if (WTPProjectsUtil.isJavaEEProject(project)) { return; } IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); Set<Action> actions = new LinkedHashSet<Action>(); installJavaFacet(actions, project, facetedProject); if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_FACET)) { actions.add( new IFacetedProject.Action( IFacetedProject.Action.Type.INSTALL, WTPProjectsUtil.UTILITY_10, null)); } else if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_10)) { actions.add( new IFacetedProject.Action( IFacetedProject.Action.Type.VERSION_CHANGE, WTPProjectsUtil.UTILITY_10, null)); } if (!actions.isEmpty()) { facetedProject.modify(actions, monitor); } // MNGECLIPSE-904 remove tests folder links for utility jars // TODO handle modules in a parent pom (the following doesn't work) removeTestFolderLinks(project, mavenProject, monitor, "/"); // Remove "library unavailable at runtime" warning. setNonDependencyAttributeToContainer(project, monitor); }
/** * Link a project's file to a specific deployment destination. Existing links will be deleted * beforehand. * * @param project * @param customFile the existing file to deploy * @param targetRuntimePath the target runtime/deployment location of the file * @param monitor * @throws CoreException */ protected void linkFile( IProject project, String customFile, String targetRuntimePath, IProgressMonitor monitor) throws CoreException { IPath runtimePath = new Path(targetRuntimePath); // We first delete any existing links WTPProjectsUtil.deleteLinks(project, runtimePath, monitor); if (customFile != null) { // Create the new link IVirtualComponent component = ComponentCore.createComponent(project); if (component != null) { IVirtualFile virtualCustomFile = component.getRootFolder().getFile(runtimePath); IPath virtualCustomFilePath = new Path(customFile); virtualCustomFile.createLink(virtualCustomFilePath, 0, monitor); } } }