JavaScript Development Tools
Release 3.2

org.eclipse.wst.jsdt.launching
Class JavaRuntime

java.lang.Object
  extended by org.eclipse.wst.jsdt.launching.JavaRuntime

public final class JavaRuntime
extends Object

The central access point for launching support. This class manages the registered VM types contributed through the "org.eclipse.wst.jsdt.launching.vmType" extension point. As well, this class provides VM install change notification, and computes includepaths and source lookup paths for launch configurations.

This class provides static methods only; it is not intended to be instantiated or subclassed by clients.

Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Field Summary
static String ATTR_CMDLINE
          Deprecated. - use IProcess.ATTR_CMDLINE
static String BASE_BROWSER_LIB
           
static String CLASSPATH_ATTR_LIBRARY_PATH_ENTRY
          Attribute key for a includepath attribute referencing a list of shared libraries that should appear on the -Djava.library.path system property.
static int DEF_CONNECT_TIMEOUT
          Default launch/connect timeout (ms).
static String DEFAULT_SUPER_TYPE
           
static String DEFAULT_SUPER_TYPE_LIBRARY
           
static int ERR_UNABLE_TO_RESOLVE_JRE
          A status code indicating that a JRE could not be resolved for a project.
static String EXTENSION_POINT_EXECUTION_ENVIRONMENTS
          Simple identifier constant (value "executionEnvironments") for the execution environments extension point.
static String EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS
          Simple identifier constant (value "runtimeClasspathEntryResolvers") for the runtime includepath entry resolvers extension point.
static String EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS
          Simple identifier constant (value "classpathProviders") for the runtime includepath providers extension point.
static String EXTENSION_POINT_VM_INSTALLS
          Simple identifier constant (value "vmInstalls") for the VM installs extension point.
static String JRE_CONTAINER
          Classpath container used for a project's JRE (value "org.eclipse.wst.jsdt.launching.JRE_CONTAINER").
static String JRELIB_VARIABLE
          Classpath variable name used for the default JRE's library (value "JRE_LIB").
static String JRESRC_VARIABLE
          Classpath variable name used for the default JRE's library source (value "JRE_SRC").
static String JRESRCROOT_VARIABLE
          Classpath variable name used for the default JRE's library source root (value "JRE_SRCROOT").
static String PREF_CONNECT_TIMEOUT
          Preference key for launch/connect timeout.
static String PREF_VM_XML
          Preference key for the String of XML that defines all installed VMs.
 
Method Summary
static void addContainerResolver(IRuntimeClasspathEntryResolver resolver, String containerIdentifier)
          Registers the given resolver for the specified container.
static String[] computeDefaultRuntimeClassPath(IJavaScriptProject jproject)
          Computes the default application includepath entries for the given project.
static IRuntimeClasspathEntry computeJREEntry(ILaunchConfiguration configuration)
          Returns a runtime includepath entry identifying the JRE to use when launching the specified configuration or null if none is specified.
static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(IJavaScriptProject project)
          Computes and returns the default unresolved runtime includepath for the given project.
static IVMInstall computeVMInstall(ILaunchConfiguration configuration)
          Returns the VM install for the given launch configuration.
static void fireVMAdded(IVMInstall vm)
          Notifies all VM install changed listeners of the VM addition
static void fireVMChanged(PropertyChangeEvent event)
          Notifies all VM install changed listeners of the given property change.
static void fireVMRemoved(IVMInstall vm)
          Notifies all VM install changed listeners of the VM removal
static String getCompositeIdFromVM(IVMInstall vm)
          Returns a String that uniquely identifies the specified VM across all VM types.
static IIncludePathEntry getDefaultJREContainerEntry()
          Creates and returns a includepath entry describing the default JRE container entry.
static IVMInstall getDefaultVMInstall()
          Return the default VM set with setDefaultVM().
static String getExecutionEnvironmentId(IPath jreContainerPath)
          Returns the execution environment identifier in the following JRE includepath container path, or null if none.
static IJavaScriptProject getJavaProject(ILaunchConfiguration configuration)
          Return the IJavaScriptProject referenced in the specified configuration or null if none.
static LibraryLocation[] getLibraryLocations(IVMInstall vm)
          Evaluates library locations for a IVMInstall.
static Preferences getPreferences()
          Returns the preference store for the launching plug-in.
static IVMInstall getVMFromCompositeId(String idString)
          Return the VM corresponding to the specified composite Id.
static IVMInstall getVMInstall(IJavaScriptProject project)
          Returns the VM assigned to build the given JavaScript project.
static IVMInstallType getVMInstallType(String id)
          Returns the VM install type with the given unique id.
