~ubuntu-branches/ubuntu/vivid/eclipse-wtp/vivid

« back to all changes in this revision

Viewing changes to org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2013-06-28 08:42:01 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130628084201-houvqyt5uc6a3p27
Tags: 3.5.0-1
* New upstream release.
* Refreshed d/patches:
  - debian-custom-build.patch
  - regenerate-xpath2-parser.patch.
* Add patch for compatibility with rhino 1.7R4.
* Regenerate code from EMF models.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
12
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.List;
 
15
 
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$
42
46
 
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$
44
49
 
45
50
        /**
46
51
         * @param project
47
52
         * @return the IPath to the "root" of the web contents
48
53
         */
49
54
        static IPath getWebContentRootPath(IProject project) {
 
55
                if (project == null)
 
56
                        return null;
 
57
 
50
58
                if (!ModuleCoreNature.isFlexibleProject(project))
51
 
                        return project.getFullPath();
 
59
                        return null;
52
60
 
53
61
                IPath path = null;
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();
57
 
                }
58
 
                else {
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);
 
67
                        }
60
68
                }
61
69
                return path;
62
70
        }
74
82
                                IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
75
83
                                is = is || (faceted != null && faceted.hasProjectFacet(facet));
76
84
                        }
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));
80
88
                        }
 
89
                        if (!is && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
 
90
                                IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
 
91
                                is = is || (faceted != null && faceted.hasProjectFacet(facet));
 
92
                        }
81
93
                }
82
94
                catch (CoreException e) {
83
95
                        Logger.logException(e);
90
102
                        return new IPath[]{project.getFullPath()};
91
103
                }
92
104
 
93
 
                IPath[] paths = null;
 
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();
100
 
                        }
 
110
                                if (workspaceFolders[i].getFolder(FacetModuleCoreSupport.META_INF_RESOURCES_PATH).isAccessible())
 
111
                                        paths.add(workspaceFolders[i].getFullPath().append(FacetModuleCoreSupport.META_INF_RESOURCES_PATH));
 
112
                                else
 
113
                                        paths.add(workspaceFolders[i].getFullPath());
 
114
                        }
 
115
                        
 
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)
 
121
                                                continue;
 
122
                                        IVirtualComponent component = referencedComponent.getComponent();
 
123
                                        if (component == null)
 
124
                                                continue;
 
125
                                        IVirtualFolder rootFolder = component.getRootFolder();
 
126
                                        if (rootFolder == null)
 
127
                                                continue;
 
128
                                        IPath referencedPathRoot = rootFolder.getWorkspaceRelativePath();
 
129
                                        /* http://bugs.eclipse.org/410161 */
 
130
                                        if (referencedPathRoot != null) {
 
131
                                                /*
 
132
                                                 * See Servlet 3.0, section 4.6 ; this is the only
 
133
                                                 * referenced module/component type we support
 
134
                                                 */
 
135
                                                IPath resources = referencedPathRoot.append(FacetModuleCoreSupport.META_INF_RESOURCES);
 
136
                                                if (resources != null && component.getProject().findMember(resources.removeFirstSegments(1)) != null) {
 
137
                                                        paths.add(resources);
 
138
                                                }
 
139
                                        }
 
140
                                }
 
141
                        }
 
142
 
101
143
                }
102
144
                else {
103
 
                        paths = new IPath[]{project.getFullPath()};
 
145
                        paths.add(new IPath[]{project.getFullPath()});
104
146
                }
105
 
                return paths;
 
147
                return (IPath[]) paths.toArray(new IPath[paths.size()]);
106
148
        }
107
149
 
108
150
        static IPath getDefaultRoot(IProject project) {