Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 106683 | Differences between
and this patch

Collapse All | Expand All

(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
    <classpathentry kind="src" path="j9/"/>
4
    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6
    <classpathentry kind="output" path="bin"/>
7
</classpath>
(-).cvsignore (+8 lines)
Added Link Here
1
bin
2
build.xml
3
j9launching.jar
4
j9launchingsrc.zip
5
org.eclipse.jdt.launching.j9_*.jar
6
publish.xml
7
publish_all.xml
8
temp.folder
(-).options (+2 lines)
Added Link Here
1
org.eclipse.jdt.launching.j9/debug = false
2
org.eclipse.jdt.launching.j9/command_line = false
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.jdt.launching.j9</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.jdt.core.javanature</nature>
26
		<nature>org.eclipse.pde.PluginNature</nature>
27
	</natures>
28
</projectDescription>
(-)build.properties (+7 lines)
Added Link Here
1
bin.includes = plugin.xml,\
2
               about.html,\
3
               plugin.properties,\
4
               j9launching.jar
5
source.j9launching.jar = j9/
6
7
src.includes=about.html
(-)epl-1.0.html (+328 lines)
Added Link Here
1
<html xmlns:o="urn:schemas-microsoft-com:office:office"
2
xmlns:w="urn:schemas-microsoft-com:office:word"
3
xmlns="http://www.w3.org/TR/REC-html40">
4
5
<head>
6
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
7
<meta name=ProgId content=Word.Document>
8
<meta name=Generator content="Microsoft Word 9">
9
<meta name=Originator content="Microsoft Word 9">
10
<link rel=File-List
11
href="./Eclipse%20EPL%202003_11_10%20Final_files/filelist.xml">
12
<title>Eclipse Public License - Version 1.0</title>
13
<!--[if gte mso 9]><xml>
14
 <o:DocumentProperties>
15
  <o:Revision>2</o:Revision>
16
  <o:TotalTime>3</o:TotalTime>
17
  <o:Created>2004-03-05T23:03:00Z</o:Created>
18
  <o:LastSaved>2004-03-05T23:03:00Z</o:LastSaved>
19
  <o:Pages>4</o:Pages>
20
  <o:Words>1626</o:Words>
21
  <o:Characters>9270</o:Characters>
22
   <o:Lines>77</o:Lines>
23
  <o:Paragraphs>18</o:Paragraphs>
24
  <o:CharactersWithSpaces>11384</o:CharactersWithSpaces>
25
  <o:Version>9.4402</o:Version>
26
 </o:DocumentProperties>
27
</xml><![endif]--><!--[if gte mso 9]><xml>
28
 <w:WordDocument>
29
  <w:TrackRevisions/>
30
 </w:WordDocument>
31
</xml><![endif]-->
32
<style>
33
<!--
34
 /* Font Definitions */
35
@font-face
36
	{font-family:Tahoma;
37
	panose-1:2 11 6 4 3 5 4 4 2 4;
38
	mso-font-charset:0;
39
	mso-generic-font-family:swiss;
40
	mso-font-pitch:variable;
41
	mso-font-signature:553679495 -2147483648 8 0 66047 0;}
42
 /* Style Definitions */
43
p.MsoNormal, li.MsoNormal, div.MsoNormal
44
	{mso-style-parent:"";
45
	margin:0in;
46
	margin-bottom:.0001pt;
47
	mso-pagination:widow-orphan;
48
	font-size:12.0pt;
49
	font-family:"Times New Roman";
50
	mso-fareast-font-family:"Times New Roman";}
51
p
52
	{margin-right:0in;
53
	mso-margin-top-alt:auto;
54
	mso-margin-bottom-alt:auto;
55
	margin-left:0in;
56
	mso-pagination:widow-orphan;
57
	font-size:12.0pt;
58
	font-family:"Times New Roman";
59
	mso-fareast-font-family:"Times New Roman";}
60
p.BalloonText, li.BalloonText, div.BalloonText
61
	{mso-style-name:"Balloon Text";
62
	margin:0in;
63
	margin-bottom:.0001pt;
64
	mso-pagination:widow-orphan;
65
	font-size:8.0pt;
66
	font-family:Tahoma;
67
	mso-fareast-font-family:"Times New Roman";}
68
@page Section1
69
	{size:8.5in 11.0in;
70
	margin:1.0in 1.25in 1.0in 1.25in;
71
	mso-header-margin:.5in;
72
	mso-footer-margin:.5in;
73
	mso-paper-source:0;}
74
div.Section1
75
	{page:Section1;}
76
-->
77
</style>
78
</head>
79
80
<body lang=EN-US style='tab-interval:.5in'>
81
82
<div class=Section1>
83
84
<p align=center style='text-align:center'><b>Eclipse Public License - v 1.0</b>
85
</p>
86
87
<p><span style='font-size:10.0pt'>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER
88
THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (&quot;AGREEMENT&quot;). ANY USE,
89
REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
90
OF THIS AGREEMENT.</span> </p>
91
92
<p><b><span style='font-size:10.0pt'>1. DEFINITIONS</span></b> </p>
93
94
<p><span style='font-size:10.0pt'>&quot;Contribution&quot; means:</span> </p>
95
96
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>a)
97
in the case of the initial Contributor, the initial code and documentation
98
distributed under this Agreement, and<br clear=left>
99
b) in the case of each subsequent Contributor:</span></p>
100
101
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>i)
102
changes to the Program, and</span></p>
103
104
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>ii)
105
additions to the Program;</span></p>
106
107
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>where
108
such changes and/or additions to the Program originate from and are distributed
109
by that particular Contributor. A Contribution 'originates' from a Contributor
110
if it was added to the Program by such Contributor itself or anyone acting on
111
such Contributor's behalf. Contributions do not include additions to the
112
Program which: (i) are separate modules of software distributed in conjunction
113
with the Program under their own license agreement, and (ii) are not derivative
114
works of the Program. </span></p>
115
116
<p><span style='font-size:10.0pt'>&quot;Contributor&quot; means any person or
117
entity that distributes the Program.</span> </p>
118
119
<p><span style='font-size:10.0pt'>&quot;Licensed Patents &quot; mean patent
120
claims licensable by a Contributor which are necessarily infringed by the use
121
or sale of its Contribution alone or when combined with the Program. </span></p>
122
123
<p><span style='font-size:10.0pt'>&quot;Program&quot; means the Contributions
124
distributed in accordance with this Agreement.</span> </p>
125
126
<p><span style='font-size:10.0pt'>&quot;Recipient&quot; means anyone who
127
receives the Program under this Agreement, including all Contributors.</span> </p>
128
129
<p><b><span style='font-size:10.0pt'>2. GRANT OF RIGHTS</span></b> </p>
130
131
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>a)
132
Subject to the terms of this Agreement, each Contributor hereby grants Recipient
133
a non-exclusive, worldwide, royalty-free copyright license to<span
134
style='color:red'> </span>reproduce, prepare derivative works of, publicly
135
display, publicly perform, distribute and sublicense the Contribution of such
136
Contributor, if any, and such derivative works, in source code and object code
137
form.</span></p>
138
139
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>b)
140
Subject to the terms of this Agreement, each Contributor hereby grants
141
Recipient a non-exclusive, worldwide,<span style='color:green'> </span>royalty-free
142
patent license under Licensed Patents to make, use, sell, offer to sell, import
143
and otherwise transfer the Contribution of such Contributor, if any, in source
144
code and object code form. This patent license shall apply to the combination
145
of the Contribution and the Program if, at the time the Contribution is added
146
by the Contributor, such addition of the Contribution causes such combination
147
to be covered by the Licensed Patents. The patent license shall not apply to
148
any other combinations which include the Contribution. No hardware per se is
149
licensed hereunder. </span></p>
150
151
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>c)
152
Recipient understands that although each Contributor grants the licenses to its
153
Contributions set forth herein, no assurances are provided by any Contributor
154
that the Program does not infringe the patent or other intellectual property
155
rights of any other entity. Each Contributor disclaims any liability to Recipient
156
for claims brought by any other entity based on infringement of intellectual
157
property rights or otherwise. As a condition to exercising the rights and
158
licenses granted hereunder, each Recipient hereby assumes sole responsibility
159
to secure any other intellectual property rights needed, if any. For example,
160
if a third party patent license is required to allow Recipient to distribute
161
the Program, it is Recipient's responsibility to acquire that license before
162
distributing the Program.</span></p>
163
164
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>d)
165
Each Contributor represents that to its knowledge it has sufficient copyright
166
rights in its Contribution, if any, to grant the copyright license set forth in
167
this Agreement. </span></p>
168
169
<p><b><span style='font-size:10.0pt'>3. REQUIREMENTS</span></b> </p>
170
171
<p><span style='font-size:10.0pt'>A Contributor may choose to distribute the
172
Program in object code form under its own license agreement, provided that:</span>
173
</p>
174
175
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>a)
176
it complies with the terms and conditions of this Agreement; and</span></p>
177
178
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>b)
179
its license agreement:</span></p>
180
181
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>i)
182
effectively disclaims on behalf of all Contributors all warranties and
183
conditions, express and implied, including warranties or conditions of title
184
and non-infringement, and implied warranties or conditions of merchantability
185
and fitness for a particular purpose; </span></p>
186
187
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>ii)
188
effectively excludes on behalf of all Contributors all liability for damages,
189
including direct, indirect, special, incidental and consequential damages, such
190
as lost profits; </span></p>
191
192
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>iii)
193
states that any provisions which differ from this Agreement are offered by that
194
Contributor alone and not by any other party; and</span></p>
195
196
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>iv)
197
states that source code for the Program is available from such Contributor, and
198
informs licensees how to obtain it in a reasonable manner on or through a
199
medium customarily used for software exchange.<span style='color:blue'> </span></span></p>
200
201
<p><span style='font-size:10.0pt'>When the Program is made available in source
202
code form:</span> </p>
203
204
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>a)
205
it must be made available under this Agreement; and </span></p>
206
207
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt'>b) a
208
copy of this Agreement must be included with each copy of the Program. </span></p>
209
210
<p><span style='font-size:10.0pt'>Contributors may not remove or alter any
211
copyright notices contained within the Program. </span></p>
212
213
<p><span style='font-size:10.0pt'>Each Contributor must identify itself as the
214
originator of its Contribution, if any, in a manner that reasonably allows
215
subsequent Recipients to identify the originator of the Contribution. </span></p>
216
217
<p><b><span style='font-size:10.0pt'>4. COMMERCIAL DISTRIBUTION</span></b> </p>
218
219
<p><span style='font-size:10.0pt'>Commercial distributors of software may
220
accept certain responsibilities with respect to end users, business partners
221
and the like. While this license is intended to facilitate the commercial use
222
of the Program, the Contributor who includes the Program in a commercial
223
product offering should do so in a manner which does not create potential
224
liability for other Contributors. Therefore, if a Contributor includes the
225
Program in a commercial product offering, such Contributor (&quot;Commercial
226
Contributor&quot;) hereby agrees to defend and indemnify every other
227
Contributor (&quot;Indemnified Contributor&quot;) against any losses, damages and
228
costs (collectively &quot;Losses&quot;) arising from claims, lawsuits and other
229
legal actions brought by a third party against the Indemnified Contributor to
230
the extent caused by the acts or omissions of such Commercial Contributor in
231
connection with its distribution of the Program in a commercial product
232
offering. The obligations in this section do not apply to any claims or Losses
233
relating to any actual or alleged intellectual property infringement. In order
234
to qualify, an Indemnified Contributor must: a) promptly notify the Commercial
235
Contributor in writing of such claim, and b) allow the Commercial Contributor
236
to control, and cooperate with the Commercial Contributor in, the defense and
237
any related settlement negotiations. The Indemnified Contributor may participate
238
in any such claim at its own expense.</span> </p>
239
240
<p><span style='font-size:10.0pt'>For example, a Contributor might include the
241
Program in a commercial product offering, Product X. That Contributor is then a
242
Commercial Contributor. If that Commercial Contributor then makes performance
243
claims, or offers warranties related to Product X, those performance claims and
244
warranties are such Commercial Contributor's responsibility alone. Under this
245
section, the Commercial Contributor would have to defend claims against the
246
other Contributors related to those performance claims and warranties, and if a
247
court requires any other Contributor to pay any damages as a result, the
248
Commercial Contributor must pay those damages.</span> </p>
249
250
<p><b><span style='font-size:10.0pt'>5. NO WARRANTY</span></b> </p>
251
252
<p><span style='font-size:10.0pt'>EXCEPT AS EXPRESSLY SET FORTH IN THIS
253
AGREEMENT, THE PROGRAM IS PROVIDED ON AN &quot;AS IS&quot; BASIS, WITHOUT
254
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING,
255
WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
256
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
257
responsible for determining the appropriateness of using and distributing the
258
Program and assumes all risks associated with its exercise of rights under this
259
Agreement , including but not limited to the risks and costs of program errors,
260
compliance with applicable laws, damage to or loss of data, programs or
261
equipment, and unavailability or interruption of operations. </span></p>
262
263
<p><b><span style='font-size:10.0pt'>6. DISCLAIMER OF LIABILITY</span></b> </p>
264
265
<p><span style='font-size:10.0pt'>EXCEPT AS EXPRESSLY SET FORTH IN THIS
266
AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR
267
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
268
(INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY
269
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
270
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF
271
THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF
272
THE POSSIBILITY OF SUCH DAMAGES.</span> </p>
273
274
<p><b><span style='font-size:10.0pt'>7. GENERAL</span></b> </p>
275
276
<p><span style='font-size:10.0pt'>If any provision of this Agreement is invalid
277
or unenforceable under applicable law, it shall not affect the validity or
278
enforceability of the remainder of the terms of this Agreement, and without
279
further action by the parties hereto, such provision shall be reformed to the
280
minimum extent necessary to make such provision valid and enforceable.</span> </p>
281
282
<p><span style='font-size:10.0pt'>If Recipient institutes patent litigation
283
against any entity (including a cross-claim or counterclaim in a lawsuit)
284
alleging that the Program itself (excluding combinations of the Program with
285
other software or hardware) infringes such Recipient's patent(s), then such
286
Recipient's rights granted under Section 2(b) shall terminate as of the date
287
such litigation is filed. </span></p>
288
289
<p><span style='font-size:10.0pt'>All Recipient's rights under this Agreement
290
shall terminate if it fails to comply with any of the material terms or
291
conditions of this Agreement and does not cure such failure in a reasonable
292
period of time after becoming aware of such noncompliance. If all Recipient's
293
rights under this Agreement terminate, Recipient agrees to cease use and
294
distribution of the Program as soon as reasonably practicable. However,
295
Recipient's obligations under this Agreement and any licenses granted by
296
Recipient relating to the Program shall continue and survive. </span></p>
297
298
<p><span style='font-size:10.0pt'>Everyone is permitted to copy and distribute
299
copies of this Agreement, but in order to avoid inconsistency the Agreement is
300
copyrighted and may only be modified in the following manner. The Agreement
301
Steward reserves the right to publish new versions (including revisions) of
302
this Agreement from time to time. No one other than the Agreement Steward has
303
the right to modify this Agreement. The Eclipse Foundation is the initial
304
Agreement Steward. The Eclipse Foundation may assign the responsibility to
305
serve as the Agreement Steward to a suitable separate entity. Each new version
306
of the Agreement will be given a distinguishing version number. The Program
307
(including Contributions) may always be distributed subject to the version of
308
the Agreement under which it was received. In addition, after a new version of
309
the Agreement is published, Contributor may elect to distribute the Program
310
(including its Contributions) under the new version. Except as expressly stated
311
in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to
312
the intellectual property of any Contributor under this Agreement, whether
313
expressly, by implication, estoppel or otherwise. All rights in the Program not
314
expressly granted under this Agreement are reserved.</span> </p>
315
316
<p><span style='font-size:10.0pt'>This Agreement is governed by the laws of the
317
State of New York and the intellectual property laws of the United States of
318
America. No party to this Agreement will bring a legal action under this
319
Agreement more than one year after the cause of action arose. Each party waives
320
its rights to a jury trial in any resulting litigation.</span> </p>
321
322
<p class=MsoNormal><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
323
324
</div>
325
326
</body>
327
328
</html>
(-)plugin.properties (+16 lines)
Added Link Here
1
######################################################################
2
# Copyright (c) 2002, 2004 IBM Corporation.
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 implementation
10
######################################################################
11
12
pluginName=J9 VM Launching
13
providerName=IBM
14
15
J9PreferencePage.label=J9
16
J9PropertyPage.label=J9
(-)plugin.xml (+99 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
3
<plugin
4
   id="org.eclipse.jdt.launching.j9"
5
   name="%pluginName"
6
   version="5.7.1"
7
   provider-name="%providerName"
8
   class="org.eclipse.jdt.internal.launching.j9.J9LaunchingPlugin">
9
10
   <runtime>
11
      <library name="j9launching.jar">
12
         <export name="*"/>
13
      </library>
14
   </runtime>
15
   <requires>
16
      <import plugin="org.eclipse.core.resources"/>
17
      <import plugin="org.eclipse.core.runtime"/>
18
      <import plugin="org.eclipse.debug.core"/>
19
      <import plugin="org.eclipse.debug.ui"/>
20
      <import plugin="org.eclipse.jdt.core"/>
21
      <import plugin="org.eclipse.jdt.debug"/>
22
      <import plugin="org.eclipse.jdt.debug.ui"/>
23
      <import plugin="org.eclipse.jdt.launching"/>
24
      <import plugin="org.eclipse.ui"/>
25
      <import plugin="org.eclipse.ui.ide"/>
26
      <import plugin="org.eclipse.update.configurator"/>
27
   </requires>
28
29
30
<!-- Extension points -->
31
   <extension-point id="J9VMInstallLocations" name="J9 VM Install Locations"/>
32
33
<!-- Extensions -->
34
   <extension
35
         point="org.eclipse.ui.preferencePages">
36
      <page
37
            name="%J9PreferencePage.label"
38
            category="org.eclipse.jdt.ui.preferences.JavaBasePreferencePage"
39
            class="org.eclipse.jdt.internal.launching.j9.J9PreferencePage"
40
            id="com.ibm.ive.internal.j9.launcher.J9PreferencePage">
41
      </page>
42
   </extension>
43
   <extension
44
         point="org.eclipse.ui.propertyPages">
45
      <page
46
            objectClass="org.eclipse.core.resources.IProject"
47
            adaptable="true"
48
            name="%J9PropertyPage.label"
49
            class="org.eclipse.jdt.internal.launching.j9.J9PropertyPage"
50
            id="com.ibm.ive.internal.j9.launcher.J9PropertyPage">
51
         <filter
52
               name="projectNature"
53
               value="com.ibm.ive.j9.J2MENature">
54
         </filter>
55
      </page>
56
   </extension>
57
   <extension
58
         point="org.eclipse.ui.propertyPages">
59
      <page
60
            objectClass="org.eclipse.core.resources.IProject"
61
            adaptable="true"
62
            name="%J9PropertyPage.label"
63
            class="org.eclipse.jdt.internal.launching.j9.J9PropertyPage"
64
            id="com.ibm.ive.internal.j9.launcher.J9PropertyPage">
65
         <filter
66
               name="projectNature"
67
               value="com.ibm.ive.j9.CustomNature">
68
         </filter>
69
      </page>
70
   </extension>
71
   <extension
72
         point="org.eclipse.jdt.launching.vmInstallTypes">
73
      <vmInstallType
74
            class="org.eclipse.jdt.internal.launching.j9.J9VMInstallType"
75
            id="com.ibm.ive.internal.j9.launcher.J9VMType">
76
      </vmInstallType>
77
   </extension>
78
<!-- added the SocketAttach back in to keep old projects with devices happy. -->
79
   <extension
80
         point="org.eclipse.jdt.launching.vmConnectors">
81
      <vmConnector
82
            class="org.eclipse.jdt.internal.launching.j9.J9ConnectorDelegate"
83
            id="com.ibm.ive.internal.j9.launcher.J9ConnectorDelegate">
84
      </vmConnector>
85
      <vmConnector
86
            class="org.eclipse.jdt.internal.launching.j9.J9SocketAttachConnectorDelegate"
87
            id="com.ibm.ive.internal.j9.launcher.J9SocketAttachConnector">
88
      </vmConnector>
89
   </extension>
90
   <extension
91
         point="org.eclipse.jdt.debug.ui.vmInstallTypePage">
92
      <vmInstallTypePage
93
            vmInstallTypeID="com.ibm.ive.internal.j9.launcher.J9VMType"
94
            class="org.eclipse.jdt.internal.launching.j9.J9VMCommandTab"
95
            id="com.ibm.ive.internal.j9.launcher.J9VMCommandTab">
96
      </vmInstallTypePage>
97
   </extension>
98
99
</plugin>
(-)j9/org/eclipse/jdt/internal/launching/j9/ComboFieldEditor.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import org.eclipse.jface.preference.FieldEditor;
14
import org.eclipse.jface.util.Assert;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
23
/**
24
 * A field editor for a combo box that allows the drop-down selection of one of a list of items.
25
 */
26
public class ComboFieldEditor extends FieldEditor {
27
28
	/**
29
	 * The <code>Combo</code> widget.
30
	 */
31
	private Combo fCombo;
32
	
33
	/**
34
	 * The value (not the name) of the currently selected item in the Combo widget.
35
	 */
36
	private String fValue;
37
	
38
	/**
39
	 * The names (labels) and underlying values to populate the combo widget.  These should be
40
	 * arranged as: { {name1, value1}, {name2, value2}, ...}
41
	 */
42
	private String[][] fEntryNamesAndValues;
43
44
	public ComboFieldEditor(String name, String labelText, String[][] entryNamesAndValues, Composite parent) {
45
		init(name, labelText);
46
		Assert.isTrue(checkArray(entryNamesAndValues));
47
		fEntryNamesAndValues = entryNamesAndValues;
48
		createControl(parent);		
49
	}
50
51
	/**
52
	 * Checks whether given <code>String[][]</code> is of "type" 
53
	 * <code>String[][2]</code>.
54
	 *
55
	 * @return <code>true</code> if it is ok, and <code>false</code> otherwise
56
	 */
57
	private boolean checkArray(String[][] table) {
58
		if (table == null) {
59
			return false;
60
		}
61
		for (int i = 0; i < table.length; i++) {
62
			String[] array = table[i];
63
			if (array == null || array.length != 2) {
64
				return false;
65
			}
66
		}
67
		return true;
68
	}
69
70
	/**
71
	 * @see FieldEditor#adjustForNumColumns(int)
72
	 */
73
	protected void adjustForNumColumns(int numColumns) {
74
	}
75
76
	/**
77
	 * @see FieldEditor#doFillIntoGrid(Composite, int)
78
	 */
79
	protected void doFillIntoGrid(Composite parent, int numColumns) {
80
		Control control = getLabelControl(parent);
81
		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
82
		gd.horizontalSpan = 1;
83
		control.setLayoutData(gd);
84
		control = getComboBoxControl(parent);
85
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
86
		gd.horizontalSpan = 1;
87
		control.setLayoutData(gd);
88
	}
89
90
	/**
91
	 * @see FieldEditor#doLoad()
92
	 */
93
	protected void doLoad() {
94
		updateComboForValue(getPreferenceStore().getString(getPreferenceName()));
95
	}
96
97
	/**
98
	 * @see FieldEditor#doLoadDefault()
99
	 */
100
	protected void doLoadDefault() {
101
		updateComboForValue(getPreferenceStore().getDefaultString(getPreferenceName()));
102
	}
103
104
	/**
105
	 * @see FieldEditor#doStore()
106
	 */
107
	protected void doStore() {
108
		/*
109
		 * the receiver does not hear about vms added and removed while the preference page
110
		 * is open, hence the current selection can be a non-existant vm, so first ensure it
111
		 * exits before writing it to the store
112
		 */		
113
		if (fValue == null || J9PreferencePage.getVMNamesFromId(fValue) == null) {
114
			getPreferenceStore().setToDefault(getPreferenceName());
115
			return;
116
		}
117
	
118
		getPreferenceStore().setValue(getPreferenceName(), fValue);
119
	}
120
121
	/**
122
	 * @see FieldEditor#getNumberOfControls()
123
	 */
124
	public int getNumberOfControls() {
125
		return 2;
126
	}
127
128
	/**
129
	 * Lazily create and return the Combo control.
130
	 */
131
	public Combo getComboBoxControl(Composite parent) {
132
		if (fCombo == null) {
133
			fCombo = new Combo(parent, SWT.READ_ONLY);
134
			for (int i = 0; i < fEntryNamesAndValues.length; i++) {
135
				fCombo.add(fEntryNamesAndValues[i][0], i);
136
			}
137
			
138
			fCombo.addSelectionListener(new SelectionAdapter() {
139
				public void widgetSelected(SelectionEvent evt) {
140
					String oldValue = fValue;
141
					String name = fCombo.getText();
142
					fValue = getValueForName(name);
143
					setPresentsDefaultValue(false);
144
					fireValueChanged(VALUE, oldValue, fValue);					
145
				}
146
			});
147
		}
148
		return fCombo;
149
	}
150
	
151
	/**
152
	 * Given the name (label) of an entry, return the corresponding value.
153
	 */
154
	protected String getValueForName(String name) {
155
		for (int i = 0; i < fEntryNamesAndValues.length; i++) {
156
			String[] entry = fEntryNamesAndValues[i];
157
			if (name.equals(entry[0])) {
158
				return entry[1];
159
			}
160
		}
161
		return fEntryNamesAndValues[0][0];
162
	}
163
	
164
	/**
165
	 * Set the name in the combo widget to match the specified value.
166
	 */
167
	protected void updateComboForValue(String value) {
168
		fValue = value;
169
		for (int i = 0; i < fEntryNamesAndValues.length; i++) {
170
			if (value.equals(fEntryNamesAndValues[i][1])) {
171
				fCombo.setText(fEntryNamesAndValues[i][0]);
172
				return;
173
			}
174
		}
175
		if (fEntryNamesAndValues.length > 0) {
176
			fValue = fEntryNamesAndValues[0][1];
177
		}
178
	}
179
}
(-)j9/org/eclipse/jdt/internal/launching/j9/IJ9Connector.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.util.Map;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.debug.core.ILaunch;
18
import org.eclipse.jdt.launching.IVMInstall;
19
 
20
public interface IJ9Connector {
21
22
	public void postLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException;
23
	public void preLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException;
24
	
25
	/**
26
	 * Run the connector.
27
	 */
28
	public void connect(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException;	
29
	
30
	public IVMInstall getIVMInstall();
31
	public void setIVMInstall(IVMInstall vm);
32
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9ConnectorDelegate.java (+407 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
 
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.debug.core.ILaunch;
20
import org.eclipse.jdt.debug.core.JDIDebugModel;
21
import org.eclipse.jdt.launching.IVMConnector;
22
import org.eclipse.jdt.launching.IVMInstall;
23
import org.eclipse.jdt.launching.j9.IJ9LaunchConfigurationConstants;
24
import org.eclipse.jdt.launching.j9.J9Launching;
25
26
import com.sun.jdi.connect.Connector;
27
28
/**
29
 * Delegating J9 connector.  For 2.0 VMs it provides a SocketAttachConnector, 
30
 * and for 2.1 VMs it launches the listening socket and creates a Listening 
31
 * connector. 
32
 */
33
public class J9ConnectorDelegate implements IVMConnector {
34
	public final static String ARG_HOSTNAME = "hostname"; //$NON-NLS-1$
35
	public final static String ARG_PORT = "port"; //$NON-NLS-1$
36
	public final static String ARG_DBGPORT = "debugport"; //$NON-NLS-1$
37
	public final static String ARG_DEBUG_TIMEOUT = "debug_timeout"; //$NON-NLS-1$
38
	public final static String ARG_VM_INSTALL_NAME = "proxyvm"; //$NON-NLS-1$
39
	public final static String ARG_PROXY_OPTIONS = "proxy_options"; //$NON-NLS-1$
40
41
	// tbd: Note that the identifier "Default" is stored in launch configs
42
	// Therefore, the string should not be translated for nls
43
	public final static String DEFAULT_JRE_NAME = "Default"; //$NON-NLS-1$
44
45
	private IJ9Connector connector;
46
	private J9VMInstall vmInstall;
47
48
	/**
49
	 * Constructor for J9Connector.
50
	 */
51
	public J9ConnectorDelegate() {
52
		super();
53
	}
54
55
	/**
56
	 * Set up this delegate to use the following VM
57
	 */
58
	public void configure(J9VMInstall vmInstall) throws CoreException {
59
		this.vmInstall = vmInstall;
60
		if (vmInstall.is21J9Version()) {
61
			connector = new J9ListeningConnector();
62
		}
63
		else {
64
			connector = new J9SocketAttachConnector();
65
		}
66
		connector.setIVMInstall(this.getVmInstall());
67
	}
68
	
69
	public void postLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch)  throws CoreException {
70
		connector.postLaunch(arguments, monitor, launch);
71
	}
72
	
73
	public void preLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch)  throws CoreException {
74
		connector.preLaunch(arguments, monitor, launch);
75
	}
76
77
	/**
78
	 * @see org.eclipse.jdt.launching.IVMConnector#connect(Map, IProgressMonitor, ILaunch)
79
	 */
80
	public void connect(
81
		Map arguments,
82
		IProgressMonitor monitor,
83
		ILaunch launch)
84
		throws CoreException {
85
		
86
		connector.connect(arguments, monitor, launch);	
87
	}
88
89
	/**
90
	 * @see org.eclipse.jdt.launching.IVMConnector#getName()
91
	 */
92
	public String getName() {
93
		return J9LauncherMessages.getString("J9SocketAttachConnector.J9_21_(Proxied_Socket_Attach)"); //$NON-NLS-1$
94
	}
95
96
	/**
97
	 * @see org.eclipse.jdt.launching.IVMConnector#getIdentifier()
98
	 */
99
	public String getIdentifier() {
100
		return IJ9LaunchConfigurationConstants.ID_J9_SOCKET_ATTACH_VM_CONNECTOR;
101
	}
102
	
103
	/*
104
	 * Return names of configured j9 vm installs.
105
	 */
106
	private static List getJ9VMInstallNames() {
107
		IVMInstall vmInstalls[] = J9Launching.getJ9VMInstalls();
108
		ArrayList names = new ArrayList();
109
		for (int i = 0; i < vmInstalls.length; i++) {
110
			names.add(vmInstalls[i].getName());
111
		}
112
		return names;
113
	}	
114
115
	/**
116
	 * @see org.eclipse.jdt.launching.IVMConnector#getDefaultArguments()
117
	 */
118
	public Map getDefaultArguments() throws CoreException {
119
		Map def =
120
			J9Launching.getAttachingConnector()
121
				.defaultArguments();
122
        String label = J9LauncherMessages.getString("J9ConnectorDelegate.&Host_1"); //$NON-NLS-1$
123
        String description = J9LauncherMessages.getString("J9ConnectorDelegate.Host_2");              //$NON-NLS-1$
124
        Connector.StringArgument hostArg =
125
                    new StringArgumentImpl(
126
                        ARG_HOSTNAME,
127
                        description,
128
                        label,
129
                        true);   
130
        hostArg.setValue(J9ListeningConnector.getLocalIP());                
131
        def.put(hostArg.name(), hostArg);
132
                     
133
		
134
		//98093Connector.IntegerArgument portArg =
135
		//98093	(Connector.IntegerArgument) def.get(ARG_PORT);
136
		//98093portArg.setValue(IJ9LaunchConfigurationConstants.DEFAULT_DEBUG_PORT);
137
		//98093
138
		label =
139
			J9LauncherMessages.getString(
140
				"J9ConnectorDelegate.&Port"); //$NON-NLS-1$
141
		description = J9LauncherMessages.getString("J9ConnectorDelegate.Port");  //$NON-NLS-1$
142
		Connector.IntegerArgument portArg =
143
			new IntegerArgumentImpl(
144
				ARG_PORT,
145
				description,
146
				label,
147
				true,
148
				1,
149
				Integer.MAX_VALUE);
150
		portArg.setValue(IJ9LaunchConfigurationConstants.DEFAULT_DEBUG_PORT);
151
		def.put(portArg.name(), portArg);
152
		// end 98093 fix
153
		
154
		List names = getJ9VMInstallNames();
155
		names.add(0, DEFAULT_JRE_NAME);
156
	
157
		
158
		label =
159
			J9LauncherMessages.getString(
160
				"J9SocketAttachConnector.Debug_timeout"); //$NON-NLS-1$
161
		description = J9LauncherMessages.getString("J9ConnectorDelegate.Debug_timeout_(ms)_3");  //$NON-NLS-1$
162
		Connector.IntegerArgument timeoutArg =
163
			new IntegerArgumentImpl(
164
				ARG_DEBUG_TIMEOUT,
165
				description,
166
				label,
167
				false,
168
				1,
169
				Integer.MAX_VALUE);
170
        int timeout = Math.max(JDIDebugModel.getPreferences().getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT), 120000);        
171
		timeoutArg.setValue(timeout);
172
		def.put(timeoutArg.name(), timeoutArg);
173
174
		label =
175
			J9LauncherMessages.getString(
176
				"J9SocketAttachConnector.JRE_(used_for_debug_proxy)"); //$NON-NLS-1$
177
		description = J9LauncherMessages.getString("J9ConnectorDelegate.JRE_(used_for_debug_proxy)_4");		 //$NON-NLS-1$
178
		Connector.SelectedArgument vmArg =
179
			new SelectedArgumentImpl(
180
				ARG_VM_INSTALL_NAME,
181
				description,
182
				label,
183
				true,
184
				names);
185
		vmArg.setValue(DEFAULT_JRE_NAME);
186
		def.put(vmArg.name(), vmArg);
187
188
		label =
189
			J9LauncherMessages.getString(
190
				"J9SocketAttachConnector.Proxy_options"); //$NON-NLS-1$
191
		description = J9LauncherMessages.getString("J9ConnectorDelegate.Proxy_options_5"); //$NON-NLS-1$
192
		Connector.StringArgument proxyOptionsArg =
193
			new StringArgumentImpl(
194
				ARG_PROXY_OPTIONS,
195
				description,
196
				label,
197
				true);
198
		proxyOptionsArg.setValue(""); //$NON-NLS-1$
199
		def.put(proxyOptionsArg.name(), proxyOptionsArg);
200
		
201
		return def;
202
	}
203
204
	/**
205
	 * @see org.eclipse.jdt.launching.IVMConnector#getArgumentOrder()
206
	 */
207
	public List getArgumentOrder() {
208
		List list = new ArrayList(4);
209
		list.add(ARG_HOSTNAME);
210
		list.add(ARG_PORT);
211
		list.add(ARG_DEBUG_TIMEOUT);
212
		list.add(ARG_VM_INSTALL_NAME);
213
		list.add(ARG_PROXY_OPTIONS);
214
		return list;
215
	}
216
217
	/**
218
	 * Argument class for arguments that are used to establish a connection.
219
	 */
220
	public abstract class ArgumentImpl implements com.sun.jdi.connect.Connector.Argument {
221
		private String fName;
222
		private String fDescription;
223
		private String fLabel;
224
		private boolean fMustSpecify;
225
226
		protected ArgumentImpl(String name, String description, String label, boolean mustSpecify) {
227
			fName = name;
228
			fLabel = label;
229
			fDescription = description;
230
			fMustSpecify = mustSpecify;
231
		}
232
233
		public String name() { 
234
			return fName;
235
		}
236
		
237
		public String description() {
238
			return fDescription;
239
		}
240
		
241
		public String label() {
242
			return fLabel;
243
		}
244
		
245
		public boolean mustSpecify() {
246
			return fMustSpecify;
247
		}
248
		
249
		public abstract String value();
250
		public abstract void setValue(String value);
251
		public abstract boolean isValid(String value);
252
		public abstract String toString();
253
	}
254
	
255
	public class StringArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.StringArgument {
256
		private String fValue;
257
258
		protected StringArgumentImpl(String name, String description, String label, boolean mustSpecify) {
259
			super(name, description, label, mustSpecify);
260
		}
261
	 	
262
		public String value() {
263
			return fValue;
264
		}
265
		
266
		public void setValue(String value) {
267
			fValue = value;
268
		}
269
270
		public boolean isValid(String value) {
271
			return true;
272
		}
273
274
		public String toString() {
275
			return fValue;
276
		}
277
278
	}
279
	
280
	public class IntegerArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.IntegerArgument {
281
		private Integer fValue;
282
		private int fMin;
283
		private int fMax;
284
285
		protected IntegerArgumentImpl(String name, String description, String label, boolean mustSpecify, int min, int max) {
286
			super(name, description, label, mustSpecify);
287
			fMin = min;
288
			fMax = max;
289
		}
290
	 	
291
		public String value() {
292
			return fValue.toString();
293
		}
294
		
295
		public void setValue(String value) {
296
			fValue = new Integer(value);
297
		}
298
299
		public boolean isValid(String value) {
300
			Integer val;
301
			try {
302
				val = new Integer(value);
303
			} catch (NumberFormatException e) {
304
				return false;
305
			}
306
			return isValid(val.intValue());
307
		}
308
309
		public String toString() {
310
			return value();
311
		}
312
313
		public int intValue() {
314
			return fValue.intValue();
315
		}
316
		
317
		public void setValue(int value) {
318
			fValue = new Integer(value);
319
		}
320
321
		public int min() {
322
			return fMin;
323
		}
324
		
325
		public int max() {
326
			return fMax;
327
		}
328
		
329
		public boolean isValid(int value) {
330
			return fMin <= value && value <= fMax;
331
		}
332
333
		public String stringValueOf(int value) {
334
			return new Integer(value).toString();
335
		}
336
	}
337
	
338
	public class BooleanArgumentImpl extends ArgumentImpl implements com.sun.jdi.connect.Connector.BooleanArgument {
339
		private Boolean fValue;
340
		
341
		protected BooleanArgumentImpl(String name, String description, String label, boolean mustSpecify) {
342
			super(name, description, label, mustSpecify);
343
		}
344
	 	
345
		public String value() {
346
			return fValue.toString();
347
		}
348
		
349
		public void setValue(String value) {
350
			fValue = new Boolean(value);
351
		}
352
353
		public boolean isValid(String value) {
354
			return true;
355
		}
356
		
357
		public String toString() {
358
			return value();
359
		}
360
361
		public boolean booleanValue() {
362
			return fValue.booleanValue();
363
		}
364
365
		public void setValue(boolean value) {
366
			fValue = new Boolean(value);
367
		}
368
		
369
		public String stringValueOf(boolean value) {
370
			return new Boolean(value).toString();
371
		}
372
	}
373
	
374
	public class SelectedArgumentImpl extends StringArgumentImpl implements com.sun.jdi.connect.Connector.SelectedArgument {
375
		private List fChoices;
376
		
377
		protected SelectedArgumentImpl(String name, String description, String label, boolean mustSpecify, List choices) {
378
			super(name, description, label, mustSpecify);
379
			fChoices = choices;
380
		}
381
	 	
382
		public List choices() {
383
			return fChoices;
384
		}
385
		
386
		public boolean isValid(java.lang.String value) {
387
			return fChoices.contains(value);
388
		}
389
	}
390
391
392
	/**
393
	 * Returns the connector.
394
	 * @return IJ9Connector
395
	 */
396
	public IJ9Connector getConnector() {
397
		return connector;
398
	}
399
	/**
400
	 * Returns the vmInstall.
401
	 * @return J9VMInstall
402
	 */
403
	public J9VMInstall getVmInstall() {
404
		return vmInstall;
405
	}
406
407
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9DebugServerVMRunner.java (+218 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
 
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.debug.core.DebugPlugin;
23
import org.eclipse.debug.core.ILaunch;
24
import org.eclipse.debug.core.model.IProcess;
25
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
26
import org.eclipse.jdt.launching.IVMInstall;
27
import org.eclipse.jdt.launching.VMRunnerConfiguration;
28
import org.eclipse.jdt.launching.j9.J9Launching;
29
30
/**
31
 * Currently this sets up the 
32
 * launch such that the VM uses a debug server and the VM calls home to Eclipse
33
 * to establish the debug connection.  This configuration should be suitable for
34
 * all of our J9 VM 2.1 launches.  This class makes the assumption that the debug 
35
 * server will die when the VM dies.
36
 */
37
public class J9DebugServerVMRunner extends J9VMRunner {
38
39
	/**
40
	 * Constructor for J921VMRunner.
41
	 * 
42
	 * @param vmInstance the VM instance.
43
	 */
44
	public J9DebugServerVMRunner(IVMInstall vmInstance) {
45
		super(vmInstance);
46
	}
47
	
48
	/**
49
	 * @see org.eclipse.jdt.launching.IVMRunner#run(VMRunnerConfiguration, ILaunch, IProgressMonitor)
50
	 */
51
	public void run(
52
		VMRunnerConfiguration config,
53
		ILaunch launch,
54
		IProgressMonitor monitor)
55
		throws CoreException {
56
57
		J9ListeningConnector connectorManager = null;
58
		Process dbgsvrOSProcess = null, vmOSProcess = null;
59
60
		try {
61
			if (monitor == null) {
62
				monitor = new NullProgressMonitor();
63
			}
64
	
65
			// check for cancellation
66
			if (monitor.isCanceled()) {
67
				return;
68
			}	
69
	
70
			// Convert configuration to use -jxe option if requested.
71
			config = J9Launching.adaptVMRunnerConfiguration(config, getJ9VMInstall());		
72
	
73
			// Add VM options extracted from rules found on the bootclasspath
74
			addVMOptionsFromRules(config);			
75
			File workingDir = getWorkingDir(config);
76
			
77
			// check for cancellation
78
			if (monitor.isCanceled()) {	
79
				return;
80
			}	
81
	
82
			// Starts up the server socket in eclipse for connections from the debugger.
83
			Map args = launch.getLaunchConfiguration().getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, new HashMap(3));
84
			try {
85
				args.put(J9ConnectorDelegate.ARG_DBGPORT, Integer.toString(J9ListeningConnector.getFreePort()));
86
				connectorManager = new J9ListeningConnector();			
87
				connectorManager.setIVMInstall(fVMInstance);
88
				connectorManager.preLaunch(args, monitor, launch);
89
			}
90
			catch (Exception e) {
91
				J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
92
				return;
93
			}
94
			
95
	
96
			// check for cancellation
97
			if (monitor.isCanceled()) {
98
				return;
99
			}	
100
	
101
			String[] cmdLine = getCmdLine(connectorManager, config);			
102
			//start the VM
103
			vmOSProcess= exec(cmdLine, workingDir);	
104
			if (vmOSProcess == null) {
105
				return;
106
			}
107
			
108
			// check for cancellation
109
			if (monitor.isCanceled()) {
110
				return;
111
			}			
112
		
113
			try {	
114
				IProcess vmProcess= DebugPlugin.newProcess(launch, vmOSProcess, J9Launching.renderProcessLabel(cmdLine));
115
				vmProcess.setAttribute(IProcess.ATTR_CMDLINE, J9Launching.renderCommandLine(cmdLine));
116
				if (monitor.isCanceled()) {
117
					return;
118
				}			
119
				Map map = new HashMap(args);
120
				map.put(J9ListeningConnector.ARG_LABEL, J9Launching.renderDebugTarget(config.getClassToLaunch(), connectorManager.getConnectorPort())); //$NON-NLS-1$
121
				map.put(J9ListeningConnector.ARG_VMPROCESS, vmProcess);
122
				connectorManager.connect(map, monitor, launch);	
123
				
124
				//set the two processes to null to avoid them being killed by cleanUp
125
				vmOSProcess = dbgsvrOSProcess = null;	
126
			} 
127
			catch (Exception e) {
128
				J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
129
			}
130
		}
131
		finally {
132
			cleanUp(vmOSProcess, dbgsvrOSProcess, connectorManager);
133
		}
134
	}
135
136
	/**
137
	 * Method getCmdLine.  Taken and modified from J9DebugVMRunner.
138
	 * 
139
	 * @param debugServerPort
140
	 * @param connectorPort
141
	 * @param config
142
	 * @return String[]
143
	 */
144
	private String[] getCmdLine(
145
		J9ListeningConnector connector,
146
		VMRunnerConfiguration config) throws CoreException {
147
		String location= getJDKLocation();
148
		String program= constructProgramString(location, config);
149
		List arguments= new ArrayList();
150
		
151
		arguments.add(program);
152
		
153
		String[] bootCP= config.getBootClassPath();
154
		String[] cp= config.getClassPath();
155
		String[] vmArgs= config.getVMArguments();
156
		String[] programArgs= config.getProgramArguments();
157
158
		if (bootCP != null) {
159
			String bootpathOpt = isOldJ9Version() ? "-bp:" : "-Xbootclasspath:"; //$NON-NLS-1$ //$NON-NLS-2$
160
			if (bootCP.length > 0) {
161
				arguments.add(bootpathOpt+convertClassPath(bootCP));
162
			} else {
163
				// empty
164
//				arguments.add(bootpathOpt);
165
			}
166
		} 
167
		
168
		if (cp.length > 0) {
169
			arguments.add("-classpath"); //$NON-NLS-1$
170
			arguments.add(convertClassPath(cp));
171
		}
172
		if (connector.getDebugServerPort() != -1) {			
173
			arguments.add("-Xrdbginfo:" + J9ListeningConnector.getLocalIP() + ":" + connector.getDebugServerPort()); //$NON-NLS-1$ //$NON-NLS-2$
174
		}
175
		
176
		if (connector.getConnectorPort() != -1) {
177
			arguments.add("-Xrunjdwp:address=" + J9ListeningConnector.getLocalIP() + ":" + connector.getConnectorPort() + ",transport=dt_socket"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
178
			arguments.add("-Xdebug"); //$NON-NLS-1$
179
		}
180
		
181
	
182
		addArguments(vmArgs, arguments);
183
		arguments.add(config.getClassToLaunch());
184
		addArguments(programArgs, arguments);
185
186
		String[] cmdLine= new String[arguments.size()];
187
		arguments.toArray(cmdLine);
188
		return cmdLine;
189
	}
190
191
192
	/**
193
	 * Stop all processes that need stopping and stop the ListeningConnection 
194
	 * from listening any more.
195
	 * 
196
	 * @param dbgsvrOSProcess
197
	 * @param vmOSProcess
198
	 * @param manager
199
	 */
200
	private void cleanUp(Process vmOSProcess, 
201
			Process dbgsvrOSProcess, 
202
			J9ListeningConnector manager ) throws CoreException {
203
		
204
		if (dbgsvrOSProcess != null) {			
205
			dbgsvrOSProcess.destroy();
206
		}
207
		if (vmOSProcess != null) {
208
			vmOSProcess.destroy();
209
		}		
210
				
211
		try {
212
			manager.stopConnector();
213
		}
214
		catch (Exception e) {
215
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$			
216
		}		
217
	}	
218
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9DebugVMRunner.java (+153 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation.
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
 *     Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse.
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.launching.j9;
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.ILaunch;
23
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.model.IProcess;
25
import org.eclipse.jdt.debug.core.JDIDebugModel;
26
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
27
import org.eclipse.jdt.launching.IVMInstall;
28
import org.eclipse.jdt.launching.SocketUtil;
29
import org.eclipse.jdt.launching.VMRunnerConfiguration;
30
import org.eclipse.jdt.launching.j9.IJ9LaunchConfigurationConstants;
31
import org.eclipse.jdt.launching.j9.J9Launching;
32
33
import com.sun.jdi.VMDisconnectedException;
34
import com.sun.jdi.VirtualMachine;
35
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
36
37
public class J9DebugVMRunner extends J9VMRunner {
38
39
	// Use 127.0.0.1 to avoid timeout due to potential dns resolution delays
40
	private final static String LOCALHOST = "127.0.0.1"; //$NON-NLS-1$
41
	
42
	public J9DebugVMRunner(IVMInstall vmInstance) {
43
		super(vmInstance);
44
	}
45
46
	/**
47
	 * @see org.eclipse.jdt.launching.IVMRunner#run(VMRunnerConfiguration, ILaunch, IProgressMonitor)
48
	 */	
49
	public void run(VMRunnerConfiguration config, ILaunch launch, IProgressMonitor monitor) throws CoreException {
50
51
		if (monitor == null) {
52
			monitor = new NullProgressMonitor();
53
		}
54
55
		// check for cancellation
56
		if (monitor.isCanceled()) {
57
			return;
58
		}	
59
60
		/*
61
		 * LL: Migration to 3.0: SocketUtil.findUnusedLocalPort() has been deprecated.
62
		 * Use SocketUtil.findFreePort() instead.
63
		 */
64
		int port= SocketUtil.findFreePort();
65
		if (port == -1) {
66
			abort(J9LauncherMessages.getString("J9DebugVMRunner.Could_not_find_a_free_socket_for_the_debugger"), null, IJavaLaunchConfigurationConstants.ERR_NO_SOCKET_AVAILABLE); //$NON-NLS-1$
67
		}
68
		
69
		// Convert configuration to use -jxe option if requested.
70
		config = J9Launching.adaptVMRunnerConfiguration(config, getJ9VMInstall());
71
72
		// Add VM options extracted from rules found on the bootclasspath
73
		addVMOptionsFromRules(config);
74
		
75
		String[] cmdLine = getCmdLine(port, -1, null, config);	
76
		File workingDir = getWorkingDir(config);
77
		
78
		// check for cancellation
79
		if (monitor.isCanceled()) {
80
			return;
81
		}
82
83
		Process vmOSProcess= exec(cmdLine, workingDir);	
84
		if (vmOSProcess == null) {
85
			return;
86
		}
87
		
88
		// check for cancellation
89
		if (monitor.isCanceled()) {
90
			vmOSProcess.destroy();
91
			return;
92
		}	
93
94
		ILaunchConfiguration configuration = launch.getLaunchConfiguration();
95
		String[] symbolPath = J9Launching.getResolvedSymbolLookupPath(configuration);
96
97
		String debugTimeout= null;
98
		Map vmSpecificAttributes= config.getVMSpecificAttributesMap();
99
		if (vmSpecificAttributes != null) {
100
			debugTimeout = (String)vmSpecificAttributes.get(IJ9LaunchConfigurationConstants.ATTR_DEBUG_TIMEOUT);
101
		}
102
103
	
104
		Process proxyOSProcess= null;
105
		try {
106
			J9ProxyConnection proxyConnector = new J9ProxyConnection(LOCALHOST, Integer.toString(port), symbolPath, debugTimeout, (J9VMInstall)fVMInstance, ""); //$NON-NLS-1$
107
			proxyOSProcess= proxyConnector.runProxy();
108
	
109
			IProcess vmProcess= DebugPlugin.newProcess(launch, vmOSProcess, J9Launching.renderProcessLabel(cmdLine));
110
			IProcess proxyProcess= DebugPlugin.newProcess(launch, proxyOSProcess, J9Launching.renderProcessLabel(proxyConnector.getProxyCommand()));
111
			vmProcess.setAttribute(IProcess.ATTR_CMDLINE, J9Launching.renderCommandLine(cmdLine));
112
			proxyProcess.setAttribute(IProcess.ATTR_CMDLINE, J9Launching.renderCommandLine(proxyConnector.getProxyCommand()));
113
114
			boolean retry= false;
115
			do {
116
				try {
117
					// check for cancellation
118
					if (monitor.isCanceled()) {
119
						vmOSProcess.destroy();
120
						proxyOSProcess.destroy();
121
						return;
122
					}			
123
						
124
					VirtualMachine vm = proxyConnector.connect(monitor);
125
					JDIDebugModel.newDebugTarget(launch, vm, J9Launching.renderDebugTarget(config.getClassToLaunch(), port), vmProcess, true, false);
126
					return;
127
				} catch (IOException e) {
128
					String errorMessage= vmProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
129
					if (errorMessage.length() == 0) {
130
						errorMessage= proxyProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
131
					}
132
					retry = J9ProxyConnection.handleConnectException(this, e, errorMessage);
133
				} catch (VMDisconnectedException e) {
134
					String errorMessage= vmProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
135
					if (errorMessage.length() == 0) {
136
						errorMessage= proxyProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
137
					}
138
					retry = J9ProxyConnection.handleConnectException(this, e, errorMessage);
139
				} catch (IllegalConnectorArgumentsException e) {
140
					retry= false;
141
					abort(J9LauncherMessages.getString("J9DebugVMRunner.Could_not_connect_to_VM"), e, IJavaLaunchConfigurationConstants.ERR_CONNECTION_FAILED); //$NON-NLS-1$
142
				}
143
			} while (retry);
144
		} catch (CoreException e) {
145
			vmOSProcess.destroy();
146
			if (proxyOSProcess != null) proxyOSProcess.destroy();
147
			throw e;
148
		}
149
		vmOSProcess.destroy();
150
		proxyOSProcess.destroy();
151
	}	
152
153
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9LauncherMessages.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2003 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.util.MissingResourceException;
14
import java.util.ResourceBundle;
15
16
public class J9LauncherMessages {
17
18
	private static final String RESOURCE_BUNDLE= "org.eclipse.jdt.internal.launching.j9.J9LauncherMessages";//$NON-NLS-1$
19
20
	private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
21
22
	private J9LauncherMessages() {
23
	}
24
25
	public static String getString(String key) {
26
		try {
27
			return fgResourceBundle.getString(key);
28
		} catch (MissingResourceException e) {
29
			return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
30
		}
31
	}
32
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9LauncherMessages.properties (+56 lines)
Added Link Here
1
#########################################################################
2
# Copyright (c) 2002, 2004 IBM Corporation.
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 implementation
10
##########################################################################
11
12
J9DebugVMRunner.Could_not_find_a_free_socket_for_the_debugger=Could not find a free socket for the debugger
13
J9DebugVMRunner.Could_not_connect_to_VM=Could not connect to VM
14
15
J9VMType.error.notRoot=Not a J9 JDK Root; J9 VM executable or system library not found
16
J9VMType.name=J9 VM
17
18
J9Launching.format.dbgTarget={0} at localhost:{1}
19
J9Launching.format.processLabel={0} ({1})
20
21
JavaVMRunner.Specified_working_directory_does_not_exist_or_is_not_a_directory=Specified working directory does not exist or is not a directory: {0}
22
23
J9Launching.Socket_attaching_connector_not_available=Socket attaching connector not available
24
25
J9ProxyConnection.Could_not_find_a_free_socket_for_the_proxy=Could not find a free socket for the J9 debug proxy
26
J9ProxyConnection.Could_not_start_debug_proxy=Could not start the J9 debug proxy
27
28
#J9SocketAttachConnector.J9_(Proxied_Socket_Attach)=J9 (Proxied Socket Attach)
29
J9SocketAttachConnector.J9_21_(Proxied_Socket_Attach)=Not Available (Proxied Socket Attach)
30
J9SocketAttachConnector.J9_20_(Proxied_Socket_Attach)=J9 2.0 (Proxied Socket Attach)
31
J9SocketAttachConnector.Port_unspecified_for_remote_connection=Port unspecified for remote connection.
32
J9SocketAttachConnector.Hostname_unspecified_for_remote_connection=Hostname unspecified for remote connection.
33
J9SocketAttachConnector.Proxy_options_unspecified_for_remote_connection=Debug options unspecified for remote connection.
34
J9SocketAttachConnector.VM_does_not_exist_for_remote_connection=Debug VM does not exist for remote connection.
35
J9SocketAttachConnector.Debug_timeout=De&bug timeout (ms)
36
J9SocketAttachConnector.JRE_(used_for_debug_proxy)=J&RE (used for debugging)
37
J9SocketAttachConnector.Failed_to_connect_to_remote_VM_because_of_unknown_host=Failed to connect to remote VM because of unknown host \"{0}\""
38
J9SocketAttachConnector.Failed_to_connect_to_remote_VM=Failed to connect to remote VM
39
J9SocketAttachConnector.Proxy_options=Debug &options
40
J9Launching.General_settings_for_J9_Plugin_1=General settings for J9 Plugin.
41
J9Launching.Default_J9_VM_2=&Default J9 VM:
42
J9Launching.J9Pref_Notice_String=Note: this preference is updated when a J9 VM is set as default.  In the event that a J9 VM is not the default (see Java->Installed JREs), this preference indicates the default J9 VM.
43
J9Launching.Timeout_while_connecting_to_VM,_try_using_a_different_port_number_1=Timeout while connecting to VM, try using a different port number
44
J9Launching.Error_when_executing_j9_1=Error when executing j9
45
J9VMCommandTab.Run_as_console=&Run as console application
46
J9VMCommandTab.Run_from_executable_archive=&Execute using -jxe or -jar option, if applicable
47
J9VMCommandTab.J9_VM_specific_attributes_2=J9 VM specific attributes
48
J9ConnectorDelegate.&Host_1=&Host
49
J9ConnectorDelegate.Host_2=Host
50
J9ConnectorDelegate.&Port=&Port
51
J9ConnectorDelegate.Port=Port
52
J9ConnectorDelegate.Debug_timeout_(ms)_3=Debug timeout (ms)
53
J9ConnectorDelegate.JRE_(used_for_debug_proxy)_4=J&RE (used for debugging)
54
J9ConnectorDelegate.Proxy_options_5=Debug &options
55
J9_VM___4=J9 VM: 
56
J9PropertyPage.J9_VM_Not_Found_3=J9 VM Not Found
(-)j9/org/eclipse/jdt/internal/launching/j9/J9LaunchingPlugin.java (+114 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation.
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
 *     Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse.
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.launching.j9;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.ui.plugin.AbstractUIPlugin;
20
21
public class J9LaunchingPlugin extends AbstractUIPlugin {
22
	private static J9LaunchingPlugin fgPlugin;
23
	/**
24
	 * Constructor for J9LaunchingPlugin
25
	 */
26
	public J9LaunchingPlugin() {
27
		super();
28
		fgPlugin = this;
29
	}
30
31
	public static J9LaunchingPlugin getDefault() {
32
		return fgPlugin;
33
	}
34
35
	/**
36
	 * Convenience method which returns the unique identifier of this plugin.
37
	 */
38
	public static String getUniqueIdentifier() {
39
		if (getDefault() == null) {
40
			// If the default instance is not yet initialized,
41
			// return a static identifier. This identifier must
42
			// match the plugin id defined in plugin.xml
43
			return "org.eclipse.jdt.launching.j9"; //$NON-NLS-1$
44
		}
45
		/*
46
		 * LL: Migration to 3.0: IPluginDescriptor.getUniqueIdentifier() has been deprecated.
47
		 * Use Bundle.getSymbolicName() instead.
48
		 */
49
		return getDefault().getBundle().getSymbolicName();
50
	}
51
52
	/**
53
	 * Throws a core exception with an error status object built from
54
	 * the given message, lower level exception, and error code.
55
	 * 
56
	 * @param message the status message
57
	 * @param exception lower level exception associated with the
58
	 *  error, or <code>null</code> if none
59
	 * @param code error code
60
	 */
61
	public static void abort(String message, Throwable exception, int code) throws CoreException {
62
		Status status = new Status(IStatus.ERROR, J9LaunchingPlugin.getUniqueIdentifier(), code, message, exception);
63
        getDefault().getLog().log(status);
64
        throw new CoreException(status);
65
	}		
66
	public static void log(String message, Throwable exception, int code) throws CoreException {
67
		Status status = new Status(IStatus.ERROR, J9LaunchingPlugin.getUniqueIdentifier(), code, message, exception);
68
		getDefault().getLog().log(status);
69
	}		
70
71
	/**
72
	 * @see AbstractUIPlugin#initializeDefaultPreferences
73
	 */
74
	protected void initializeDefaultPreferences(IPreferenceStore prefs) {
75
		J9PreferencePage.initDefaults(prefs);
76
	}
77
78
	public void addPreferenceStoreChangeListener(IPropertyChangeListener changeListener) {
79
		getPreferenceStore().addPropertyChangeListener(changeListener);
80
	}
81
	
82
	/**
83
	 * This is used to store a temporary version of the preferred J9 Location until
84
	 * the Project has been initialized and the project properties can be used.
85
	 * @return
86
	 */
87
	/*
88
	 * This may have problems if the new project wizard is being used twice at the same time.
89
	 */
90
	public String getCurrentJ9Path() 
91
	{
92
		IPreferenceStore store = getPreferenceStore();
93
		if (store != null) 
94
		{
95
			String currentPath =
96
				store.getString(
97
					"currentJ9Path");
98
			return currentPath;
99
		} 
100
		else
101
			return null;
102
	}
103
	public void setCurrentJ9Path (String currentPath)
104
	{
105
		IPreferenceStore store = getPreferenceStore();
106
		if (store != null) 
107
		{
108
			store.setValue("currentJ9Path", currentPath);
109
		}
110
111
	}
112
113
114
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9ListeningConnector.java (+443 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.ConnectException;
16
import java.net.InetAddress;
17
import java.net.Socket;
18
import java.net.SocketException;
19
import java.net.UnknownHostException;
20
import java.util.ArrayList;
21
import java.util.Map;
22
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunch;
28
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.model.IProcess;
30
import org.eclipse.jdt.debug.core.JDIDebugModel;
31
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
32
import org.eclipse.jdt.launching.IVMInstall;
33
import org.eclipse.jdt.launching.SocketUtil;
34
import org.eclipse.jdt.launching.j9.J9Launching;
35
36
import com.sun.jdi.VirtualMachine;
37
import com.sun.jdi.connect.Connector;
38
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
39
import com.sun.jdi.connect.ListeningConnector;
40
 
41
 
42
/**
43
 * Utility class that will help manage the lifecycle of ListeningConnectors.  
44
 * This could be further extended to also support the launching of the debug 
45
 * server.  In this way any runner/launch config that needs to support 2.1 needs
46
 * only launch the VM. 
47
 * 
48
 * Implements IVMConnector for use in the device launching strategies.
49
 */
50
public class J9ListeningConnector implements IJ9Connector {
51
	
52
	public final static String ARG_LABEL = "org.eclipse.jdt.internal.launching.j9.J9ListeningConnection.LABEL"; //$NON-NLS-1$
53
	public final static String ARG_VMPROCESS = "org.eclipse.jdt.internal.launching.j9.J9ListeningConnection.VMPROCESS"; //$NON-NLS-1$
54
	public final static String ARG_TIMEOUT = "timeout"; //$NON-NLS-1$
55
	
56
	
57
	private ListeningConnector fConnector;
58
	private Map fConnectorMap;
59
	private int fConnectorPort, fDebugServerPort = -1;
60
61
	private IVMInstall fIVMInstall;
62
	
63
	/**
64
	 * Create a ListeningConnectionManager that will manage the lifecycle of 
65
	 * ListeningConnections.
66
	 */
67
	public J9ListeningConnector() {
68
69
	}
70
	
71
	/**
72
	 * @return "org.eclipse.jdt.launching.j9"
73
	 */
74
	protected String getPluginIdentifier() {
75
		return "org.eclipse.jdt.launching.j9"; //$NON-NLS-1$
76
	}
77
	
78
	/**
79
	 * Stops the connector from listening for incomming connections if it is doing so.
80
	 */
81
	public void stopConnector() throws IOException, IllegalConnectorArgumentsException {
82
		if (fConnector != null) {
83
			fConnector.stopListening(fConnectorMap);
84
		}					
85
	}
86
87
	/**
88
	 * Configure the connector to use the proper port and timeout values.
89
	 */
90
	public void setupConnector(Map map) throws IOException, CoreException, IllegalConnectorArgumentsException {
91
		fConnector = J9Launching.getListeningConnector();
92
		fConnectorMap = fConnector.defaultArguments();
93
		Connector.Argument param= (Connector.Argument) fConnectorMap.get(J9ConnectorDelegate.ARG_PORT);
94
		String portString = (String)map.get(J9ConnectorDelegate.ARG_PORT);
95
		if (portString == null) {
96
			fConnectorPort = getFreePort();
97
			portString = Integer.toString(fConnectorPort);
98
		}
99
		else {
100
			fConnectorPort = Integer.parseInt(portString);
101
		}
102
		
103
		/* Add code here to call a method to check if the specified port is in use. */
104
		//if (isPortInUse(fConnectorPort)) {
105
			param.setValue(portString);
106
		//}
107
		
108
		String debugPortString = (String)map.get(J9ConnectorDelegate.ARG_DBGPORT);
109
		if (debugPortString != null) {
110
			fDebugServerPort = Integer.parseInt(debugPortString);
111
		}
112
						
113
		param = (Connector.Argument) fConnectorMap.get(ARG_TIMEOUT);
114
		param.setValue(Integer.toString(getTimeout(map))); 
115
	}
116
	
117
	/**
118
	 * Enables the listening socket of this connector.
119
	 */
120
	public void startConnector() throws IOException, IllegalConnectorArgumentsException{
121
		fConnector.startListening(fConnectorMap);			
122
	}		
123
	
124
	/**
125
	 * @return int the port on which this connector is listening.
126
	 */
127
	public int getConnectorPort() {
128
		return fConnectorPort;
129
	}
130
131
	public int getTimeout(Map map) {
132
		int timeout;
133
		String debugTimeout = (String) map.get(J9ConnectorDelegate.ARG_DEBUG_TIMEOUT);
134
		if (debugTimeout != null) {
135
			timeout = Integer.parseInt(debugTimeout);
136
		}
137
		else {
138
			timeout = JDIDebugModel.getPreferences().getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT);
139
		}		
140
		return timeout;
141
	}
142
	
143
	public static int getFreePort() throws CoreException {
144
		/*
145
		 * LL: Migration to 3.0: SocketUtil.findUnusedLocalPort() has been deprecated.
146
		 * Use SocketUtil.findFreePort() instead.
147
		 */
148
		int freePort = SocketUtil.findFreePort();
149
		if (freePort == -1) {			
150
			throw new CoreException(
151
				new Status(
152
					Status.ERROR, 
153
					J9LaunchingPlugin.getUniqueIdentifier(), 
154
					IJavaLaunchConfigurationConstants.ERR_NO_SOCKET_AVAILABLE, 
155
					J9LauncherMessages.getString("J9DebugVMRunner.Could_not_find_a_free_socket_for_the_debugger"), //$NON-NLS-1$
156
					null));
157
		}				
158
		return freePort;
159
	}
160
161
	/**
162
	 * Checks the ListeningConnector for an incomming debug session and 
163
	 * returns the Virtual Machine associated with it.
164
	 * 
165
	 * @param monitor
166
	 * @return VirtualMachine
167
	 */
168
	private VirtualMachine connect(Map map, IProgressMonitor monitor) throws CoreException, IOException, IllegalConnectorArgumentsException {
169
		int timeout = getTimeout(map);		
170
		long timeLimit = System.currentTimeMillis() + timeout;		
171
		for(;;) {
172
			try {
173
				VirtualMachine vm = attach(fConnector, fConnectorMap, timeout);
174
				setDebugTimeout(vm, timeout);
175
				return vm;
176
			} catch (SocketException e) {
177
				// Cannot bind to vm or proxy, may still be initializing (for example loading symbol files).
178
				if (System.currentTimeMillis() > timeLimit) {
179
					throw e;
180
				} else {
181
					synchronized (fConnector) {
182
						try {
183
							fConnector.wait(250);
184
						} catch(InterruptedException ie) {
185
						}
186
					}
187
				}
188
			}
189
		}
190
191
	}
192
193
	/**
194
	 * Method attach.
195
	 * @param connector
196
	 * @param map
197
	 * @param debugTimeout
198
	 * @return VirtualMachine
199
	 */
200
	private VirtualMachine attach(
201
		final ListeningConnector connector,
202
		final Map map,
203
		final int debugTimeout) throws IOException, IllegalConnectorArgumentsException, CoreException {
204
		final Exception[] exc = new Exception[1];
205
		final VirtualMachine[] vm = new VirtualMachine[1];
206
		Runnable runnable = new Runnable() {
207
			public void run() {
208
				try {
209
					vm[0] = connector.accept(map);
210
				} catch (IOException e) {
211
					exc[0] = e;
212
				} catch (IllegalConnectorArgumentsException e) {
213
					exc[0] = e;
214
				}
215
			}
216
		};
217
		Thread thread = new Thread(runnable, "J9ProxyConnection Attach"); //$NON-NLS-1$
218
		thread.start();
219
		try {
220
			thread.join(debugTimeout);
221
		} catch (InterruptedException e) {
222
		}
223
		
224
		if (exc[0] instanceof IOException)
225
			throw (IOException)exc[0];
226
		else if (exc[0] instanceof IllegalConnectorArgumentsException)
227
			throw (IllegalConnectorArgumentsException)exc[0];
228
	
229
		if (vm[0] == null) {
230
			String msg = J9LauncherMessages.getString("J9Launching.Timeout_while_connecting_to_VM,_try_using_a_different_port_number_1"); //$NON-NLS-1$
231
			J9LaunchingPlugin.abort(msg, null, IJavaLaunchConfigurationConstants.ERR_VM_CONNECT_TIMEOUT);
232
		}
233
		return vm[0];
234
	}
235
	
236
	/**
237
	 * Set the debug timeout for the given virtual machine.
238
	 * 
239
	 * @param vm the VM
240
	 * @param timeout the timeout
241
	 */
242
	private void setDebugTimeout(VirtualMachine vm, int timeout) {
243
		if (vm instanceof org.eclipse.jdi.VirtualMachine && timeout > 0) {
244
			org.eclipse.jdi.VirtualMachine vm2= (org.eclipse.jdi.VirtualMachine)vm;
245
			vm2.setRequestTimeout(timeout);
246
		}
247
	}	
248
	
249
	/**
250
	 * The new launching strategy is quite different from the old.  Before we'd 
251
	 * launch the VM, "forget about it", then in the connector launch the proxy 
252
	 * and use it as the debug target.  This doesn't work for the Listening 
253
	 * proxy - we need to know the actual VM process to pipe it's output through
254
	 * the JDI debug target.  Because of this, we pass some bogus 'arguments' 
255
	 * in the argument map.  We pass J9ListeningConnector.ARG_LABEL (String)
256
	 * as the debug label and J9ListeningConnector.ARG_VMPROCESS (IProcess) 
257
	 * which is a reference to the IProcess corresponding to the VM process 
258
	 * (if any).  Note that this method will work with either or both of these
259
	 * properties set, but it won't be 'pretty' and the console IO won't be
260
	 * displayed in the debug window.
261
	 */
262
	public void connect(
263
			Map arguments,
264
			IProgressMonitor monitor,
265
			ILaunch launch)	throws CoreException {
266
267
		boolean retry = false;		
268
		do {
269
			IProcess vmProcess = null;
270
			try {
271
				VirtualMachine vm = connect(arguments, monitor);
272
				String label = (String)arguments.get(ARG_LABEL);
273
				vmProcess = (IProcess)arguments.get(ARG_VMPROCESS);
274
				JDIDebugModel.newDebugTarget(launch, vm, label, vmProcess, true, false);
275
			}
276
			catch (IOException e) {
277
				String errorMessage= vmProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
278
				retry = J9ProxyConnection.handleConnectException(this, e, errorMessage);
279
			}
280
			catch (IllegalConnectorArgumentsException e) {
281
				J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.Failed_to_connect_to_remote_VM"), e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); //$NON-NLS-1$
282
			}
283
		}
284
		while(retry);
285
	}
286
		
287
	/**
288
	 * @see org.eclipse.jdt.internal.launching.j9.IJ9Connector#postLaunch()
289
	 */
290
	public void postLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException {
291
		try {
292
			stopConnector();
293
		}
294
		catch (Exception e) {
295
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
296
		}
297
	}
298
299
	/**
300
	 * @see org.eclipse.jdt.internal.launching.j9.IJ9Connector#preLaunch()
301
	 */
302
	public void preLaunch(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException {
303
		try {
304
			setupConnector(arguments);
305
			setupDebugServer(arguments, monitor, launch);
306
			startConnector();
307
//		} catch (ConnectException excep) {
308
//			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Port_is_probably_in_use,_please_specify_a_different_port_number"),excep, IJavaLaunchConfigurationConstants.ERR_INVALID_PORT); //$NON-NLS-1$			 
309
		} catch (Exception e) {
310
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
311
		}
312
	}
313
314
	/**
315
	 * Method setupDebugServer.
316
	 * @param arguments
317
	 */
318
	private void setupDebugServer(Map arguments, IProgressMonitor monitor, ILaunch launch) throws CoreException, IOException {
319
		if (fDebugServerPort != -1) {		
320
			ILaunchConfiguration configuration = launch.getLaunchConfiguration();
321
			String[] symbolPath = J9Launching.getResolvedSymbolLookupPath(configuration);		
322
			String [] dbgCmdLine = getDbgCmdLine(launch.getLaunchConfiguration(), fDebugServerPort, symbolPath);
323
			String[] args = null;
324
			//needs better error checking
325
			String osName = System.getProperty("os.name"); //$NON-NLS-1$
326
				 if (osName != null) {
327
					 osName = osName.toLowerCase();
328
					 if (osName.indexOf("linux") != -1) { //$NON-NLS-1$
329
					 	int idx = dbgCmdLine[0].indexOf("j9dbgserv");
330
						args = new String[]{ "LD_LIBRARY_PATH=" + dbgCmdLine[0].substring(0, idx)};		 	
331
					 }
332
				 }  
333
  
334
		    
335
			Process dbgsvrOSProcess = Runtime.getRuntime().exec(dbgCmdLine, args);
336
			IProcess dbgsvrProcess= DebugPlugin.newProcess(launch, dbgsvrOSProcess, J9Launching.renderProcessLabel(dbgCmdLine));
337
			dbgsvrProcess.setAttribute(IProcess.ATTR_CMDLINE, J9Launching.renderCommandLine(dbgCmdLine));
338
			// check for cancellation
339
			if (monitor.isCanceled()) {
340
				return;
341
			}
342
		}
343
	}
344
	
345
	/**
346
	 * Get a command line that is suitable for launching the debug server.
347
	 * 
348
	 * @param port
349
	 * @param symbolPath
350
	 * @return String[]
351
	 */
352
	private String[] getDbgCmdLine(ILaunchConfiguration config, int port, String[] symbolPath) throws CoreException {
353
		String location= getJDKLocation();
354
		location = location + File.separator + "bin" + File.separator + "j9dbgserv"; //$NON-NLS-1$ //$NON-NLS-2$
355
		ArrayList list = new ArrayList();
356
		list.add(location);
357
		list.add("-J-Dconsole.encoding=" + System.getProperty("file.encoding"));
358
		list.add("-port:" + port); //$NON-NLS-1$
359
		StringBuffer symPath = new StringBuffer();
360
		for (int i = 0; i < symbolPath.length; i++) {
361
			if (i > 0) symPath.append(File.pathSeparatorChar);
362
			symPath.append(symbolPath[i]);
363
		}
364
		if (symPath.length() > 0) {
365
			list.add("-symfiles:" + symPath.toString()); //$NON-NLS-1$
366
		}
367
		
368
		return (String[])list.toArray(new String[list.size()]);
369
	}	
370
	
371
	protected String getJDKLocation() throws CoreException {
372
		return fIVMInstall.getInstallLocation().getAbsolutePath();
373
	}
374
	
375
	
376
	
377
	/**
378
	 * Get an IP of this machine, defaulting to 127.0.0.1 if none can be 
379
	 * determined.  Java 1.3 had problems with this if you were running on a 
380
	 * multihomed system, IIRC.  This shouldn't impact us in any way - any IP
381
	 * should do for our needs.
382
	 * 
383
	 * @return the IP.
384
	 */
385
	public static String getLocalIP() {
386
		try {
387
			return InetAddress.getLocalHost().getHostAddress();
388
		}
389
		catch (UnknownHostException e) {
390
			return "127.0.0.1"; //$NON-NLS-1$
391
		}
392
	}	
393
	
394
	/**
395
	 * Returns the debugServerPort.
396
	 * @return int
397
	 */
398
	public int getDebugServerPort() {
399
		return fDebugServerPort;
400
	}
401
402
	public IVMInstall getIVMInstall() {
403
		return fIVMInstall;
404
	}
405
	
406
	public void setIVMInstall(IVMInstall connector) {
407
		fIVMInstall = connector;
408
	}
409
	
410
	/**
411
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
412
	 */
413
	
414
	/*
415
	 * isPortInUse() method checks if the specified port is in use.
416
	 * 
417
	 */
418
	public boolean isPortInUse(int port) throws CoreException, ConnectException {
419
420
			boolean portInUse = false;
421
			Socket s= null;
422
			try {
423
				s= new Socket(getLocalIP(), port);
424
			}/* catch (ConnectException e) {
425
				portInUse = true;
426
				throw new ConnectException(e.getMessage());
427
			}*/ catch (IOException e) {
428
				portInUse = true;
429
				throw new ConnectException(e.getMessage());
430
			} finally {
431
				if (s != null) {
432
					try {
433
						s.close();
434
					} catch (IOException ioe) {
435
					}
436
				}
437
			}
438
			return portInUse;
439
	}
440
	
441
442
443
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9PreferencePage.java (+181 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import org.eclipse.jdt.launching.IVMInstall;
14
import org.eclipse.jdt.launching.IVMInstallChangedListener;
15
import org.eclipse.jdt.launching.IVMInstallType;
16
import org.eclipse.jdt.launching.JavaRuntime;
17
import org.eclipse.jdt.launching.PropertyChangeEvent;
18
import org.eclipse.jdt.launching.j9.IJ9LaunchConfigurationConstants;
19
import org.eclipse.jdt.launching.j9.J9Launching;
20
import org.eclipse.jface.preference.FieldEditorPreferencePage;
21
import org.eclipse.jface.preference.IPreferenceStore;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26
import org.eclipse.ui.IWorkbench;
27
import org.eclipse.ui.IWorkbenchPreferencePage;
28
29
/**
30
 * Preference page to select the default J9 VM
31
 */
32
public class J9PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
33
34
	private static class VMInstallListener implements IVMInstallChangedListener {
35
36
		public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
37
			// If the default vm is set to a J9 vm, the default J9 vm is set the same			
38
			String currentId = getPrefStore().getString(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9);
39
			if (current.getId().equals(currentId))
40
				return;
41
			if (J9Launching.isJ9VMInstall(current)) {
42
				setJ9(getPrefStore(), current);
43
				setJ9Default(getPrefStore(), current);
44
			}
45
		}
46
47
		public void vmRemoved(IVMInstall vm) {
48
			/*
49
			 * removing a vm will change the default, so we do not re-aquire a default
50
			 * selection here
51
			 */
52
			if (J9Launching.getDefaultJ9VMInstall() == null) {
53
				// calling this will trigger a new vm to be added
54
				calculateNewDefaultJ9Install();
55
			}
56
		}
57
58
		public void vmAdded(IVMInstall vm) {
59
			// If no J9 VM was previously available, calculate a new J9 default vm
60
			if (J9Launching.getDefaultJ9VMInstall() == null && J9Launching.isJ9VMInstall(vm)) {
61
				setJ9(getPrefStore(), vm);
62
				setJ9Default(getPrefStore(), vm);
63
			}
64
		}
65
		
66
		public void vmChanged(PropertyChangeEvent event) {
67
			// Does not effect the default J9 VM
68
		}
69
	}
70
		
71
	public J9PreferencePage() {
72
		super(GRID);
73
74
		IPreferenceStore store= J9LaunchingPlugin.getDefault().getPreferenceStore();
75
		setPreferenceStore(store);
76
		setDescription(J9LauncherMessages.getString("J9Launching.General_settings_for_J9_Plugin_1")); //$NON-NLS-1$
77
	}
78
	
79
	private static String[][] getVMNamesAndIds() {
80
		String[][] result;
81
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
82
		IVMInstall[] installs = type.getVMInstalls();
83
		result = new String[installs.length][];
84
		for (int i = 0; i < installs.length; i++) {
85
			result[i] = new String[] {installs[i].getName(),installs[i].getId()};
86
		}
87
		return result;
88
	}
89
90
91
	public static String getVMNamesFromId(String id) {
92
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
93
		IVMInstall[] installs = type.getVMInstalls();
94
		for (int i = 0; i < installs.length; i++) {
95
			if (installs[i].getId() == id)
96
				return installs[i].getName();
97
		}
98
		return null;
99
	}
100
	
101
	/**
102
	 * @see FieldEditorPreferencePage#createFieldEditors
103
	 */
104
	protected void createFieldEditors() {
105
		Composite parent = getFieldEditorParent();
106
		// add some empty space
107
		GridData tempData = new GridData(GridData.FILL_HORIZONTAL);
108
		tempData.horizontalSpan = 2;
109
		new Label(parent, SWT.NONE).setLayoutData(tempData);
110
		 
111
		
112
		ComboFieldEditor fieldEditor = new ComboFieldEditor(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9,
113
								  J9LauncherMessages.getString("J9Launching.Default_J9_VM_2"), //$NON-NLS-1$
114
								  getVMNamesAndIds(),
115
								  parent);
116
		addField(fieldEditor);
117
								   
118
		String noticeString = J9LauncherMessages.getString("J9Launching.J9Pref_Notice_String"); //$NON-NLS-1$
119
		Label notice= new Label(parent, SWT.WRAP);
120
		notice.setText(noticeString);
121
		GridData noticeData= new GridData(GridData.FILL_HORIZONTAL);
122
		noticeData.horizontalSpan = 2;
123
		noticeData.grabExcessHorizontalSpace= true;
124
		noticeData.widthHint= convertWidthInCharsToPixels(60);
125
		notice.setLayoutData(noticeData);
126
	}
127
	
128
	/**
129
	 * @see IWorkbenchPreferencePage#init(IWorkbench)
130
	 */
131
	public void init(IWorkbench workbench) {
132
	}
133
	
134
	
135
	public static void initDefaults(IPreferenceStore store) {
136
		IVMInstall newDefaultJ9 = calculateNewDefaultJ9Install();
137
		setJ9Default(store, newDefaultJ9);
138
		if (J9Launching.getDefaultJ9VMInstall() == null) {
139
			setJ9(store, newDefaultJ9);
140
		}
141
		JavaRuntime.addVMInstallChangedListener(new VMInstallListener());
142
	}
143
	
144
	private static void setJ9(IPreferenceStore store, IVMInstall install) {
145
		String id = install == null ? "" : install.getId(); //$NON-NLS-1$
146
		store.setValue(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9, id);
147
	}
148
	
149
	private static void setJ9Default(IPreferenceStore store, IVMInstall install) {
150
		String id = install == null ? "" : install.getId(); //$NON-NLS-1$
151
		store.setDefault(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9, id);
152
	}
153
	
154
	private static IPreferenceStore getPrefStore() {
155
		return J9LaunchingPlugin.getDefault().getPreferenceStore();
156
	}
157
	
158
	private static IVMInstall calculateNewDefaultJ9Install() {
159
		IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
160
		return getNewDefaultJ9Install(defaultVM);
161
	}
162
	
163
	private static IVMInstall getNewDefaultJ9Install(IVMInstall defaultVM) {
164
		IVMInstall result;
165
		if (J9Launching.isJ9VMInstall(defaultVM)) {
166
			// The workspace default VM is a J9 VM
167
			result = defaultVM;
168
		} else {
169
			// Find first J9 VM that is installed
170
			result = null;
171
			IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
172
			IVMInstall[] installs = type.getVMInstalls();
173
			for (int i = 0; result == null && i < installs.length; i++) {
174
				if (J9Launching.isJ9VMInstall(installs[i])) {
175
					result = installs[i];
176
				}
177
			}
178
		}
179
		return result;
180
	}
181
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9PropertyPage.java (+356 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
 
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import org.eclipse.core.internal.resources.ResourceException;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.core.runtime.QualifiedName;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.List;
32
import org.eclipse.ui.IWorkbenchPropertyPage;
33
import org.eclipse.ui.dialogs.PropertyPage;
34
import org.eclipse.ui.help.WorkbenchHelp;
35
36
public class J9PropertyPage 
37
	extends PropertyPage 
38
	implements IWorkbenchPropertyPage 
39
{
40
	private List J9List = null;
41
	
42
	private static final String J9_DOT_FILE = ".j9"; //$NON-NLS-1$
43
	public static final String J9_EMPTY_VERSION = "0.0.0"; //$NON-NLS-1$
44
	
45
	private static final QualifiedName THIS_PROJECT_J9 = 
46
		new QualifiedName ("org.eclipse.jdt.launching.j9", "current_j9"); //$NON-NLS-1$ //$NON-NLS-2$
47
	private Composite parentComposite = null;
48
	
49
	public String getCurrentJ9 ()
50
	{
51
		IResource resource = (IResource) getElement();
52
53
		try
54
		{
55
			String propValue = 
56
				resource.getPersistentProperty(THIS_PROJECT_J9);
57
			if (propValue != null)
58
				return propValue;
59
			 
60
		}
61
		catch (ResourceException e)
62
		{
63
			// the project doesn't exist yet.  Get value from persistent store
64
			return getCurrentJ9PreferenceStore();
65
		}
66
		catch (CoreException e)
67
		{
68
			e.printStackTrace();
69
		}
70
71
		// Try to load out of the J9 File
72
		String storedJ9 = readCurrentJ9 (J9_DOT_FILE);
73
		if (storedJ9 != null)
74
		{
75
			setCurrentJ9 (storedJ9);
76
			return storedJ9;
77
		}
78
79
		return J9VMContentProvider.getDefaultVMVersion();
80
		
81
	}
82
	
83
	private String validateCurrentJ9 (String initialValue)
84
	{
85
86
		// Special case default 0.0.0
87
		if (initialValue.compareTo (J9_EMPTY_VERSION) == 0) //$NON-NLS-1$
88
		{
89
			return J9_EMPTY_VERSION; //$NON-NLS-1$
90
			//J9VMContentProvider.getDefaultVMName();		
91
		}	
92
		
93
		String[][] availableJ9s = J9VMContentProvider.getVMNamesAndVersions();
94
		// Try to match initial value in the names
95
		for (int i = 0; i < availableJ9s.length; i++)
96
		{ // [0] is the name [1] is the version value
97
			if (initialValue.compareTo (availableJ9s[i][1]) == 0)
98
			{
99
				return initialValue;
100
			}
101
			int lastSegment = initialValue.lastIndexOf ('.');
102
			if (lastSegment != -1)
103
			{
104
				String tmp = new String (initialValue.substring(0, lastSegment));
105
				if (tmp.compareTo (availableJ9s[i][1]) == 0)
106
					return initialValue;
107
			}
108
		}
109
		
110
		return null;
111
	}
112
	
113
	public boolean setCurrentJ9 (String value)
114
	{
115
		boolean success = false;
116
		
117
		String newValue = validateCurrentJ9 (value);
118
		if (newValue == null)
119
			return false;
120
		IResource resource = (IResource) getElement();
121
		try
122
		{
123
			resource.setPersistentProperty (THIS_PROJECT_J9, value);
124
			success = true;
125
			writeCurrentJ9 (J9_DOT_FILE, value);
126
			readCurrentJ9 (J9_DOT_FILE);
127
		}
128
		catch (ResourceException e)
129
		{
130
			// The resource does not exist, save in the persistent store
131
			setCurrentJ9PreferenceStore (value);
132
			success = true;
133
		}
134
		catch (CoreException e)
135
		{
136
			e.printStackTrace();
137
		}
138
		catch (NullPointerException e)
139
		{
140
			e.printStackTrace();
141
		}
142
		return success;
143
	}
144
	
145
	private String getCurrentJ9PreferenceStore ()
146
	{
147
		J9LaunchingPlugin j9LaunchingPlugin = J9LaunchingPlugin.getDefault();
148
		return j9LaunchingPlugin.getCurrentJ9Path();
149
150
	}
151
152
	private void setCurrentJ9PreferenceStore (String value)
153
	{
154
		J9LaunchingPlugin j9LaunchingPlugin = J9LaunchingPlugin.getDefault();
155
		j9LaunchingPlugin.setCurrentJ9Path(value);
156
	}
157
		
158
	public J9PropertyPage ()
159
	{
160
		super();
161
	}
162
	public J9PropertyPage (IAdaptable element)
163
	{
164
		this ();
165
		this.setElement (element);
166
		
167
	}
168
	protected Control createContents (Composite parent)
169
	{
170
		parentComposite = parent;
171
		Composite composite = new Composite (parent, SWT.NONE);
172
		GridLayout layout = new GridLayout();
173
		composite.setLayout (layout);
174
		
175
		
176
		String currentJ9 = getCurrentJ9();
177
		if (currentJ9 == null)
178
			getUserJ9(composite);
179
		else
180
			displayUserJ9(composite, currentJ9);
181
		return parent;
182
	}
183
	
184
	protected void displayUserJ9(Composite composite, String currentJ9)
185
	{
186
		// KMH: Probably only want to do this if we have a value
187
		noDefaultAndApplyButton();
188
189
		Label description = new Label (composite, SWT.NONE);
190
		if (currentJ9 != null)
191
		{
192
			String name = J9VMContentProvider.getVMNameFromVersion(currentJ9);
193
			description.setText (J9LauncherMessages.getString("J9_VM___4") + currentJ9 + " (" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
194
		}
195
		else
196
			description.setText (J9LauncherMessages.getString("J9_VM___4") + J9LauncherMessages.getString("J9PropertyPage.J9_VM_Not_Found_3")); //$NON-NLS-1$ //$NON-NLS-2$
197
	}
198
	
199
	/* (non-Javadoc)
200
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
201
	 */
202
	public void createControl(Composite parent) {
203
		super.createControl (parent);
204
		WorkbenchHelp.setHelp(parent, "org.eclipse.jdt.internal.launching.j9" + ".J9LaunchindPlugin" + ".J9PropertyPage_context"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
205
206
	}
207
	
208
	protected void getUserJ9 (Composite composite)
209
	{
210
		J9List = new List (composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
211
212
		J9VMContentProvider availableJ9 = new J9VMContentProvider();
213
		String[][]newJ9s = J9VMContentProvider.getVMNamesAndVersions();
214
		
215
		GridData gd =
216
			new GridData(
217
				GridData.FILL_BOTH
218
				);
219
	
220
		composite.setLayoutData(gd);
221
		GridData listGd =
222
			new GridData(
223
				GridData.FILL_BOTH
224
				);
225
		listGd.verticalSpan = 1;
226
		J9List.setLayoutData(listGd);
227
		
228
		for (int i = 0; i < newJ9s.length; i++)
229
			J9List.add(newJ9s[i][0] + " (" + newJ9s[i][1] + ")"); //$NON-NLS-1$ //$NON-NLS-2$
230
		J9List.setSelection(0);
231
		//J9SelectionChanged();
232
	}
233
234
	private void J9SelectionChanged ()
235
	{
236
		String selection = ((String) J9List.getSelection()[0]);
237
		int firstIndex = selection.indexOf("("); //$NON-NLS-1$
238
		int endIndex = selection.indexOf (")"); //$NON-NLS-1$
239
		String versionSelection = selection.substring(firstIndex + 1, endIndex);
240
		//setCurrentJ9 ((String) J9List.getSelection()[0]);
241
		boolean a = setCurrentJ9 (versionSelection);
242
	}
243
	
244
	/* (non-Javadoc)
245
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
246
	 */
247
	protected void performApply() {
248
		super.performApply();
249
		J9SelectionChanged();
250
	}
251
	
252
	
253
	/* (non-Javadoc)
254
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
255
	 */
256
	protected void performDefaults() {
257
		super.performDefaults();
258
		// J9List only matters when we are filling data, not on the display
259
		// only
260
		if (J9List != null)
261
			J9List.setSelection(0);
262
	}
263
	/* (non-Javadoc)
264
	 * @see org.eclipse.jface.dialogs.IDialogPage#performHelp()
265
	 */
266
	public void performHelp() {
267
		// Auto-generated method stub
268
	
269
	}
270
	/* (non-Javadoc)
271
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
272
	 */
273
	public boolean performOk() {
274
		// J9List only matters when we are filling data, not on the display
275
		// only
276
		if (J9List != null)
277
		{
278
			String[] tmp = J9List.getSelection();
279
			if (tmp != null)
280
				if (tmp.length > 0)
281
				{
282
					setCurrentJ9 ((String) J9List.getSelection()[0]);
283
					J9SelectionChanged();
284
				}
285
		}
286
287
		return true;
288
	}
289
290
	// Store the backup file with the current J9 value
291
	// Note: This will only be used when a project is imported, since the value
292
	// is stored in a property.
293
	public void writeCurrentJ9(String key, String value)
294
	{
295
		try
296
		{
297
			IResource resource = (IResource) getElement();
298
	        IProject project = resource.getProject();
299
			IFile rscFile = project.getFile(key);
300
			InputStream inputStream = new ByteArrayInputStream(value.getBytes());
301
			// update the resource content
302
			if (rscFile.exists()) 
303
			{
304
				if (rscFile.isReadOnly()) 
305
				{
306
					// provide opportunity to checkout read-only value file 
307
					ResourcesPlugin.getWorkspace().validateEdit(new IFile[]{rscFile}, null);
308
				}
309
				rscFile.setContents(inputStream, IResource.FORCE, null);
310
			} 
311
			else 
312
			{
313
				rscFile.create(inputStream, IResource.FORCE, null);
314
			}
315
		}
316
		catch (CoreException e)
317
		{
318
			// Output error writing file
319
			e.printStackTrace();
320
		}
321
	}
322
	
323
	// Try to read the backup file with the current J9 value
324
	public String readCurrentJ9(String key)
325
	{
326
		try
327
		{
328
			IResource resource = (IResource) getElement();
329
			IProject project = resource.getProject();
330
			IFile rscFile = project.getFile(key);
331
			// update the resource content
332
			if (rscFile.exists()) 
333
			{
334
				InputStream is = rscFile.getContents();
335
				byte[] b = new byte[5];
336
				int stat = is.read(b, 0, 5);
337
				if (stat == -1)
338
					return null;
339
				String output = new String (b);
340
				return output;
341
			} 
342
			return null;
343
		}
344
		catch (CoreException e)
345
		{
346
			// Output error writing file
347
			e.printStackTrace();
348
		}
349
		catch (IOException e)
350
		{
351
			// Output error writing file
352
			e.printStackTrace();
353
		}
354
		return null;
355
	}
356
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9ProxyConnection.java (+250 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.SocketException;
16
import java.util.ArrayList;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.StringTokenizer;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.debug.core.DebugPlugin;
26
import org.eclipse.debug.core.IStatusHandler;
27
import org.eclipse.jdt.debug.core.JDIDebugModel;
28
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
29
import org.eclipse.jdt.launching.SocketUtil;
30
import org.eclipse.jdt.launching.j9.J9Launching;
31
32
import com.sun.jdi.VirtualMachine;
33
import com.sun.jdi.connect.AttachingConnector;
34
import com.sun.jdi.connect.Connector;
35
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
36
37
/**
38
 * A J9 JVM debug socket attaching connector connecting through the J9 debug proxy.
39
 */
40
public class J9ProxyConnection {
41
42
	// Use 127.0.0.1 to avoid timeout due to dns resolution delays
43
	public final static String LOCALHOST = "127.0.0.1"; //$NON-NLS-1$
44
	private final static String ARG_HOSTNAME = "hostname"; //$NON-NLS-1$
45
	private final static String ARG_PORT = "port"; //$NON-NLS-1$
46
47
	private String fHost;
48
	private String fPort;
49
	private String[] fSymbolPath;
50
	private String fDebugTimeout;
51
	private J9VMInstall fVMInstall;
52
	private String fProxyOptions;
53
	private Process fProxyProcess;
54
	private String[] fProxyCmd;
55
	private String fProxyPort;
56
	
57
58
	/**
59
	 * Constructor for J9ProxyAttachConnector.
60
	 * 
61
	 * @param host			Host name of target vm proxy must connect to
62
	 * @param port			Port name of target vm proxy must connect to
63
	 * @param symbolPath	Symbol file path.
64
	 * @param debugTimeout	Debug timeout in ms, or null for global default
65
	 * @param vmInstall	J9 VM install of proxy utility location
66
	 */
67
	public J9ProxyConnection(String host, String port, String symbolPath[], String debugTimeout, J9VMInstall vmInstall, String proxyOptions) {
68
		fHost = host;
69
		fPort = port;
70
		fSymbolPath = symbolPath;
71
		fDebugTimeout = debugTimeout;
72
		fVMInstall = vmInstall;
73
		fProxyOptions = proxyOptions;
74
	}
75
	
76
	private List getProxyOptions() throws CoreException {
77
		StringTokenizer tokenizer = new StringTokenizer(fProxyOptions);
78
		List result = new ArrayList(tokenizer.countTokens() + 1);
79
		while (tokenizer.hasMoreTokens()) {
80
			result.add(tokenizer.nextToken());
81
		}
82
		if (!fVMInstall.isPre20J9Version()) {
83
			result.add("-timeout=" + getDebugTimeout()); //$NON-NLS-1$
84
		}
85
		return result;
86
	}
87
88
	public Process runProxy() throws CoreException {
89
		/*
90
		 * LL: Migration to 3.0: SocketUtil.findUnusedLocalPort() has been deprecated.
91
		 * Use SocketUtil.findFreePort() instead.
92
		 */
93
		int proxyPort= SocketUtil.findFreePort();
94
		if (proxyPort == -1) {
95
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9ProxyConnection.Could_not_find_a_free_socket_for_the_proxy"), null, IJavaLaunchConfigurationConstants.ERR_NO_SOCKET_AVAILABLE); //$NON-NLS-1$
96
		}
97
		fProxyPort = Integer.toString(proxyPort);
98
99
		StringBuffer proxy= new StringBuffer(fVMInstall.getInstallLocation().getAbsolutePath());
100
		proxy.append(File.separatorChar);
101
		proxy.append("bin"); //$NON-NLS-1$
102
		proxy.append(File.separatorChar);
103
		proxy.append("j9proxy"); //$NON-NLS-1$
104
		StringBuffer symPath = new StringBuffer();
105
		for (int i = 0; i < fSymbolPath.length; i++) {
106
			if (i > 0) symPath.append(File.pathSeparatorChar);
107
			symPath.append(fSymbolPath[i]);
108
		}
109
		List proxyCmd = new ArrayList();
110
		proxyCmd.add(proxy.toString());
111
		proxyCmd.addAll(getProxyOptions());
112
		proxyCmd.add(fHost + ':'+ fPort);
113
		proxyCmd.add(fProxyPort);
114
		proxyCmd.add(symPath.toString());
115
		fProxyCmd = (String[])proxyCmd.toArray(new String[proxyCmd.size()]);
116
		try {
117
			fProxyProcess = Runtime.getRuntime().exec(fProxyCmd);
118
		} catch (IOException e) {
119
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9ProxyConnection.Could_not_start_debug_proxy"), e, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
120
		}
121
122
		return fProxyProcess;
123
	}
124
125
	/**
126
	 * Create a JDI socket attching connector and connect it to the J9 VM 
127
	 * through the j9 debug proxy.
128
	 * 
129
	 * @exception CoreException if unable to create the connector
130
	 */
131
	public VirtualMachine connect(IProgressMonitor monitor) throws CoreException, IOException, IllegalConnectorArgumentsException {
132
133
		AttachingConnector connector= J9Launching.getAttachingConnector();
134
		Map map= connector.defaultArguments();
135
		Connector.Argument param= (Connector.Argument) map.get(ARG_HOSTNAME);
136
		param.setValue(LOCALHOST);
137
		param= (Connector.Argument) map.get(ARG_PORT);
138
		param.setValue(fProxyPort);
139
140
		int debugTimeout = getDebugTimeout();
141
		long timeLimit = System.currentTimeMillis() + debugTimeout;
142
		for(;;) {
143
			try {
144
				VirtualMachine vm = attach(connector, map, debugTimeout);
145
				setDebugTimeout(vm, debugTimeout);
146
				return vm;
147
			} catch (SocketException e) {
148
				// Cannot bind to vm or proxy, may still be initializing (for example loading symbol files).
149
				if (System.currentTimeMillis() > timeLimit) {
150
					throw e;
151
				} else {
152
					synchronized (connector) {
153
						try {
154
							connector.wait(250);
155
						} catch(InterruptedException ie) {
156
						}
157
					}
158
				}
159
			}
160
		}
161
	}
162
163
	private int getDebugTimeout() {
164
		if (fDebugTimeout == null) {
165
			return JDIDebugModel.getPreferences().getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT);
166
		} else {
167
			return Integer.parseInt(fDebugTimeout);
168
		}
169
	}	
170
171
	/**
172
	 * Attaches to a virtual machine. This method implemts using a timeout to avoid
173
	 * hanging indefinitely in SocketTransportImpl.PerformHandshake.
174
	 */
175
	private VirtualMachine attach(final AttachingConnector connector, final Map map, final int debugTimeout) throws CoreException, IOException, IllegalConnectorArgumentsException {
176
		final Exception[] exc = new Exception[1];
177
		final VirtualMachine[] vm = new VirtualMachine[1];
178
		Runnable runnable = new Runnable() {
179
			public void run() {
180
				try {
181
					vm[0] = connector.attach(map);
182
				} catch (IOException e) {
183
					exc[0] = e;
184
				} catch (IllegalConnectorArgumentsException e) {
185
					exc[0] = e;
186
				}
187
			}
188
		};
189
		Thread thread = new Thread(runnable, "J9ProxyConnection Attach"); //$NON-NLS-1$
190
		thread.start();
191
		try {
192
			thread.join(debugTimeout);
193
		} catch (InterruptedException e) {
194
		}
195
		
196
		if (exc[0] instanceof IOException)
197
			throw (IOException)exc[0];
198
		else if (exc[0] instanceof IllegalConnectorArgumentsException)
199
			throw (IllegalConnectorArgumentsException)exc[0];
200
	
201
		if (vm[0] == null) {
202
			String msg = J9LauncherMessages.getString("J9Launching.Timeout_while_connecting_to_VM,_try_using_a_different_port_number_1"); //$NON-NLS-1$
203
			J9LaunchingPlugin.abort(msg, null, IJavaLaunchConfigurationConstants.ERR_VM_CONNECT_TIMEOUT);
204
		}
205
		return vm[0];
206
	}
207
208
	public String[] getProxyCommand() {
209
		return fProxyCmd;
210
	}
211
212
	/**
213
	 * Set the debug request timeout of a vm in ms, if supported by the vm implementation.
214
	 */
215
	private static void setDebugTimeout(VirtualMachine vm, int timeOut) {
216
		if (vm instanceof org.eclipse.jdi.VirtualMachine && timeOut > 0) {
217
			org.eclipse.jdi.VirtualMachine vm2= (org.eclipse.jdi.VirtualMachine)vm;
218
			vm2.setRequestTimeout(timeOut);
219
		}
220
	}
221
222
	/**
223
	 * Utility function to consult status handler (if there is one) for errors and connect
224
	 * timeouts, or else throw a CoreException. Always abort for fatal errors.
225
	 */
226
	public static boolean handleConnectException(Object errorSource, Exception e, String errorStreamMonitorContents) throws CoreException {
227
		boolean retry = false;
228
		if (errorStreamMonitorContents != null && errorStreamMonitorContents.length() != 0) {
229
			J9LaunchingPlugin.abort(errorStreamMonitorContents, e, IJavaLaunchConfigurationConstants.ERR_VM_LAUNCH_ERROR);
230
		} else {
231
			// timeout, consult status handler if there is one
232
			IStatus status = new Status(IStatus.ERROR, "org.eclipse.jdt.launching.j9", IJavaLaunchConfigurationConstants.ERR_VM_CONNECT_TIMEOUT, e.getLocalizedMessage(), e); //$NON-NLS-1$
233
			IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
234
			
235
			retry= false;
236
			if (handler == null) {
237
				// if there is no handler, throw the exception
238
				throw new CoreException(status);
239
			} else {
240
				Object result = handler.handleStatus(status, errorSource);
241
				if (result instanceof Boolean) {
242
					retry = ((Boolean)result).booleanValue();
243
				}
244
			} 
245
		}
246
		return retry;
247
	}
248
249
}
250
(-)j9/org/eclipse/jdt/internal/launching/j9/J9SocketAttachConnector.java (+200 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.io.IOException;
14
import java.net.UnknownHostException;
15
import java.text.MessageFormat;
16
import java.util.ArrayList;
17
import java.util.List;
18
import java.util.Map;
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.ILaunch;
25
import org.eclipse.debug.core.ILaunchConfiguration;
26
import org.eclipse.debug.core.model.IDebugTarget;
27
import org.eclipse.debug.core.model.IProcess;
28
import org.eclipse.jdi.TimeoutException;
29
import org.eclipse.jdt.debug.core.JDIDebugModel;
30
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
31
import org.eclipse.jdt.launching.IVMInstall;
32
import org.eclipse.jdt.launching.j9.J9Launching;
33
34
import com.sun.jdi.VMDisconnectedException;
35
import com.sun.jdi.VirtualMachine;
36
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
37
38
/**
39
 * A J9 JVM debug proxy socket attaching IVMConnector
40
 */
41
public class J9SocketAttachConnector implements IJ9Connector{
42
43
	public final static String ARG_HOSTNAME = "hostname"; //$NON-NLS-1$
44
	public final static String ARG_PORT = "port"; //$NON-NLS-1$
45
	public final static String ARG_DEBUG_TIMEOUT = "debug_timeout"; //$NON-NLS-1$
46
	public final static String ARG_VM_INSTALL_NAME = "proxyvm"; //$NON-NLS-1$
47
	public final static String ARG_PROXY_OPTIONS = "proxy_options"; //$NON-NLS-1$
48
49
	// tbd: Note that the identifier "Default" is stored in launch configs
50
	// Therefore, the string should not be translated for nls
51
	public final static String DEFAULT_JRE_NAME = "Default"; //$NON-NLS-1$
52
53
	private IVMInstall fIVMInstall; 
54
	
55
	public IVMInstall getIVMInstall() {
56
		return fIVMInstall;
57
	}
58
	
59
	public void setIVMInstall(IVMInstall  connector) {
60
		fIVMInstall = connector;
61
	}
62
	
63
	/**
64
	 * @see org.eclipse.jdt.launching.IVMConnector#connect(Map, IProgressMonitor, ILaunch)
65
	 */
66
	public void connect(
67
			Map arguments,
68
			IProgressMonitor monitor,
69
			ILaunch launch)	throws CoreException {
70
71
		ILaunchConfiguration configuration = launch.getLaunchConfiguration();
72
73
		String port = (String) arguments.get(ARG_PORT);
74
		if (port == null) {
75
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.Port_unspecified_for_remote_connection"), null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_PORT); //$NON-NLS-1$
76
		}
77
		String host = (String) arguments.get(ARG_HOSTNAME);
78
		if (host == null) {
79
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.Hostname_unspecified_for_remote_connection"), null, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_HOSTNAME); //$NON-NLS-1$
80
		}
81
		
82
		String symbolPath[] = J9Launching.getResolvedSymbolLookupPath(configuration);
83
		String debugTimeout = (String) arguments.get(ARG_DEBUG_TIMEOUT);
84
85
		if (fIVMInstall == null) {
86
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.VM_does_not_exist_for_remote_connection"), null, IJavaLaunchConfigurationConstants.ERR_VM_INSTALL_DOES_NOT_EXIST); //$NON-NLS-1$
87
		}
88
89
		String proxyOptions = (String) arguments.get(ARG_PROXY_OPTIONS);
90
		if (proxyOptions == null) {
91
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.Proxy_options_unspecified_for_remote_connection"), null, IStatus.OK); //$NON-NLS-1$
92
		}
93
94
		boolean allowTerminate = false;
95
		if (configuration != null) {
96
			allowTerminate = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_ALLOW_TERMINATE, false);
97
		}
98
99
		Process proxyOSProcess = null;
100
		try {
101
			J9ProxyConnection proxyConnector = new J9ProxyConnection(host, port, symbolPath, debugTimeout, (J9VMInstall)fIVMInstall, proxyOptions);
102
			proxyOSProcess = proxyConnector.runProxy();
103
			IProcess proxyProcess= DebugPlugin.newProcess(launch, proxyOSProcess, J9Launching.renderProcessLabel(proxyConnector.getProxyCommand()));
104
			proxyProcess.setAttribute(IProcess.ATTR_CMDLINE, J9Launching.renderCommandLine(proxyConnector.getProxyCommand()));
105
106
			boolean retry = false;		
107
			do {
108
				try {
109
					// check for cancellation
110
					if (monitor.isCanceled()) {
111
						proxyOSProcess.destroy();
112
						return;
113
					}			
114
						
115
					VirtualMachine vm = proxyConnector.connect(monitor);
116
					String vmLabel = constructVMLabel(vm, host, port, configuration);
117
					IDebugTarget debugTarget= JDIDebugModel.newDebugTarget(launch, vm, vmLabel, null, allowTerminate, true);
118
					launch.addDebugTarget(debugTarget);
119
					return;
120
				} catch (UnknownHostException e) {
121
					J9LaunchingPlugin.abort(MessageFormat.format(J9LauncherMessages.getString("J9SocketAttachConnector.Failed_to_connect_to_remote_VM_because_of_unknown_host"), new String[]{host}), e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); //$NON-NLS-1$
122
				} catch (IOException e) {
123
					String errorMessage= proxyProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
124
					retry = J9ProxyConnection.handleConnectException(this, e, errorMessage);
125
				} catch (VMDisconnectedException e) {
126
					String errorMessage= proxyProcess.getStreamsProxy().getErrorStreamMonitor().getContents();
127
					retry = J9ProxyConnection.handleConnectException(this, e, errorMessage);
128
				} catch (IllegalConnectorArgumentsException e) {
129
					J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9SocketAttachConnector.Failed_to_connect_to_remote_VM"), e, IJavaLaunchConfigurationConstants.ERR_REMOTE_VM_CONNECTION_FAILED); //$NON-NLS-1$
130
131
				}
132
			} while (retry);
133
		} catch (CoreException e) {
134
			if (proxyOSProcess != null) proxyOSProcess.destroy();
135
			throw e;
136
		}
137
		proxyOSProcess.destroy();
138
	}
139
140
	/**
141
	 * Helper method that constructs a human-readable label for a remote VM.
142
	 */
143
	protected String constructVMLabel(VirtualMachine vm, String host, String port, ILaunchConfiguration configuration) {
144
		String name = null;
145
		try {
146
			name = vm.name();
147
		} catch (TimeoutException e) {
148
			// do nothing
149
		} catch (VMDisconnectedException e) {
150
			// do nothing
151
		}
152
		if (name == null) {
153
			if (configuration == null) {
154
				name = ""; //$NON-NLS-1$
155
			} else {
156
				name = configuration.getName();
157
			}
158
		}
159
		StringBuffer buffer = new StringBuffer(name);
160
		buffer.append('['); //$NON-NLS-1$
161
		buffer.append(host);
162
		buffer.append(':'); //$NON-NLS-1$
163
		buffer.append(port);
164
		buffer.append(']'); //$NON-NLS-1$
165
		return buffer.toString();
166
	}
167
		
168
	/*
169
	 * Return names of configured j9 vm installs.
170
	 */
171
	private static List getJ9VMInstallNames() {
172
		IVMInstall vmInstalls[] = J9Launching.getJ9VMInstalls();
173
		ArrayList names = new ArrayList();
174
		for (int i = 0; i < vmInstalls.length; i++) {
175
			names.add(vmInstalls[i].getName());
176
		}
177
		return names;
178
	}
179
180
	/**
181
	 * @see org.eclipse.jdt.internal.launching.j9.IJ9Connector#postLaunch(Map, IProgressMonitor, ILaunch)
182
	 */
183
	public void postLaunch(
184
		Map arguments,
185
		IProgressMonitor monitor,
186
		ILaunch launch)
187
		throws CoreException {
188
	}
189
190
	/**
191
	 * @see org.eclipse.jdt.internal.launching.j9.IJ9Connector#preLaunch(Map, IProgressMonitor, ILaunch)
192
	 */
193
	public void preLaunch(
194
		Map arguments,
195
		IProgressMonitor monitor,
196
		ILaunch launch)
197
		throws CoreException {
198
	}
199
200
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9SocketAttachConnectorDelegate.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
/**
14
 * THIS CLASS IS A THROWAWAY! 
15
 * 
16
 * It's an unchanged subclass of J9Connector 
17
 * delegate.  This allows us to add another vmconnector extension point with a
18
 * different ID.  The vmconnector point uses the ID supplied by the created class
19
 * and not the plugin descriptor itself... we'll use the migration plugin to take
20
 * care of this issue in 5.6
21
 */
22
public final class J9SocketAttachConnectorDelegate
23
	extends J9ConnectorDelegate {
24
25
	/**
26
	 * Constructor for J9SocketAttachConnectorDelegate.
27
	 */
28
	public J9SocketAttachConnectorDelegate() {
29
		super();
30
	}
31
32
	/**
33
	 * @see org.eclipse.jdt.launching.IVMConnector#getIdentifier()
34
	 */
35
	public String getIdentifier() {
36
		return "com.ibm.ive.internal.j9.launcher.J9SocketAttachConnector"; //$NON-NLS-1$
37
	}
38
	
39
	/**
40
	 * @see org.eclipse.jdt.launching.IVMConnector#getName()
41
	 */
42
	public String getName() {
43
		return J9LauncherMessages.getString("J9SocketAttachConnector.J9_20_(Proxied_Socket_Attach)"); //$NON-NLS-1$
44
	}
45
46
47
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMCommandTab.java (+108 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.debug.core.ILaunchConfiguration;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
20
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
21
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
22
import org.eclipse.jdt.launching.j9.IJ9LaunchConfigurationConstants;
23
import org.eclipse.jdt.launching.j9.J9Launching;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Composite;
29
30
/**
31
 * User interface for J9 specific launch attributes
32
 */
33
public class J9VMCommandTab extends AbstractLaunchConfigurationTab {
34
35
	protected Button fRunAsConsoleButton;
36
	protected Button fExecFromArchiveButton;
37
38
	/**
39
	 * @see ILaunchConfigurationTab#createControl(Composite)
40
	 */
41
	public void createControl(Composite parent) {
42
		
43
		Composite comp = new Composite(parent, SWT.NONE);
44
		setControl(comp);
45
		GridLayout topLayout = new GridLayout();
46
		comp.setLayout(topLayout);
47
		topLayout.marginWidth= 0;
48
		topLayout.marginHeight= 0;
49
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
50
		comp.setLayoutData(gd);
51
		
52
//		createVerticalSpacer(comp, 2);
53
		
54
		fRunAsConsoleButton = new Button(comp, SWT.CHECK);
55
		fRunAsConsoleButton.setText(J9LauncherMessages.getString("J9VMCommandTab.Run_as_console")); //$NON-NLS-1$
56
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
57
		gd.horizontalSpan = 2;
58
		fRunAsConsoleButton.setLayoutData(gd);
59
60
		fExecFromArchiveButton = new Button(comp, SWT.CHECK);
61
		fExecFromArchiveButton.setText(J9LauncherMessages.getString("J9VMCommandTab.Run_from_executable_archive")); //$NON-NLS-1$
62
		gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
63
		gd.horizontalSpan = 2;
64
		fExecFromArchiveButton.setLayoutData(gd);
65
66
		setControl(comp);
67
	}
68
69
	/**
70
	 * @see ILaunchConfigurationTab#getName()
71
	 */
72
	public String getName() {
73
		return J9LauncherMessages.getString("J9VMCommandTab.J9_VM_specific_attributes_2"); //$NON-NLS-1$
74
	}
75
76
	/**
77
	 * @see ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
78
	 */
79
	public void initializeFrom(ILaunchConfiguration configuration) {
80
		try {
81
			Map attributeMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map)null);
82
			fRunAsConsoleButton.setSelection(J9Launching.runAsConsole(attributeMap));
83
			fExecFromArchiveButton.setSelection(J9Launching.executeFromArchive(attributeMap));
84
		} catch(CoreException ce) {
85
			JDIDebugUIPlugin.log(ce);		
86
		}
87
	}
88
89
	/**
90
	 * @see ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy)
91
	 */
92
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
93
		Map attributeMap = new HashMap(1);
94
		attributeMap.put(IJ9LaunchConfigurationConstants.ATTR_RUN_AS_CONSOLE, new Boolean(fRunAsConsoleButton.getSelection()).toString());
95
		attributeMap.put(IJ9LaunchConfigurationConstants.ATTR_EXECUTE_FROM_ARCHIVE, new Boolean(fExecFromArchiveButton.getSelection()).toString());
96
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, attributeMap);
97
	}
98
99
	/**
100
	 * @see ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy)
101
	 */
102
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
103
		Map attributeMap = new HashMap(1);
104
		attributeMap.put(IJ9LaunchConfigurationConstants.ATTR_RUN_AS_CONSOLE, new Boolean(J9Launching.runAsConsole(null)).toString());
105
		attributeMap.put(IJ9LaunchConfigurationConstants.ATTR_EXECUTE_FROM_ARCHIVE, new Boolean(J9Launching.executeFromArchive(null)).toString());
106
		configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, attributeMap);
107
	}
108
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMContentProvider.java (+269 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.util.Vector;
14
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.launching.IVMInstall;
19
import org.eclipse.jdt.launching.IVMInstallType;
20
import org.eclipse.jdt.launching.JavaRuntime;
21
import org.eclipse.jdt.launching.j9.IJ9LaunchConfigurationConstants;
22
import org.eclipse.jdt.launching.j9.J9Launching;
23
import org.eclipse.jface.viewers.IStructuredContentProvider;
24
import org.eclipse.jface.viewers.Viewer;
25
 
26
/**
27
 * Retrieve all known J9 VMs in the system
28
 */
29
public class J9VMContentProvider 
30
	implements IStructuredContentProvider 
31
{
32
	/* (non-Javadoc)
33
	 * Object is determined from internal references.  arg0 is ignored.
34
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
35
	 */
36
	public Object[] getElements(Object arg0) {
37
		return getVMNames().toArray();
38
	}
39
	
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
42
	 */
43
	public void dispose() {
44
	}
45
	
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
48
	 */
49
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
50
	}
51
52
	public Vector getVMNames ()
53
	{
54
		String[][] namesAndIds = getVMNamesAndIds();
55
		Vector elementNames = new Vector ();
56
		for (int i = 0; i < namesAndIds.length; i++)
57
		{
58
			elementNames.add (namesAndIds[i][0]);
59
		}
60
		elementNames.trimToSize();
61
		
62
		return elementNames;
63
	}
64
	
65
	private static String[][] getVMNamesAndIds() {
66
		String[][] result;
67
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
68
		IVMInstall[] installs = type.getVMInstalls();
69
		result = new String[installs.length][];
70
		for (int i = 0; i < installs.length; i++) {
71
			result[i] = new String[] {installs[i].getName(),installs[i].getId()};
72
		}
73
		return result;
74
	}
75
	
76
	public static String[][] getVMNamesAndVersions() {
77
		String[][] result;
78
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
79
		IVMInstall[] installs = type.getVMInstalls();
80
		result = new String[installs.length][];
81
		for (int i = 0; i < installs.length; i++) {
82
			try
83
			{
84
				String J9Version = ((J9VMInstall)installs[i]).getJ9Version();
85
				int countDots = 0;
86
				int currentIndex = 0;
87
				while (currentIndex != -1)
88
				{
89
					currentIndex = J9Version.indexOf('.', currentIndex);
90
					if (currentIndex != -1)
91
					{
92
						countDots++; // Increment Count
93
						currentIndex++; // Continue to look starting at the next character
94
					}
95
				}
96
				if (countDots == 1)
97
					J9Version = J9Version + ".0"; //$NON-NLS-1$
98
				
99
				// Since there is no version below 2.2.0 that can be found in the metadata
100
				// reset the version to 0.0.0
101
				if (J9Version.compareTo ("2.2.0") < 0) //$NON-NLS-1$
102
					J9Version = "0.0.0";  // $NON-NLS-1$
103
				result[i] = new String[] {installs[i].getName(),J9Version};
104
			}
105
			catch (CoreException e)
106
			{
107
				result[i] = new String[] {installs[i].getName(),""}; //$NON-NLS-1$
108
			}
109
		}
110
		return result;
111
	}
112
113
114
115
	public static String getVMNamesFromId(String id) {
116
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
117
		IVMInstall[] installs = type.getVMInstalls();
118
		for (int i = 0; i < installs.length; i++) {
119
			if (installs[i].getId() == id)
120
				return installs[i].getName();
121
		}
122
		return null;
123
	}
124
	
125
	public static IVMInstall getVMfromName(String Name) {
126
		IVMInstallType type = JavaRuntime.getVMInstallType(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
127
		IVMInstall[] installs = type.getVMInstalls();
128
		for (int i = 0; i < installs.length; i++) {
129
			if (Name.compareTo (installs[i].getName()) == 0)
130
				return installs[i];
131
		}
132
		return null;
133
	}
134
	public static String getVMInstallNameFromResource (IJavaProject javaProject)
135
	{
136
		return 	J9VMContentProvider.getVMInstallNameFromResource (javaProject.getResource());
137
	}
138
	
139
	public static String getVMNameFromVersion (String version)
140
	{
141
		if (version == null)
142
			return getDefaultVMName ();
143
			
144
		String[][] availableJ9s = J9VMContentProvider.getVMNamesAndVersions();
145
		// Try to match initial value in the names
146
		for (int i = 0; i < availableJ9s.length; i++)
147
		{ // [0] is the name [1] is the version value
148
			if (version.compareTo (availableJ9s[i][1]) == 0)
149
				return availableJ9s[i][0];
150
			int lastSegment = version.lastIndexOf ('.');
151
			if (lastSegment != -1)
152
			{
153
				String tmp = new String (version.substring(0, lastSegment));
154
				if (tmp.compareTo (availableJ9s[i][1]) == 0)
155
					return availableJ9s[i][0];
156
			}
157
		}
158
		return getDefaultVMName ();
159
	}
160
	
161
	public static String getVMVersionFromName (String name)
162
	{
163
		if (name == null)
164
			return getDefaultVMVersion();
165
		
166
		//if (name.compareTo ("0.0.0") == 0) 
167
		  //return J9VMContentProvider.getDefaultVMName();		
168
169
		String[][] availableJ9s = J9VMContentProvider.getVMNamesAndVersions();
170
		// Try to match initial value in the names
171
		for (int i = 0; i < availableJ9s.length; i++)
172
		{ // [0] is the name [1] is the version value
173
			if (name.compareTo (availableJ9s[i][0]) == 0)
174
				return availableJ9s[i][1];
175
			int lastSegment = name.lastIndexOf ('.');
176
			if (lastSegment != -1)
177
			{
178
				String tmp = new String (name.substring(0, lastSegment));
179
				if (tmp.compareTo (availableJ9s[i][1]) == 0)
180
					return availableJ9s[i][1];
181
			}
182
		}
183
		return J9VMContentProvider.getDefaultVMName();
184
	}
185
186
	public static String getVMVersionFromResource (IResource resource)
187
	{
188
		if (resource == null)
189
		{
190
//			System.out.println ("1 v " + getDefaultVMVersion());
191
			return getDefaultVMVersion();
192
		}
193
			
194
		J9PropertyPage propertyPage = new J9PropertyPage (resource);
195
		if (propertyPage == null)
196
		{
197
//			System.out.println ("2 v " + getDefaultVMVersion());
198
			return getDefaultVMVersion();
199
		}
200
			
201
		String j9Version = propertyPage.getCurrentJ9();
202
//		System.out.println ("3 v " + j9Version);
203
		return j9Version;
204
	}
205
206
207
	public static String getVMInstallNameFromResource (IResource resource)
208
	{
209
		String j9Version = getVMVersionFromResource (resource);
210
		if (j9Version == null)
211
			return null;
212
213
		String j9Name = getVMNameFromVersion (j9Version);
214
		return	j9Name;
215
	}
216
	
217
	public static IVMInstall getVMInstallFromResource (IJavaProject javaProject)
218
	{
219
		if (javaProject == null)
220
			return J9Launching.getDefaultJ9VMInstall();
221
		
222
		try
223
		{		
224
			IVMInstall vmInstall = J9VMContentProvider.getVMInstallFromResource (javaProject.getResource());
225
			if (vmInstall == null)
226
				vmInstall = JavaRuntime.getVMInstall(javaProject);
227
	
228
			return vmInstall;
229
		}
230
		catch (CoreException e)
231
		{
232
			return getDefaultVMInstall ();
233
		}
234
	}
235
	
236
	public static IVMInstall getVMInstallFromResource (IResource resource)
237
	{
238
		if (resource == null)
239
			return getDefaultVMInstall ();
240
		
241
		J9PropertyPage propertyPage = new J9PropertyPage (resource);
242
		if (propertyPage == null)
243
			return getDefaultVMInstall ();
244
245
			
246
		String j9Name = getVMNameFromVersion (propertyPage.getCurrentJ9());
247
		if (j9Name != null)
248
			return J9VMContentProvider.getVMfromName(j9Name);
249
		return getDefaultVMInstall ();
250
	}
251
	
252
	public static IVMInstall getDefaultVMInstall ()
253
	{
254
		return J9VMContentProvider.getVMInstallFromResource ((IJavaProject) null);
255
	}
256
	public static String getDefaultVMName ()
257
	{
258
		IVMInstall defaultJ9 = getDefaultVMInstall();
259
		return defaultJ9.getName();
260
	}		
261
	
262
	public static String getDefaultVMVersion ()
263
	{
264
		IVMInstall defaultJ9 = getDefaultVMInstall();
265
		return getVMVersionFromName (defaultJ9.getName());
266
	}		
267
268
269
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMInstall.java (+140 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation.
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
 *     Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse.
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.launching.j9;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.debug.core.ILaunchManager;
21
import org.eclipse.jdt.launching.AbstractVMInstall;
22
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
23
import org.eclipse.jdt.launching.IVMInstallType;
24
import org.eclipse.jdt.launching.IVMRunner;
25
26
public class J9VMInstall extends AbstractVMInstall {
27
28
	private final static String J9_VERSION_PREFIX = "J9 - VM for the Java(TM) platform, Version "; //$NON-NLS-1$
29
	// TODO: Standardize a location to store this and change each version.
30
	private final static String J9_VERSION_DEFAULT = "2.2"; //$NON-NLS-1$
31
	private String j9Version;
32
33
	/**
34
	 * Constructor for J9VM
35
	 */
36
	J9VMInstall(IVMInstallType type, String id) {
37
		super(type, id);
38
	}
39
40
	/**
41
	 * @see IVMInstall#getVMRunner(String)
42
	 */
43
	public IVMRunner getVMRunner(String mode) {
44
		if (ILaunchManager.RUN_MODE.equals(mode)) {
45
			return new J9VMRunner(this);
46
		} else if (ILaunchManager.DEBUG_MODE.equals(mode)) {
47
			try {
48
				if (is21J9Version()) {
49
					return new J9DebugServerVMRunner(this);				
50
				}
51
				else {
52
					return new J9DebugVMRunner(this);
53
				}
54
			}
55
			catch (CoreException e) {
56
				return new J9DebugVMRunner(this);				
57
			}
58
		}
59
		return null;
60
	}
61
	
62
	public Process getVersionProcess() throws IOException {
63
		J9VMRunner runner = new J9VMRunner(this);
64
        return runner.getVersionProcess();
65
	}
66
	
67
	/**
68
	 * Get the version identifier as returned by j9 -version
69
	 * Throws CoreException if version cannot be determined.
70
	 */
71
	public String getJ9Version() throws CoreException {
72
		if (j9Version == null) {
73
			try {
74
				Process p = getVersionProcess();
75
				InputStream is = p.getInputStream();
76
				BufferedReader br = new BufferedReader(new InputStreamReader(is));
77
				for(;;) {
78
					String line = br.readLine();
79
					if (line == null)
80
					{
81
						j9Version = J9_VERSION_DEFAULT;
82
						break;
83
					}
84
					if (line != null) { // && line.startsWith(J9_VERSION_PREFIX)) {
85
						j9Version = line; //line.substring(J9_VERSION_PREFIX.length());
86
						break;
87
					}
88
				}
89
				if (j9Version == null) {
90
					InputStream es = p.getErrorStream();
91
					BufferedReader er = new BufferedReader(new InputStreamReader(es));
92
					StringBuffer msg = new StringBuffer();
93
					String line = null;
94
					do {
95
						line = er.readLine();
96
						if (line != null) {
97
							msg.append(line);
98
							msg.append("\n"); //$NON-NLS-1$
99
						}
100
					} while (line != null);
101
//					J9LaunchingPlugin.abort(msg.toString(), null, IJavaLaunchConfigurationConstants.ERR_VM_LAUNCH_ERROR);
102
					J9LaunchingPlugin.log(msg.toString(), null, IJavaLaunchConfigurationConstants.ERR_VM_LAUNCH_ERROR);
103
					j9Version = J9_VERSION_DEFAULT;
104
				}
105
			} catch (IOException e) {
106
				String msg = J9LauncherMessages.getString("J9Launching.Error_when_executing_j9_1"); //$NON-NLS-1$
107
//				J9LaunchingPlugin.abort(msg, e, IJavaLaunchConfigurationConstants.ERR_VM_LAUNCH_ERROR);
108
				J9LaunchingPlugin.log(msg, e, IJavaLaunchConfigurationConstants.ERR_VM_LAUNCH_ERROR);
109
				j9Version=J9_VERSION_DEFAULT;
110
			}
111
		}
112
		return j9Version;
113
	}
114
115
	/**
116
	 * Return true if the j9 version is before 2.0
117
	 * @throws CoreException if version cannot be determined.
118
	 */
119
	public boolean isPre20J9Version() throws CoreException {
120
		String j9Version = getJ9Version();
121
		return j9Version != null && j9Version.compareTo("2.0") < 0; //$NON-NLS-1$
122
	}
123
124
	/**
125
	 * Returns true if the j9 version is 2.1 or greater
126
	 * @throws CoreException if version cannot be determined.
127
	 */
128
	public boolean is21J9Version() throws CoreException {
129
		String j9Version = getJ9Version();
130
		return j9Version != null && j9Version.compareTo("2.0") > 0; //$NON-NLS-1$		
131
	}
132
	/**
133
	 * Return true if the j9 version is before 2.0
134
	 * @throws CoreException if version cannot be determined.
135
	 */
136
	public boolean isPre22J9Version() throws CoreException {
137
		String j9Version = getJ9Version();
138
		return j9Version != null && j9Version.compareTo("2.2") < 0; //$NON-NLS-1$
139
	}
140
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMInstallType.java (+245 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation.
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
 *     Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse.
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.launching.j9;
13
14
import java.io.File;
15
import java.net.URL;
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IExtensionPoint;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.jdt.launching.AbstractVMInstallType;
27
import org.eclipse.jdt.launching.IVMInstall;
28
import org.eclipse.jdt.launching.LibraryLocation;
29
import org.eclipse.update.configurator.ConfiguratorUtils;
30
import org.eclipse.update.configurator.IPlatformConfiguration.ISiteEntry;
31
32
public class J9VMInstallType extends AbstractVMInstallType {
33
34
	public IVMInstall doCreateVMInstall(String id) {
35
		return new J9VMInstall(this, id);
36
	}
37
	
38
	public String getName() {
39
		return J9LauncherMessages.getString("J9VMType.name"); //$NON-NLS-1$
40
	}
41
	
42
	/**
43
	 * @see IVMInstallType#validateInstallLocation(java.io.File)
44
	 * Check if the j9 vm executable and the detected libraries exist.
45
	 */
46
	public IStatus validateInstallLocation(File installLocation) {
47
		if (isInstallLocationValid(installLocation)) {
48
			return new Status(IStatus.OK, J9LaunchingPlugin.getUniqueIdentifier(), 0, "ok", null); //$NON-NLS-1$
49
		}
50
		return new Status(IStatus.ERROR, J9LaunchingPlugin.getUniqueIdentifier(), 0, J9LauncherMessages.getString("J9VMType.error.notRoot"), null); //$NON-NLS-1$
51
	}
52
53
	/**
54
	 * Check if the j9 vm executable and the detected libraries exist.
55
	 */
56
	private boolean isInstallLocationValid(File installLocation) {
57
		File java= new File(installLocation, "bin"+File.separator+"j9"); //$NON-NLS-2$ //$NON-NLS-1$
58
		File javaExe= new File(installLocation, "bin"+File.separator+"j9.exe"); //$NON-NLS-2$ //$NON-NLS-1$
59
		if (java.isFile() || javaExe.isFile()) {
60
			// KMH: Save this for next updates when we move the J9 to each libary.
61
			// return true;			
62
			LibraryLocation libraryLocations[] = getDefaultLibraryLocations(installLocation);
63
			boolean allLibrariesExist = true;
64
			for (int i = 0; i < libraryLocations.length; i++) {
65
				if (!libraryExists(libraryLocations[i])) {
66
					allLibrariesExist = false;
67
				}
68
			}
69
			if (allLibrariesExist) {
70
				return true;
71
			}
72
		}
73
		return false;
74
	}
75
76
	/**
77
	 * Find all of the entries related to the J9VMInstallLocations Extension Point
78
	 * @return localData from extension point
79
	 */
80
	public IConfigurationElement[] getConfigurationElement ()
81
	{
82
		IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(J9LaunchingPlugin.getUniqueIdentifier() + ".J9VMInstallLocations"); //$NON-NLS-1$
83
		IConfigurationElement[] configs= extensionPoint.getConfigurationElements();
84
		return configs;
85
	} 
86
87
	/**
88
	 * Get the location of the J9 version if available for this path
89
	 * @param configs The J9VMInstallLocations extension point data
90
	 * @param sites The possible sites where it can be installed
91
	 * @return
92
	 */
93
	public File getHomePath (IConfigurationElement configs, ISiteEntry sites[])
94
	{
95
		String relPath = configs.getAttribute("path"); //$NON-NLS-1$
96
		for (int j = 0; j < sites.length; j++) {
97
			URL siteURL = sites[j].getURL();
98
			IPath path = new Path(siteURL.getPath());
99
			path = path.append(relPath);
100
			File home = new File(path.toOSString());
101
			if (home.exists() && isInstallLocationValid(home)) {
102
				return home;
103
			}
104
		}
105
		return null;
106
	}
107
	/**
108
	 * @see IVMInstallType#detectInstallLocation()
109
	 * Matches the first J9 VM found in the list of locations specified in a J9VMInstallLocations extension, or else
110
	 * the J9 VM the workbench may be running on.
111
	 * A J9VMInstallLocation extension specifies a path to the J9 VM home relative to the
112
	 * known configured sites.
113
	 */
114
	// NOTE: This is where we find the J9
115
	public File detectInstallLocation() {
116
		IConfigurationElement[] configs = getConfigurationElement();
117
118
		File home;
119
		// NOTE: This is a list of sites where the root of the eclipse tree is located.
120
		// NOTE: The search order here is to look at the first entry in an extension point and see
121
		// NOTE: If that can be found as a child of one of these directories.  If not, keep on going.
122
		// NOTE: Once one match is found, stop looking. 
123
		//
124
		// NOTE: Added attribute "current" to try to refine search to not be arbitrary order.  Look for
125
		// NOTE: those marked current, Value="true" first, hopefully there will be only one, but order if
126
		// NOTE: more then one is arbitrary
127
128
		ISiteEntry sites[] = ConfiguratorUtils.getCurrentPlatformConfiguration().getConfiguredSites();
129
		for (int i= 0; i < configs.length; i++) {
130
			// Look to see if this is marked as the current (i.e. latest) J9
131
			String isCurrent = configs[i].getAttribute ("current"); //$NON-NLS-1$
132
			if (isCurrent != null)
133
				if (isCurrent.compareToIgnoreCase("true") == 0) //$NON-NLS-1$
134
				{
135
					home = getHomePath (configs[i], sites);
136
					if (home != null)
137
						return home;
138
				}
139
		}
140
		for (int i= 0; i < configs.length; i++) {
141
			// Look to see if this is marked as the current (i.e. latest) J9
142
			String isCurrent = configs[i].getAttribute ("current"); //$NON-NLS-1$
143
			if (isCurrent == null || isCurrent.compareToIgnoreCase("true") != 0) //$NON-NLS-1$
144
				{
145
					home = getHomePath (configs[i], sites);
146
					if (home != null)
147
						return home;
148
				}
149
		}
150
151
152
		if (!"J9".equals(System.getProperty("java.vm.name"))) //$NON-NLS-2$ //$NON-NLS-1$
153
			return null;
154
			
155
		home = new File (System.getProperty("java.home")); //$NON-NLS-1$
156
		if (home.exists() && isInstallLocationValid(home)) {
157
			return home;
158
		}
159
160
		return null;
161
	}
162
	
163
	/**
164
	 * Get the symbolic name for a J9 implementation from the J9VMInstallLocations Extension Point
165
	 * @param name The name that comes from the calling code is the end of the path for the ive directory
166
	 * @return
167
	 */
168
	public String getSymbolicName (String name)
169
	{
170
		IConfigurationElement[] configs = getConfigurationElement();
171
		for (int i= 0; i < configs.length; i++)
172
		{
173
			String relPath = configs[i].getAttribute("path"); //$NON-NLS-1$
174
            if (relPath != null && relPath.endsWith(name))
175
            {
176
				String symbolicName = configs[i].getAttribute ("symbolicName" ); //$NON-NLS-1$
177
				if (symbolicName != null)
178
					return symbolicName;
179
	        }
180
		}
181
182
		return null;
183
	}
184
185
	/**
186
	 * @see IVMInstallType#getDefaultSystemLibraryDescription(File)
187
	 */
188
	public LibraryLocation[] getDefaultLibraryLocations(File installLocation) {
189
		IPath libFolder = new Path(installLocation + "/lib"); //$NON-NLS-1$
190
		IPath jclFolder = null; 
191
		
192
		boolean libraryFound = false;
193
		List libraryList = new ArrayList(3);
194
		
195
		String [] foundationAttempts = {"/jclFoundation10", "/jclFoundation"};
196
		
197
		for (int i = 0; i < foundationAttempts.length && !libraryFound; i++)
198
		{
199
			jclFolder = new Path(libFolder + foundationAttempts[i]); //$NON-NLS-1$
200
	
201
			LibraryLocation libraryLocation;
202
	
203
			libraryLocation = getLibraryLocation(jclFolder, "classes.zip", "source/source.zip"); //$NON-NLS-1$ //$NON-NLS-2$
204
			if (libraryExists(libraryLocation)) {
205
				libraryFound = true;
206
				libraryList.add(libraryLocation);
207
			
208
				libraryLocation = getLibraryLocation(jclFolder, "locale.zip", "source/locale-src.zip"); //$NON-NLS-1$ //$NON-NLS-2$
209
				if (libraryExists(libraryLocation)) {
210
					libraryList.add(libraryLocation);
211
				}
212
		
213
				libraryLocation = getLibraryLocation(libFolder, "charconv.zip", "charconv-src.zip"); //$NON-NLS-1$ //$NON-NLS-2$
214
				if (libraryExists(libraryLocation)) {
215
					libraryList.add(libraryLocation);
216
				}
217
			}
218
			
219
		}
220
		LibraryLocation libraryLocations[] = new LibraryLocation[libraryList.size()];
221
		libraryList.toArray(libraryLocations);
222
		return libraryLocations;
223
	}
224
225
	/**
226
	 * Return a LibraryLocation for one of the J9 system libraries.
227
	 */
228
	private static LibraryLocation getLibraryLocation(
229
		IPath libPath,
230
		String libName,
231
		String libSrc) {
232
		IPath lib = libPath.append(libName);
233
		IPath source = libPath.append(libSrc);
234
		IPath path = new Path(""); //$NON-NLS-1$
235
		return new LibraryLocation(lib, source, path);
236
	}
237
238
	/**
239
	 * Test if the system library of the LibraryLocation (still) exists on the file system.
240
	 */
241
	private static boolean libraryExists(LibraryLocation libraryLocation) {
242
		return libraryLocation.getSystemLibraryPath().toFile().exists();
243
	}
244
245
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMRunner.java (+599 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2004 IBM Corporation.
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
 *     Lester Lopez (IBM Corp.) - Support latest version of JVM and Eclipse.
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.launching.j9;
13
14
import java.io.File;
15
import java.io.FileNotFoundException;
16
import java.io.IOException;
17
import java.net.URL;
18
import java.util.ArrayList;
19
import java.util.Arrays;
20
import java.util.List;
21
import java.util.Locale;
22
import java.util.Map;
23
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.NullProgressMonitor;
28
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.core.runtime.Status;
30
import org.eclipse.debug.core.DebugPlugin;
31
import org.eclipse.debug.core.ILaunch;
32
import org.eclipse.debug.core.IStatusHandler;
33
import org.eclipse.debug.core.model.IProcess;
34
import org.eclipse.debug.internal.core.DebugCoreMessages;
35
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
36
import org.eclipse.jdt.launching.IVMInstall;
37
import org.eclipse.jdt.launching.LibraryLocation;
38
import org.eclipse.jdt.launching.VMRunnerConfiguration;
39
import org.eclipse.jdt.launching.j9.J9Launching;
40
import org.eclipse.jdt.launching.j9.J9VMOptionsParser;
41
42
public class J9VMRunner extends JavaVMRunner {
43
	//	boolean DEBUG;
44
	//	private static J9LaunchingPlugin plugin;
45
46
	public J9VMRunner(IVMInstall vmInstance) {
47
		super(vmInstance);
48
49
		//		String dprop = System.getProperty("debug");
50
		//		if ( (dprop != null) && (dprop.equals("true"))) {
51
		//			DEBUG = true;
52
		//		}
53
	}
54
55
	public String[] getCmdLine(int port, int debugServerPort, String debugHost,
56
			VMRunnerConfiguration config) throws CoreException {
57
		String location = getJDKLocation();
58
		String program = constructProgramString(location, config);
59
		List arguments = new ArrayList();
60
61
		arguments.add(program);
62
63
		String[] bootCP = config.getBootClassPath();
64
		String[] cp = config.getClassPath();
65
		String[] vmArgs = config.getVMArguments();
66
		String[] programArgs = config.getProgramArguments();
67
68
		
69
		// 12-08-05 cf Commented out for J2 options
70
		// Set up the the bootclasspath
71
		//		if (bootCP != null) {
72
		//			String bootpathOpt = isOldJ9Version() ? "-bp:" : "-Xbootclasspath:";
73
		// //$NON-NLS-1$ //$NON-NLS-2$
74
		//			if (bootCP.length > 0) {
75
		//				arguments.add(bootpathOpt+convertClassPath(bootCP));
76
		//			} else {
77
		//				// empty
78
		//				arguments.add(bootpathOpt);
79
		//			}
80
		//		}
81
82
		if (cp.length > 0) {
83
			arguments.add("-classpath"); //$NON-NLS-1$
84
			arguments.add(convertClassPath(cp));
85
		}
86
87
		if (port != -1) {
88
			if (isNewJ9Version()) {
89
				arguments
90
						.add("-Xrunjdwp:transport=dt_socket,address=" + debugHost + ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
91
				arguments.add("-Xdebug"); //$NON-NLS-1$				
92
				if (debugServerPort != -1) {
93
					arguments
94
							.add("-Xrdbginfo:" + debugHost + ":" + debugServerPort); //$NON-NLS-1$ //$NON-NLS-2$
95
				}
96
			} else {
97
				arguments.add("-debug:" + port); //$NON-NLS-1$				
98
			}
99
		}
100
101
		addArguments(vmArgs, arguments);
102
103
		String classToLaunch = config.getClassToLaunch();
104
		if (classToLaunch.length() > 0) {
105
			arguments.add(classToLaunch);
106
		}
107
108
		addArguments(programArgs, arguments);
109
110
		String[] cmdLine = new String[arguments.size()];
111
		arguments.toArray(cmdLine);
112
113
		return cmdLine;
114
	}
115
116
	public void addVMOptionsFromRules(VMRunnerConfiguration config)
117
			throws CoreException {
118
		List additionalOptions = extractVMOptionsFromRules(config);
119
		if (additionalOptions.size() > 0) {
120
			List newArgList = new ArrayList();
121
			newArgList.addAll(additionalOptions);
122
			newArgList.addAll(Arrays.asList(config.getVMArguments()));
123
			String[] newVmArgs = (String[]) newArgList
124
					.toArray(new String[newArgList.size()]);
125
			config.setVMArguments(newVmArgs);
126
		}
127
	}
128
129
	public void addJitArgumentWhenNotDefault(VMRunnerConfiguration config)
130
			throws CoreException {
131
		if (isOldJ9Version()) {
132
			if (!containsOption(config.getVMArguments(), "-jit")) { //$NON-NLS-1$
133
				List newArgList = new ArrayList();
134
				newArgList.add("-jit"); //$NON-NLS-1$
135
				newArgList.addAll(Arrays.asList(config.getVMArguments()));
136
				String[] newVmArgs = (String[]) newArgList
137
						.toArray(new String[newArgList.size()]);
138
				config.setVMArguments(newVmArgs);
139
			}
140
		}
141
	}
142
143
	protected J9VMInstall getJ9VMInstall() {
144
		return (J9VMInstall) fVMInstance;
145
	}
146
147
	/**
148
	 * @see org.eclipse.jdt.launching.IVMRunner#run(VMRunnerConfiguration,
149
	 *      ILaunch, IProgressMonitor)
150
	 */
151
	public void run(VMRunnerConfiguration config, ILaunch launch,
152
			IProgressMonitor monitor) throws CoreException {
153
154
		if (monitor == null) {
155
			monitor = new NullProgressMonitor();
156
		}
157
158
		// check for cancellation
159
		if (monitor.isCanceled()) {
160
			return;
161
		}
162
163
		// Add -jit argument for old VMs
164
		addJitArgumentWhenNotDefault(config);
165
166
		// Convert configuration to use -jxe option if requested.
167
		config = J9Launching.adaptVMRunnerConfiguration(config,
168
				getJ9VMInstall());
169
170
		// Add VM options extracted from rules found on the bootclasspath
171
		addVMOptionsFromRules(config);
172
173
		String[] cmdLine = getCmdLine(-1, -1, null, config);
174
		File workingDir = getWorkingDir(config);
175
176
		// Added plugin tracing, this can be activated in the Run-time Workspace
177
		if (J9LaunchingPlugin.getDefault().isDebugging()) {
178
			// Display the command line args in the Console
179
			System.out.println("Command Line Args:");
180
			for (int i = 0; i < cmdLine.length; i++) {
181
				// If it starts with "-", it's an option so join it to the next
182
				// string.
183
				if ((cmdLine[i].startsWith("-classpath")) ||(cmdLine[i].startsWith("-cp")) ) {
184
					String tStr = cmdLine[i++].toString();
185
					if (!cmdLine[i].startsWith("-")) {
186
						System.out.println("\t" + tStr + " "
187
								+ cmdLine[i].toString());
188
					} else {
189
						System.out.println("\t" + tStr);
190
						System.out.println("\t" + cmdLine[i].toString());
191
					}
192
				} else {
193
					System.out.println("\t" + cmdLine[i].toString());
194
				}
195
			}
196
		}
197
198
		// check for cancellation
199
		if (monitor.isCanceled()) {
200
			return;
201
		}
202
203
		Process p = exec(cmdLine, workingDir);
204
		if (p != null) {
205
			IProcess process = DebugPlugin.newProcess(launch, p, J9Launching
206
					.renderProcessLabel(cmdLine));
207
			process.setAttribute(IProcess.ATTR_CMDLINE, J9Launching
208
					.renderCommandLine(cmdLine));
209
		}
210
	}
211
212
	/**
213
	 * Launch the VM. If the OS is Linux, you must set teh LD_LIBRARY_PATH
214
	 * environment variable to {ive}\bin prior to launch. NOTE! This may cause
215
	 * some expectations to break. There is no way from within Java to get the
216
	 * environment variables used to launch your VM so there is no way to simply
217
	 * append LD_LIBRARY_PATH to the environment variables. This code will
218
	 * replace them with that variable. See Bug 98297 for further discussions.
219
	 */
220
	protected Process exec(String[] cmdLine, File workingDirectory)
221
			throws CoreException {
222
		String[] env = null;
223
		try {
224
			//Defect 99510- modified by Sri! -start
225
			//On Linux systems, AWT apps seem to need these 3 environment
226
			// variables to run.
227
			// So we use the env to get these and if env is not set on systems
228
			// then use the
229
			// java environment (using properties to get the same and as a third
230
			// option use default values.
231
			String osName = System.getProperty("os.name"); //$NON-NLS-1$
232
			if (osName != null) {
233
				osName = osName.toLowerCase();
234
				if (osName.indexOf("linux") != -1) { //$NON-NLS-1$  
235
236
					//Get the LD_LIBRARY_PATH value
237
					String libPath = getJ9VMInstall().getInstallLocation()
238
							.getAbsolutePath()
239
							+ File.separator + "bin";
240
241
					//execute env to get the environment for HOME and DISPLAY
242
					String homeEnv = null;
243
					String dispEnv = null;
244
					String localeEnv = null;
245
					String gdmlangEnv = null;
246
					String lppathEnv = null;
247
					try {
248
249
						java.util.Properties prop = new java.util.Properties();
250
						prop.load(Runtime.getRuntime().exec("env")
251
								.getInputStream());
252
						homeEnv = (String) prop.get("HOME");
253
						dispEnv = (String) prop.get("DISPLAY");
254
						localeEnv = (String) prop.get("LANG");
255
						gdmlangEnv = (String) prop.get("GDM_LANG");
256
						lppathEnv = (String) prop.get("LD_LIBRARY_PATH");
257
258
					} catch (IOException e) {
259
					}
260
261
					//env is not set on system, use the java environment
262
					if (homeEnv == null) {
263
						try {
264
							homeEnv = System.getProperty("user.home");
265
						} catch (SecurityException e) {
266
						}
267
					}//homeEnv
268
269
					//if at this point we don't have proper values, give
270
					// default values
271
					if (homeEnv == null)
272
						homeEnv = "/root";
273
					if (dispEnv == null)
274
						dispEnv = ":0";
275
					if (localeEnv == null)
276
						localeEnv = Locale.getDefault().toString();
277
					if (gdmlangEnv == null)
278
						gdmlangEnv = localeEnv + ".UTF-8"; //uses format
279
														   // en_US.UTF-8
280
281
					// Make environment list
282
					env = new String[] {
283
							"LD_LIBRARY_PATH=" + libPath + ":" + lppathEnv,
284
							"HOME=" + homeEnv, "LANG=" + localeEnv,
285
							"GDM_LANG=" + gdmlangEnv, "DISPLAY=" + dispEnv };
286
287
				}//linux specific
288
289
			}
290
		} catch (Exception e) {
291
		}
292
		//Defect 99510- modified by Sri! - end
293
		return exec(cmdLine, env, workingDirectory);
294
	}
295
296
	/**
297
	 * The version process method needs to use the LD_LIBRARY_PATH fix as well.
298
	 * 
299
	 * @return
300
	 * @throws IOException
301
	 */
302
	public Process getVersionProcess() throws IOException {
303
		VMRunnerConfiguration config = new VMRunnerConfiguration(
304
				"", new String[] {}); //$NON-NLS-1$
305
		String JDKLocation = getJDKLocation();
306
		String j9Command = constructProgramString(JDKLocation, config);
307
308
		//        String versionCommand[] = { j9Command, "-version" }; //$NON-NLS-1$
309
310
		List arguments = new ArrayList();
311
312
		arguments.add(j9Command);
313
314
		J9VMInstallType j9VMInstallType = (J9VMInstallType) getJ9VMInstall()
315
				.getVMInstallType();
316
		LibraryLocation[] libraryLocation = j9VMInstallType
317
				.getDefaultLibraryLocations(new File(JDKLocation));
318
319
		if (libraryLocation != null) {
320
			String bootpathOpt = "-Xbootclasspath:"; //$NON-NLS-1$ //$NON-NLS-2$
321
			if (libraryLocation.length > 0) {
322
				arguments.add(bootpathOpt + convertClassPath(libraryLocation));
323
			} else {
324
				// empty
325
				arguments.add(bootpathOpt);
326
			}
327
		}
328
329
		String cp = null;
330
331
		/*
332
		 * LL: Migration to 3.0: getDescriptor().getInstallURL() are both now
333
		 * deprecated.
334
		 */
335
		URL pluginURL = J9LaunchingPlugin.getDefault().getBundle()
336
				.getEntry("/");
337
		/*
338
		 * LL: 108345: Check for existence of jar file. If it doesn't exist,
339
		 * assume it is a runtime workbench and look for the bin folder then.
340
		 * Note that we are harcoding the name of the output folder to bin. This
341
		 * is not necessarily true since it can be configured.
342
		 */
343
		URL newURL = null;
344
345
		try {
346
			newURL = Platform.resolve(new URL(pluginURL + "j9launching.jar"));
347
		} catch (FileNotFoundException e) {
348
			newURL = Platform.resolve(new URL(pluginURL + "bin"));
349
		}
350
351
		if (newURL != null && newURL.getProtocol().equals("file")) {
352
			cp = newURL.getFile().replace('/', File.separatorChar);
353
			arguments.add("-classpath"); //$NON-NLS-1$
354
			arguments.add(cp);
355
		}
356
		arguments.add("-jcl:foun10");
357
		arguments.add("org.eclipse.jdt.internal.launching.j9.J9VMVersion");
358
		String[] cmdLine = new String[arguments.size()];
359
		arguments.toArray(cmdLine);
360
361
		try {
362
			//return exec(versionCommand, null);
363
			return exec(cmdLine, null);
364
		} catch (CoreException e) {
365
			// since we use a copy of the DebugPluging.exec to launch this,
366
			// we'll need to worry about CoreExceptions, not IOExceptions.
367
			// However, if we DO catch a CoreException chances are it's been
368
			// caused by an IOException. Try to extract and rethrow such a
369
			// beast. Otherwise create and throw a new one.
370
			Throwable t = e.getStatus().getException();
371
			if (t instanceof IOException) {
372
				throw (IOException) t;
373
			} else {
374
				throw new IOException();
375
			}
376
		}
377
	}
378
379
	/**
380
	 * Copy of DebugPlugin.exec() that supports environment variables.
381
	 * 
382
	 * @param cmdLine
383
	 * @param env
384
	 * @param workingDirectory
385
	 * @return
386
	 * @throws CoreException
387
	 */
388
	public static Process exec(String[] cmdLine, String[] env,
389
			File workingDirectory) throws CoreException {
390
		Process p = null;
391
		try {
392
			if (workingDirectory == null) {
393
				p = Runtime.getRuntime().exec(cmdLine, env);
394
			} else {
395
				p = Runtime.getRuntime().exec(cmdLine, env, workingDirectory);
396
			}
397
		} catch (IOException e) {
398
			if (p != null) {
399
				p.destroy();
400
			}
401
			Status status = new Status(
402
					IStatus.ERROR,
403
					DebugPlugin.getUniqueIdentifier(),
404
					DebugPlugin.INTERNAL_ERROR,
405
					DebugCoreMessages.DebugPlugin_Exception_occurred_executing_command_line__1,e);
406
				
407
			throw new CoreException(status);
408
		} catch (NoSuchMethodError e) {
409
			//attempting launches on 1.2.* - no ability to set working
410
			// directory
411
			IStatus status = new Status(
412
					IStatus.ERROR,
413
					DebugPlugin.getUniqueIdentifier(),
414
					DebugPlugin.ERR_WORKING_DIRECTORY_NOT_SUPPORTED,
415
					DebugCoreMessages.DebugPlugin_Eclipse_runtime_does_not_support_working_directory_2,e);
416
			IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(
417
					status);
418
419
			if (handler != null) {
420
				Object result = handler.handleStatus(status, null);
421
				if (result instanceof Boolean
422
						&& ((Boolean) result).booleanValue()) {
423
					p = exec(cmdLine, env, null);
424
				}
425
			}
426
		}
427
		return p;
428
	}
429
430
	protected String constructProgramString(String location,
431
			VMRunnerConfiguration config) {
432
		String command = null;
433
		Map map = config.getVMSpecificAttributesMap();
434
		if (map != null) {
435
			command = (String) map
436
					.get(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND);
437
		}
438
439
		StringBuffer program = new StringBuffer();
440
		program.append(location).append(File.separator)
441
				.append("bin").append(File.separator); //$NON-NLS-1$
442
		if (command == null) {
443
			int directoryLength = program.length();
444
			program.append("j9w.exe"); //$NON-NLS-1$
445
			File j9w = new File(program.toString());
446
447
			boolean localMachine = false;
448
			if (location != null) {
449
				if (location.indexOf("\\win32\\") != -1) // if win32 is in the
450
														 // path I am local
451
					localMachine = true;
452
				else if (location.indexOf("\\linux\\") != -1) // if linux is in
453
															  // the path I am
454
															  // local
455
					localMachine = true;
456
				else if (location.indexOf("\\runtimes\\") == -1) // if runtimes
457
																 // is not in
458
																 // the path, I
459
																 // am local
460
					localMachine = true;
461
			}
462
			if (!j9w.exists()) {
463
				program.replace(directoryLength, program.length(), "j9"); //$NON-NLS-1$
464
			}
465
			// only check to see if runAsConsole is set for platforms that are
466
			// not emulator/local platforms
467
			if (!localMachine && J9Launching.runAsConsole(map))
468
				program.replace(directoryLength, program.length(), "j9"); //$NON-NLS-1$
469
		} else {
470
			program.append(command);
471
		}
472
473
		return program.toString();
474
	}
475
476
	protected boolean shouldIncludeInPath(String path) {
477
		return true;
478
	}
479
480
	protected String convertClassPath(String[] cp) {
481
		int pathCount = 0;
482
		StringBuffer buf = new StringBuffer();
483
		for (int i = 0; i < cp.length; i++) {
484
			if (pathCount > 0) {
485
				buf.append(File.pathSeparator);
486
			}
487
			buf.append(cp[i]);
488
			pathCount++;
489
		}
490
		return buf.toString();
491
	}
492
493
	protected String convertClassPath(LibraryLocation[] cp) {
494
		int pathCount = 0;
495
		StringBuffer buf = new StringBuffer();
496
		for (int i = 0; i < cp.length; i++) {
497
			if (pathCount > 0) {
498
				buf.append(File.pathSeparator);
499
			}
500
			buf.append(cp[i].getSystemLibraryPath());
501
			pathCount++;
502
		}
503
		return buf.toString();
504
	}
505
506
	protected boolean isOldJ9Version() throws CoreException {
507
		return ((J9VMInstall) fVMInstance).isPre20J9Version();
508
	}
509
510
	protected boolean isNewJ9Version() throws CoreException {
511
		return ((J9VMInstall) fVMInstance).is21J9Version();
512
	}
513
514
	public List extractVMOptionsFromRules(VMRunnerConfiguration config)
515
			throws CoreException {
516
		String[] bootCP = config.getBootClassPath();
517
		String[] vmArgs = config.getVMArguments();
518
		String optionName = extractOptionName(config.getClassToLaunch());
519
		// When executing using -jar, the jar is not on the boot path
520
		boolean executeFromArchive = optionName.equalsIgnoreCase("jxe") || //$NON-NLS-1$
521
				containsOption(vmArgs, "-jxe"); //$NON-NLS-1$
522
523
		// When using default bootclaspath, make sure that the libraries
524
		// on the default bootclasspath are searched for rules
525
		if (bootCP == null && !executeFromArchive) {
526
			LibraryLocation libraries[] = fVMInstance.getLibraryLocations();
527
			if (libraries == null) {
528
				libraries = fVMInstance.getVMInstallType()
529
						.getDefaultLibraryLocations(
530
								fVMInstance.getInstallLocation());
531
			}
532
			bootCP = new String[libraries.length];
533
			for (int i = 0; i < libraries.length; i++) {
534
				bootCP[i] = libraries[i].getSystemLibraryPath().toOSString();
535
			}
536
		}
537
538
		ArrayList result = new ArrayList();
539
		if (bootCP != null) {
540
			for (int i = 0; i < bootCP.length; i++) {
541
				result.addAll(J9VMOptionsParser.extractVMOptions(bootCP[i]));
542
			}
543
544
			for (int j = result.size() - 1; j >= 0; j--) {
545
				String option = (String) result.get(j);
546
				if (containsOption(vmArgs, option)) {
547
					result.remove(j);
548
				}
549
			}
550
		}
551
552
		return result;
553
	}
554
555
	private static boolean containsOption(String[] vmArgs, String option) {
556
		String optionName = extractOptionName(option);
557
		for (int i = 0; i < vmArgs.length; i++) {
558
			if (extractOptionName(vmArgs[i]).equalsIgnoreCase(optionName)) {
559
				return true;
560
			}
561
		}
562
		return false;
563
	}
564
565
	public static String extractOptionName(String option) {
566
		if (option.startsWith("-no")) { //$NON-NLS-1$
567
			option = option.substring(3);
568
		} else if (option.startsWith("-")) { //$NON-NLS-1$
569
			option = option.substring(1);
570
		} else {
571
			return ""; //$NON-NLS-1$
572
		}
573
		int p = option.indexOf(':');
574
		if (p == -1)
575
			p = option.indexOf(' ');
576
		return p == -1 ? option : option.substring(0, p);
577
	}
578
579
	/**
580
	 * Tests whether the current execution is a runtime workbench.
581
	 * 
582
	 * @return true if the current execution is a runtime workbench, otherwise
583
	 *         false.
584
	 */
585
	public static boolean isRunTimeWorkBench() {
586
		String[] sCmdList = Platform.getCommandLineArgs();
587
588
		for (int iCount = 0; iCount < sCmdList.length; iCount++) {
589
			/*
590
			 * LL: -pdelaunch is passed as a command line argument when running
591
			 * a runtime-workbench.
592
			 */
593
			if (sCmdList[iCount].toString().equalsIgnoreCase("-pdelaunch")) {
594
				return true;
595
			}
596
		}
597
		return false;
598
	} //isRunTimeWorkBench
599
}
(-)j9/org/eclipse/jdt/internal/launching/j9/J9VMVersion.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
/**
14
 * Simple class to be executed by J9VMRunner to figure out the J9 version
15
 */
16
public class J9VMVersion {
17
18
	public static void main(String[] args) {
19
		System.out.println (System.getProperty( "java.vm.version", ""));
20
	}
21
}
(-)j9/org/eclipse/jdt/internal/launching/j9/JavaVMRunner.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.internal.launching.j9;
12
13
import java.io.File;
14
import java.text.MessageFormat;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jdt.launching.AbstractVMRunner;
19
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20
import org.eclipse.jdt.launching.IVMInstall;
21
import org.eclipse.jdt.launching.VMRunnerConfiguration;
22
23
public abstract class JavaVMRunner extends AbstractVMRunner {
24
25
	protected IVMInstall fVMInstance;
26
27
	public JavaVMRunner(IVMInstall vmInstance) {
28
		fVMInstance= vmInstance;
29
	}
30
	
31
	protected void addArguments(String[] args, List v) {
32
		if (args == null)
33
			return;
34
		for (int i= 0; i < args.length; i++)
35
			v.add(args[i]);
36
	}
37
	
38
	protected String getJDKLocation() {
39
		File location= fVMInstance.getInstallLocation();
40
		return location.getAbsolutePath();
41
	}
42
	
43
	/**
44
	 * Returns the working directory to use for the launched VM,
45
	 * or <code>null</code> if the working directory is to be inherited
46
	 * from the current process.
47
	 * 
48
	 * @return the working directory to use
49
	 * @exception CoreException if the working directory specified by
50
	 *  the configuration does not exist or is not a directory
51
	 */	
52
	protected File getWorkingDir(VMRunnerConfiguration config) throws CoreException {
53
		String path = config.getWorkingDirectory();
54
		if (path == null) {
55
			return null;
56
		}
57
		File dir = new File(path);
58
		if (!dir.isDirectory()) {
59
			abort(MessageFormat.format(J9LauncherMessages.getString("JavaVMRunner.Specified_working_directory_does_not_exist_or_is_not_a_directory"), new String[] {path}), null, IJavaLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST); //$NON-NLS-1$
60
		}
61
		return dir;
62
	}	
63
	
64
	/**
65
	 * @see VMRunner#getPluginIdentifier()
66
	 */
67
	protected String getPluginIdentifier() {
68
		return J9LaunchingPlugin.getUniqueIdentifier();
69
	}
70
}
(-)j9/org/eclipse/jdt/launching/j9/IJ9LaunchConfigurationConstants.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.launching.j9;
12
13
import org.eclipse.jdt.internal.launching.j9.J9LaunchingPlugin;
14
15
public interface IJ9LaunchConfigurationConstants {
16
17
	/**
18
	 * Identifier for the J9 Socket Attaching VM connector
19
	 * (value <code>com.ibm.ive.internal.j9.launcher.J9VMType</code>).
20
	 */
21
	public static final String ID_J9_VM_INSTALL_TYPE = "com.ibm.ive.internal.j9.launcher.J9VMType"; //$NON-NLS-1$
22
23
	/**
24
	 * Identifier for the J9 Socket Attaching VM connector
25
	 * (value <code>com.ibm.ive.internal.j9.launcher.J9SocketAttachConnector</code>).
26
	 */
27
	public static final String ID_J9_SOCKET_ATTACH_VM_CONNECTOR = "com.ibm.ive.internal.j9.launcher.J9ConnectorDelegate"; //$NON-NLS-1$
28
29
	/**
30
	 * Preference for the default J9 VM.
31
	 */
32
	public static final String PREF_DEFAULT_J9 = "com.ibm.ive.internal.j9.launcher.default_j9_vm"; //$NON-NLS-1$
33
34
	/**
35
	 * J9 VM specific launch configuration attribute key. The value is a boolean specifying
36
	 * to run the J9 VM as console application or as background application.
37
	 */
38
	public static final String ATTR_RUN_AS_CONSOLE = J9LaunchingPlugin.getUniqueIdentifier() + ".RUN_AS_CONSOLE"; //$NON-NLS-1$	
39
40
	/**
41
	 * J9 VM specific launch configuration attribute key. The value is a boolean specifying
42
	 * to search for an executable archive on the classpath, and if found, run it using
43
	 * the -jxe option.
44
	 */
45
	public static final String ATTR_EXECUTE_FROM_ARCHIVE = J9LaunchingPlugin.getUniqueIdentifier() + ".EXECUTE_FROM_ARCHIVE"; //$NON-NLS-1$	
46
47
	/**
48
	 * J9 VM specific launch configuration attribute key. The value is an integer specifying
49
	 * the debug request timeout in milliseconds.
50
	 */
51
	public static final String ATTR_DEBUG_TIMEOUT = J9LaunchingPlugin.getUniqueIdentifier() + ".DEBUG_TIMEOUT"; //$NON-NLS-1$	
52
53
	/**
54
	 * Launch configuration attribute key. The value is an identifier of a
55
	 * j9 debug symbol path provider extension used to compute the symbol file lookup path
56
	 * for a launch configuration. When unspecified, a default symbol lookup
57
	 * path provider is used.
58
	 */
59
	public static final String ATTR_SYMBOL_PATH_PROVIDER = J9LaunchingPlugin.getUniqueIdentifier() + ".SYMBOL_PATH_PROVIDER";	 //$NON-NLS-1$
60
			
61
	/**
62
	 * Launch configuration attribute key. The value is an ordered list of
63
	 * strings which are mementos for associated runtime classpath entries
64
	 * interpreted as locations in which to look for symbol files.
65
	 */
66
	public static final String ATTR_SYMBOL_PATH = J9LaunchingPlugin.getUniqueIdentifier() + ".SYMBOL_PATH";	 //$NON-NLS-1$
67
		
68
	/**
69
	 * Launch configuration attribute key. The value is a boolean specifying
70
	 * whether a default symbol lookup path should be used. A default symbol
71
	 * lookup path is the same as a launch configuration's classpath. When
72
	 * <code>false</code> a symbol path must be specified via the
73
	 * <code>ATTR_SYMBOL_PATH</code> attribute.
74
	 */
75
	public static final String ATTR_DEFAULT_SYMBOL_PATH = J9LaunchingPlugin.getUniqueIdentifier() + ".DEFAULT_SYMBOL_PATH"; //$NON-NLS-1$
76
77
	/**
78
	 * Default debug ip port number VM will be listening on.
79
	 */
80
	public static final String DEFAULT_DEBUG_PORT = "8096"; //$NON-NLS-1$
81
82
}
83
(-)j9/org/eclipse/jdt/launching/j9/J9Launching.java (+560 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.launching.j9;
12
13
import java.io.File;
14
import java.io.FileFilter;
15
import java.io.FileInputStream;
16
import java.io.IOException;
17
import java.text.DateFormat;
18
import java.text.MessageFormat;
19
import java.util.ArrayList;
20
import java.util.Arrays;
21
import java.util.Date;
22
import java.util.HashMap;
23
import java.util.Iterator;
24
import java.util.List;
25
import java.util.Map;
26
import java.util.jar.Attributes;
27
import java.util.jar.JarFile;
28
import java.util.jar.Manifest;
29
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IConfigurationElement;
32
import org.eclipse.core.runtime.IExtensionPoint;
33
import org.eclipse.core.runtime.IPath;
34
import org.eclipse.core.runtime.Path;
35
import org.eclipse.core.runtime.Platform;
36
import org.eclipse.debug.core.ILaunchConfiguration;
37
import org.eclipse.jdi.Bootstrap;
38
import org.eclipse.jdt.core.IJavaProject;
39
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
40
import org.eclipse.jdt.internal.launching.RuntimeClasspathProvider;
41
import org.eclipse.jdt.internal.launching.j9.J9ConnectorDelegate;
42
import org.eclipse.jdt.internal.launching.j9.J9LauncherMessages;
43
import org.eclipse.jdt.internal.launching.j9.J9LaunchingPlugin;
44
import org.eclipse.jdt.internal.launching.j9.J9SocketAttachConnector;
45
import org.eclipse.jdt.internal.launching.j9.J9VMContentProvider;
46
import org.eclipse.jdt.internal.launching.j9.J9VMInstall;
47
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
48
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
49
import org.eclipse.jdt.launching.IRuntimeClasspathProvider;
50
import org.eclipse.jdt.launching.IVMConnector;
51
import org.eclipse.jdt.launching.IVMInstall;
52
import org.eclipse.jdt.launching.IVMInstallType;
53
import org.eclipse.jdt.launching.JavaRuntime;
54
import org.eclipse.jdt.launching.VMRunnerConfiguration;
55
import org.eclipse.jface.preference.IPreferenceStore;
56
57
import com.sun.jdi.connect.AttachingConnector;
58
import com.sun.jdi.connect.ListeningConnector;
59
60
/**
61
 * The central access point for J9 launching support, 
62
 * similar to <code>JavaRuntime</code>
63
 * <p>
64
 * This class provides static methods only; it is not intended to be
65
 * instantiated or subclassed by clients.
66
 * </p>
67
 * @see org.eclipse.jdt.launching.JavaRuntime
68
 */
69
public class J9Launching {
70
71
	/**
72
	 * Default j9 debug symbol path providers.
73
	 */
74
	private static IRuntimeClasspathProvider fgDefaultSymbolPathProvider = new StandardSymbolPathProvider();
75
76
	/**
77
	 * Path providers keyed by id
78
	 */
79
	private static Map fgPathProviders = null;
80
	
81
	/**
82
	 * Check if a VM install is a J9 VM install.
83
	 * 
84
	 * @param vmInstall The vm install to check.
85
	 * @return True if the id of the IVMInstallType of vmInstall equals ID_J9_VM_INSTALL_TYPE
86
	 */
87
	public static boolean isJ9VMInstall(IVMInstall vmInstall) {
88
		return vmInstall.getVMInstallType().getId().equals(IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
89
	}
90
91
	/**
92
	 * Get all J9 VMs.
93
	 * 
94
	 * @return all configured J9 VM instance
95
	 */
96
	public static IVMInstall[] getJ9VMInstalls() {
97
		IVMInstallType vmInstallType =
98
			JavaRuntime.getVMInstallType(
99
				IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
100
		return vmInstallType.getVMInstalls();
101
	}
102
103
	/**
104
	 * Finds the J9 VM with the given name.
105
	 * 
106
	 * @param name the VM name
107
	 * @return a VM instance, or <code>null</code> if not found
108
	 */
109
	public static J9VMInstall findJ9VMInstallByName(String name) {
110
		IVMInstallType vmInstallType =
111
			JavaRuntime.getVMInstallType(
112
				IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
113
		return (J9VMInstall)vmInstallType.findVMInstallByName(name);
114
	}
115
116
	/**
117
	 * Finds the J9 VM with the given id.
118
	 * 
119
	 * @param id the VM id
120
	 * @return a VM instance, or <code>null</code> if not found
121
	 */
122
	public static J9VMInstall findJ9VMInstall(String id) {
123
		IVMInstallType vmInstallType =
124
			JavaRuntime.getVMInstallType(
125
				IJ9LaunchConfigurationConstants.ID_J9_VM_INSTALL_TYPE);
126
		return (J9VMInstall)vmInstallType.findVMInstall(id);
127
	}
128
129
	/**
130
	 * Returns the path to the default J9 install, or null if there is no default J9 install.
131
	 * 
132
	 * @return IPath
133
	 */
134
	public static IPath getDefaultIveDir() {
135
		IVMInstall vm = getDefaultJ9VMInstall();
136
		
137
		if (vm == null) {
138
			return null;
139
		}
140
		
141
		return new Path(vm.getInstallLocation().getAbsolutePath());
142
	}
143
144
	/**
145
	 * Get the default J9 VM.
146
	 *
147
	 * @return the workspace default J9VM instance, 
148
	 * Returns <code>null</code> if no J9 VMs have been configured.
149
	 */
150
	public static J9VMInstall getDefaultJ9VMInstall() {
151
		IPreferenceStore store = J9LaunchingPlugin.getDefault().getPreferenceStore();
152
		String id = store.getString(IJ9LaunchConfigurationConstants.PREF_DEFAULT_J9);
153
		if (id == null || "".equals(id)) { //$NON-NLS-1$
154
			return null;
155
		} else {
156
			return findJ9VMInstall(id);
157
		}
158
	}
159
160
	/**
161
	 * Returns the VM assigned to build the given Java project
162
	 * if it is a J9 VM.
163
	 * If not, the workspace default J9 VM is returned.
164
	 * @param project If <code>null</code>, the default J9 VM is returned
165
	 * @return J9 IVMInstall of project, or the default J9 VM.
166
	 * Returns <code>null</code> if no J9 VMs have been configured.
167
	 */
168
	public static J9VMInstall getJ9VMInstall(IJavaProject project) {
169
		try {
170
			if (project != null) {
171
				IVMInstall projectDefaultVM = null;
172
				projectDefaultVM = J9VMContentProvider.getVMInstallFromResource(project);
173
				if (projectDefaultVM == null)
174
					projectDefaultVM = JavaRuntime.getVMInstall(project);
175
				if (projectDefaultVM != null && isJ9VMInstall(projectDefaultVM)) {
176
					return (J9VMInstall)projectDefaultVM;
177
				}
178
			}
179
		} catch (CoreException e) {
180
			J9LaunchingPlugin.getDefault().getLog().log(e.getStatus());
181
		}
182
		return getDefaultJ9VMInstall();
183
	}
184
	
185
	/**
186
	 * Return a JDI socket transport attaching connector
187
	 * 
188
	 * @exception CoreException if unable to locate the connector
189
	 */
190
	public static AttachingConnector getAttachingConnector() throws CoreException {
191
		AttachingConnector connector= null;
192
		Iterator iter= Bootstrap.virtualMachineManager().attachingConnectors().iterator();
193
		while (iter.hasNext()) {
194
			AttachingConnector lc= (AttachingConnector) iter.next();
195
			if (lc.name().equals("com.sun.jdi.SocketAttach")) { //$NON-NLS-1$
196
				connector= lc;
197
				break;
198
			}
199
		}
200
		if (connector == null) {
201
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Socket_attaching_connector_not_available"), null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE); //$NON-NLS-1$
202
		}
203
		return connector;
204
	}
205
	
206
	/**
207
	 * 
208
	 * @exception CoreException if unable to locate the connector
209
	 */
210
	public static ListeningConnector getListeningConnector() throws CoreException {
211
		ListeningConnector connector= null;
212
		Iterator iter= Bootstrap.virtualMachineManager().listeningConnectors().iterator();
213
		while (iter.hasNext()) {
214
			ListeningConnector lc= (ListeningConnector) iter.next();
215
			if (lc.name().equals("com.sun.jdi.SocketListen")) { //$NON-NLS-1$
216
				connector= lc;
217
				break;
218
			}
219
		}
220
		if (connector == null) {
221
			J9LaunchingPlugin.abort(J9LauncherMessages.getString("J9Launching.Socket_attaching_connector_not_available"), null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE); //$NON-NLS-1$
222
		}
223
		return connector;
224
	}
225
	
226
227
	/**
228
	 * Utility function to return string "{element} at localhost:{port}" for rendering debug target.
229
	 */
230
	public static String renderDebugTarget(String elementToRun, int host) {
231
		String format= J9LauncherMessages.getString("J9Launching.format.dbgTarget"); //$NON-NLS-1$
232
		return MessageFormat.format(format, new String[] { elementToRun, String.valueOf(host) });
233
	}
234
235
	/**
236
	 * Utility function to return string "{commandLine[0]} ({timestamp})" for rendering a debug process.
237
	 */
238
	public static String renderProcessLabel(String[] commandLine) {
239
		String format= J9LauncherMessages.getString("J9Launching.format.processLabel"); //$NON-NLS-1$
240
		String timestamp= DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
241
		return MessageFormat.format(format, new String[] { commandLine[0], timestamp });
242
	}
243
	
244
	/**
245
	 * Return string "commandLine[1..max]" for rendering debug process.
246
	 */
247
	public static String renderCommandLine(String[] commandLine) {
248
		if (commandLine.length < 1)
249
			return ""; //$NON-NLS-1$
250
		StringBuffer buf= new StringBuffer(commandLine[0]);
251
		for (int i= 1; i < commandLine.length; i++) {
252
			buf.append(' ');
253
			buf.append(commandLine[i]);
254
		}	
255
		return buf.toString();
256
	}	
257
	
258
	/**
259
	 * Returns the j9 debug symbol lookup path provider for the given launch configuration.
260
	 * 
261
	 * @param configuration launch configuration
262
	 * @return symbol lookup path provider
263
	 * @exception CoreException if unable to resolve the path provider
264
	 * @since 2.0
265
	 */
266
	public static IRuntimeClasspathProvider getSymbolLookupPathProvider(ILaunchConfiguration configuration) throws CoreException {
267
		String providerId = configuration.getAttribute(IJ9LaunchConfigurationConstants.ATTR_SYMBOL_PATH_PROVIDER, (String)null);
268
		IRuntimeClasspathProvider provider = null;
269
		if (providerId == null) {
270
			provider = fgDefaultSymbolPathProvider;
271
		} else {
272
			provider = (IRuntimeClasspathProvider)getClasspathProviders().get(providerId);
273
		}
274
		return provider;
275
	}	
276
277
	/**
278
	 * Computes and returns the unresolved j9 debug symbol lookup path for the given launch
279
	 * configuration.
280
	 * 
281
	 * @param configuration launch configuration
282
	 * @return runtime classpath entries
283
	 * @exception CoreException if unable to compute the symbol lookup path
284
	 * @since 2.0
285
	 */
286
	public static IRuntimeClasspathEntry[] computeUnresolvedSymbolLookupPath(ILaunchConfiguration configuration) throws CoreException {
287
		return getSymbolLookupPathProvider(configuration).computeUnresolvedClasspath(configuration);
288
	}
289
	
290
	/**
291
	 * Resolves the given j9 debug symbol lookup path, returning the resolved symbol lookup path
292
	 * in the context of the given launch configuration.
293
	 * 
294
	 * @param entries unresolved entries
295
	 * @param configuration launch configuration
296
	 * @return resolved entries
297
	 * @exception CoreException if unable to resolve the symbol lookup path
298
	 * @since 2.0
299
	 */
300
	public static IRuntimeClasspathEntry[] resolveSymbolLookupPath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) throws CoreException {
301
		return getSymbolLookupPathProvider(configuration).resolveClasspath(entries, configuration);
302
	}	
303
	
304
	/**
305
	 * Return the resolved and absolute j9 debug symbol path calculated from the 
306
	 * resolved symbol classpath of a launch configuration.
307
	 * 
308
	 * @param configuration launch configuration
309
	 * @return the set of absolute directory names containing 1 or more symbol files
310
	 * @see J9ProxyAttachConnector#J9ProxyAttachConnector(String, String, String[], String, IVMInstall)
311
	 */
312
	public static String[] getResolvedSymbolLookupPath(ILaunchConfiguration configuration) throws CoreException {
313
		IRuntimeClasspathEntry[] entries = J9Launching.computeUnresolvedSymbolLookupPath(configuration);
314
		entries = J9Launching.resolveSymbolLookupPath(entries, configuration);
315
		List symbolPath = new ArrayList(entries.length);
316
		for (int i = 0; i < entries.length; i++) {
317
			String entry = entries[i].getLocation();
318
            // entry will be null in the case where you originally had a project in your symbol path that has since been deleted.
319
            if (entry != null) {
320
                addSymbolFileEntry(symbolPath, entry);
321
            }
322
		}
323
		return (String[])symbolPath.toArray(new String[symbolPath.size()]);
324
	}
325
	
326
	/**
327
	 * @return Returns J9 IVMInstall for connector, 
328
	 * or null if connector has no J9 IVMInstall
329
	 */	
330
	public static J9VMInstall getJ9VMInstall(IVMConnector connector, Map arguments, IJavaProject project) throws CoreException {
331
		if (connector instanceof J9ConnectorDelegate) {
332
			String vmName = (String)arguments.get(J9SocketAttachConnector.ARG_VM_INSTALL_NAME);
333
			
334
			// If default VM is selected, take default VM for project
335
			if (vmName == null || vmName.equals(J9SocketAttachConnector.DEFAULT_JRE_NAME)) {
336
				return getJ9VMInstall(project);
337
			} else {
338
				return findJ9VMInstallByName(vmName);
339
			}
340
		}
341
		return getJ9VMInstall(project);
342
	}
343
344
	/**
345
	 * If the entry denotes a symbol file, add it. If the entry
346
	 * does not denote a symbol file, but the directory of the entry
347
	 * contains symbol files, add that directory.
348
	 */
349
	private static void addSymbolFileEntry(List symbolPath, String entry) {
350
		if (!entry.toLowerCase().endsWith(".sym")) { //$NON-NLS-1$
351
			File dir = new File(entry);
352
			if (!dir.isDirectory()) {
353
				dir = dir.getParentFile();
354
			}
355
			File files[] = dir.listFiles(new FileFilter() {
356
				public boolean accept(File target) {
357
					return target.getName().toLowerCase().endsWith(".sym"); //$NON-NLS-1$
358
				}
359
			});
360
			if (files == null || files.length == 0) {
361
				return;
362
			}
363
			entry = dir.getAbsolutePath();
364
		}
365
		if (!symbolPath.contains(entry)) {
366
			symbolPath.add(entry);
367
		}
368
	}
369
370
	/**
371
	 * Returns all registered classpath providers.
372
	 */
373
	private static Map getClasspathProviders() {
374
		if (fgPathProviders == null) {
375
			initializeProviders();
376
		}
377
		return fgPathProviders;
378
	}
379
		
380
	private static void initializeProviders() {
381
		/*
382
		 * LL: Migration to 3.0: IPluginDescriptor.getExtensionPoint() has been deprecated.
383
		 * Use Platform.getExtensionRegistry().getExtensionPoint() instead.
384
		 */
385
		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.getUniqueIdentifier(), JavaRuntime.EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS); 
386
		IConfigurationElement[] extensions = point.getConfigurationElements();
387
		fgPathProviders = new HashMap(extensions.length);
388
		for (int i = 0; i < extensions.length; i++) {
389
			RuntimeClasspathProvider res = new RuntimeClasspathProvider(extensions[i]);
390
			fgPathProviders.put(res.getIdentifier(), res);
391
		}		
392
	}
393
	
394
	/**
395
	 * @return Returns whether to run the J9 VM as console application.
396
	 * Returns true by default, if no vm specific attributes are provided.
397
	 */
398
	public static boolean runAsConsole(Map vmSpecificAttributesMap) { // KMH
399
		if (vmSpecificAttributesMap == null)
400
			return true;  // the default for run on console is true.
401
		return Boolean.valueOf((String)vmSpecificAttributesMap.get(IJ9LaunchConfigurationConstants.ATTR_RUN_AS_CONSOLE)).booleanValue();
402
	}
403
	
404
	/**
405
	 * @return Returns whether the -jxe option should be used to run an application, if possible.
406
	 * Returns true by default, if no vm specific attributes are provided.
407
	 */
408
	public static boolean executeFromArchive(Map vmSpecificAttributesMap) {
409
		return vmSpecificAttributesMap == null || Boolean.valueOf((String)vmSpecificAttributesMap.get(IJ9LaunchConfigurationConstants.ATTR_EXECUTE_FROM_ARCHIVE)).booleanValue();
410
	}
411
	
412
	private static File getExecutableArchiveFile(String workingDir, String archiveFileName, String startupClass) {
413
		File archiveFile = new File(archiveFileName);
414
		if (workingDir != null && !archiveFile.isAbsolute()) {
415
			archiveFile = new File(workingDir, archiveFileName);
416
		}
417
418
		if (!startupClass.equals(getStartupClass(archiveFile))) {
419
			return null;
420
		}
421
422
		// Make file relative
423
		// Commented out because it makes path translation for devices harder
424
//		if (workingDir != null) {
425
//			int index = archiveFileName.indexOf(workingDir);
426
//			if (index != -1) {
427
//				archiveFile = new File(archiveFileName.substring(workingDir.length() + 1, archiveFileName.length()));
428
//			}
429
//		}
430
		return archiveFile;
431
	}
432
	
433
	public static boolean isJxeArchive(File archiveFile) {
434
		return archiveFile.getName().endsWith(".jxe"); //$NON-NLS-1$
435
	}
436
	
437
	public static boolean isJarArchive(File archiveFile) {
438
		return archiveFile.getName().endsWith(".jar"); //$NON-NLS-1$
439
	}
440
	
441
	/**
442
	 * @return Returns startup class (using dots in the qualified name, not slashes), or null
443
	 */
444
	public static String getStartupClass(File archiveFile) {
445
		try {
446
			String startupClass = null;
447
			if (isJxeArchive(archiveFile)) {
448
				JxeInfo jxeInfo = new JxeInfo(new FileInputStream(archiveFile));
449
				startupClass = jxeInfo.getStartupClass();
450
			} else if (isJarArchive(archiveFile)) {
451
				JarFile jar = new JarFile(archiveFile);
452
				Manifest m = jar.getManifest();
453
				if (m != null) {
454
					startupClass = m.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
455
				}
456
				jar.close(); //Sri! 104644
457
			}
458
			return startupClass == null ? null : startupClass.replace('/','.');
459
		} catch (IOException e) {
460
			// Assume not a jxe/jar file
461
		}
462
		return null;
463
	}
464
	
465
	/**
466
	 * Adapt the VMRunnerConfiguration to ATTR_EXECUTE_FROM_ARCHIVE.
467
	 * If the option is set, the boot- and classpath will be scanned for
468
	 * a JXE or JAR with a startup class.
469
	 * If an executable JXE is found, the -jxe option will be used to launch the application, 
470
	 * and all boot- and classpath entries will be moved to the boot path.
471
	 * If an executable JAR is found on the classpath and the vm supports it, 
472
	 * the -jar option will be used to launch the application.
473
	 * An executable jar on the boot path is ignored because -jar puts classes on the classpath.
474
	 */
475
	public static VMRunnerConfiguration adaptVMRunnerConfiguration(VMRunnerConfiguration config, J9VMInstall vm) throws CoreException {
476
		if (executeFromArchive(config.getVMSpecificAttributesMap())) {
477
			List bootPath = new ArrayList();
478
			if (config.getBootClassPath() != null) {
479
				bootPath.addAll(Arrays.asList(config.getBootClassPath()));
480
			}
481
			List classPath = new ArrayList(Arrays.asList(config.getClassPath()));
482
			List combinedPath = new ArrayList(bootPath);
483
			combinedPath.addAll(classPath);
484
			for (Iterator iter = combinedPath.iterator(); iter.hasNext();) {
485
				String archiveFileName = (String)iter.next();
486
				File archiveFile = getExecutableArchiveFile(config.getWorkingDirectory(), archiveFileName, config.getClassToLaunch());
487
				if (archiveFile != null) {
488
					boolean isJxeArchive = isJxeArchive(archiveFile);
489
					if (isJxeArchive || (!vm.isPre20J9Version() && !bootPath.contains(archiveFileName))) {
490
						String vmArgs[] = config.getVMArguments();
491
						List vmArgList = new ArrayList(vmArgs.length + 2);
492
						vmArgList.addAll(Arrays.asList(vmArgs));
493
						String newBootPath[];
494
						String newClassPath[];
495
						String classToLaunch = config.getClassToLaunch();
496
						// TODO remove this special case which takes the bin folder
497
						// off the class path only when a .jxe is being built
498
						List removeList = new ArrayList();
499
						for (Iterator iterator = classPath.iterator(); iterator.hasNext();) {
500
							String element = (String) iterator.next();
501
							if (element.endsWith("bin")) {  //$NON-NLS-1$
502
								removeList.add(element);
503
							}
504
						}
505
						classPath.removeAll(removeList);
506
						newClassPath = (String[])classPath.toArray(new String[classPath.size()]);
507
						combinedPath.removeAll(removeList);
508
						
509
						if (isJxeArchive) {
510
							if (vm.is21J9Version()) {
511
								if (config.getBootClassPath().length == 0) {
512
									config.setBootClassPath(null);
513
									newBootPath = new String[0];
514
								} else 
515
									newBootPath = config.getBootClassPath();
516
							} else {
517
								// there is no class to launch for this case
518
								classToLaunch = ""; //$NON-NLS-1$								
519
                                combinedPath.remove(archiveFileName);
520
								vmArgList.add("-jxe:"+archiveFile.getPath()); //$NON-NLS-1$
521
								newBootPath = new String[combinedPath.size()];
522
								combinedPath.toArray(newBootPath);
523
								newClassPath = new String[0];
524
							}
525
						} 
526
						else {
527
							if (config.getBootClassPath().length == 0) {
528
								config.setBootClassPath(null);
529
								newBootPath = new String[0];
530
							} else 
531
								newBootPath = config.getBootClassPath();
532
//							vmArgList.add("-jar"); //$NON-NLS-1$
533
//							vmArgList.add(archiveFile.getPath());
534
//							newBootPath = new String[bootPath.size()];
535
//							bootPath.toArray(newBootPath);
536
//							classPath.remove(archiveFileName);
537
//							newClassPath = new String[classPath.size()];
538
//							classPath.toArray(newClassPath);
539
						}
540
						VMRunnerConfiguration adaptedConfig = new VMRunnerConfiguration(classToLaunch, newClassPath); //$NON-NLS-1$
541
						if (newBootPath.length == 0 && config.getBootClassPath() == null) {
542
							adaptedConfig.setBootClassPath(null);
543
						} else {
544
							adaptedConfig.setBootClassPath(newBootPath);
545
						}
546
						vmArgs = new String[vmArgList.size()];
547
						vmArgList.toArray(vmArgs);
548
						adaptedConfig.setProgramArguments(config.getProgramArguments());
549
						adaptedConfig.setVMArguments(vmArgs);
550
						adaptedConfig.setWorkingDirectory(config.getWorkingDirectory());
551
						adaptedConfig.setVMSpecificAttributesMap(config.getVMSpecificAttributesMap());
552
						
553
						return adaptedConfig;
554
					}
555
				}
556
			}
557
		}
558
		return config;
559
	}
560
}
(-)j9/org/eclipse/jdt/launching/j9/J9VMOptionsParser.java (+154 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.launching.j9;
12
13
import java.io.BufferedReader;
14
import java.io.File;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
import java.util.ArrayList;
19
import java.util.Enumeration;
20
import java.util.List;
21
import java.util.zip.ZipEntry;
22
import java.util.zip.ZipFile;
23
24
public class J9VMOptionsParser {
25
26
	private BufferedReader reader;
27
	private ArrayList vmOptions = new ArrayList();
28
	private String tokens[] = new String[0];
29
	private int tokenIndex;
30
31
	public J9VMOptionsParser(InputStream in) throws IOException {
32
		reader = new BufferedReader(new InputStreamReader(in));
33
		String token;
34
		while ((token = getNextToken()) != null) {
35
			if (token.equalsIgnoreCase("-vmOption")) { //$NON-NLS-1$
36
				vmOptions.add(getNextToken());
37
			}
38
		}
39
		reader.close();
40
	}
41
42
	public List getVMOptions() {
43
		return vmOptions;
44
	}
45
46
	private String getNextToken() throws IOException {
47
		while (tokenIndex == tokens.length) {
48
			String line = reader.readLine();
49
			if (line == null) {
50
				return null;
51
			}
52
			tokens = tokenizeLine(line);
53
			tokenIndex = 0;
54
		}
55
		return tokens[tokenIndex++];
56
	}
57
58
	private static String[] tokenizeLine(String line) {
59
		ArrayList tokens = new ArrayList();
60
		char chars[] = line.toCharArray();
61
		int curIndex = 0;
62
63
		while (curIndex < chars.length) {
64
			String token = null;
65
			int endIndex;
66
			int newCurIndex;
67
			char curChar = 0;
68
69
			// skip whitespace
70
			while ((curIndex < chars.length)
71
				&& (Character.isWhitespace(curChar = chars[curIndex]))) {
72
				curIndex++;
73
			}
74
75
			// handle comment and end of line
76
			if (curIndex == chars.length) {
77
				break;
78
			}
79
			// Handle comments as tokens as well
80
			if ('#' == curChar) {
81
				endIndex = chars.length;
82
				newCurIndex = chars.length;
83
			} else 
84
			// handle quoted strings
85
			if ('"' == curChar) {
86
				endIndex = line.indexOf('"', curIndex + 1);
87
				if (-1 == endIndex) {
88
					endIndex = chars.length;
89
				}
90
				curIndex++;
91
				newCurIndex = endIndex + 1;
92
			}
93
94
			// handle non-quoted strings
95
			else {
96
				for (endIndex = curIndex + 1;
97
					endIndex < chars.length;
98
					endIndex++) {
99
					curChar = chars[endIndex];
100
					if (Character.isWhitespace(curChar) || '#' == curChar)
101
						break;
102
				}
103
				newCurIndex = (curChar == '#' ? endIndex : endIndex + 1);
104
			}
105
			token = line.substring(curIndex, endIndex);
106
			curIndex = newCurIndex;
107
			tokens.add(token);
108
109
		}
110
111
		String[] result = new String[tokens.size()];
112
		tokens.toArray(result);
113
		return result;
114
	}
115
116
	public static List extractVMOptions(String file) {
117
		List result = new ArrayList();
118
		try {
119
			ZipFile zipFile = new ZipFile(file);
120
			for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
121
				ZipEntry entry = (ZipEntry)entries.nextElement();
122
				String entryName = entry.getName();
123
				if (entryName.equals("META-INF/JXE.MF")) { //$NON-NLS-1$
124
					readJxeMetaInfo(zipFile.getInputStream(entry), result);
125
				} else if (new File(entryName).getName().equals("jxeLink.rules")) { //$NON-NLS-1$
126
					// Parse without expanding macros
127
					J9VMOptionsParser parser = new J9VMOptionsParser(zipFile.getInputStream(entry));
128
					result.addAll(parser.getVMOptions());
129
				}
130
			}
131
			zipFile.close();
132
		} catch (IOException e) {
133
			// Not a (zip) file or no jxeLink.rules entry.
134
		}
135
		return result;
136
	}
137
138
	private static void readJxeMetaInfo(InputStream input, List result) throws IOException {
139
		BufferedReader reader = new BufferedReader(new InputStreamReader(input));
140
		String line,key,value; 
141
		while ((line = reader.readLine()) != null) {
142
			int p = line.indexOf(0);
143
			int q = line.indexOf(0, p+1);
144
			if (q > p) {
145
				key = line.substring(0, p);
146
				if (key.equals("vmOption")) { //$NON-NLS-1$
147
					value = line.substring(p+1, q);
148
					result.add(value);
149
				}
150
			}
151
		}
152
	}
153
154
}
(-)j9/org/eclipse/jdt/launching/j9/JxeInfo.java (+71 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.launching.j9;
12
13
import java.io.BufferedReader;
14
import java.io.FileInputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
import java.util.Properties;
19
import java.util.zip.ZipEntry;
20
import java.util.zip.ZipInputStream;
21
22
/**
23
 * A <code>JxeInfo</code> decodes the meta-information from a J9 Executable JXE application file.
24
 */
25
public class JxeInfo {
26
27
	private Properties jxeMetaInfo = new Properties();
28
29
	public JxeInfo(String file) throws IOException {
30
		this(new FileInputStream(file));
31
	}
32
33
	public JxeInfo(InputStream input) throws IOException {
34
			ZipInputStream zipInput = new ZipInputStream(input);
35
			ZipEntry ze;
36
			do {
37
				ze = zipInput.getNextEntry();
38
				if (ze != null && ze.getName().equals("META-INF/JXE.MF")) { //$NON-NLS-1$
39
					readJxeMetaInfo(zipInput);
40
				}
41
			} while (ze != null);
42
	}
43
	
44
	public Properties getJxeMetaInfo() {
45
		return jxeMetaInfo;
46
	}
47
48
	public String getStartupClass() {
49
		return jxeMetaInfo.getProperty("startupClass"); //$NON-NLS-1$
50
	}
51
52
	private void readJxeMetaInfo(InputStream input) throws IOException {
53
		BufferedReader reader = new BufferedReader(new InputStreamReader(input));
54
		String line,key,value,oldValue; 
55
		while ((line = reader.readLine()) != null) {
56
			int p = line.indexOf(0);
57
			int q = line.indexOf(0, p+1);
58
			if (q > p) {
59
				key = line.substring(0, p);
60
				value = line.substring(p+1, q);
61
				// when several entries with the same key 
62
				if (jxeMetaInfo.containsKey(key)) {
63
					oldValue = (String)jxeMetaInfo.get(key);
64
					value = value+","+oldValue;  //$NON-NLS-1$
65
				}
66
				jxeMetaInfo.setProperty(key,value);
67
			}
68
		}
69
	}
70
71
}
(-)j9/org/eclipse/jdt/launching/j9/StandardSymbolPathProvider.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation.
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
package org.eclipse.jdt.launching.j9;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.debug.core.ILaunchConfiguration;
15
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
16
import org.eclipse.jdt.launching.StandardSourcePathProvider;
17
18
/**
19
 * Default implementation of j9 debug symbol lookup path computation and resolution.
20
 * <p>
21
 * This class may be subclassed.
22
 * </p>
23
 */
24
public class StandardSymbolPathProvider extends StandardSourcePathProvider {
25
	
26
	/**
27
	 * @see IRuntimeClasspathProvider#computeUnresolvedClasspath(ILaunchConfiguration)
28
	 */
29
	public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException {
30
		boolean useDefault = configuration.getAttribute(IJ9LaunchConfigurationConstants.ATTR_DEFAULT_SYMBOL_PATH, true);
31
		IRuntimeClasspathEntry[] entries = null;
32
		if (useDefault) {
33
			// the default symbol lookup path is the same as the classpath
34
			entries = super.computeUnresolvedClasspath(configuration);
35
		} else {
36
			// recover persisted symbol path
37
			entries = recoverRuntimePath(configuration, IJ9LaunchConfigurationConstants.ATTR_SYMBOL_PATH);
38
		}
39
		return entries;
40
	}
41
	
42
}

Return to bug 106683