static IVMInstallType[] getVMInstallTypes()
          Returns the list of registered VM types.
static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IResource resource)
          Returns a new runtime includepath entry for the given archive.
static IPath newDefaultJREContainerPath()
          Returns a path for the JRE includepath container identifying the default VM install.
static IPath newJREContainerPath(IVMInstall vm)
          Returns a path for the JRE includepath container identifying the specified VM install by type and name.
static IPath newJREContainerPath(String typeId, String name)
          Returns a path for the JRE includepath container identifying the specified VM install by type and name.
static IRuntimeClasspathEntry newProjectRuntimeClasspathEntry(IJavaScriptProject project)
          Returns a new runtime includepath entry for the given project.
static IRuntimeClasspathEntry newRuntimeClasspathEntry(String memento)
          Returns a runtime includepath entry constructed from the given memento.
static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path, int classpathProperty)
          Returns a runtime includepath entry for the given container path with the given includepath property.
static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path, int classpathProperty, IJavaScriptProject project)
          Returns a runtime includepath entry for the given container path with the given includepath property to be resolved in the context of the given JavaScript project.
static IRuntimeClasspathEntry newVariableRuntimeClasspathEntry(IPath path)
          Returns a new runtime includepath entry for the includepath variable with the given path.
static IRuntimeClasspathEntry[] resolveRuntimeClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration)
          Resolves the given includepath, returning the resolved includepath in the context of the given launch configuration.
static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, ILaunchConfiguration configuration)
          Returns resolved entries for the given entry in the context of the given launch configuration.
static void savePreferences()
          Saves the preferences for the launching plug-in.
static void saveVMConfiguration()
          Saves the VM configuration information to the preferences.
static void setDefaultVMInstall(IVMInstall vm, IProgressMonitor monitor)
          Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.
static void setDefaultVMInstall(IVMInstall vm, IProgressMonitor monitor, boolean savePreference)
          Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JRELIB_VARIABLE

public static final String JRELIB_VARIABLE
Classpath variable name used for the default JRE's library (value "JRE_LIB").

See Also:
Constant Field Values

JRESRC_VARIABLE

public static final String JRESRC_VARIABLE
Classpath variable name used for the default JRE's library source (value "JRE_SRC").

See Also:
Constant Field Values

JRESRCROOT_VARIABLE

public static final String JRESRCROOT_VARIABLE
Classpath variable name used for the default JRE's library source root (value "JRE_SRCROOT").

See Also:
Constant Field Values

EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS

public static final String EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS
Simple identifier constant (value "runtimeClasspathEntryResolvers") for the runtime includepath entry resolvers extension point.

See Also:
Constant Field Values

EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS

public static final String EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS
Simple identifier constant (value "classpathProviders") for the runtime includepath providers extension point.

See Also:
Constant Field Values

EXTENSION_POINT_EXECUTION_ENVIRONMENTS

public static final String EXTENSION_POINT_EXECUTION_ENVIRONMENTS
Simple identifier constant (value "executionEnvironments") for the execution environments extension point.

See Also:
Constant Field Values

EXTENSION_POINT_VM_INSTALLS

public static final String EXTENSION_POINT_VM_INSTALLS
Simple identifier constant (value "vmInstalls") for the VM installs extension point.

See Also:
Constant Field Values

JRE_CONTAINER

public static final String JRE_CONTAINER
Classpath container used for a project's JRE (value "org.eclipse.wst.jsdt.launching.JRE_CONTAINER"). A container is resolved in the context of a specific JavaScript project, to one or more system libraries contained in a JRE. The container can have zero or two path segments following the container name. When no segments follow the container name, the workspace default JRE is used to build a project. Otherwise the segments identify a specific JRE used to build a project:
  1. VM Install Type Identifier - identifies the type of JRE used to build the project. For example, the standard VM.
  2. VM Install Name - a user defined name that identifies that a specific VM of the above kind. For example, IBM 1.3.1. This information is shared in a projects includepath file, so teams must agree on JRE naming conventions.

Since 3.2, the path may also identify an execution environment as follows:

  1. Execution environment extension point name (value executionEnvironments)
  2. Identifier of a contributed execution environment

See Also:
Constant Field Values

BASE_BROWSER_LIB

public static final String BASE_BROWSER_LIB
See Also:
Constant Field Values

DEFAULT_SUPER_TYPE

public static final String DEFAULT_SUPER_TYPE
See Also:
Constant Field Values

DEFAULT_SUPER_TYPE_LIBRARY

public static final String DEFAULT_SUPER_TYPE_LIBRARY
See Also:
Constant Field Values

