1
1
/*******************************************************************************
2
* Copyright (c) 2007, 2012 IBM Corporation and others.
2
* Copyright (c) 2007, 2013 IBM Corporation and others.
3
3
* All rights reserved. This program and the accompanying materials
4
4
* are made available under the terms of the Eclipse License v1.0
5
5
* which accompanies this distribution, and is available at
10
10
*******************************************************************************/
11
11
package org.eclipse.wst.html.ui.internal.wizard;
13
import java.util.ArrayList;
14
import java.util.List;
13
16
import org.eclipse.core.resources.IContainer;
14
17
import org.eclipse.core.resources.IProject;
15
18
import org.eclipse.core.runtime.CoreException;
19
22
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
20
23
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
21
24
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
25
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
22
26
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
23
27
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
24
28
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
41
45
private final static String JST_WEB_MODULE = "jst.web"; //$NON-NLS-1$
43
47
private final static String WST_WEB_MODULE = "wst.web"; //$NON-NLS-1$
48
private final static String JST_WEBFRAGMENT_MODULE = "jst.webfragment"; //$NON-NLS-1$
47
52
* @return the IPath to the "root" of the web contents
49
54
static IPath getWebContentRootPath(IProject project) {
50
58
if (!ModuleCoreNature.isFlexibleProject(project))
51
return project.getFullPath();
54
62
IVirtualComponent component = ComponentCore.createComponent(project);
55
if (component != null && component.exists()) {
63
if (component != null && component.exists() && component.getRootFolder() != null) {
56
64
path = component.getRootFolder().getWorkspaceRelativePath();
59
path = project.getFullPath();
65
if (component.getRootFolder().getFolder(FacetModuleCoreSupport.META_INF_RESOURCES_PATH).getUnderlyingFolder().isAccessible()) {
66
path = path.append(FacetModuleCoreSupport.META_INF_RESOURCES_PATH);
74
82
IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
75
83
is = is || (faceted != null && faceted.hasProjectFacet(facet));
77
if (ProjectFacetsManager.isProjectFacetDefined(WST_WEB_MODULE)) {
85
if (!is && ProjectFacetsManager.isProjectFacetDefined(WST_WEB_MODULE)) {
78
86
IProjectFacet facet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE);
79
87
is = is || (faceted != null && faceted.hasProjectFacet(facet));
89
if (!is && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
90
IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
91
is = is || (faceted != null && faceted.hasProjectFacet(facet));
82
94
catch (CoreException e) {
83
95
Logger.logException(e);
90
102
return new IPath[]{project.getFullPath()};
105
List paths = new ArrayList();
94
106
IVirtualFolder componentFolder = ComponentCore.createFolder(project, Path.ROOT);
95
107
if (componentFolder != null && componentFolder.exists()) {
96
108
IContainer[] workspaceFolders = componentFolder.getUnderlyingFolders();
97
paths = new IPath[workspaceFolders.length];
98
109
for (int i = 0; i < workspaceFolders.length; i++) {
99
paths[i] = workspaceFolders[i].getFullPath();
110
if (workspaceFolders[i].getFolder(FacetModuleCoreSupport.META_INF_RESOURCES_PATH).isAccessible())
111
paths.add(workspaceFolders[i].getFullPath().append(FacetModuleCoreSupport.META_INF_RESOURCES_PATH));
113
paths.add(workspaceFolders[i].getFullPath());
116
IVirtualReference[] references = ComponentCore.createComponent(project).getReferences();
117
if (references != null) {
118
for (int i = 0; i < references.length; i++) {
119
IVirtualComponent referencedComponent = references[i].getReferencedComponent();
120
if (referencedComponent == null)
122
IVirtualComponent component = referencedComponent.getComponent();
123
if (component == null)
125
IVirtualFolder rootFolder = component.getRootFolder();
126
if (rootFolder == null)
128
IPath referencedPathRoot = rootFolder.getWorkspaceRelativePath();
129
/* http://bugs.eclipse.org/410161 */
130
if (referencedPathRoot != null) {
132
* See Servlet 3.0, section 4.6 ; this is the only
133
* referenced module/component type we support
135
IPath resources = referencedPathRoot.append(FacetModuleCoreSupport.META_INF_RESOURCES);
136
if (resources != null && component.getProject().findMember(resources.removeFirstSegments(1)) != null) {
137
paths.add(resources);
103
paths = new IPath[]{project.getFullPath()};
145
paths.add(new IPath[]{project.getFullPath()});
147
return (IPath[]) paths.toArray(new IPath[paths.size()]);
108
150
static IPath getDefaultRoot(IProject project) {