Bug 511790: VMInstallTestsLibraryLocationResolver should not block headless test runs
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 8310356..bbbe697 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
@@ -21,7 +21,6 @@
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.internal.launching.JavaFxLibraryResolver;
 import org.eclipse.jdt.internal.launching.LaunchingPlugin;
 import org.eclipse.jdt.launching.ILibraryLocationResolver;
 import org.eclipse.jdt.launching.IVMInstall;
@@ -36,20 +35,6 @@
  */
 public class VMInstallTests extends AbstractDebugTest {
 
-	private static boolean isTesting = false;
-	
-	static boolean applies(IPath path) {
-		if (!isTesting)
-			return false;
-
-		for (int i = 0; i < path.segmentCount(); i++) {
-			if ("ext".equals(path.segment(i))) {
-				return !JavaFxLibraryResolver.JFXRT_JAR.equals(path.lastSegment());
-			}
-		}
-		return false;
-	}
-
 	public VMInstallTests() {
 		super("VM Install tests");
 	}
@@ -119,7 +104,7 @@
 	 * @throws Exception
 	 */
 	public void testLibraryResolver1() throws Exception {
-		isTesting = true;
+		VMInstallTestsLibraryLocationResolver.isTesting = true;
 		IVMInstall vm = JavaRuntime.getDefaultVMInstall();
 		assertNotNull("There must be a default VM", vm);
 		
@@ -133,7 +118,7 @@
 			assertResolvedLibraryLocations(locs);
 		}
 		finally {
-			isTesting = false;
+			VMInstallTestsLibraryLocationResolver.isTesting = false;
 			//force a re-compute to remove the bogus paths
 			vm.getVMInstallType().disposeVMInstall(vm.getId());
 		}
@@ -146,7 +131,7 @@
 	 * @throws Exception
 	 */
 	public void testLibraryResolver2() throws Exception {
-		isTesting = true;
+		VMInstallTestsLibraryLocationResolver.isTesting = true;
 		try {
 			String filename = "/testfiles/test-jre/bin/test-resolver.ee";
 			if(Platform.OS_WIN32.equals(Platform.getOS())) {
@@ -158,7 +143,7 @@
 			assertResolvedLibraryLocations(locs);
 		}
 		finally {
-			isTesting = false;
+			VMInstallTestsLibraryLocationResolver.isTesting = false;
 		}
 	}
 	
@@ -169,7 +154,7 @@
 	 * @throws Exception
 	 */
 	public void testLibraryResolver3() throws Exception {
-		isTesting = true;
+		VMInstallTestsLibraryLocationResolver.isTesting = true;
 		IVMInstall vm = JavaRuntime.getDefaultVMInstall();
 		assertNotNull("There must be a default VM", vm);
 		try {
@@ -182,7 +167,7 @@
 			assertResolvedLibraryLocations(locs);
 		}
 		finally {
-			isTesting = false;
+			VMInstallTestsLibraryLocationResolver.isTesting = false;
 			vm.getVMInstallType().disposeVMInstall(vm.getId());
 		}
 	}
@@ -195,7 +180,7 @@
 	 * @throws Exception
 	 */
 	public void testLibraryResolver4() throws Exception {
-		isTesting = true;
+		VMInstallTestsLibraryLocationResolver.isTesting = true;
 		try {
 			String filename = "/testfiles/test-jre/bin/test-resolver2.ee";
 			if(Platform.OS_WIN32.equals(Platform.getOS())) {
@@ -207,7 +192,7 @@
 			String locpath = null;
 			for (int i = 0; i < locs.length; i++) {
 				IPath path = locs[i].getSystemLibraryPath();
-				if(applies(path)) {
+				if(VMInstallTestsLibraryLocationResolver.applies(path)) {
 					locpath = path.toString();
 					assertTrue("The original source path should be set on the ext lib [" + locpath + "]",
 							locs[i].getSystemLibrarySourcePath().toString().indexOf("source.txt") > -1);
@@ -215,7 +200,7 @@
 			}
 		}
 		finally {
-			isTesting = false;
+			VMInstallTestsLibraryLocationResolver.isTesting = false;
 		}
 	}
 	
@@ -228,7 +213,7 @@
 		String locpath = null;
 		for (int i = 0; i < locs.length; i++) {
 			IPath path = locs[i].getSystemLibraryPath();
-			if(applies(path)) {
+			if(VMInstallTestsLibraryLocationResolver.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);
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTestsLibraryLocationResolver.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTestsLibraryLocationResolver.java
index e136faa..08c779a 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTestsLibraryLocationResolver.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/VMInstallTestsLibraryLocationResolver.java
@@ -18,10 +18,29 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.jdt.debug.testplugin.JavaTestPlugin;
+import org.eclipse.jdt.internal.launching.JavaFxLibraryResolver;
 import org.eclipse.jdt.launching.ILibraryLocationResolver;
 
 
 public class VMInstallTestsLibraryLocationResolver implements ILibraryLocationResolver {
+
+	// This used to be in VMInstallTests. Moved here to support headless test runs,
+	// which previously failed because VMInstallTests extends a UI class.
+	static boolean isTesting = false;
+
+	static boolean applies(IPath path) {
+		if (!isTesting) {
+			return false;
+		}
+	
+		for (int i = 0; i < path.segmentCount(); i++) {
+			if ("ext".equals(path.segment(i))) {
+				return !JavaFxLibraryResolver.JFXRT_JAR.equals(path.lastSegment());
+			}
+		}
+		return false;
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -29,7 +48,7 @@
 	 */
 	@Override
 	public IPath getPackageRoot(IPath libraryPath) {
-		if (VMInstallTests.applies(libraryPath)) {
+		if (applies(libraryPath)) {
 			return new Path("src");
 		}
 		return Path.EMPTY;
@@ -42,7 +61,7 @@
 	 */
 	@Override
 	public IPath getSourcePath(IPath libraryPath) {
-		if (VMInstallTests.applies(libraryPath)) {
+		if (applies(libraryPath)) {
 			File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/test_resolver_src.zip"));
 			if (file.isFile()) {
 				return new Path(file.getAbsolutePath());
@@ -58,7 +77,7 @@
 	 */
 	@Override
 	public URL getJavadocLocation(IPath libraryPath) {
-		if (VMInstallTests.applies(libraryPath)) {
+		if (applies(libraryPath)) {
 			File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/test_resolver_javadoc.zip"));
 			if (file.isFile()) {
 				try {
@@ -79,7 +98,7 @@
 	 */
 	@Override
 	public URL getIndexLocation(IPath libraryPath) {
-		if (VMInstallTests.applies(libraryPath)) {
+		if (applies(libraryPath)) {
 			File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/test_resolver_index.index"));
 			if (file.isFile()) {
 				try {