ERR_UNABLE_TO_RESOLVE_JRE

public static final int ERR_UNABLE_TO_RESOLVE_JRE
A status code indicating that a JRE could not be resolved for a project. When a JRE cannot be resolved for a project by this plug-in's container initializer, an exception is thrown with this status code. A status handler may be registered for this status code. The source object provided to the status handler is the JavaScript project for which the path could not be resolved. The status handler must return an IVMInstall or null. The container resolver will re-set the project's includepath if required.

See Also:
Constant Field Values

PREF_CONNECT_TIMEOUT

public static final String PREF_CONNECT_TIMEOUT
Preference key for launch/connect timeout. VM Runners should honor this timeout value when attempting to launch and connect to a debuggable VM. The value is an int, indicating a number of milliseconds.

See Also:
Constant Field Values

PREF_VM_XML

public static final String PREF_VM_XML
Preference key for the String of XML that defines all installed VMs.

See Also:
Constant Field Values

DEF_CONNECT_TIMEOUT

public static final int DEF_CONNECT_TIMEOUT
Default launch/connect timeout (ms).

See Also:
Constant Field Values

ATTR_CMDLINE

public static final String ATTR_CMDLINE
Deprecated. - use IProcess.ATTR_CMDLINE
Attribute key for a process property. The class org.eclipse.debug.core.model.IProcess allows attaching String properties to processes. The value of this attribute is the command line a process was launched with. Implementers of IVMRunner should use this attribute key to attach the command lines to the processes they create.

See Also:
Constant Field Values

CLASSPATH_ATTR_LIBRARY_PATH_ENTRY

public static final String CLASSPATH_ATTR_LIBRARY_PATH_ENTRY
Attribute key for a includepath attribute referencing a list of shared libraries that should appear on the -Djava.library.path system property.

The factory methods newLibraryPathsAttribute(String[]) and getLibraryPaths(IIncludePathAttribute) should be used to encode and decode the attribute value.

Each string is used to create an IPath using the constructor Path(String), and may contain IStringVariable's. Variable substitution is performed on the string prior to constructing a path from the string. If the resulting IPath is a relative path, it is interpreted as relative to the workspace location. If the path is absolute, it is interpreted as an absolute path in the local file system.

See Also:
IIncludePathAttribute, Constant Field Values
Method Detail

getVMInstall

public static IVMInstall getVMInstall(IJavaScriptProject project)
                               throws CoreException
Returns the VM assigned to build the given JavaScript project. The project must exist. The VM assigned to a project is determined from its build path.

Parameters:
project - the project to retrieve the VM from
Returns:
the VM instance that is assigned to build the given JavaScript project Returns null if no VM is referenced on the project's build path.
Throws:
CoreException - if unable to determine the project's VM install

getVMInstallType

public static IVMInstallType getVMInstallType(String id)
Returns the VM install type with the given unique id.

Parameters:
id - the VM install type unique id
Returns:
The VM install type for the given id, or null if no VM install type with the given id is registered.

setDefaultVMInstall

public static void setDefaultVMInstall(IVMInstall vm,
                                       IProgressMonitor monitor)
                                throws CoreException
Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.

Parameters:
vm - The vm to make the default. May be null to clear the default.
monitor - progress monitor or null
Throws:
CoreException

setDefaultVMInstall

public static void setDefaultVMInstall(IVMInstall vm,
                                       IProgressMonitor monitor,
                                       boolean savePreference)
                                throws CoreException
Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.

Parameters:
vm - The vm to make the default. May be null to clear the default.
monitor - progress monitor or null
savePreference - If true, update workbench preferences to reflect the new default VM.
Throws:
CoreException

getDefaultVMInstall

public static IVMInstall getDefaultVMInstall()
Return the default VM set with setDefaultVM().

Returns:
Returns the default VM. May return null when no default VM was set or when the default VM has been disposed.

getVMInstallTypes

public static IVMInstallType[] getVMInstallTypes()
Returns the list of registered VM types. VM types are registered via "org.eclipse.wst.jsdt.launching.vmTypes" extension point. Returns an empty list if there are no registered VM types.

Returns:
the list of registered VM types

getCompositeIdFromVM

public static String getCompositeIdFromVM(IVMInstall vm)
Returns a String that uniquely identifies the specified VM across all VM types.

Parameters:
vm - the instance of IVMInstallType to be identified

getVMFromCompositeId

public static IVMInstall getVMFromCompositeId(String idString)
Return the VM corresponding to the specified composite Id. The id uniquely identifies a VM across all vm types.

