blob: 14f0718f618673c1a83a77d0881606dea86fa640 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2012 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
*******************************************************************************/
package org.eclipse.jdt.debug.tests.core;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstall2;
import org.eclipse.jdt.launching.IVMInstall3;
import org.eclipse.jdt.launching.JavaRuntime;
/**
* Tests for installed VMs
*/
public class VMInstallTests extends AbstractDebugTest {
/**
* Constructor
* @param name the name of the test
*/
public VMInstallTests(String name) {
super(name);
}
/**
* Tests the java version from the VMInstall
*/
public void testJavaVersion() {
IVMInstall def = JavaRuntime.getDefaultVMInstall();
assertTrue("should be an IVMInstall2", def instanceof IVMInstall2);
IVMInstall2 vm2 = (IVMInstall2)def;
String javaVersion = vm2.getJavaVersion();
assertNotNull("default VM is missing java.version", javaVersion);
}
/**
* Test acquiring the set of system properties
* @throws CoreException
*/
public void testSystemProperties() throws CoreException {
IVMInstall def = JavaRuntime.getDefaultVMInstall();
assertTrue("should be an IVMInstall3", def instanceof IVMInstall3);
IVMInstall3 vm3 = (IVMInstall3)def;
Map<String, String> map = vm3.evaluateSystemProperties(new String[]{"user.home"}, new NullProgressMonitor());
assertNotNull("No system properties returned", map);
assertEquals("Wrong number of properties", 1, map.size());
String value = map.get("user.home");
assertNotNull("missing user.home", value);
}
/**
* Test acquiring the set of system properties that have been asked for - they should be cached in JDT launching
* @throws CoreException
*/
public void testSystemPropertiesCaching() throws CoreException {
IVMInstall def = JavaRuntime.getDefaultVMInstall();
assertTrue("should be an IVMInstall3", def instanceof IVMInstall3);
IVMInstall3 vm3 = (IVMInstall3)def;
Map<String, String> map = vm3.evaluateSystemProperties(new String[]{"user.home"}, new NullProgressMonitor());
assertNotNull("No system properties returned", map);
assertEquals("Wrong number of properties", 1, map.size());
String value = map.get("user.home");
assertNotNull("missing user.home", value);
//check the prefs
String key = getSystemPropertyKey(def, "user.home");
value = Platform.getPreferencesService().getString(
LaunchingPlugin.ID_PLUGIN,
key,
null,
null);
assertNotNull("'user.home' system property should be cached", value);
}
/**
* Generates a key used to cache system property for this VM in this plug-ins
* preference store.
*
* @param property system property name
* @return preference store key
*/
private String getSystemPropertyKey(IVMInstall vm, String property) {
StringBuffer buffer = new StringBuffer();
buffer.append("PREF_VM_INSTALL_SYSTEM_PROPERTY");
buffer.append("."); //$NON-NLS-1$
buffer.append(vm.getVMInstallType().getId());
buffer.append("."); //$NON-NLS-1$
buffer.append(vm.getId());
buffer.append("."); //$NON-NLS-1$
buffer.append(property);
return buffer.toString();
}
}