diff options
author | nitind | 2007-10-10 17:17:42 +0000 |
---|---|---|
committer | nitind | 2007-10-10 17:17:42 +0000 |
commit | 7ff9df6552555a81c6af90d946b195250cf75086 (patch) | |
tree | 62aaa3491fb0d79a7dbeb663cb6327a905509362 | |
parent | d23714d08aadd8399cc02731ac73f328e5a752bb (diff) | |
download | webtools.sourceediting-7ff9df6552555a81c6af90d946b195250cf75086.tar.gz webtools.sourceediting-7ff9df6552555a81c6af90d946b195250cf75086.tar.xz webtools.sourceediting-7ff9df6552555a81c6af90d946b195250cf75086.zip |
[203062] Facets and Module Core should be optional
8 files changed, 292 insertions, 62 deletions
diff --git a/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF index d9dd3316d9..503ede8cef 100644 --- a/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF @@ -42,8 +42,8 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", - org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)", - org.eclipse.wst.common.modulecore;bundle-version="[1.1.0,1.2.0)", + org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)";resolution:=optional, + org.eclipse.wst.common.modulecore;bundle-version="[1.1.0,1.2.0)";resolution:=optional, com.ibm.icu;bundle-version="[3.4.4,4.0.0)" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java new file mode 100644 index 0000000000..91583ceeb6 --- /dev/null +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupport.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.css.ui.internal.wizard; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; + +/** + * This class encapsulates any used Module Core and Facets APIs along with + * fallbacks for use on non-compliant projects and when those services are not + * available at runtime. + * + * Because ModuleCore API calls can result in locks needing to be acquired, + * none of these methods should be called while other thread locks have + * already been acquired. + */ +final class FacetModuleCoreSupport { + static final boolean _dump_NCDFE = false; + + /** + * @param project + * @return the IPath to the "root" of the web contents + */ + public static IPath getWebContentRootPath(IProject project) { + IPath path = null; + try { + path = FacetModuleCoreSupportDelegate.getWebContentRootPath(project); + } + catch (NoClassDefFoundError e) { + if (_dump_NCDFE) + e.printStackTrace(); + } + return path; + } + + /** + * @param project + * @return + * @throws CoreException + */ + public static boolean isWebProject(IProject project) { + try { + return FacetModuleCoreSupportDelegate.isWebProject(project); + } + catch (NoClassDefFoundError e) { + if (_dump_NCDFE) + e.printStackTrace(); + } + return true; + } + + +} diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java new file mode 100644 index 0000000000..f7c6fd8552 --- /dev/null +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/FacetModuleCoreSupportDelegate.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.css.ui.internal.wizard; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +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.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.css.ui.internal.Logger; + +/** + * Wrapper class for all Facet-related calls. If the Facet or ModuleCore + * bundles are not available, this class will not load, or if it does, its + * methods will cause NoClassDefFoundErrors. This allows us to + * compartmentalize the dependencies. + * + */ +final class FacetModuleCoreSupportDelegate { + /** + * Copied to avoid unneeded extra dependency (plus it's unclear why the + * value is in that plug-in). + * + * @see org.eclipse.wst.common.componentcore.internal.util.IModuleConstants.JST_WEB_MODULE + */ + private final static String JST_WEB_MODULE = "jst.web"; //$NON-NLS-1$ + + private final static String WST_WEB_MODULE = "wst.web"; //$NON-NLS-1$ + + /** + * @param project + * @return the IPath to the "root" of the web contents + */ + static IPath getWebContentRootPath(IProject project) { + if (!ModuleCoreNature.isFlexibleProject(project)) + return project.getFullPath(); + + IPath path = null; + IVirtualComponent component = ComponentCore.createComponent(project); + if (component != null && component.exists()) { + path = component.getRootFolder().getWorkspaceRelativePath(); + } + else { + path = project.getFullPath(); + } + return path; + } + + /** + * @param project + * @return + * @throws CoreException + */ + static boolean isWebProject(IProject project) { + try { + IFacetedProject faceted = ProjectFacetsManager.create(project); + IProjectFacet jstModuleFacet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE); + IProjectFacet wstModuleFacet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE); + if (faceted != null && (faceted.hasProjectFacet(jstModuleFacet) || faceted.hasProjectFacet(wstModuleFacet))) { + return true; + } + } + catch (CoreException e) { + Logger.logException(e); + } + return false; + } +} diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java index 6c73061359..4cc64240bd 100644 --- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java @@ -19,7 +19,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; @@ -28,16 +27,10 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; import org.eclipse.wst.css.core.internal.CSSCorePlugin; import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames; import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; import org.eclipse.wst.css.ui.internal.CSSUIMessages; -import org.eclipse.wst.css.ui.internal.Logger; class NewCSSFileWizardPage extends WizardNewFileCreationPage { @@ -216,20 +209,7 @@ class NewCSSFileWizardPage extends WizardNewFileCreationPage { * @return true if the project is web project, otherwise false */ private boolean isWebProject(IProject project) { - IFacetedProject faceted = null; - try { - faceted = ProjectFacetsManager.create(project); - } catch (CoreException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - if (faceted != null && - (faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.WST_WEB_MODULE)) || - faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE)))) { - return true; - } - - return false; + return FacetModuleCoreSupport.isWebProject(project); } /** @@ -239,14 +219,7 @@ class NewCSSFileWizardPage extends WizardNewFileCreationPage { * @return IPath of the web contents folder */ private IPath getWebContentPath(IProject project) { - IPath path = null; - - if (project != null && isWebProject(project)) { - IVirtualComponent component = ComponentCore.createComponent(project); - path = component.getRootFolder().getWorkspaceRelativePath(); - } - - return path; + return FacetModuleCoreSupport.getWebContentRootPath(project); } } diff --git a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF index f5e050891f..479df6c24e 100644 --- a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF @@ -43,8 +43,8 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.wst.validation;bundle-version="[1.1.0,1.2.0)", org.eclipse.wst.javascript.ui;bundle-version="[1.0.0,1.1.0)", - org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)", - org.eclipse.wst.common.modulecore;bundle-version="[1.1.0,1.2.0)", + org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)";resolution:=optional, + org.eclipse.wst.common.modulecore;bundle-version="[1.1.0,1.2.0)";resolution:=optional, com.ibm.icu;bundle-version="[3.4.4,4.0.0)" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java new file mode 100644 index 0000000000..dbc6074b86 --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupport.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.html.ui.internal.wizard; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; + +/** + * This class encapsulates any used Module Core and Facets APIs along with + * fallbacks for use on non-compliant projects and when those services are not + * available at runtime. + * + * Because ModuleCore API calls can result in locks needing to be acquired, + * none of these methods should be called while other thread locks have + * already been acquired. + */ +final class FacetModuleCoreSupport { + static final boolean _dump_NCDFE = false; + + /** + * @param project + * @return the IPath to the "root" of the web contents + */ + public static IPath getWebContentRootPath(IProject project) { + IPath path = null; + try { + path = FacetModuleCoreSupportDelegate.getWebContentRootPath(project); + } + catch (NoClassDefFoundError e) { + if (_dump_NCDFE) + e.printStackTrace(); + } + return path; + } + + /** + * @param project + * @return + * @throws CoreException + */ + public static boolean isWebProject(IProject project) { + try { + return FacetModuleCoreSupportDelegate.isWebProject(project); + } + catch (NoClassDefFoundError e) { + if (_dump_NCDFE) + e.printStackTrace(); + } + return true; + } + + +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java new file mode 100644 index 0000000000..f0cab0c20c --- /dev/null +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/FacetModuleCoreSupportDelegate.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.html.ui.internal.wizard; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +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.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.html.ui.internal.Logger; + +/** + * Wrapper class for all Facet-related calls. If the Facet or ModuleCore + * bundles are not available, this class will not load, or if it does, its + * methods will cause NoClassDefFoundErrors. This allows us to + * compartmentalize the dependencies. + * + */ +final class FacetModuleCoreSupportDelegate { + /** + * Copied to avoid unneeded extra dependency (plus it's unclear why the + * value is in that plug-in). + * + * @see org.eclipse.wst.common.componentcore.internal.util.IModuleConstants.JST_WEB_MODULE + */ + private final static String JST_WEB_MODULE = "jst.web"; //$NON-NLS-1$ + + private final static String WST_WEB_MODULE = "wst.web"; //$NON-NLS-1$ + + /** + * @param project + * @return the IPath to the "root" of the web contents + */ + static IPath getWebContentRootPath(IProject project) { + if (!ModuleCoreNature.isFlexibleProject(project)) + return project.getFullPath(); + + IPath path = null; + IVirtualComponent component = ComponentCore.createComponent(project); + if (component != null && component.exists()) { + path = component.getRootFolder().getWorkspaceRelativePath(); + } + else { + path = project.getFullPath(); + } + return path; + } + + /** + * @param project + * @return + * @throws CoreException + */ + static boolean isWebProject(IProject project) { + try { + IFacetedProject faceted = ProjectFacetsManager.create(project); + IProjectFacet jstModuleFacet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE); + IProjectFacet wstModuleFacet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE); + if (faceted != null && (faceted.hasProjectFacet(jstModuleFacet) || faceted.hasProjectFacet(wstModuleFacet))) { + return true; + } + } + catch (CoreException e) { + Logger.logException(e); + } + return false; + } +} diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java index e541788044..110d80015a 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java @@ -19,7 +19,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; @@ -28,16 +27,10 @@ import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; import org.eclipse.wst.html.core.internal.HTMLCorePlugin; import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML; import org.eclipse.wst.html.ui.internal.HTMLUIMessages; -import org.eclipse.wst.html.ui.internal.Logger; class NewHTMLFileWizardPage extends WizardNewFileCreationPage { @@ -216,20 +209,7 @@ class NewHTMLFileWizardPage extends WizardNewFileCreationPage { * @return true if the project is web project, otherwise false */ private boolean isWebProject(IProject project) { - IFacetedProject faceted = null; - try { - faceted = ProjectFacetsManager.create(project); - } catch (CoreException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - - if (faceted != null && - (faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.WST_WEB_MODULE)) || - faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE)))) { - return true; - } - - return false; + return FacetModuleCoreSupport.isWebProject(project); } /** @@ -239,13 +219,6 @@ class NewHTMLFileWizardPage extends WizardNewFileCreationPage { * @return IPath of the web contents folder */ private IPath getWebContentPath(IProject project) { - IPath path = null; - - if (project != null && isWebProject(project)) { - IVirtualComponent component = ComponentCore.createComponent(project); - path = component.getRootFolder().getWorkspaceRelativePath(); - } - - return path; + return FacetModuleCoreSupport.getWebContentRootPath(project); } } |