Author: fbricon
Date: 2012-02-13 06:09:55 -0500 (Mon, 13 Feb 2012)
New Revision: 38651
Added:
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/utils/xpl/
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/utils/xpl/JSFAppConfigUtils.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/my-faces-config.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/web.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/AbstractMavenConfiguratorTest.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java
Log:
JBIDE-10831 : detect faces-config from javax.faces.CONFIG_FILES context param declared in
web.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/JSFProjectConfigurator.java 2012-02-13
10:41:07 UTC (rev 38650)
+++
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFProjectConfigurator.java 2012-02-13
11:09:55 UTC (rev 38651)
@@ -172,21 +172,23 @@
markerManager.deleteMarkers(fproj.getProject(),
MavenJSFConstants.JSF_CONFIGURATION_ERROR_MARKER_ID);
if (!fproj.hasProjectFacet(JSF_FACET)) {
-
+ IProject project = fproj.getProject();
//JBIDE-10785 : refresh parent to prevent
// org.osgi.service.prefs.BackingStoreException: Resource
'/parent/web/.settings' does not exist.
MavenUtil.refreshParent(mavenProject);
- String warSourceDir = getWarSourceDirectory(mavenProject,fproj.getProject());
+ String warSourceDir = getWarSourceDirectory(mavenProject,project);
String facesConfigPath = "WEB-INF/faces-config.xml";
- IFile facesConfig =
fproj.getProject().getFolder(warSourceDir).getFile(facesConfigPath);
- IFile generatedFacesConfig =
ProjectUtil.getGeneratedWebResourceFile(fproj.getProject(), facesConfigPath);
-
+ IFile defaultFacesConfig = project.getFolder(warSourceDir).getFile(facesConfigPath);
+ IFile generatedFacesConfig = ProjectUtil.getGeneratedWebResourceFile(project,
facesConfigPath);
+ IFile actualFacesConfig = JSFUtils.getFacesconfig(project);
+
//faces-config.xml will not be created in the source folder and it doesn't exist
yet
// => We'll have to fix it after setting the JSF facet
boolean shouldFixFacesConfig = generatedFacesConfig != null
- &&
!generatedFacesConfig.getLocation().equals(facesConfig.getLocation())
+ &&
!generatedFacesConfig.getLocation().equals(defaultFacesConfig.getLocation())
&& !generatedFacesConfig.exists();
+ boolean defaultFacesConfigAlreadyExists = defaultFacesConfig.exists();
IProjectFacetVersion facetVersion = null;
boolean configureServlet = false;//Fix for JBIDE-9454, where existing web.xml is
completely overwritten.
@@ -198,7 +200,6 @@
}
else if (jsfVersionString.startsWith(JSF_VERSION_2_0)) {
facetVersion = JSF_FACET_VERSION_2_0;
- //configureServlet = configureWebxml();
}
if (facetVersion != null) {
@@ -216,20 +217,25 @@
}
if (shouldFixFacesConfig && generatedFacesConfig.exists()) {
- if (facesConfig.exists()) {
+ if (defaultFacesConfig.exists()) {
//We have 2 config files. Delete the gen'd one
generatedFacesConfig.delete(true, monitor);
}
else {
//move the gen'd config file to the appropriate source folder
- IContainer destination = facesConfig.getParent();
+ IContainer destination = defaultFacesConfig.getParent();
if (destination != null && !destination.exists()) {
destination.getLocation().toFile().mkdirs();
}
- generatedFacesConfig.move(facesConfig.getFullPath(), true, monitor);
+ generatedFacesConfig.move(defaultFacesConfig.getFullPath(), true, monitor);
}
}
-
+ if (actualFacesConfig != null
+ && !defaultFacesConfigAlreadyExists
+ &&
!defaultFacesConfig.getLocation().equals(actualFacesConfig.getLocation())
+ && defaultFacesConfig.exists()/*file has just been created*/) {
+ defaultFacesConfig.delete(true, monitor);
+ }
}
}
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-02-13
10:41:07 UTC (rev 38650)
+++
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/configurators/JSFUtils.java 2012-02-13
11:09:55 UTC (rev 38651)
@@ -11,6 +11,7 @@
package org.jboss.tools.maven.jsf.configurators;
import java.io.InputStream;
+import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -30,6 +31,7 @@
import org.jboss.tools.common.util.EclipseJavaUtil;
import org.jboss.tools.maven.core.ProjectUtil;
import org.jboss.tools.maven.jsf.utils.FacesConfigQuickPeek;
+import org.jboss.tools.maven.jsf.utils.xpl.JSFAppConfigUtils;
import org.jboss.tools.maven.ui.Activator;
import org.w3c.dom.Document;
@@ -53,7 +55,17 @@
* Return the faces-config.xml of the given project, or null if faces-config.xml
doesn't exist
*/
public static IFile getFacesconfig(IProject project) {
- IFile facesConfig = ProjectUtil.getWebResourceFile(project,
"WEB-INF/faces-config.xml");
+ IFile facesConfig = null;
+ @SuppressWarnings("unchecked")
+ List<String> configFiles =
JSFAppConfigUtils.getConfigFilesFromContextParam(project);
+ for (String configFile : configFiles) {
+ facesConfig = ProjectUtil.getWebResourceFile(project, configFile);
+ if (facesConfig != null && facesConfig.exists()) {
+ return facesConfig;
+ }
+ }
+ facesConfig = ProjectUtil.getWebResourceFile(project,
"WEB-INF/faces-config.xml");
+
return facesConfig;
}
Added:
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/utils/xpl/JSFAppConfigUtils.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/utils/xpl/JSFAppConfigUtils.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.jsf/src/org/jboss/tools/maven/jsf/utils/xpl/JSFAppConfigUtils.java 2012-02-13
11:09:55 UTC (rev 38651)
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Oracle Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.maven.jsf.utils.xpl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jst.j2ee.common.ParamValue;
+import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
+import org.eclipse.jst.j2ee.model.IModelProvider;
+import org.eclipse.jst.j2ee.model.ModelProviderManager;
+import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit;
+import org.eclipse.jst.j2ee.webapplication.ContextParam;
+import org.eclipse.jst.j2ee.webapplication.WebApp;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.jboss.tools.maven.jsf.MavenJSFActivator;
+
+/**
+ * Class copied from {@link org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigUtils}.
+ * <ul>
+ * <li>getConfigFilesFromContextParam() method modified to allow reading of
javax.faces.CONFIG_FILES
+ * value in web.xml on projects not having the JSF facet already</li>
+ * <li>Unused methods have been removed</li>
+ * <li>Code changed to use Java 1.5+ features</li>
+ * </ul>
+ *
+ * JSFAppConfigUtils provides utility methods useful in processing of a JSF
+ * application configuration.
+ *
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class JSFAppConfigUtils {
+
+ /**
+ * Name of JSF CONFIG_FILES context parameter ("javax.faces.CONFIG_FILES").
+ */
+ public static final String CONFIG_FILES_CONTEXT_PARAM_NAME =
"javax.faces.CONFIG_FILES"; //$NON-NLS-1$
+
+ /**
+ * Location in JAR file of application configuration resource file
+ * ("META-INF/faces-config.xml").
+ */
+ public static final String FACES_CONFIG_IN_JAR_PATH =
"META-INF/faces-config.xml"; //$NON-NLS-1$
+
+
+ /**
+ * Gets list of application configuration file names as listed in the JSF
+ * CONFIG_FILES context parameter ("javax.faces.CONFIG_FILES"). Will return
+ * an empty list if WebArtifactEdit is null, if WebApp is null, if context
+ * parameter does not exist, or if trimmed context parameter's value is
+ * an empty String.
+ *
+ * @param project IProject instance for which to get the context
+ * parameter's value.
+ * @return List of application configuration file names as listed in the
+ * JSF CONFIG_FILES context parameter ("javax.faces.CONFIG_FILES"); list
+ * may be empty.
+ */
+ public static List<String> getConfigFilesFromContextParam(IProject project) {
+ List<String> filesList = Collections.emptyList();
+ if (ModuleCoreNature.isFlexibleProject(project)) {
+ IModelProvider provider = ModelProviderManager.getModelProvider(project);
+ Object webAppObj = provider.getModelObject();
+ if (webAppObj != null){
+ if (webAppObj instanceof WebApp)
+ filesList = getConfigFilesForJ2EEApp(project);
+ else if (webAppObj instanceof org.eclipse.jst.javaee.web.WebApp)
+ filesList = getConfigFilesForJEEApp((org.eclipse.jst.javaee.web.WebApp)webAppObj);
+ }
+
+ }
+ return filesList;
+ }
+
+ private static List<String>
getConfigFilesForJEEApp(org.eclipse.jst.javaee.web.WebApp webApp) {
+ String filesString = null;
+ for (org.eclipse.jst.javaee.core.ParamValue paramValue : webApp.getContextParams()) {
+ if (paramValue.getParamName().equals(CONFIG_FILES_CONTEXT_PARAM_NAME)) {
+ filesString = paramValue.getParamValue();
+ break;
+ }
+ }
+ return parseFilesString(filesString);
+ }
+
+ private static List<String> getConfigFilesForJ2EEApp(IProject project){
+ List<String> filesList = new ArrayList<String>();
+ WebArtifactEdit webArtifactEdit = WebArtifactEdit.getWebArtifactEditForRead(project);
+ if (webArtifactEdit != null) {
+ try {
+ WebApp webApp = null;
+ try {
+ webApp = webArtifactEdit.getWebApp();
+ } catch(ClassCastException cce) {
+ //occasionally thrown from WTP code in RC3 and possibly later
+ MavenJSFActivator.log(cce);
+ return filesList;
+ }
+ if (webApp != null) {
+ String filesString = null;
+ //need to branch here due to model version differences (BugZilla #119442)
+ if (webApp.getVersionID() == J2EEVersionConstants.WEB_2_3_ID) {
+ EList contexts = webApp.getContexts();
+ Iterator itContexts = contexts.iterator();
+ while (itContexts.hasNext()) {
+ ContextParam contextParam = (ContextParam)itContexts.next();
+ if (contextParam.getParamName().equals(CONFIG_FILES_CONTEXT_PARAM_NAME)) {
+ filesString = contextParam.getParamValue();
+ break;
+ }
+ }
+ } else {
+ EList contextParams = webApp.getContextParams();
+ Iterator itContextParams = contextParams.iterator();
+ while (itContextParams.hasNext()) {
+ ParamValue paramValue = (ParamValue)itContextParams.next();
+ if (paramValue.getName().equals(CONFIG_FILES_CONTEXT_PARAM_NAME)) {
+ filesString = paramValue.getValue();
+ break;
+ }
+ }
+ }
+ filesList = parseFilesString(filesString);
+ }
+ } finally {
+ webArtifactEdit.dispose();
+ }
+ }
+
+ return filesList;
+ }
+
+ private static List<String> parseFilesString(String filesString) {
+ List<String> filesList = new ArrayList<String>();
+ if (filesString != null && filesString.trim().length() > 0) {
+ StringTokenizer stFilesString = new StringTokenizer(filesString, ",");
//$NON-NLS-1$
+ while (stFilesString.hasMoreTokens()) {
+ String configFile = stFilesString.nextToken().trim();
+ filesList.add(configFile);
+ }
+ }
+ return filesList;
+ }
+
+}
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/pom.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/pom.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/pom.xml 2012-02-13
11:09:55 UTC (rev 38651)
@@ -0,0 +1,19 @@
+<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>foo.bar</groupId>
+ <artifactId>jsf-customfacesconfig</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>war</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/my-faces-config.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/my-faces-config.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/my-faces-config.xml 2012-02-13
11:09:55 UTC (rev 38651)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<faces-config
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0">
+
+</faces-config>
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/web.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/web.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jsf/JBIDE-10831/jsf-customfacesconfig/src/main/webapp/WEB-INF/web.xml 2012-02-13
11:09:55 UTC (rev 38651)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
+ <display-name>aa</display-name>
+ <context-param>
+ <param-name>javax.faces.CONFIG_FILES</param-name>
+ <param-value>/WEB-INF/my-faces-config.xml</param-value>
+</context-param>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ <welcome-file>index.htm</welcome-file>
+ <welcome-file>index.jsp</welcome-file>
+ <welcome-file>default.html</welcome-file>
+ <welcome-file>default.htm</welcome-file>
+ <welcome-file>default.jsp</welcome-file>
+ </welcome-file-list>
+</web-app>
\ No newline at end of file
Modified:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java 2012-02-13
10:41:07 UTC (rev 38650)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/AbstractMavenConfiguratorTest.java 2012-02-13
11:09:55 UTC (rev 38651)
@@ -27,6 +27,7 @@
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.maven.jsf.configurators.JSFProjectConfigurator;
+import org.jboss.tools.maven.jsf.configurators.JSFUtils;
public abstract class AbstractMavenConfiguratorTest extends
AbstractMavenProjectTestCase {
@@ -45,7 +46,7 @@
assertNotNull(project.getName() + " is not a faceted project",
facetedProject);
assertEquals("Unexpected JSF Version", expectedJSFVersion,
facetedProject.getInstalledVersion(JSFProjectConfigurator.JSF_FACET));
assertTrue("Java Facet is
missing", facetedProject.hasProjectFacet(JavaFacet.FACET));
- assertTrue("faces-config.xml is missing",
project.getFile("src/main/webapp/WEB-INF/faces-config.xml").exists());
+ assertTrue("faces-config.xml is missing",
JSFUtils.getFacesconfig(project).exists());
}
/**
@@ -73,18 +74,17 @@
if (newPomName != null) {
copyContent(project, newPomName, "pom.xml");
}
- IProgressMonitor mon = new NullProgressMonitor();
IProjectConfigurationManager configurationManager =
MavenPlugin.getProjectConfigurationManager();
ResolverConfiguration configuration = new ResolverConfiguration();
- configurationManager.enableMavenNature(project, configuration, mon);
- configurationManager.updateProjectConfiguration(project, mon);
- waitForJobsToComplete(mon);
+ configurationManager.enableMavenNature(project, configuration, monitor);
+ configurationManager.updateProjectConfiguration(project, monitor);
+ waitForJobsToComplete(monitor);
- project.build(IncrementalProjectBuilder.FULL_BUILD, mon);
+ project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
if (waitTime > 0) {
Thread.sleep(waitTime);
}
- waitForJobsToComplete(mon);
+ waitForJobsToComplete(monitor);
}
protected void updateProject(IProject project) throws Exception {
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-02-13
10:41:07 UTC (rev 38650)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/configurators/tests/JSFConfiguratorTest.java 2012-02-13
11:09:55 UTC (rev 38651)
@@ -132,6 +132,18 @@
assertTrue(jsfProject.getName() + " doesn't have the expected Web facet",
facetedProject.hasProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB_25));
}
+ @Test
+ public void testJBIDE10831_detectCustomFacesConfig() throws Exception {
+ String projectLocation = "projects/jsf/JBIDE-10831/jsf-customfacesconfig";
+ IProject jsfProject = importProject(projectLocation+"/pom.xml");
+ waitForJobsToComplete(new NullProgressMonitor());
+ assertIsJSFProject(jsfProject, JSFProjectConfigurator.JSF_FACET_VERSION_2_0);
+
+ IFile facesConfigXml =
jsfProject.getFile("src/main/webapp/WEB-INF/faces-config.xml");
+ assertFalse("A new faces-config.xml was added to the project!",
facesConfigXml.exists());
+
+ }
+
private void assertHasJSFConfigurationError(IProject project, String message) throws
Exception {
WorkspaceHelpers.assertErrorMarker(MavenJSFConstants.JSF_CONFIGURATION_ERROR_MARKER_ID,
message, 1, "", project);
}