Parameters:
idString - the composite id that specifies an instance of IVMInstall

newProjectRuntimeClasspathEntry

public static IRuntimeClasspathEntry newProjectRuntimeClasspathEntry(IJavaScriptProject project)
Returns a new runtime includepath entry for the given project.

Parameters:
project - JavaScript project
Returns:
runtime includepath entry

newArchiveRuntimeClasspathEntry

public static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IResource resource)
Returns a new runtime includepath entry for the given archive.

Parameters:
resource - archive resource
Returns:
runtime includepath entry

newVariableRuntimeClasspathEntry

public static IRuntimeClasspathEntry newVariableRuntimeClasspathEntry(IPath path)
Returns a new runtime includepath entry for the includepath variable with the given path.

Parameters:
path - variable path; first segment is the name of the variable; trailing segments are appended to the resolved variable value
Returns:
runtime includepath entry

newRuntimeContainerClasspathEntry

public static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path,
                                                                       int classpathProperty)
                                                                throws CoreException
Returns a runtime includepath entry for the given container path with the given includepath property.

Parameters:
path - container path
includepathProperty - the type of entry - one of USER_CLASSES, BOOTSTRAP_CLASSES, or STANDARD_CLASSES
Returns:
runtime includepath entry
Throws:
CoreException - if unable to construct a runtime includepath entry

newRuntimeContainerClasspathEntry

public static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path,
                                                                       int classpathProperty,
                                                                       IJavaScriptProject project)
                                                                throws CoreException
Returns a runtime includepath entry for the given container path with the given includepath property to be resolved in the context of the given JavaScript project.

Parameters:
path - container path
includepathProperty - the type of entry - one of USER_CLASSES, BOOTSTRAP_CLASSES, or STANDARD_CLASSES
project - JavaScript project context used for resolution, or null if to be resolved in the context of the launch configuration this entry is referenced in
Returns:
runtime includepath entry
Throws:
CoreException - if unable to construct a runtime includepath entry

newRuntimeClasspathEntry

public static IRuntimeClasspathEntry newRuntimeClasspathEntry(String memento)
                                                       throws CoreException
Returns a runtime includepath entry constructed from the given memento.

Parameters:
memento - a memento for a runtime includepath entry
Returns:
runtime includepath entry
Throws:
CoreException - if unable to construct a runtime includepath entry

computeUnresolvedRuntimeClasspath

public static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(IJavaScriptProject project)
                                                                  throws CoreException
Computes and returns the default unresolved runtime includepath for the given project.

Returns:
runtime includepath entries
Throws:
CoreException - if unable to compute the runtime includepath
See Also:
IRuntimeClasspathEntry

resolveRuntimeClasspathEntry

public static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry,
                                                                    ILaunchConfiguration configuration)
                                                             throws CoreException
Returns resolved entries for the given entry in the context of the given launch configuration. If the entry is of kind VARIABLE or CONTAINER, variable and container resolvers are consulted. If the entry is of kind PROJECT, and the associated JavaScript project specifies non-default output locations, the corresponding output locations are returned. Otherwise, the given entry is returned.

If the given entry is a variable entry, and a resolver is not registered, the entry itself is returned. If the given entry is a container, and a resolver is not registered, resolved runtime includepath entries are calculated from the associated container includepath entries, in the context of the project associated with the given launch configuration.

Parameters:
entry - runtime includepath entry
configuration - launch configuration
Returns:
resolved runtime includepath entry
Throws:
CoreException - if unable to resolve
See Also:
IRuntimeClasspathEntryResolver

resolveRuntimeClasspath

public static IRuntimeClasspathEntry[] resolveRuntimeClasspath(IRuntimeClasspathEntry[] entries,
                                                               ILaunchConfiguration configuration)
                                                        throws CoreException
Resolves the given includepath, returning the resolved includepath in the context of the given launch configuration.

Parameters:
entries - unresolved includepath
configuration - launch configuration
Returns:
resolved runtime includepath entries
Throws:
CoreException - if unable to compute the includepath

getJavaProject

public static IJavaScriptProject getJavaProject(ILaunchConfiguration configuration)
                                         throws CoreException
Return the IJavaScriptProject referenced in the specified configuration or null if none.

Throws:
CoreException - if the referenced JavaScript project does not exist

computeVMInstall

public static IVMInstall computeVMInstall(ILaunchConfiguration configuration)
                                   throws CoreException
