Bug 399798 - StandardVMType should allow... - add more tests for EE
files
diff --git a/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32-2.ee b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32-2.ee
new file mode 100644
index 0000000..2940682
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32-2.ee
@@ -0,0 +1,31 @@
+##################################################################################
+# Copyright (c) 2013 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
+##################################################################################
+
+-Dee.executable=jrew.txt
+-Dee.executable.console=jre.txt
+
+-Dee.bootclasspath=..\lib\classes.txt:..\lib\others.txt
+-Dee.src=..\lib\source\source.txt
+-Dee.src.map=..\lib\endorsed\*.jar=..\lib\source\*.txt:..\lib\ext\ext?*.jar=..\lib\source\source.txt:..\lib\additional\*.???=..\lib\source\source*source.???
+-Dee.javadoc=http:\\a.javadoc.location
+-Dee.additional.dirs=..\lib\additional
+-Dee.ext.dirs=..\lib\ext:..\lib\opt-ext
+-Dee.endorsed.dirs=..\lib\endorsed
+
+# test new index attribute
+-Dee.index=http:\\a.index.location
+
+-Dee.language.level=1.7
+-Dee.class.library.level=J2SE-1.7
+-Dee.id=J2SE-1.7
+-Dee.name=Library Location Resolver Test JRE Definition
+-Dee.description=Foundation Specification v1.1
+-Dee.copyright=(c) Copyright IBM Corp. 2013 All Rights Reserved
diff --git a/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32.ee b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32.ee
new file mode 100644
index 0000000..3f5a097
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver-win32.ee
@@ -0,0 +1,31 @@
+##################################################################################
+# Copyright (c) 2013 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
+##################################################################################
+
+-Dee.executable=jrew.txt
+-Dee.executable.console=jre.txt
+
+-Dee.bootclasspath=..\lib\classes.txt:..\lib\others.txt
+-Dee.src=..\lib\source\source.txt
+-Dee.src.map=..\lib\endorsed\*.jar=..\lib\source\*.txt:..\lib\additional\*.???=..\lib\source\source*source.???
+-Dee.javadoc=http:\\a.javadoc.location
+-Dee.additional.dirs=..\lib\additional
+-Dee.ext.dirs=..\lib\ext:..\lib\opt-ext
+-Dee.endorsed.dirs=..\lib\endorsed
+
+# test new index attribute
+-Dee.index=http://a.index.location
+
+-Dee.language.level=1.7
+-Dee.class.library.level=J2SE-1.7
+-Dee.id=J2SE-1.7
+-Dee.name=Library Location Resolver Test JRE Definition
+-Dee.description=Foundation Specification v1.1
+-Dee.copyright=(c) Copyright IBM Corp. 2013 All Rights Reserved
diff --git a/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver.ee b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver.ee
new file mode 100644
index 0000000..c9ca87b
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver.ee
@@ -0,0 +1,41 @@
+##################################################################################
+# Copyright (c) 2013 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
+##################################################################################
+
+-Dee.executable=jrew.txt
+-Dee.executable.console=jre.txt
+
+-Dee.bootclasspath=../lib/classes.txt:../lib/others.txt
+-Dee.src=../lib/source/source.txt
+-Dee.src.map=../lib/endorsed/*.jar=../lib/source/*.txt:../lib/additional/*.???=../lib/source/source*source.???
+-Dee.javadoc=http://a.javadoc.location
+-Dee.additional.dirs=../lib/additional
+-Dee.ext.dirs=../lib/ext:../lib/opt-ext
+-Dee.endorsed.dirs=../lib/endorsed
+
+# all args should get passed through to command line
+-XspecialArg:123
+
+# tests an empty property
+-Dee.empty=
+
+# test new index attribute
+-Dee.index=http://a.index.location
+
+-Dee.language.level=1.7
+-Dee.class.library.level=J2SE-1.7
+-Dee.id=J2SE-1.7
+-Dee.name=Library Location Resolver Test JRE Definition
+-Dee.description=Foundation Specification v1.1
+-Dee.copyright=(c) Copyright IBM Corp. 2013 All Rights Reserved
+-Djava.home=..
+
+# all args should get passed through to command line
+-XspecialArg2=456
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver2.ee b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver2.ee
new file mode 100644
index 0000000..6d2fd41
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testfiles/test-jre/bin/test-resolver2.ee
@@ -0,0 +1,41 @@
+##################################################################################
+# Copyright (c) 2013 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
+##################################################################################
+
+-Dee.executable=jrew.txt
+-Dee.executable.console=jre.txt
+
+-Dee.bootclasspath=../lib/classes.txt:../lib/others.txt
+-Dee.src=../lib/source/source.txt
+-Dee.src.map=../lib/endorsed/*.jar=../lib/source/*.txt:../lib/ext/ext?*.jar=../lib/source/source.txt:../lib/additional/*.???=../lib/source/source*source.???
+-Dee.javadoc=http://a.javadoc.location
+-Dee.additional.dirs=../lib/additional
+-Dee.ext.dirs=../lib/ext:../lib/opt-ext
+-Dee.endorsed.dirs=../lib/endorsed
+
+# all args should get passed through to command line
+-XspecialArg:123
+
+# tests an empty property
+-Dee.empty=
+
+# test new index attribute
+-Dee.index=http://a.index.location
+
+-Dee.language.level=1.7
+-Dee.class.library.level=J2SE-1.7
+-Dee.id=J2SE-1.7
+-Dee.name=Library Location Resolver Test JRE Definition
+-Dee.description=Foundation Specification v1.1
+-Dee.copyright=(c) Copyright IBM Corp. 2013 All Rights Reserved
+-Djava.home=..
+
+# all args should get passed through to command line
+-XspecialArg2=456
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTests.java
index 774a193..d441454 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTests.java
@@ -32,13 +32,14 @@
import org.eclipse.jdt.launching.IVMInstall3;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.LibraryLocation;
+import org.eclipse.jdt.launching.VMStandin;
/**
* Tests for installed VMs
*/
public class VMInstallTests extends AbstractDebugTest implements ILibraryLocationResolver {
- boolean isTesting = false;
+ static boolean isTesting = false;
public VMInstallTests() {
super("VM Install tests");
@@ -102,53 +103,155 @@
}
/**
- * Test the new support for {@link ILibraryLocationResolver}s
+ * Tests the new support for {@link ILibraryLocationResolver}s asking for {@link LibraryLocation}s
+ * using the {@link JavaRuntime#getLibraryLocations(IVMInstall)}s API
*
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=399798
* @throws Exception
*/
- public void _testLibraryResolver1() throws Exception {
- //set this flag when testing the resolver to avoid it setting bogus
- //testing paths in a target workspace
+ public void testLibraryResolver1() throws Exception {
+ isTesting = true;
+ IVMInstall vm = JavaRuntime.getDefaultVMInstall();
+ assertNotNull("There must be a default VM", vm);
+
+ //invalidate it, causing a reset, then collect it again
+ vm.getVMInstallType().disposeVMInstall(vm.getId());
+ vm = JavaRuntime.getDefaultVMInstall();
+ assertNotNull("There must be a default VM after a reset", vm);
+ try {
+ LibraryLocation[] locs = JavaRuntime.getLibraryLocations(vm);
+ assertNotNull("there must be some default library locations", locs);
+ assertResolvedLibraryLocations(locs);
+ }
+ finally {
+ isTesting = false;
+ //force a re-compute to remove the bogus paths
+ vm.getVMInstallType().disposeVMInstall(vm.getId());
+ }
+ }
+
+ /**
+ * Tests the {@link ILibraryLocationResolver} asking for libs using an EE description file
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=399798
+ * @throws Exception
+ */
+ public void testLibraryResolver2() throws Exception {
+ isTesting = true;
+ try {
+ String filename = "/testfiles/test-jre/bin/test-resolver.ee";
+ if(Platform.OS_WIN32.equals(Platform.getOS())) {
+ filename = "/testfiles/test-jre/bin/test-resolver-win32.ee";
+ }
+ VMStandin vm = getEEStandin(filename);
+ IVMInstall install = vm.convertToRealVM();
+ LibraryLocation[ ] locs = install.getLibraryLocations();
+ assertResolvedLibraryLocations(locs);
+ }
+ finally {
+ isTesting = false;
+ }
+ }
+
+ /**
+ * Tests the {@link ILibraryLocationResolver} asking for libs directly from the backing type of the {@link IVMInstall}
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=399798
+ * @throws Exception
+ */
+ public void testLibraryResolver3() throws Exception {
isTesting = true;
IVMInstall vm = JavaRuntime.getDefaultVMInstall();
assertNotNull("There must be a default VM", vm);
try {
- //force a re-compute
- vm.setLibraryLocations(null);
- LibraryLocation[] locs = JavaRuntime.getLibraryLocations(vm);
- assertNotNull("there must be some default library locations", locs);
- //try to find an 'ext' dir to see if it has some lib infos
- //the test resolver sets a source path of ../test_resolver_src.zip on
- //any libs in the ext dir
+ //reset it
+ vm.getVMInstallType().disposeVMInstall(vm.getId());
+ vm = JavaRuntime.getDefaultVMInstall();
+ assertNotNull("There must be a default VM", vm);
+
+ LibraryLocation[] locs = vm.getVMInstallType().getDefaultLibraryLocations(vm.getInstallLocation());
+ assertResolvedLibraryLocations(locs);
+ }
+ finally {
+ isTesting = false;
+ vm.getVMInstallType().disposeVMInstall(vm.getId());
+ }
+ }
+
+ /**
+ * Tests the {@link ILibraryLocationResolver} asking for libs using an EE description file that provides
+ * a source path for the ext dirs does *not* get overridden by the resolver
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=399798
+ * @throws Exception
+ */
+ public void testLibraryResolver4() throws Exception {
+ isTesting = true;
+ try {
+ String filename = "/testfiles/test-jre/bin/test-resolver2.ee";
+ if(Platform.OS_WIN32.equals(Platform.getOS())) {
+ filename = "/testfiles/test-jre/bin/test-resolver-win32-2.ee";
+ }
+ VMStandin vm = getEEStandin(filename);
+ IVMInstall install = vm.convertToRealVM();
+ LibraryLocation[ ] locs = install.getLibraryLocations();
String locpath = null;
for (int i = 0; i < locs.length; i++) {
IPath path = locs[i].getSystemLibraryPath();
if(applies(path)) {
locpath = path.toString();
- assertTrue("There should be a source path ending in test_resolver_src.zip on the ext lib ["+locpath+"]",
- locs[i].getSystemLibrarySourcePath().toString().indexOf("test_resolver_src.zip") > -1);
- IPath root = locs[i].getPackageRootPath();
- assertTrue("The source root path should be 'src' for ext lib ["+locpath+"]", root.toString().equals("src"));
- URL url = locs[i].getJavadocLocation();
- assertNotNull("There should be a Javadoc URL set for ext lib ["+locpath+"]", url);
- assertTrue("There should be a javadoc path of test_resolver_javadoc.zip on the ext lib ["+locpath+"]",
- url.getPath().indexOf("test_resolver_javadoc.zip") > -1);
- url = locs[i].getIndexLocation();
- assertNotNull("There should be an index path of test_resolver_index.index on the ext lib ["+locpath+"]", url);
- assertTrue("There should be an index path of test_resolver_index.index on the ext lib ["+locpath+"]",
- url.getPath().indexOf("test_resolver_index.index") > -1);
+ assertTrue("The original source path should be set on the ext lib ["+locpath+"]",
+ locs[i].getSystemLibrarySourcePath().toString().indexOf("source.txt") > -1);
}
}
}
finally {
isTesting = false;
- //force a re-compute to remove the bogus paths
- vm.setLibraryLocations(null);
}
}
/**
+ * Checks the given {@link LibraryLocation}s to ensure they reference the testing resolver paths
+ *
+ * @param locs
+ */
+ void assertResolvedLibraryLocations(LibraryLocation[] locs) {
+ String locpath = null;
+ for (int i = 0; i < locs.length; i++) {
+ IPath path = locs[i].getSystemLibraryPath();
+ if(applies(path)) {
+ locpath = path.toString();
+ assertTrue("There should be a source path ending in test_resolver_src.zip on the ext lib ["+locpath+"]",
+ locs[i].getSystemLibrarySourcePath().toString().indexOf("test_resolver_src.zip") > -1);
+ IPath root = locs[i].getPackageRootPath();
+ assertTrue("The source root path should be 'src' for ext lib ["+locpath+"]", root.toString().equals("src"));
+ URL url = locs[i].getJavadocLocation();
+ assertNotNull("There should be a Javadoc URL set for ext lib ["+locpath+"]", url);
+ assertTrue("There should be a javadoc path of test_resolver_javadoc.zip on the ext lib ["+locpath+"]",
+ url.getPath().indexOf("test_resolver_javadoc.zip") > -1);
+ url = locs[i].getIndexLocation();
+ assertNotNull("There should be an index path of test_resolver_index.index on the ext lib ["+locpath+"]", url);
+ assertTrue("There should be an index path of test_resolver_index.index on the ext lib ["+locpath+"]",
+ url.getPath().indexOf("test_resolver_index.index") > -1);
+ }
+ }
+ }
+
+ /**
+ * Creates a {@link VMStandin} for the given EE file. Does not return <code>null</code>
+ * @param filename
+ * @return the {@link VMStandin}
+ * @throws CoreException
+ */
+ VMStandin getEEStandin(String filename) throws CoreException {
+ File ee = JavaTestPlugin.getDefault().getFileInPlugin(new Path(filename));
+ assertNotNull("The EE file "+filename+" was not found", ee);
+ VMStandin vm = JavaRuntime.createVMFromDefinitionFile(ee, "resolver-ee", "resolver-ee-id");
+ assertNotNull("the VM standin should exist for "+filename, vm);
+ return vm;
+ }
+
+ /**
* Generates a key used to cache system property for this VM in this plug-ins
* preference store.
*
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
index 01d456f..967c3c0 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
@@ -14,6 +14,7 @@
import java.io.File;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -69,6 +70,17 @@
public static final String ID_STANDARD_VM_TYPE = "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"; //$NON-NLS-1$
/**
+ * Name filter for files ending in .jar or .zip
+ *
+ * @since 3.7.0
+ */
+ private static FilenameFilter fgArchiveFilter = new FilenameFilter() {
+ public boolean accept(File arg0, String arg1) {
+ return arg1.endsWith(".zip") || arg1.endsWith(".jar"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ };
+
+ /**
* The root path for the attached source
*/
private String fDefaultRootPath = ""; //$NON-NLS-1$
@@ -451,40 +463,33 @@
List<LibraryLocation> libraries = new ArrayList<LibraryLocation>();
for (int i = 0; i < dirPaths.length; i++) {
File extDir = new File(dirPaths[i]);
- if (extDir.exists() && extDir.isDirectory()) {
- String[] names = extDir.list();
+ if (extDir.isDirectory()) {
+ String[] names = extDir.list(fgArchiveFilter);
if (names != null) {
for (int j = 0; j < names.length; j++) {
- String name = names[j];
- File jar = new File(extDir, name);
+ File jar = new File(extDir, names[j]);
if (jar.isFile()) {
- int length = name.length();
- if (length > 4) {
- String suffix = name.substring(length - 4);
- if (suffix.equalsIgnoreCase(".zip") || suffix.equalsIgnoreCase(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ IPath libPath = new Path(jar.getCanonicalPath());
+ IPath sourcePath = Path.EMPTY;
+ IPath packageRoot = Path.EMPTY;
+ URL javadocLocation = null;
+ URL indexLocation = null;
+ for( ILibraryLocationResolver resolver : getLibraryLocationResolvers() ) {
try {
- IPath libPath = new Path(jar.getCanonicalPath());
- IPath sourcePath = Path.EMPTY;
- IPath packageRoot = Path.EMPTY;
- URL javadocLocation = null;
- URL indexLocation = null;
- for( ILibraryLocationResolver resolver : getLibraryLocationResolvers() ) {
- try {
- sourcePath = resolver.getSourcePath(libPath);
- packageRoot = resolver.getPackageRoot(libPath);
- javadocLocation = resolver.getJavadocLocation(libPath);
- indexLocation = resolver.getIndexLocation(libPath);
- break;
- } catch(Exception e) {
- LaunchingPlugin.log(e);
- }
- }
- LibraryLocation library = new LibraryLocation(libPath, sourcePath, packageRoot, javadocLocation, indexLocation);
- libraries.add(library);
- } catch (IOException e) {
+ sourcePath = resolver.getSourcePath(libPath);
+ packageRoot = resolver.getPackageRoot(libPath);
+ javadocLocation = resolver.getJavadocLocation(libPath);
+ indexLocation = resolver.getIndexLocation(libPath);
+ break;
+ } catch(Exception e) {
LaunchingPlugin.log(e);
}
}
+ LibraryLocation library = new LibraryLocation(libPath, sourcePath, packageRoot, javadocLocation, indexLocation);
+ libraries.add(library);
+ } catch (IOException e) {
+ LaunchingPlugin.log(e);
}
}
}
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
index 9a3f9d8..51abb56 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
@@ -1705,6 +1705,7 @@
} else {
javadocLocations[i]= defJavaDocLocation;
}
+ indexes[i] = dflts[i].getIndexLocation();
if (!libraryPaths[i].toFile().isFile()) {
libraryPaths[i]= Path.EMPTY;
}