-
Notifications
You must be signed in to change notification settings - Fork 55
/
jdee-run.el
1666 lines (1457 loc) · 62.7 KB
/
jdee-run.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; jdee-run.el --- runs the Java app in the current buffer.
;; Author: Paul Kinnucan <paulk@mathworks.com>
;; Maintainer: Paul Landes <landes <at> mailc dt net>
;; Keywords: tools, processes
;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008 Paul Kinnucan
;; Copyright (C) 2009 by Paul Landes
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;; Code:
(require 'cl-lib)
(require 'eieio)
(require 'jdee-classpath)
(require 'jdee-files)
(require 'jdee-jdk-manager)
(require 'jdee-open-source);; jdee-find-class-source-file
(require 'jdee-parse)
(defcustom jdee-run-mode-hook nil
"*List of hook functions run by `jdee-run-mode' (see `run-hooks')."
:group 'jdee-project
:type 'hook)
(defcustom jdee-run-application-class ""
"*Name of the Java class to run.
This is the class that is run if you select JDE->Run App from the JDE
menu or type C-c C-v C-r. If this option is the empty string, the JDE
runs the class corresponding to the source file in the current
buffer. Note that the specified class must have a static public main
method."
:group 'jdee-project
:type 'string)
(defcustom jdee-run-working-directory ""
"*Path of the working directory for this application.
If you specify a path, the JDE launches the application from the
directory specified by the path."
:group 'jdee-project
:type 'file)
(defcustom jdee-vm-path ""
"*Path of the Java virtual machine executable. The path
can include environment variables, e.g.,
$JDK_HOME/bin/java. If the value of this variable is the
empty string, the JDE uses the vm that comes with the
version of the JDK specified by jdee-jdk or, if jdee-jdk
is not set, the vm on the system command path."
:group 'jdee-project
:type 'file)
(defcustom jdee-run-classic-mode-vm nil
"Runs applications in the classic (i.e., not HotSpot) mode."
:group 'jdee-project
:type 'boolean)
(defcustom jdee-run-read-vm-args nil
"*Read vm arguments from the minibuffer.
If this variable is non-nil, the jdee-run command reads vm arguments
from the minibuffer and appends them to those specified by
the `jdee-run-option' variable group."
:group 'jdee-project
:type 'boolean)
(defvar jdee-run-interactive-vm-arg-history nil
"History of vm arguments read from the minibuffer")
(defcustom jdee-run-read-app-args nil
"*Read arguments to be passed to application from the minibuffer."
:group 'jdee-project
:type 'boolean)
(defvar jdee-run-interactive-app-arg-history nil
"History of application arguments read from the minibuffer")
(defgroup jdee-run-options nil
"JDE Interpreter Options"
:group 'jdee
:prefix "jdee-run-option-")
;; (makunbound 'jdee-run-option-classpath)
(defcustom jdee-run-option-classpath "global"
"*Specify paths of classes required to run this application.
Choose Global from the customization buffer value menu to use
the paths specified by `jdee-global-classpath'.
Choose Local from the menu to override the
`jdee-global-classpath' option. Choose None to specify
no classpath."
:group 'jdee-run-options
:type '(choice
(const :menu-tag "Global" "global")
(repeat :menu-tag "Local" (file :tag "Path"))
(const :menu-tag "None" "none")))
(defcustom jdee-run-option-verbose (list nil nil nil)
"*Print messages about the running process.
The messages are printed in the run buffer."
:group 'jdee-run-options
:type '(list :indent 2
(checkbox :format "\n %[%v%] %h \n"
:doc "Print classes loaded.
Prints a message in the run buffer each time a class is loaded.")
(checkbox :format "%[%v%] %h \n"
:doc "Print memory freed.
Prints a message in the run buffer each time the garbage collector
frees memory.")
(checkbox :format "%[%v%] %h \n"
:doc "Print JNI info.
Prints JNI-related messages including information about which native
methods have been linked and warnings about excessive creation of
local references.")))
;;(makunbound 'jdee-run-option-properties)
(defcustom jdee-run-option-properties nil
"*Specify property values.
Enter the name of the property, for example, awt.button.color, in the
Property Name field; enter its value, for example, green, in the
Property Value field. You can specify as many properties as you like."
:group 'jdee-run-options
:type '(repeat (cons :tag "Property"
(string :tag "Name")
(string :tag "Value"))))
(defcustom jdee-run-option-heap-size (list
(cons 1 "megabytes")
(cons 16 "megabytes"))
"*Specify the initial and maximum size of the interpreter heap."
:group 'jdee-run-options
:type '(list
(cons (integer :tag "Start")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))
(cons (integer :tag "Max")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))))
(defcustom jdee-run-option-stack-size (list
(cons 128 "kilobytes")
(cons 400 "kilobytes"))
"*Specify size of the C and Java stacks."
:group 'jdee-run-options
:type '(list
(cons (integer :tag "C Stack")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))
(cons (integer :tag "Java Stack")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))))
(defcustom jdee-run-option-garbage-collection (list t t)
"*Specify garbage collection options."
:group 'jdee-run-options
:type '(list :indent 2
(checkbox :format "%[%v%] %t \n"
:tag "Collect garbage asynchronously.")
(checkbox :format "%[%v%] %t \n"
:tag "Collect unused classes.")))
(defcustom jdee-run-option-java-profile (cons nil "./java.prof")
"*Enable Java profiling."
:group 'jdee-run-options
:type '(cons boolean
(file :tag "File"
:help-echo
"Specify where to put profile results here.")))
(defcustom jdee-run-option-heap-profile (cons nil
(list "./java.hprof"
5
20
"Allocation objects"))
"*Output heap profiling data."
:group 'jdee-run-options
:type '(cons boolean
(list
(string :tag "Output File Path")
(integer :tag "Stack Trace Depth")
(integer :tag "Allocation Sites")
(radio-button-choice :format "%t \n%v"
:tag "Sort output based on:"
(const "Allocation objects")
(const "Live objects")))))
;; (makunbound 'jdee-run-option-verify)
(defcustom jdee-run-option-verify (list nil t)
"*Verify classes."
:group 'jdee-run-options
:type '(list :indent 2
(checkbox :format "%[%v%] %t \n"
:tag "Executed code in all classes.")
(checkbox :format "%[%v%] %t \n"
:tag "Classes loaded by a classloader.")))
;; (makunbound 'jdee-run-option-boot-classpath)
(defcustom jdee-run-option-boot-classpath nil
"Specify a list of directories, JAR archives, and ZIP archives to
search for boot class files.
To specify the standard boot classpath, select \"standard\" from the
Value Menu. To specify a custom boot classpath, select \"custom\" from
the Value Menu. Emacs displays a \"Custom Mode\" Value Menu and an
\"INS\" button for creating a list of directories and/or JAR and ZIP
archives. To append the custom list to the standard list, select
\"append\" from the Value Menu. To prepend the custom list to the
standard list, select \"prepend\" from the Value Menu. To replace the
standard list with the custom list, select \"replace\" from the Value
Menu.
Note that if `jdee-jdk' specifies the 1.2.x version of the JDK, the
JDEE replaces the standard list with the custom list regardless of the
setting of the \"Custom Mode\" Value Menu. The JDEE ignores this
option if `jdee-jdk' specifies the 1.1.x version of the JDK.
Note also that the value of this variable is either nil or a cons
whose cdr is a list of strings, each of which specifies a path. The
JDE converts this list to a colon- or semicolon-separated list before
inserting it in the compiler or vm command line. The paths may start
with a tilde (~) and may include environment variables. The JDE
replaces the ~ with your home directory and replaces each instance of
an environment variable with its value before inserting it into a
command line. The paths may also start with a . (period) to indicate
that the path is a relative path. If `jdee-resolve-relative-paths-p' is
nonnil, the JDEE treats the paths as relative to the location of the
project file for the current project and replaces the period (.) with
the path of the directory containing the project file."
:group 'jdee-run-options
:type '(choice
:tag "Classpath Options"
(const :tag "standard" nil)
(cons :tag "custom" :inline nil
(choice
:tag "Custom Mode"
(const "append")
(const "prepend")
(const "replace"))
(repeat
:tag "Classpath"
(file :tag "Path")))))
;; (makunbound 'jdee-run-option-debug)
(defcustom jdee-run-option-debug nil
"*If \"Connect\" is selected, this option allows the application to
start and then connect to a debugger, for example, jdb or JDEbug.
\"Mode\" specifies the method for establishing the connection. The
options are \"Server\" (allow a debugger to attach to the application
after the application starts) or \"Client\" (allows the application to connect
to a listening debugger).
\"Data Transport\" specifies the method that the debuggee process uses to
communicate with the debugger. The \"Shared Memory\" option is valid
only when the the debuggee process and the debugger are both running
on the same Microsoft Windows system. (It is also the best choice for
such debugging sessions.) You must choose \"Socket\" if the debugger
and the debuggee process run on different systems or if they both
run on the same Unix system.
The \"Shared Memory Name\" option specifies the name of the shared
memory connection used to connect the debugger and the application.
This option applies only when you specify a shared memory connection
to the debugger.
The \"Socket Host\" specifes the host on which a remote debugger
resides. This option applies only when you run the process in
client mode, using a socket transport.
The \"Socket Port\" option specifies the socket port used to
connect this process to the debugger. This option applies only
when you select socket as the transport method.
The \"Suspend\" option specifies whether the vm should suspend
this process on startup."
:group 'jdee-run-options
:type '(choice
:tag "Debug Connection Options"
(const :tag "No connect" nil)
(list
:tag "Connect"
:inline nil
(choice
:tag "Mode"
(const "Server")
(const "Client"))
(choice
:tag "Data Transport"
(const "Shared Memory")
(const "Socket"))
(choice
:tag "Shared Memory Name"
(const :menu-tag "Default" "javadebug")
(string :menu-tag "Custom" :tag "Name"))
(choice
:tag "Socket Host"
(const :menu-tag "Local" nil)
(string :menu-tag "Remote" :tag "Name"))
(choice
:tag "Socket Port"
(const :menu-tag "Default" "4444")
(string :menu-tag "Custom" :tag "Address"))
(choice
:tag "Suspend?"
(const :tag "No" nil)
(const :tag "Yes" t)))))
(defcustom jdee-run-option-interpret-mode nil
"Causes the vm to interpret all byte codes. By default VMs
predating JDK 1.3 use a JIT compiler to execute bytecodes. A JIT
compiler translates the class bytecodes into native machine code when
a class is loaded. Beginning with JDK 1.3, VMs use a Hotspot
compiler. A Hotspot compiler compiles sections of code that execute
frequently."
:group 'jdee-run-options
:type 'boolean)
(defcustom jdee-run-option-jar nil
"Execute a program encapsulated in a JAR file.
Set `jdee-run-application-class' to the name of a JAR file instead of a
startup class name. In order for this option to work, the manifest of
the JAR file must contain a line of the form Main-Class:
classname. Here, classname identifies the class having the public
static void main(String[] args) method that serves as your
application's starting point. See the Jar tool reference page and the
Jar trail of the Java Tutorial for information about working with Jar
files and Jar-file manifests. When you use this option, the JAR file
is the source of all user classes, and other user class path settings
are ignored."
:group 'jdee-run-options
:type 'boolean)
(defcustom jdee-run-option-hotspot-type 'client
"Specify whether to use the Hotspot client or server vm."
:group 'jdee-run-options
:type '(choice :tag "vm type"
(const :tag "client" client)
(const :tag "server" server)))
;;(makunbound 'jdee-run-option-enable-assertions)
(defcustom jdee-run-option-enable-assertions "Nowhere"
"Enable assertions for the current project.
To disable assertions everywhere (the default), select \"Nowhere\"
from the Value Menu. To enable assertions everywhere except in system
classes, select \"Everywhere\" from the Value Menu. To enable
assertions in specific locations, select \"Somewhere\" from the Value
Menu. The customization buffer expands, allowing you to enable
assertions in the package in the current directory (the directory of
the current Java source buffer), and in specific packages and classes.
To enable assertions everwhere except in specified locations, set this
option to \"Everywhere\" and use `jdee-run-option-disable-assertions'
to specify the exceptions. To enable assertions in system classes, set
`jdee-run-option-enable-system-assertions' on.
The JDEE ignores this option if `jdee-jdk' specifies a version
of the JDK that precedes version 1.4, which
introduced assertions into Java."
:group 'jdee-run-options
:type '(choice :tag "Enable assertions"
(const "Nowhere")
(const "Everywhere")
(cons :tag "Somewhere" :inline "Everywhere"
(boolean :tag "In current directory")
(repeat :tag "In the following locations"
(cons :tag "Location"
(choice :tag "Type"
(const "package")
(const "class"))
(string :tag "Name"))))))
;;(makunbound 'jdee-run-option-disable-assertions)
(defcustom jdee-run-option-disable-assertions "Nowhere"
"Enable assertions.
Use this option to specify exceptions to packages and classes enabled
by `jdee-run-option-enable-assertions'. To not disable assertions
anywhere (the default), select \"Nowhere\" from the Value Menu. To
disable assertions everywhere except in system classes, select
\"Everywhere except system\" from the Value Menu or set
`jdee-run-option-enable-system-assertions' on. To disable assertions
in specific locations, select \"Somewhere\" from the Value Menu. The
customization buffer expands, allowing you to enable assertions in the
package in the current directory (the directory of the current Java
source buffer), and in specific packages and classes.
The JDEE ignores this option if `jdee-jdk' specifies a version
of the JDK that precedes version 1.4, which
introduced assertions into Java."
:group 'jdee-run-options
:type '(choice :tag "Disable assertions"
(const "Nowhere")
(const "Everywhere")
(cons :tag "Somewhere" :inline "Everywhere"
(boolean :tag "In current directory")
(repeat :tag "In the following locations"
(cons :tag "Location"
(choice :tag "Type"
(const "package")
(const "class"))
(string :tag "Name"))))))
(defcustom jdee-run-option-enable-system-assertions nil
"Enable assertions in system classes."
:group 'jdee-run-options
:type 'boolean)
(defcustom jdee-run-option-disable-system-assertions nil
"Disable assertions in system classes."
:group 'jdee-run-options
:type 'boolean)
(defcustom jdee-run-option-vm-args nil
"*Specify arguments to be passed to the Java vm.
This option allows you to specify one or more arguments to be passed
to the Java interpreter. It is an alternative to using JDE Run Option
variables, such as `jdee-run-option-stack-size', to specify Java
interpreter options. Also, it makes it possible to use the JDE with
interpreters that accept command line arguments not supported by
the JDE Run Option variable set."
:group 'jdee-run-options
:type '(repeat (string :tag "Argument")))
(defcustom jdee-run-option-application-args nil
"*Specify command-line arguments to pass to the application.
The JDE passes the specified arguments to the application on
the command line."
:group 'jdee-run-options
:type '(repeat (string :tag "Argument")))
(defcustom jdee-run-applet-viewer ""
"*Specify name of viewer to use to display page containing the applet."
:group 'jdee-project
:type 'file)
(defcustom jdee-run-applet-doc ""
"*Specify name of document containing applet to be viewed.
If no document is specified, JDE assumes that the document name is
APPLET.html, where APPLET is the name of the applet to be viewed."
:group 'jdee-project
:type 'file)
(defcustom jdee-appletviewer-option-encoding ""
"*Specify encoding of the HTML file displayed by the appletviewer."
:group 'jdee-run-options
:type 'string)
(defcustom jdee-appletviewer-option-vm-args nil
"*Specify arguments (e.g., -Xmx16m) to the vm that runs appletviewer.
This option allows you to set the environment of the
virtual machine that runs appletviewer."
:group 'jdee-run-options
:type '(repeat (string :tag "Argument")))
(defcustom jdee-run-executable ""
"*Specifies the executable to be run by the JDE's run command.
If you do not specify an executable, the JDE runs the vm specified
by `jdee-run-get-vm'."
:group 'jdee-project
:type 'file)
(defcustom jdee-run-executable-args nil
"*Specify arguments to be passed to the application executable.
This option allows you to specify one or more arguments to be passed
to the executable specified by `jdee-run-executable'."
:group 'jdee-run-options
:type '(repeat (string :tag "Argument")))
(defmacro save-w32-show-window (&rest body)
"Saves the value of the w32-start-process-show-window variable
before evaluating body and restores the value afterwards."
`(let ((win32-start-process-show-window t)
(w32-start-process-show-window t)
(w32-quote-process-args ?\")
(win32-quote-process-args ?\") ;; XEmacs
(windowed-process-io t)
(process-connection-type nil))
,@body))
(defun jdee-run-parse-args (s)
"Converts a string of command-line arguments to a list of arguments.
Any substring that is enclosed in single or double quotes or does not include
whitespace is considered a parameter."
(let ((n (string-match "[^\"' ][^ ]*\\|\"[^\"]*\"\\|'[^']*'" s))
(tok)
(tokens '()))
(while n
(setq n (match-end 0))
(setq tok (match-string 0 s))
(if (string-match "[\"']\\([^\"']*\\)[\"']" tok)
(setq tok (match-string 1 tok)))
(setq tokens (append tokens (list tok)))
(setq n (string-match "[^\"' ][^ ]*\\|\"[^\"]*\"\\|'[^']*'" s n)))
tokens))
(defun jdee-run-make-arg-string (args)
"Converts a list of command-line arguments to a string of arguments."
(let ((str "")
(n (length args))
(i 0))
(while (< i n)
(if (not (string= str ""))
(setq str (concat str " ")))
(setq str (concat str (nth i args)))
(setq i (+ i 1)))
str))
;;;###autoload
(defun jdee-run-set-app (app)
"Specify the name of the application class to run."
(interactive
"sEnter application class: ")
(setq jdee-run-application-class app))
;;;###autoload
(defun jdee-run-set-args (args)
"Specify arguments to be passed to the Java vm.
This command serves as an alternative to using the JDE Run Options
panel to specify command-line arguments for the Java interpreter."
(interactive
"sEnter arguments: ")
(setq jdee-run-option-vm-args (jdee-run-parse-args args)))
;;;###autoload
(defun jdee-run-set-app-args (args)
"Specify the arguments to be passed to the Java application class.
This command provides an alternative to using the JDE Run Options panel
to specify command-line arguments to pass to the application when starting
the application."
(interactive
"sEnter arguments: ")
(setq jdee-run-option-application-args (jdee-run-parse-args args)))
;;;###autoload
(defun jdee-run-set-applet-viewer (viewer)
"Sets the viewer to be used to view an applet. The default is
appletviewer."
(interactive
"sEnter viewer name: ")
(setq jdee-run-applet-viewer viewer))
;;;###autoload
(defun jdee-run-set-applet-doc (doc)
"Specify the doc to be used to view an applet.
This command provides an alternative to using the JDE Options
panel to specifying the applet document."
(interactive
"sEnter applet doc name: ")
(if (string= doc "")
(setq jdee-run-applet-doc nil)
(setq jdee-run-applet-doc doc)))
(defclass jdee-run-vm ()
((version :initarg :version
:type string
:initform ""
:documentation
"Java virtual machine version number.")
(path :initarg :path
:type string
:documentation
"Path of the compiler executable.")
(buffer :initarg :buffer
:type buffer
:documentation
"Compilation buffer")
(main-class :initarg :main-class
:type string
:documentation
"Name of main class."))
"Class of Java virtual machines.")
(defmethod jdee-run-classpath-arg ((this jdee-run-vm))
"Returns the classpath argument for this vm."
(let ((classpath
(if jdee-run-option-classpath
(if (and (stringp jdee-run-option-classpath)
(string= jdee-run-option-classpath "global"))
jdee-global-classpath
(unless (and (stringp jdee-run-option-classpath)
(string= jdee-run-option-classpath "none"))
jdee-run-option-classpath))))
(symbol
(if (and jdee-run-option-classpath
(stringp jdee-run-option-classpath)
(string= jdee-run-option-classpath "global"))
'jdee-global-classpath
'jdee-run-option-classpath)))
(if classpath
(list
"-classpath"
(jdee-build-classpath
classpath symbol)))))
(defmethod jdee-run-classic-mode-arg ((this jdee-run-vm))
"Get classic-mode option>"
(if jdee-run-classic-mode-vm
(list "-classic")))
(defmethod jdee-run-property-args ((this jdee-run-vm))
"Get property arguments."
(mapcar
(lambda (prop)
(format "-D%s=%s" (car prop) (cdr prop)))
jdee-run-option-properties))
(defmethod jdee-run-heap-size-args ((this jdee-run-vm))
"Get heap size arguments."
(let* ((memory-unit-abbrevs
(list (cons "bytes" "")
(cons "kilobytes" "k")
(cons "megabytes" "m")
(cons "gigabytes" "g")))
(start-cons (nth 0 jdee-run-option-heap-size))
(start-size (format "%d%s" (car start-cons)
(cdr (assoc (cdr start-cons)
memory-unit-abbrevs))))
(max-cons (nth 1 jdee-run-option-heap-size))
(max-size (format "%d%s" (car max-cons)
(cdr (assoc (cdr max-cons)
memory-unit-abbrevs)))))
(append
(if (not (string= start-size "1m"))
(list (concat "-Xms" start-size)))
(if (not (string= max-size "16m"))
(list (concat "-Xmx" max-size))))))
(defmethod jdee-run-stack-size-args ((this jdee-run-vm))
"Get stack size arguments."
(let* ((memory-unit-abbrevs
(list (cons "bytes" "")
(cons "kilobytes" "k")
(cons "megabytes" "m")
(cons "gigabytes" "g")))
(c-cons (nth 0 jdee-run-option-stack-size))
(c-size (format "%d%s" (car c-cons)
(cdr (assoc (cdr c-cons)
memory-unit-abbrevs))))
(java-cons (nth 1 jdee-run-option-stack-size))
(java-size (format "%d%s" (car java-cons)
(cdr (assoc (cdr java-cons)
memory-unit-abbrevs)))))
(append
(if (not (string= c-size "128k"))
(list (concat "-Xss" c-size)))
(if (not (string= java-size "400k"))
(list (concat "-Xoss" java-size))))))
(defmethod jdee-run-java-profile-arg ((this jdee-run-vm))
"Get Java profile option."
(let ((profilep (car jdee-run-option-java-profile))
(file (cdr jdee-run-option-java-profile)))
(if profilep
(if (string= file "./java.prof")
'("-Xprof")
(list (concat "-Xprof:" file))))))
(defmethod jdee-run-heap-profile-arg ((this jdee-run-vm))
"Get heap profile argument."
(let* ((profilep (car jdee-run-option-heap-profile))
(prof-options (cdr jdee-run-option-heap-profile))
(file (nth 0 prof-options))
(depth (nth 1 prof-options))
(top (nth 2 prof-options))
(sort
(downcase (substring (nth 3 prof-options) 0 1))))
(if profilep
(if (and (string= file "./java.hprof")
(equal depth 5)
(equal top 20)
(string= sort "a"))
'("-Xhprof")
(list
(format
"-Xhprof:file=%s,depth=%d,top=%d,sort=%s"
file depth top sort))))))
(defmethod jdee-run-vm-args ((this jdee-run-vm))
"Get command line args."
jdee-run-option-vm-args)
(defmethod jdee-run-vm-launch ((this jdee-run-vm))
(let ((run-buf-name (concat "*" (oref this :main-class) "*"))
(source-directory default-directory)
(working-directory (if (string= jdee-run-working-directory "")
default-directory
(jdee-normalize-path 'jdee-run-working-directory))))
(if (not (comint-check-proc run-buf-name))
(let* ((run-buffer (get-buffer-create run-buf-name))
(win32-p (eq system-type 'windows-nt))
(prog (oref this :path))
(prog-args (append
(jdee-run-get-vm-args this)
(if jdee-run-read-vm-args
(jdee-run-parse-args
(read-from-minibuffer
"Vm args: "
(car jdee-run-interactive-vm-arg-history)
nil nil
'jdee-run-interactive-vm-arg-history)))
(list (oref this :main-class))
jdee-run-option-application-args
(if jdee-run-read-app-args
(jdee-run-parse-args
(read-from-minibuffer
"Application args: "
(car jdee-run-interactive-app-arg-history)
nil nil
'jdee-run-interactive-app-arg-history)))
))
(command-string (concat prog " "
(jdee-run-make-arg-string
prog-args)
"\n\n")))
(with-current-buffer run-buffer
(erase-buffer)
(cd working-directory)
(insert (concat "cd " working-directory "\n"))
(insert command-string)
(jdee-run-mode))
(save-w32-show-window
(comint-exec run-buffer (oref this :main-class) prog nil prog-args))
(pop-to-buffer run-buffer)
(save-excursion
(goto-char (point-min))
(jdee-run-etrace-update-current-marker))
(cd source-directory))
(message "An instance of %s is running." (oref this :main-class))
(pop-to-buffer run-buf-name))))
(defclass jdee-run-vm-1-1 (jdee-run-vm) ()
"Represents the JDK 1.1.x vm")
(defmethod initialize-instance ((this jdee-run-vm-1-1) &rest fields)
"Constructor for the class representing the JDK 1.1 vm."
;; Call parent initializer.
(call-next-method)
(oset this :version "1.1"))
(defmethod jdee-run-verbose-arg ((this jdee-run-vm-1-1))
"Set the verbose options."
(let ((print-classes-loaded
(nth 0 jdee-run-option-verbose))
(print-memory-freed
(nth 1 jdee-run-option-verbose))
(print-jni-info
(nth 2 jdee-run-option-verbose)))
(append
(if print-classes-loaded (list "-verbose"))
(if print-memory-freed (list "-verbosegc"))
(if print-jni-info (list "-verbose")))))
(defmethod jdee-run-gc-args ((this jdee-run-vm-1-1))
"Get garbage collection arguments."
(let ((no-gc-asynch (not
(nth 0 jdee-run-option-garbage-collection)))
(no-gc-classes (not
(nth 1 jdee-run-option-garbage-collection))))
(append
(if no-gc-asynch
'("-noasyncgc"))
(if no-gc-classes
'("-noclassgc")))))
(defmethod jdee-run-verify-args ((this jdee-run-vm-1-1))
"Get verify arguments."
(let ((verify-all (nth 0 jdee-run-option-verify))
(verify-remote (nth 1 jdee-run-option-verify)))
(append
(if verify-all
'("-verify"))
(if (and
(not verify-all)
(not verify-remote))
'("-noverify")))))
(defmethod jdee-run-debug-args ((this jdee-run-vm-1-1))
"Get arguments required to allow process to connect
to a debugger."
(if jdee-run-option-debug
'("-debug")))
(defmethod jdee-run-interpret-mode-arg ((this jdee-run-vm-1-1))
"Get argument required to enable interpret mode."
(if jdee-run-option-interpret-mode
'("-nojit")))
(defmethod jdee-run-get-vm-args ((this jdee-run-vm-1-1))
(append
(jdee-run-classpath-arg this)
(jdee-run-verbose-arg this)
(jdee-run-property-args this)
(jdee-run-heap-size-args this)
(jdee-run-stack-size-args this)
(jdee-run-gc-args this)
(jdee-run-java-profile-arg this)
(jdee-run-heap-profile-arg this)
(jdee-run-verify-args this)
(jdee-run-interpret-mode-arg this)
(jdee-run-debug-args this)
(jdee-run-vm-args this)))
(defclass jdee-run-vm-1-2 (jdee-run-vm-1-1) ()
"Represents the JDK 1.2.x vm")
(defmethod initialize-instance ((this jdee-run-vm-1-2) &rest fields)
"Constructor for the class representing the JDK 1.2 vm."
;; Call parent initializer.
(call-next-method)
(oset this :version "1.2"))
(defmethod jdee-run-boot-classpath-arg ((this jdee-run-vm-1-2))
"Returns the boot classpath argument for this vm."
(if jdee-run-option-boot-classpath
(list
(concat
"-Xbootclasspath:"
(jdee-build-classpath
(cdr jdee-run-option-boot-classpath)
'jdee-run-option-boot-classpath)))))
(defmethod jdee-run-verbose-arg ((this jdee-run-vm-1-2))
"Set the verbose options."
(let ((print-classes-loaded
(nth 0 jdee-run-option-verbose))
(print-memory-freed
(nth 1 jdee-run-option-verbose))
(print-jni-info
(nth 2 jdee-run-option-verbose)))
(append
(if print-classes-loaded (list "-verbose:class"))
(if print-memory-freed (list "-verbose:gc"))
(if print-jni-info (list "-verbose:jni")))))
(defmethod jdee-run-gc-args ((this jdee-run-vm-1-2))
"Get garbage collection arguments."
(let ((no-gc-asynch (not
(nth 0 jdee-run-option-garbage-collection)))
(no-gc-classes (not
(nth 1 jdee-run-option-garbage-collection))))
(append
(if no-gc-asynch
'("-Xnoasyncgc"))
(if no-gc-classes
'("-Xnoclassgc")))))
(defmethod jdee-run-debug-args ((this jdee-run-vm-1-2))
"Get arguments required to allow process to connect
to a debugger."
(if jdee-run-option-debug
'("-Xdebug")))
(defmethod jdee-run-interpret-mode-arg ((this jdee-run-vm-1-2))
"Get argument required to disable use of JIT compiler."
(if jdee-run-option-interpret-mode
'("-Djava.compiler=NONE")))
(defmethod jdee-run-jar-arg ((this jdee-run-vm-1-2))
"Get argument that specifies use of a jar file to run an app."
(if jdee-run-option-jar
'("-jar")))
(defmethod jdee-run-get-vm-args ((this jdee-run-vm-1-2))
(append
;; Classic mode argument must come first.
(jdee-run-classic-mode-arg this)
(jdee-run-boot-classpath-arg this)
(jdee-run-classpath-arg this)
(jdee-run-verbose-arg this)
(jdee-run-property-args this)
(jdee-run-heap-size-args this)
(jdee-run-stack-size-args this)
(jdee-run-gc-args this)
(jdee-run-java-profile-arg this)
(jdee-run-heap-profile-arg this)
(jdee-run-debug-args this)
(jdee-run-interpret-mode-arg this)
(jdee-run-vm-args this)
(jdee-run-jar-arg this) ;; must be last
))
(defclass jdee-run-vm-1-3 (jdee-run-vm-1-2) ()
"Represents the JDK 1.3.x vm")
(defmethod initialize-instance ((this jdee-run-vm-1-3) &rest fields)
"Constructor for the class representing the JDK 1.3 vm."
;; Call parent initializer.
(call-next-method)
(oset this :version "1.3"))
(defmethod jdee-run-boot-classpath-arg ((this jdee-run-vm-1-3))
"Returns the boot classpath argument for this vm."
(if jdee-run-option-boot-classpath
(list
(concat
"-Xbootclasspath"
(let ((mode (car jdee-run-option-boot-classpath)))
(cond
((string= mode "append")
"/a:")
((string= mode "prepend")
"/p:")
((string= mode "replace")
":")
(t
(error "Illegal custom classpath mode: %s" mode))))
(jdee-build-classpath
(cdr jdee-run-option-boot-classpath)
'jdee-run-option-boot-classpath)))))
(defmethod jdee-run-debug-args ((this jdee-run-vm-1-3))
"Get arguments required to allow process to connect
to a debugger."
(if jdee-run-option-debug
(let ((mode (nth 0 jdee-run-option-debug))
(transport (nth 1 jdee-run-option-debug))
(shared-mem-name (nth 2 jdee-run-option-debug))
(socket-host (nth 3 jdee-run-option-debug))
(socket-port (nth 4 jdee-run-option-debug))
(suspend (nth 5 jdee-run-option-debug))
(ms-windows (eq system-type 'windows-nt)))
(list "-Xdebug"
(format
"-Xrunjdwp:transport=%s,address=%s,server=%s,suspend=%s"
(if (string= transport "Shared Memory")
(if ms-windows
"dt_shmem"
(error "Shared memory transport is valid only on Windows."))
"dt_socket")
(if (string= transport "Shared Memory")
shared-mem-name
(if (string= mode "Client")
(if socket-host
(concat socket-host ":" socket-port)
socket-port)
socket-port))
(if (string= mode "Server") "y" "n")
(if suspend "y" "n"))))))
(defmethod jdee-run-get-vm-args ((this jdee-run-vm-1-3))
(append
;; Classic mode argument must come first.
(jdee-run-classic-mode-arg this)
(jdee-run-boot-classpath-arg this)
(jdee-run-classpath-arg this)
(jdee-run-verbose-arg this)
(jdee-run-property-args this)
(jdee-run-heap-size-args this)
(jdee-run-stack-size-args this)