Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNitin Dahyabhai2021-01-04 04:42:32 +0000
committerNitin Dahyabhai2021-01-04 04:42:32 +0000
commitd794650016a414aca9002f747e1f1a727e64007a (patch)
tree811f20027edc757975a4d1ef7d1f0ffbee9b10da
parent40f468eb2cfd468b8c74d49fc8c99a42afc5c613 (diff)
downloadwebtools.sourceediting-d794650016a414aca9002f747e1f1a727e64007a.tar.gz
webtools.sourceediting-d794650016a414aca9002f747e1f1a727e64007a.tar.xz
webtools.sourceediting-d794650016a414aca9002f747e1f1a727e64007a.zip
[565328] More tests for DeploymentDescriptorPropertyCache version detection
-rw-r--r--web/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/contenttype/DeploymentDescriptorPropertyCache.java8
-rw-r--r--web/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java32
-rw-r--r--web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection1/WEB-INF/web.xml10
-rw-r--r--web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection2/WEB-INF/web.xml9
4 files changed, 57 insertions, 2 deletions
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 8a4203cdd3..6d28e2c85a 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
@@ -684,7 +684,7 @@ public final class DeploymentDescriptorPropertyCache {
if (version[0] == null) {
// try determining from schema declarations
String schemaLocations = webapp.getAttribute(SCHEMA_LOCATION);
- if (schemaLocations.length() > 0) {
+ if (schemaLocations != null && schemaLocations.length() > 0) {
if (schemaLocations.contains("/web-app_5_0.xsd")) {
version[0] = new Float(5);
}
@@ -721,6 +721,10 @@ public final class DeploymentDescriptorPropertyCache {
}
}
}
+ if (version[0] == null) {
+ version[0] = new Float(DEFAULT_WEBAPP_VERSION);
+ }
+
NodeList propertyGroupElements = document.getElementsByTagName(JSP_PROPERTY_GROUP);
int length = propertyGroupElements.getLength();
subMonitor.beginTask("Reading Property Groups", length); //$NON-NLS-1$
@@ -837,7 +841,7 @@ public final class DeploymentDescriptorPropertyCache {
IStructuredModel model = null;
List<PropertyGroup> propertyGroupList = new ArrayList<>();
List<StringMatcher> urlPatterns = new ArrayList<>();
- Float[] version = new Float[]{new Float(DEFAULT_WEBAPP_VERSION)};
+ Float[] version = new Float[1];
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 2);
DocumentBuilder builder = CommonXML.getDocumentBuilder(false);
builder.setEntityResolver(getEntityNonResolver());
diff --git a/web/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java b/web/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
index d6e7c11765..b7ceb8c238 100644
--- a/web/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
+++ b/web/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
@@ -497,6 +497,38 @@ public class JSPJavaTranslatorCoreTest extends TestCase {
// assertEquals("Unexpected root package", "javax.servlet", servletAPIVersion.getRootPackage());
}
+ public void testDDVersionDetection1() throws Exception {
+ String testName = "testversiondetection1";
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
+ synchronized (creationLock) {
+ if (!project.isAccessible()) {
+ // Create new project
+ project = BundleResourceUtil.createSimpleProject(testName, null, new String[] {});
+ assertTrue(project.exists());
+ BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
+ }
+ }
+ Float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(project.getFullPath());
+ assertNotNull("no API version was detected", version);
+ assertEquals(2.3f, version);
+ }
+
+ public void testDDVersionDetection2() throws Exception {
+ String testName = "testversiondetection2";
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
+ synchronized (creationLock) {
+ if (!project.isAccessible()) {
+ // Create new project
+ project = BundleResourceUtil.createSimpleProject(testName, null, new String[] {});
+ assertTrue(project.exists());
+ BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
+ }
+ }
+ Float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(project.getFullPath());
+ assertNotNull("no API version was detected", version);
+ assertEquals(2.2f, version);
+ }
+
public void test_codas() throws Exception {
String testName = "testPreludeAndCodas";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
diff --git a/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection1/WEB-INF/web.xml b/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection1/WEB-INF/web.xml
new file mode 100644
index 0000000000..dcdcb26827
--- /dev/null
+++ b/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection1/WEB-INF/web.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
+ version="3.1"
+ xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xml="http://www.w3.org/XML/1998/namespace"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
+ <display-name>A Created Web Application, determining the version from the web-app version</display-name>
+</web-app>
diff --git a/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection2/WEB-INF/web.xml b/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection2/WEB-INF/web.xml
new file mode 100644
index 0000000000..f90a54f1e9
--- /dev/null
+++ b/web/tests/org.eclipse.jst.jsp.core.tests/testfiles/testversiondetection2/WEB-INF/web.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
+ xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xml="http://www.w3.org/XML/1998/namespace"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd">
+ <display-name>A Created Web Application, determining the version from the schema location(s).</display-name>
+</web-app>

Back to the top