KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > launching > VMRunnerConfiguration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.launching;
13
14  
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jdt.internal.launching.LaunchingMessages;
18
19 /**
20  * Holder for various arguments passed to a VM runner.
21  * Mandatory parameters are passed in the constructor; optional arguments, via setters.
22  * <p>
23  * Clients may instantiate this class; it is not intended to be subclassed.
24  * </p>
25  */

26 public class VMRunnerConfiguration {
27     private String JavaDoc fClassToLaunch;
28     private String JavaDoc[] fVMArgs;
29     private String JavaDoc[] fProgramArgs;
30     private String JavaDoc[] fEnvironment;
31     private String JavaDoc[] fClassPath;
32     private String JavaDoc[] fBootClassPath;
33     private String JavaDoc fWorkingDirectory;
34     private Map JavaDoc fVMSpecificAttributesMap;
35     private boolean fResume = true;
36     
37     private static final String JavaDoc[] fgEmpty= new String JavaDoc[0];
38     
39     /**
40      * Creates a new configuration for launching a VM to run the given main class
41      * using the given class path.
42      *
43      * @param classToLaunch The fully qualified name of the class to launch. May not be null.
44      * @param classPath The classpath. May not be null.
45      */

46     public VMRunnerConfiguration(String JavaDoc classToLaunch, String JavaDoc[] classPath) {
47         if (classToLaunch == null) {
48             throw new IllegalArgumentException JavaDoc(LaunchingMessages.vmRunnerConfig_assert_classNotNull);
49         }
50         if (classPath == null) {
51             throw new IllegalArgumentException JavaDoc(LaunchingMessages.vmRunnerConfig_assert_classPathNotNull);
52         }
53         fClassToLaunch= classToLaunch;
54         fClassPath= classPath;
55     }
56
57     /**
58      * Sets the <code>Map</code> that contains String name/value pairs that represent
59      * VM-specific attributes.
60      *
61      * @param map the <code>Map</code> of VM-specific attributes.
62      * @since 2.0
63      */

64     public void setVMSpecificAttributesMap(Map JavaDoc map) {
65         fVMSpecificAttributesMap = map;
66     }
67
68     /**
69      * Sets the custom VM arguments. These arguments will be appended to the list of
70      * VM arguments that a VM runner uses when launching a VM. Typically, these VM arguments
71      * are set by the user.
72      * These arguments will not be interpreted by a VM runner, the client is responsible for
73      * passing arguments compatible with a particular VM runner.
74      *
75      * @param args the list of VM arguments
76      */

77     public void setVMArguments(String JavaDoc[] args) {
78         if (args == null) {
79             throw new IllegalArgumentException JavaDoc(LaunchingMessages.vmRunnerConfig_assert_vmArgsNotNull);
80         }
81         fVMArgs= args;
82     }
83     
84     /**
85      * Sets the custom program arguments. These arguments will be appended to the list of
86      * program arguments that a VM runner uses when launching a VM (in general: none).
87      * Typically, these VM arguments are set by the user.
88      * These arguments will not be interpreted by a VM runner, the client is responsible for
89      * passing arguments compatible with a particular VM runner.
90      *
91      * @param args the list of arguments
92      */

93     public void setProgramArguments(String JavaDoc[] args) {
94         if (args == null) {
95             throw new IllegalArgumentException JavaDoc(LaunchingMessages.vmRunnerConfig_assert_programArgsNotNull);
96         }
97         fProgramArgs= args;
98     }
99     
100     /**
101      * Sets the environment for the Java program. The Java VM will be
102      * launched in the given environment.
103      *
104      * @param environment the environment for the Java program specified as an array
105      * of strings, each element specifying an environment variable setting in the
106      * format <i>name</i>=<i>value</i>
107      * @since 3.0
108      */

109     public void setEnvironment(String JavaDoc[] environment) {
110         fEnvironment= environment;
111     }
112         
113     /**
114      * Sets the boot classpath. Note that the boot classpath will be passed to the
115      * VM "as is". This means it has to be complete. Interpretation of the boot class path
116      * is up to the VM runner this object is passed to.
117      * <p>
118      * In release 3.0, support has been added for appending and prepending the
119      * boot classpath. Generally an <code>IVMRunner</code> should use the prepend,
120      * main, and append boot classpaths provided. However, in the case that an
121      * <code>IVMRunner</code> does not support these options, a complete bootpath
122      * should also be specified.
123      * </p>
124      * @param bootClassPath The boot classpath. An empty array indicates an empty
125      * bootpath and <code>null</code> indicates a default bootpath.
126      */

127     public void setBootClassPath(String JavaDoc[] bootClassPath) {
128         fBootClassPath= bootClassPath;
129     }
130     
131     /**
132      * Returns the <code>Map</code> that contains String name/value pairs that represent
133      * VM-specific attributes.
134      *
135      * @return The <code>Map</code> of VM-specific attributes or <code>null</code>.
136      * @since 2.0
137      */

138     public Map JavaDoc getVMSpecificAttributesMap() {
139         return fVMSpecificAttributesMap;
140     }
141     
142     /**
143      * Returns the name of the class to launch.
144      *
145      * @return The fully qualified name of the class to launch. Will not be <code>null</code>.
146      */

147     public String JavaDoc getClassToLaunch() {
148         return fClassToLaunch;
149     }
150     
151     /**
152      * Returns the classpath.
153      *
154      * @return the classpath
155      */

156     public String JavaDoc[] getClassPath() {
157         return fClassPath;
158     }
159     
160     /**
161      * Returns the boot classpath. An empty array indicates an empty
162      * bootpath and <code>null</code> indicates a default bootpath.
163      * <p>
164      * In 3.0, support has been added for prepending and appending to the
165      * boot classpath. The new attributes are stored in the VM specific
166      * attributes map using the following keys defined in
167      * <code>IJavaLaunchConfigurationConstants</code>:
168      * <ul>
169      * <li>ATTR_BOOTPATH_PREPEND</li>
170      * <li>ATTR_BOOTPATH_APPEND</li>
171      * <li>ATTR_BOOTPATH</li>
172      * </ul>
173      * </p>
174      * @return The boot classpath. An empty array indicates an empty
175      * bootpath and <code>null</code> indicates a default bootpath.
176      * @see #setBootClassPath(String[])
177      * @see IJavaLaunchConfigurationConstants
178      */

179     public String JavaDoc[] getBootClassPath() {
180         return fBootClassPath;
181     }
182
183     /**
184      * Returns the arguments to the VM itself.
185      *
186      * @return The VM arguments. Default is an empty array. Will not be <code>null</code>.
187      * @see #setVMArguments(String[])
188      */

189     public String JavaDoc[] getVMArguments() {
190         if (fVMArgs == null) {
191             return fgEmpty;
192         }
193         return fVMArgs;
194     }
195     
196     /**
197      * Returns the arguments to the Java program.
198      *
199      * @return The Java program arguments. Default is an empty array. Will not be <code>null</code>.
200      * @see #setProgramArguments(String[])
201      */

202     public String JavaDoc[] getProgramArguments() {
203         if (fProgramArgs == null) {
204             return fgEmpty;
205         }
206         return fProgramArgs;
207     }
208     
209     /**
210      * Returns the environment for the Java program or <code>null</code>
211      *
212      * @return The Java program environment. Default is <code>null</code>
213      * @since 3.0
214      */

215     public String JavaDoc[] getEnvironment() {
216         return fEnvironment;
217     }
218     
219     /**
220      * Sets the working directory for a launched VM.
221      *
222      * @param path the absolute path to the working directory
223      * to be used by a launched VM, or <code>null</code> if
224      * the default working directory is to be inherited from the
225      * current process
226      * @since 2.0
227      */

228     public void setWorkingDirectory(String JavaDoc path) {
229         fWorkingDirectory = path;
230     }
231     
232     /**
233      * Returns the working directory of a launched VM.
234      *
235      * @return the absolute path to the working directory
236      * of a launched VM, or <code>null</code> if the working
237      * directory is inherited from the current process
238      * @since 2.0
239      */

240     public String JavaDoc getWorkingDirectory() {
241         return fWorkingDirectory;
242     }
243     
244     /**
245      * Sets whether the VM is resumed on startup when launched in
246      * debug mode. Has no effect when not in debug mode.
247      *
248      * @param resume whether to resume the VM on startup
249      * @since 3.0
250      */

251     public void setResumeOnStartup(boolean resume) {
252         fResume = resume;
253     }
254     
255     /**
256      * Returns whether the VM is resumed on startup when launched
257      * in debug mode. Has no effect when no in debug mode. Default
258      * value is <code>true</code> for backwards compatibility.
259      *
260      * @return whether to resume the VM on startup
261      * @since 3.0
262      */

263     public boolean isResumeOnStartup() {
264         return fResume;
265     }
266 }
267
Popular Tags