Author: fbricon
Date: 2012-04-02 11:25:21 -0400 (Mon, 02 Apr 2012)
New Revision: 39966
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/jsf-jsfapi-21/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/jsf-jsfapi-21/pom.xml
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFUtils.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java
Log:
JBIDE-11416: fix JSF 2.1 dependencies ignored by JSFProjectConfigurator.
JSF Facet 2.1 now supported if run under Juno, otherwise, falls back on JSF Facet 2.0
https://issues.jboss.org/browse/JBIDE-11416
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java 2012-04-02
15:22:04 UTC (rev 39965)
+++
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java 2012-04-02
15:25:21 UTC (rev 39966)
@@ -12,7 +12,7 @@
import static org.jboss.tools.maven.jsf.configurators.JSFUtils.JSF_VERSION_1_1;
import static org.jboss.tools.maven.jsf.configurators.JSFUtils.JSF_VERSION_1_2;
-import static org.jboss.tools.maven.jsf.configurators.JSFUtils.JSF_VERSION_2_0;
+import static org.jboss.tools.maven.jsf.configurators.JSFUtils.*;
import java.util.List;
@@ -26,6 +26,7 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -67,6 +68,7 @@
private static final String WAR_SOURCE_FOLDER = "/src/main/webapp";
public static final IProjectFacet JSF_FACET;
+ public static final IProjectFacetVersion JSF_FACET_VERSION_2_1;
public static final IProjectFacetVersion JSF_FACET_VERSION_2_0;
public static final IProjectFacetVersion JSF_FACET_VERSION_1_2;
public static final IProjectFacetVersion JSF_FACET_VERSION_1_1;
@@ -78,6 +80,16 @@
JSF_FACET_VERSION_2_0 = JSF_FACET.getVersion(JSF_VERSION_2_0);
JSF_FACET_VERSION_1_2 = JSF_FACET.getVersion(JSF_VERSION_1_2); //$NON-NLS-1$
JSF_FACET_VERSION_1_1 = JSF_FACET.getVersion(JSF_VERSION_1_1); //$NON-NLS-1$
+
+ IProjectFacetVersion jsf21Version = null;
+ try {
+ jsf21Version = JSF_FACET.getVersion(JSF_VERSION_2_1);
+ } catch (Exception e) {
+ Activator.log("JSF 2.1 Facet is unavailable, fall back to 2.0");
+ jsf21Version = JSF_FACET_VERSION_2_0;
+ }
+ JSF_FACET_VERSION_2_1 = jsf21Version;
+
m2Facet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$
m2Version = m2Facet.getVersion("1.0"); //$NON-NLS-1$
}
@@ -204,7 +216,10 @@
else if (jsfVersionString.startsWith(JSF_VERSION_2_0)) {
facetVersion = JSF_FACET_VERSION_2_0;
}
-
+ else if (jsfVersionString.startsWith(JSF_VERSION_2_1)) {
+ facetVersion = JSF_FACET_VERSION_2_1;
+ }
+
if (facetVersion != null) {
IStatus status = facetVersion.getConstraint().check(fproj.getProjectFacets());
if (status.isOK()) {
@@ -240,6 +255,7 @@
defaultFacesConfig.delete(true, monitor);
}
//JBIDE-11413 : don't create an unnecessary lib folder
+ libFolder.refreshLocal(IResource.DEPTH_ZERO, monitor);
if (!libFolderAlreadyExists
&& libFolder.exists()
&& libFolder.members().length == 0){
@@ -308,7 +324,7 @@
version = Activator.getDefault().getDependencyVersion(mavenProject, JSF_API_GROUP_ID,
JSF_API_ARTIFACT_ID);
}
if (version == null) {
- //Check if there's a JSF 2 dependency
+ //Check if there's a JSF 2.x dependency
version = Activator.getDefault().getDependencyVersion(mavenProject, JSF_API2_GROUP_ID,
JSF_API_ARTIFACT_ID);
}
if (version == null) {
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFUtils.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFUtils.java 2012-04-02
15:22:04 UTC (rev 39965)
+++
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFUtils.java 2012-04-02
15:25:21 UTC (rev 39966)
@@ -23,7 +23,9 @@
import org.codehaus.plexus.util.IOUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
@@ -41,6 +43,8 @@
private static final String FACES_SERVLET_XPATH =
"//servlet[servlet-class=\"" + FACES_SERVLET + "\"]";
+ public static final String JSF_VERSION_2_1 = "2.1";
+
public static final String JSF_VERSION_2_0 = "2.0";
public static final String JSF_VERSION_1_2 = "1.2";
@@ -78,6 +82,7 @@
if (facesConfig != null) {
InputStream in = null;
try {
+ facesConfig.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
in = facesConfig.getContents();
FacesConfigQuickPeek peek = new FacesConfigQuickPeek(in);
version = peek.getVersion();
@@ -134,7 +139,7 @@
* Determines the JSF version by searching for the methods of
javax.faces.application.Application
* in the project's classpath.
* @param project : the java project to analyze
- * @return the JSF version (1.1, 1.2, 2.0) found in the classpath,
+ * @return the JSF version (1.1, 1.2, 2.0, 2.1) found in the classpath,
* or null if the project doesn't depend on JSF
*/
public static String getJSFVersionFromClasspath(IProject project) {
@@ -143,19 +148,20 @@
if (javaProject != null) {
IType type = null;
try {
- type = EclipseJavaUtil.findType(javaProject,
- "javax.faces.application.Application");//$NON-NLS-1$
+ type = EclipseJavaUtil.findType(javaProject,
"javax.faces.context.FacesContext");//$NON-NLS-1$
} catch (JavaModelException e) {
e.printStackTrace();
}
if (type != null) {
String[] emptyParams = new String[0];
- if (type.getMethod("getResourceHandler", emptyParams).exists() &&
- type.getMethod("getProjectStage", emptyParams).exists()) {
+ if (type.getMethod("isReleased", emptyParams).exists()) {
+ return JSF_VERSION_2_1;
+ }
+ if (type.getMethod("getAttributes", emptyParams).exists() &&
+ type.getMethod("getPartialViewContext", emptyParams).exists()) {
return JSF_VERSION_2_0;
}
- if (type.getMethod("getELResolver", emptyParams).exists() &&
- type.getMethod("getExpressionFactory", emptyParams).exists()) {
+ if (type.getMethod("getELContext", emptyParams).exists()) {
return JSF_VERSION_1_2;
}
version = JSF_VERSION_1_1;
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/jsf-jsfapi-21/pom.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/jsf-jsfapi-21/pom.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/jsf-jsfapi-21/pom.xml 2012-04-02
15:25:21 UTC (rev 39966)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.tools.maven.tests</groupId>
+ <artifactId>jsf-jsfapi</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>war</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <!-- not in central, hence requires the JBoss repo -->
+ <artifactId>jsf-api</artifactId>
+ <version>2.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <!-- You should seriously consider using a repository manager or declare repositories
in your settings.xml.
+ See
http://www.sonatype.com/people/2009/02/why-putting-repositories-in-your-p...
-->
+ <repository>
+ <!-- The JBoss Public repository is a composite repository of several major
repositories.
+ See
http://community.jboss.org/wiki/MavenGettingStarted-Users -->
+ <id>jboss-public-repository</id>
+ <
url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <!-- You can disable snapshot resolution to speed up your builds -->
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+</project>
+
Modified:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java 2012-04-02
15:22:04 UTC (rev 39965)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java 2012-04-02
15:25:21 UTC (rev 39966)
@@ -1,5 +1,7 @@
package org.jboss.tools.maven.configurators.tests;
+import static org.jboss.tools.maven.jsf.configurators.JSFUtils.JSF_VERSION_2_1;
+
import java.io.File;
import org.eclipse.core.resources.IFile;
@@ -10,6 +12,7 @@
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.tests.common.WorkspaceHelpers;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.maven.jsf.MavenJSFConstants;
import org.jboss.tools.maven.jsf.configurators.JSFProjectConfigurator;
@@ -145,8 +148,6 @@
}
-
-
@Test
public void testJBIDE11413_WebInfLib() throws Exception {
IProject[] projects = importProjects("projects/jsf/JBIDE-11413", new
String[]{ "jsf-nolib/pom.xml","jsf-lib/pom.xml"}, new
ResolverConfiguration());
@@ -162,6 +163,24 @@
assertTrue("WEB-INF/lib was removed from the project!", lib.exists());
}
+ @Test
+ public void testJBIDE11416_supportJSF21Dependencies() throws Exception {
+ IProject project = importProject("projects/jsf/jsf-jsfapi-21/pom.xml");
+ waitForJobsToComplete(new NullProgressMonitor());
+ assertNoErrors(project);
+
+ boolean isJsf21available = false;
+ try {
+ isJsf21available = null !=
ProjectFacetsManager.getProjectFacet("jst.jsf").getVersion(JSF_VERSION_2_1);
+ } catch (Exception e) {
+ //ignore
+ }
+
+ IProjectFacetVersion expectedJsfVersion = isJsf21available?
JSFProjectConfigurator.JSF_FACET_VERSION_2_1
+ :JSFProjectConfigurator.JSF_FACET_VERSION_2_0;
+ assertIsJSFProject(project,expectedJsfVersion);
+ }
+
private void assertHasJSFConfigurationError(IProject project, String message) throws
Exception {
WorkspaceHelpers.assertErrorMarker(MavenJSFConstants.JSF_CONFIGURATION_ERROR_MARKER_ID,
message, 1, "", project);
}