Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoritrimble2011-08-24 14:36:13 -0400
committeritrimble2011-08-24 14:36:13 -0400
commit8e53eec12f3f6f49a7cfdbd1c82bc11f72a0e97c (patch)
tree46a5fd2489d65c5060254e634112343ffb1643d1
parenta56723dc2a345b22b440dd0104dac1f1736a8ea0 (diff)
downloadwebtools.jsf-8e53eec12f3f6f49a7cfdbd1c82bc11f72a0e97c.tar.gz
webtools.jsf-8e53eec12f3f6f49a7cfdbd1c82bc11f72a0e97c.tar.xz
webtools.jsf-8e53eec12f3f6f49a7cfdbd1c82bc11f72a0e97c.zip
Bug 353834 - JSF Facet completely overwrites the web.xml if the deployment assembly contains several folders
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java70
1 files changed, 61 insertions, 9 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java
index 3b5789d86..57b50fb3a 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java
@@ -16,12 +16,18 @@ package org.eclipse.jst.jsf.core.internal.project.facet;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig;
import org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig;
@@ -289,13 +295,21 @@ public final class JSFFacetInstallDelegate implements IDelegate {
/**
* @param project
* @param jsfConfigPath
+ * @param jsfUtils
* @return absolute IPath to jsfConfig
*/
- private IPath resolveConfigPath(final IProject project, final String jsfConfigPath) {
- return ComponentCore.createComponent(project).getRootFolder()
- .getUnderlyingFolder().getRawLocation().append(
- new Path(jsfConfigPath));
-
+ private IPath resolveConfigPath(
+ final IProject project, final String jsfConfigPath, final JSFUtils jsfUtils) {
+ IPath path = null;
+ final IPath webXMLPath = getWebXMLPathFromModel(jsfUtils);
+ if (webXMLPath != null) {
+ path = webXMLPath.removeLastSegments(2).append(jsfConfigPath);
+ }
+ if (path == null) {
+ path = ComponentCore.createComponent(project).getRootFolder()
+ .getUnderlyingFolder().getRawLocation().append(new Path(jsfConfigPath));
+ }
+ return path;
}
/**
@@ -310,7 +324,11 @@ public final class JSFFacetInstallDelegate implements IDelegate {
final IProgressMonitor monitor, final JSFUtils jsfUtil) {
- final IPath configPath = resolveConfigPath(project, config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH));
+ final IPath configPath =
+ resolveConfigPath(
+ project,
+ config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH),
+ jsfUtil);
try {
// do not overwrite if the file exists
if (!configPath.toFile().exists()) {
@@ -345,7 +363,7 @@ public final class JSFFacetInstallDelegate implements IDelegate {
if (jsfUtil.isJavaEE(provider.getModelObject()))
{
provider.modify(new UpdateWebXMLForJavaEE(project, config, jsfUtil),
- doesDDFileExist(project, webXMLPath) ? webXMLPath
+ doesDDFileExist(jsfUtil) ? webXMLPath
: IModelProvider.FORCESAVE);
} else
{// must be 2.3 or 2.4
@@ -356,8 +374,42 @@ public final class JSFFacetInstallDelegate implements IDelegate {
// Check if runtime is MyFaces or Sun-RI
}
- private boolean doesDDFileExist(final IProject project, final IPath webXMLPath) {
- return project.getProjectRelativePath().append(webXMLPath).toFile().exists();
+ private boolean doesDDFileExist(final JSFUtils jsfUtils) {
+ boolean exists = false;
+ IPath path = getWebXMLPathFromModel(jsfUtils);
+ if (path != null) {
+ exists = path.toFile().exists();
+ }
+ return exists;
+ }
+
+ private IPath getWebXMLPathFromModel(final JSFUtils jsfUtils) {
+ IPath path = null;
+ if (jsfUtils != null) {
+ final IModelProvider provider = jsfUtils.getModelProvider();
+ if (provider != null) {
+ final Object modelObject = provider.getModelObject();
+ if (modelObject instanceof EObject) {
+ final Resource resource = ((EObject)modelObject).eResource();
+ if (resource != null) {
+ final URI uri = resource.getURI();
+ if (uri != null && uri.isPlatformResource()) {
+ final IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace != null) {
+ final IWorkspaceRoot root = workspace.getRoot();
+ if (root != null) {
+ final IResource iResource = root.findMember(new Path(uri.toPlatformString(true)));
+ if (iResource != null) {
+ path = iResource.getLocation();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return path;
}
private class UpdateWebXMLForJavaEE implements Runnable {

Back to the top