Returns the VM install for the given launch configuration. The VM install is determined in the following prioritized way:
  1. The VM install is explicitly specified on the launch configuration via the ATTR_JRE_CONTAINER_PATH attribute (since 3.2).
  2. The VM install is explicitly specified on the launch configuration via the ATTR_VM_INSTALL_TYPE and ATTR_VM_INSTALL_ID attributes.
  3. If no explicit VM install is specified, the VM install associated with the launch configuration's project is returned.
  4. If no project is specified, or the project does not specify a custom VM install, the workspace default VM install is returned.

Parameters:
configuration - launch configuration
Returns:
vm install
Throws:
CoreException - if unable to compute a vm install

computeDefaultRuntimeClassPath

public static String[] computeDefaultRuntimeClassPath(IJavaScriptProject jproject)
                                               throws CoreException
Computes the default application includepath entries for the given project.

Parameters:
jproject - The project to compute the includepath for
Returns:
The computed includepath. May be empty, but not null.
Throws:
CoreException - if unable to compute the default includepath

saveVMConfiguration

public static void saveVMConfiguration()
                                throws CoreException
Saves the VM configuration information to the preferences. This includes the following information:

getLibraryLocations

public static LibraryLocation[] getLibraryLocations(IVMInstall vm)
Evaluates library locations for a IVMInstall. If no library locations are set on the install, a default location is evaluated and checked if it exists.

Returns:
library locations with paths that exist or are empty

getDefaultJREContainerEntry

public static IIncludePathEntry getDefaultJREContainerEntry()
Creates and returns a includepath entry describing the default JRE container entry.

Returns:
a new IIncludePathEntry that describes the default JRE container entry

newDefaultJREContainerPath

public static IPath newDefaultJREContainerPath()
Returns a path for the JRE includepath container identifying the default VM install.

Returns:
includepath container path

newJREContainerPath

public static IPath newJREContainerPath(IVMInstall vm)
Returns a path for the JRE includepath container identifying the specified VM install by type and name.

Parameters:
vm - vm install
Returns:
includepath container path

newJREContainerPath

public static IPath newJREContainerPath(String typeId,
                                        String name)
Returns a path for the JRE includepath container identifying the specified VM install by type and name.

Parameters:
typeId - vm install type identifier
name - vm install name
Returns:
includepath container path

getExecutionEnvironmentId

public static String getExecutionEnvironmentId(IPath jreContainerPath)
Returns the execution environment identifier in the following JRE includepath container path, or null if none.

Parameters:
jreContainerPath - includepath container path
Returns:
execution environment identifier or null

computeJREEntry

public static IRuntimeClasspathEntry computeJREEntry(ILaunchConfiguration configuration)
                                              throws CoreException
Returns a runtime includepath entry identifying the JRE to use when launching the specified configuration or null if none is specified. The entry returned represents a either a includepath variable or includepath container that resolves to a JRE.

The entry is resolved as follows:

  1. If the ATTR_JRE_CONTAINER_PATH is present, it is used to create a includepath container referring to a JRE.
  2. Next, if the ATTR_VM_INSTALL_TYPE and ATTR_VM_INSTALL_NAME attributes are present, they are used to create a includepath container.
  3. When none of the above attributes are specified, a default entry is created which refers to the JRE referenced by the build path of the configuration's associated JavaScript project. This could be a includepath variable or includepath container.
  4. When there is no JavaScript project associated with a configuration, the workspace default JRE is used to create a container path.

Parameters:
configuration -
Returns:
includepath container path identifying a JRE or null
Throws:
org.eclipse.core.runtime.CoreException - if an exception occurs retrieving attributes from the specified launch configuration
CoreException

getPreferences

public static Preferences getPreferences()
Returns the preference store for the launching plug-in.

Returns:
the preference store for the launching plug-in

savePreferences

public static void savePreferences()
Saves the preferences for the launching plug-in.


addContainerResolver

public static void addContainerResolver(IRuntimeClasspathEntryResolver resolver,
                                        String containerIdentifier)
Registers the given resolver for the specified container.

Parameters:
resolver - runtime includepath entry resolver
containerIdentifier - identifier of the includepath container to register for

fireVMChanged

public static void fireVMChanged(PropertyChangeEvent event)
Notifies all VM install changed listeners of the given property change.

Parameters:
event - event describing the change.

fireVMAdded

public static void fireVMAdded(IVMInstall vm)
Notifies all VM install changed listeners of the VM addition

Parameters:
vm - the VM that has been added

fireVMRemoved

public static void fireVMRemoved(IVMInstall vm)
Notifies all VM install changed listeners of the VM removal

Parameters:
vm - the VM that has been removed

JavaScript Development Tools
Release 3.2

Copyright (c) IBM Corp. and others 2000, 2010. All Rights Reserved.