Author: scabanovich
Date: 2011-11-16 17:15:50 -0500 (Wed, 16 Nov 2011)
New Revision: 36384
Modified:
trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ProjectHome.java
Log:
JBIDE-10177
https://issues.jboss.org/browse/JBIDE-10177
Fix for default web content folder for XModel.
Modified: trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2011-11-16
21:29:02 UTC (rev 36383)
+++ trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2011-11-16
22:15:50 UTC (rev 36384)
@@ -79,6 +79,9 @@
org.eclipse.ltk.ui.refactoring;visibility:=reexport;bundle-version="3.5.100",
org.eclipse.wst.common.uriresolver;bundle-version="1.1.401",
org.eclipse.wst.common.modulecore;bundle-version="1.2.100",
+ org.eclipse.jst.j2ee;bundle-version="1.1.500",
+ org.eclipse.jst.j2ee.core;bundle-version="1.2.100",
+ org.eclipse.wst.common.project.facet.core;bundle-version="1.4.200",
org.eclipse.jem.util;bundle-version="2.1.2",
org.eclipse.wst.common.emfworkbench.integration;bundle-version="1.2.100",
org.eclipse.core.resources;visibility:=reexport;bundle-version="3.7.100",
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ProjectHome.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ProjectHome.java 2011-11-16
21:29:02 UTC (rev 36383)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/project/ProjectHome.java 2011-11-16
22:15:50 UTC (rev 36384)
@@ -11,6 +11,8 @@
package org.jboss.tools.common.model.project;
import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -18,14 +20,19 @@
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.common.model.XModelConstants;
import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.plugin.ModelPlugin;
@@ -98,7 +105,11 @@
}
//Taken from J2EEUtils and modified
- public static IPath getWebInfPath(IProject project) {
+ public static IPath getWebInfPath(IProject project) {
+ IPath[] ps = getWebInfPaths(project);
+ if(ps.length > 0) {
+ return ps[0];
+ }
IVirtualComponent component = ComponentCore.createComponent(project);
if(component == null || component.getRootFolder() == null) return null;
IVirtualFolder webInfDir = component.getRootFolder().getFolder(new
Path("/WEB-INF")); //$NON-NLS-1$
@@ -109,17 +120,29 @@
public static IPath[] getWebInfPaths(IProject project) {
IVirtualComponent component = ComponentCore.createComponent(project);
if(component != null && component.getRootFolder() != null) {
- IVirtualFolder webInfDir = component.getRootFolder().getFolder(new
Path("/WEB-INF")); //$NON-NLS-1$
- if(webInfDir.exists()) {
- IContainer[] cs = webInfDir.getUnderlyingFolders();
- List<IPath> ps = new ArrayList<IPath>();
- for (IContainer c: cs) {
- if(c.exists()) {
- ps.add(c.getFullPath());
+ List<IPath> ps = new ArrayList<IPath>();
+ IContainer[] cs = getWebRootFolders(project, true);
+ for (IContainer c: cs) {
+ if(c.exists()) {
+ IFolder f = c.getFolder(new Path("/WEB-INF")); //$NON-NLS-1$
+ if(f.exists()) {
+ ps.add(f.getFullPath());
}
}
- return ps.toArray(new IPath[0]);
}
+ return ps.toArray(new IPath[0]);
+
+// IVirtualFolder webInfDir = component.getRootFolder().getFolder(new
Path("/WEB-INF")); //$NON-NLS-1$
+// if(webInfDir.exists()) {
+// IContainer[] cs = webInfDir.getUnderlyingFolders();
+// List<IPath> ps = new ArrayList<IPath>();
+// for (IContainer c: cs) {
+// if(c.exists()) {
+// ps.add(c.getFullPath());
+// }
+// }
+// return ps.toArray(new IPath[0]);
+// }
}
return new IPath[0];
}
@@ -127,17 +150,30 @@
public static IPath[] getWebContentPaths(IProject project) {
IVirtualComponent component = ComponentCore.createComponent(project);
if(component != null && component.getRootFolder() != null) {
- IVirtualFolder webDir = component.getRootFolder().getFolder(new Path("/"));
//$NON-NLS-1$
- if(webDir.exists()) {
- IContainer[] cs = webDir.getUnderlyingFolders();
- List<IPath> ps = new ArrayList<IPath>();
- for (IContainer c: cs) {
- if(c.exists()) {
- ps.add(c.getFullPath());
+
+ List<IPath> ps = new ArrayList<IPath>();
+ IContainer[] cs = getWebRootFolders(project, true);
+ for (IContainer c: cs) {
+ if(c.exists()) {
+ IFolder f = c.getFolder(new Path("/WEB-INF")); //$NON-NLS-1$
+ if(f.exists()) {
+ ps.add(f.getFullPath());
}
}
- return ps.toArray(new IPath[0]);
}
+ return ps.toArray(new IPath[0]);
+
+// IVirtualFolder webDir = component.getRootFolder().getFolder(new
Path("/")); //$NON-NLS-1$
+// if(webDir.exists()) {
+// IContainer[] cs = webDir.getUnderlyingFolders();
+// List<IPath> ps = new ArrayList<IPath>();
+// for (IContainer c: cs) {
+// if(c.exists()) {
+// ps.add(c.getFullPath());
+// }
+// }
+// return ps.toArray(new IPath[0]);
+// }
}
return new IPath[0];
}
@@ -147,10 +183,83 @@
IVirtualComponent vc = ComponentCore.createComponent(project);
if (vc == null || vc.getRootFolder() == null)
return null;
+ IContainer[] cs = getWebRootFolders(project, true);
+ for (IContainer c: cs) {
+ if(c.exists()) {
+ return c.getFullPath();
+ }
+ }
if (ModuleCoreNature.isFlexibleProject(project)) {
modulePath = vc.getRootFolder().getWorkspaceRelativePath();
}
return modulePath;
}
+
+ public static IContainer[] getWebRootFolders(IProject project, boolean ignoreDerived) {
+ IFacetedProject facetedProject = null;
+ try {
+ facetedProject = ProjectFacetsManager.create(project);
+ } catch (CoreException e) {
+ ModelPlugin.getDefault().logError(e);
+ }
+ if(facetedProject!=null &&
facetedProject.getProjectFacetVersion(IJ2EEFacetConstants.DYNAMIC_WEB_FACET)!=null) {
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ if(component!=null) {
+ IVirtualFolder webRootVirtFolder = component.getRootFolder().getFolder(new
Path("/")); //$NON-NLS-1$
+
+ IPath defaultPath = getDefaultDeploymentDescriptorFolder(webRootVirtFolder);
+
+ IContainer[] folders = webRootVirtFolder.getUnderlyingFolders();
+ if(folders.length > 1){
+ ArrayList<IContainer> containers = new ArrayList<IContainer>();
+ for(IContainer container : folders){
+ if(!ignoreDerived || !container.isDerived(IResource.CHECK_ANCESTORS)) {
+ if(defaultPath!=null && defaultPath.equals(container.getFullPath())) {
+ containers.add(0, container); // Put default root folder to the first position of
the list
+ } else {
+ containers.add(container);
+ }
+ }
+ }
+ return containers.toArray(new IContainer[containers.size()]);
+ } else {
+ return folders;
+ }
+ }
+ }
+ return EMPTY_ARRAY;
+ }
+
+ private static final IContainer[] EMPTY_ARRAY = new IContainer[0];
+ private static boolean WTP_3_3_0 = false;
+
+ /**
+ * Returns all the web root folders of the project.
+ * If the project is not a web project then the method will return an empty array.
+ * All the derived resources or resources belonged to derived containers will be
eliminated.
+ * If some folder is set as default web root source folder (available since WTP 3.3.1)
then this folder will be places in the very beginning of the result array.
+ * @param project
+ * @return
+ */
+ public static IPath getDefaultDeploymentDescriptorFolder(IVirtualFolder folder) {
+ if(!WTP_3_3_0) {
+ try {
+ Method getDefaultDeploymentDescriptorFolder =
J2EEModuleVirtualComponent.class.getMethod("getDefaultDeploymentDescriptorFolder",
IVirtualFolder.class); //$NON-NLS-1$
+ return (IPath) getDefaultDeploymentDescriptorFolder.invoke(null, folder);
+ } catch (NoSuchMethodException nsme) {
+ // Not available in this WTP version, let's ignore it
+ WTP_3_3_0 = true;
+ } catch (IllegalArgumentException e) {
+ ModelPlugin.getDefault().logError(e);
+ } catch (IllegalAccessException e) {
+ ModelPlugin.getDefault().logError(e);
+ } catch (InvocationTargetException e) {
+ // Not available in this WTP version, let's ignore it
+ WTP_3_3_0 = true;
+ }
+ }
+ return null;
+ }
+
}