[465975] JSPJavaTranslatorCoreTest Junit failure in WTP builds
Since the original bug was about processing the contents of a JSP fragment that
is only know through being referenced in the deployment descriptor, actively
test for those results rather than a lack of Problem Markers.
diff --git a/tests/org.eclipse.jst.jsp.core.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.jst.jsp.core.tests/META-INF/MANIFEST.MF
index 0723c62..aaf2242 100644
--- a/tests/org.eclipse.jst.jsp.core.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.jst.jsp.core.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.jst.jsp.core.tests;singleton:=true
-Bundle-Version: 1.0.800.qualifier
+Bundle-Version: 1.0.900.qualifier
Bundle-ClassPath: jspcoretests.jar
Bundle-Activator: org.eclipse.jst.jsp.core.tests.JSPCoreTestsPlugin
Bundle-Vendor: %Bundle-Vendor.0
diff --git a/tests/org.eclipse.jst.jsp.core.tests/pom.xml b/tests/org.eclipse.jst.jsp.core.tests/pom.xml
index 23c56d3..3b65b44 100644
--- a/tests/org.eclipse.jst.jsp.core.tests/pom.xml
+++ b/tests/org.eclipse.jst.jsp.core.tests/pom.xml
@@ -22,7 +22,7 @@
<groupId>org.eclipse.webtools.sourceediting</groupId>
<artifactId>org.eclipse.jst.jsp.core.tests</artifactId>
- <version>1.0.800-SNAPSHOT</version>
+ <version>1.0.900-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/WebContainerInitializer.java b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/WebContainerInitializer.java
index bfb6f76..095a5be 100644
--- a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/WebContainerInitializer.java
+++ b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/WebContainerInitializer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 IBM Corporation and others.
+ * Copyright (c) 2014, 2015 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
@@ -10,11 +10,10 @@
*******************************************************************************/
package org.eclipse.jst.jsp.core.tests;
-import java.io.IOException;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
@@ -24,36 +23,43 @@
import org.eclipse.jdt.core.JavaCore;
public class WebContainerInitializer extends ClasspathContainerInitializer {
-
+ IClasspathEntry bundles[] = null;
public WebContainerInitializer() {
}
public void initialize(final IPath containerPath, IJavaProject project) throws CoreException {
+ if (bundles == null) {
+ try {
+ IClasspathEntry servlet = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet")).getAbsolutePath()), null, null);
+ IClasspathEntry jsp = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet.jsp")).getAbsolutePath()), null, null);
+ bundles = new IClasspathEntry[] {servlet, jsp};
+ }
+ catch (Exception e) {
+ bundles = new IClasspathEntry[0];
+ System.err.println("Couldn't find a necessary bundle " + e);
+ e.printStackTrace();
+ Logger.logException(e);
+ }
+ }
+
IClasspathContainer container = new IClasspathContainer() {
-
public IPath getPath() {
return containerPath;
}
public int getKind() {
- return IClasspathContainer.K_SYSTEM;
+ return IClasspathContainer.K_APPLICATION;
}
public String getDescription() {
- return "JARs for the Java Web Project";
+ return "JARs for a Java Web Project";
}
public IClasspathEntry[] getClasspathEntries() {
- try {
- IClasspathEntry servlet = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet")).getAbsolutePath()), null, null);
- IClasspathEntry jsp = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet.jsp")).getAbsolutePath()), null, null);
- return new IClasspathEntry[] { servlet, jsp };
- }
- catch (IOException e) { }
- return new IClasspathEntry[0];
+ return bundles;
}
};
- JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
+ JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, new NullProgressMonitor());
}
}
diff --git a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
index 8bee331..48cf31b 100644
--- a/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
+++ b/tests/org.eclipse.jst.jsp.core.tests/src/org/eclipse/jst/jsp/core/tests/translation/JSPJavaTranslatorCoreTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 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
@@ -20,13 +20,10 @@
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -42,6 +39,7 @@
import org.eclipse.jst.jsp.core.internal.java.JSPTranslation;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension;
+import org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslator;
import org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP;
import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
@@ -57,14 +55,14 @@
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.validation.ValidationFramework;
-import org.eclipse.wst.validation.ValidationResult;
-import org.eclipse.wst.validation.ValidationState;
import org.eclipse.wst.validation.internal.operations.ValidatorManager;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import junit.framework.TestCase;
+
public class JSPJavaTranslatorCoreTest extends TestCase {
static final String WTP_AUTOTEST_NONINTERACTIVE = "wtp.autotest.noninteractive";
@@ -99,6 +97,7 @@
IProject project = BundleResourceUtil.createSimpleProject(projectName, null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
+ project.open(new NullProgressMonitor());
IFile file = project.getFile("WebContent/test107338.jsp");
assertTrue(file.exists());
@@ -270,32 +269,30 @@
}
public void test_109721() throws Exception {
- boolean doValidateSegments = JSPCorePlugin.getDefault().getPluginPreferences().getBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS);
+ /*
+ * https://bugs.eclipse.org/109721 JSP editor does not find taglib
+ * directives in include-prelude or jsp:include, make sure the
+ * contents were processed
+ */
String testName = "bug_109721";
// Create new project
- IProject project = BundleResourceUtil.createSimpleProject(testName, Platform.getStateLocation(JSPCoreTestsPlugin.getDefault().getBundle()).append(testName), null);
- assertTrue(project.exists());
+ final IProject project = BundleResourceUtil.createSimpleProject(testName, null, null);
+ assertTrue(project.isAccessible());
- /*
- * Should be set to false. A referenced class in an included segment
- * does not exist.
- */
- JSPCorePlugin.getDefault().getPluginPreferences().setValue(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, false);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/struts.jar", "/" + testName + "/WebContent/WEB-INF/lib/struts.jar");
waitForBuildAndValidation(project);
- JSPCorePlugin.getDefault().getPluginPreferences().setValue(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, doValidateSegments);
- IFile main = project.getFile("WebContent/main.jsp");
- ValidationResult result = new JSPJavaValidator().validate(main, IResourceDelta.ADDED, new ValidationState(), new NullProgressMonitor());
- List messages = result.getReporter(null).getMessages();
+ String filename = "/WebContent/main.jsp";
+ IStructuredModel sm = StructuredModelManager.getModelManager().getModelForRead(project.getFile(filename));
+ assertNotNull("couldn't load JSP for test", sm);
+ JSPTranslationUtil translationUtil = new JSPTranslationUtil(sm.getStructuredDocument());
+ String translation = translationUtil.getTranslation().getJavaText();
+ sm.releaseFromRead();
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < messages.size(); i++) {
- s.append("\nproblem on line " + ((IMessage)messages.get(i)).getAttribute(IMarker.LINE_NUMBER) + ": " + ((IMessage)messages.get(i)).getText());
- }
- assertEquals("problem markers found" + s.toString(), 0, messages.size());
+ assertTrue("Java content from Fragment included by web.xml is missing", translation.indexOf("int alpha = 5;") > 0);
+ assertTrue("Tag that could only be known by processing Fragment included only by web.xml is not in the translation", translation.indexOf("org.apache.struts.taglib.bean.DefineTag") > 0);
}
public void test_181057a() throws Exception {
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java
index ccff6a6..427e54c 100644
--- a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java
+++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPTranslationEditorInput.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2015 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
@@ -27,7 +27,7 @@
/**
* @author nitin
- *
+ *
*/
public class JSPTranslationEditorInput implements IStorageEditorInput {
private class JSPTranslationStorage implements IStorage {
@@ -63,7 +63,7 @@
* @see org.eclipse.core.resources.IStorage#getFullPath()
*/
public IPath getFullPath() {
- return new Path(getTranslationAdapter().getJSPTranslation().getJavaPath());
+ return new Path(fModel.getBaseLocation() + ".java");
}
/*
@@ -72,7 +72,6 @@
* @see org.eclipse.core.resources.IStorage#getName()
*/
public String getName() {
-// return getTranslationAdapter().getJSPTranslation().getCompilationUnit().getElementName();
return new Path(fModel.getBaseLocation()).lastSegment() + ".java";
}
@@ -164,6 +163,4 @@
JSPTranslationAdapter adapter = (JSPTranslationAdapter) fModel.getDocument().getAdapterFor(IJSPTranslation.class);
return adapter;
}
-
-
}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
index c621169..d3cf2ef 100644
--- a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
+++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/ShowTranslationHandler.java
@@ -62,7 +62,6 @@
public ShowTranslationHandler() {
}
-
/*
* (non-Javadoc)
*
@@ -71,8 +70,6 @@
* .ExecutionEvent)
*/
public Object execute(final ExecutionEvent event) throws ExecutionException {
- // IDE.openEditor(event.getApplicationContext(), createEditorInput(),
- // JavaUI.ID_CU_EDITOR, true);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List list = ((IStructuredSelection) selection).toList();