[nobug] Add the ability to report the web fragment facet version
Change-Id: I44c62495b02bb57af5ef6f0bfb1878246553543c
Change-Id: I330bce66827b19304fd9044b71ca4c8b6aaee5fa
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
index 1812afa..f941156 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2022 IBM Corporation and others.
+ * Copyright (c) 2007, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -830,7 +830,7 @@
* facet version and looking at available API classes and methods.
*/
private ServletAPIDescriptor discoverServletAPIVersion(IProject project) {
- if (FacetModuleCoreSupport.isDynamicWebProject(project) || FacetModuleCoreSupport.isWebFragmentProject(project)) {
+ if (FacetModuleCoreSupport.isDynamicWebProject(project)) {
float version = FacetModuleCoreSupport.getDynamicWebProjectVersion(project);
if (version >= 5) {
return doCacheDescriptor(project.getName(), new ServletAPIDescriptor(JAKARTA_SERVLET, version, ServletAPIDescriptor.ORIGIN.FACET));
@@ -840,11 +840,23 @@
}
}
+ if (FacetModuleCoreSupport.isWebFragmentProject(project)) {
+ float version = FacetModuleCoreSupport.getDynamicWebFragmentVersion(project);
+ if (version >= 5) {
+ return doCacheDescriptor(project.getName(), new ServletAPIDescriptor(JAKARTA_SERVLET, version, ServletAPIDescriptor.ORIGIN.FFACET));
+ }
+ if (version > 0) {
+ return doCacheDescriptor(project.getName(), new ServletAPIDescriptor(JAVAX_SERVLET, version, ServletAPIDescriptor.ORIGIN.FFACET));
+ }
+ }
IJavaProject javaProject = JavaCore.create(project);
if (javaProject == null || !javaProject.exists()) {
return null;
}
+ if (findType(javaProject, "jakarta.servlet.ServletConnection") != null) { //$NON-NLS-1$
+ return doCacheDescriptor(project.getName(), new ServletAPIDescriptor(JAKARTA_SERVLET, 6, ServletAPIDescriptor.ORIGIN.BUILD_PATH));
+ }
if (findType(javaProject, "jakarta.servlet.GenericFilter") != null) { //$NON-NLS-1$
return doCacheDescriptor(project.getName(), new ServletAPIDescriptor(JAKARTA_SERVLET, 5, ServletAPIDescriptor.ORIGIN.BUILD_PATH));
}
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
index 4c4b6ce..bc0ddf6 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/ServletAPIDescriptor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020, 2022 IBM Corporation and others.
+ * Copyright (c) 2020, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -24,10 +24,14 @@
**/
BUILD_PATH,
/**
- * This descriptor is based on the project's Facet(s)
+ * This descriptor is based on the project's Dynamic Web Module facet
**/
FACET,
/**
+ * This descriptor is based on the project's Web Fragment Module facet
+ **/
+ FFACET,
+ /**
* This descriptor is merely a set of defaults.
**/
DEFAULT
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
index 3d23d36..212394d 100755
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupport.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2022 IBM Corporation and others.
+ * Copyright (c) 2007, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -69,6 +69,23 @@
/**
* @param project
+ * @return the version of the JST Web Fragment facet installed on the project, -1 otherwise
+ * @throws org.eclipse.core.runtime.CoreException
+ */
+ public static float getDynamicWebFragmentVersion(IProject project) {
+ float version = -1;
+ try {
+ version = FacetModuleCoreSupportDelegate.getDynamicWebFragmentVersion(project);
+ }
+ catch (NoClassDefFoundError e) {
+ if (_dump_NCDFE)
+ e.printStackTrace();
+ }
+ return version;
+ }
+
+ /**
+ * @param project
* @return the version of the JST Web facet installed on the project, -1 otherwise
* @throws org.eclipse.core.runtime.CoreException
*/
diff --git a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
index eaef667..c9b8483 100644
--- a/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
+++ b/web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/FacetModuleCoreSupportDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2022 IBM Corporation and others.
+ * Copyright (c) 2007, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -88,6 +88,34 @@
}
/**
+ * @param project
+ * @return the version of the JST Web Fragment facet, a default version otherwise
+ * @throws CoreException
+ */
+ static float getDynamicWebFragmentVersion(IProject project) {
+ if (project == null)
+ return -1;
+
+ float version = -1;
+ try {
+ IFacetedProject faceted = ProjectFacetsManager.create(project);
+ if (faceted != null && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
+ IProjectFacet webFragmentFacet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
+ if (faceted.hasProjectFacet(webFragmentFacet)) {
+ version = Float.parseFloat(faceted.getInstalledVersion(webFragmentFacet).getVersionString());
+ }
+ }
+ }
+ catch (NumberFormatException e) {
+ Logger.logException(e);
+ }
+ catch (CoreException e) {
+ Logger.logException(e);
+ }
+ return version;
+ }
+
+ /**
* @param path -
* the full path to a resource within the workspace
* @return - the runtime path of the resource if one exists, null