[565328] More tests for DeploymentDescriptorPropertyCache version detection
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 8a4203c..6d28e2c 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 @@ 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 @@ } } } + 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 @@ 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 d6e7c11..b7ceb8c 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 @@ // 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 0000000..dcdcb26 --- /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 0000000..f90a54f --- /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>