-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIsawInstaller.java
1483 lines (1338 loc) · 45.6 KB
/
IsawInstaller.java
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
/*
* File: Isawinstaller.java
*
* Copyright (C) 2002, Peter Peterson
*
* This program 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
* of the License, or (at your option) any later version.
*
* This program 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 this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Contact : Peter F. Peterson <[email protected]>
* Intense Pulsed Neutron Source Division
* Argonne National Laboratory
* 9700 South Cass Avenue, Bldg 360
* Argonne, IL 60439-4845, USA
*
* This work was supported by the Intense Pulsed Neutron Source Division
* of Argonne National Laboratory, Argonne, IL 60439-4845, USA.
*
* For further information, see <http://www.pns.anl.gov/ISAW/>
*
* $Author$
* $Date$
* $Revision$
*
* Modified:
*
* $Log$
* Revision 1.34 2007/08/27 03:49:57 dennis
* Changed check for unix shared libraries (.so) to allow for
* version numbers liks .so.2, since the new jnexus rquires libs
* with particular numbered suffixs.
*
* Revision 1.33 2007/08/15 16:12:20 dennis
* Removed use of gluegen-rt.jar, to step back to JSR231
* jogl version 1.0 instead of version 1.1
*
* Revision 1.32 2007/08/14 16:50:27 dennis
* Removed reference to separate MessageTools.jar file, since
* the MessageTools package is inside the Isaw.jar file.
*
* Revision 1.31 2007/08/14 15:47:28 dennis
* Updated to include gluegen-rt.jar and MessageTools.jar after
* upgrading jogl to the JSR231 version.
*
* Revision 1.30 2005/08/04 19:32:05 dennis
* Changed default memory size from 128M to 256M in the batch file
* to run ISAW.
*
* Revision 1.29 2005/08/03 19:41:14 dennis
* Added SSG_Tools.jar to classpath
*
* Revision 1.28 2005/05/31 16:48:09 dennis
* Removed dependence on WindowShower, since the installer did not
* run out of the jar file when it used the WindowShower. Now just
* calls setVisible(true).
*
* Revision 1.27 2005/05/25 18:01:08 dennis
* Replaced direct call to .show() method for window,
* since .show() is deprecated in java 1.5.
* Now calls WindowShower.show() to create a runnable
* that is run from the Swing thread and sets the
* visibility of the window true.
*
* Revision 1.26 2005/03/08 02:51:12 dennis
* Added jython.jar to the list of jar files included in the
* script to run Isaw that is written during the installation.
*
* Revision 1.25 2005/01/10 15:55:01 dennis
* Removed empty statement.
*
* Revision 1.24 2004/07/28 21:31:46 dennis
* Added ISIS.jar
*
* Revision 1.23 2004/06/08 01:26:35 dennis
* Fixed syntax error in batch file to run Isaw on Windows.
*
* Revision 1.22 2004/06/04 22:46:25 dennis
* Added jogl.jar and native libraries for jogl.
*
* Revision 1.21 2004/04/23 19:07:50 dennis
* Removed -server option from batch file for running ISAW
* for all operating systems besides Linux. (Java on
* Win XP Pro does not support the -server option and I
* am not currently able to test this change on SUN or MAC
* systems.)
*
* Revision 1.20 2004/04/15 16:01:46 dennis
* Changed to run Isaw in "server mode" which takes a bit
* longer to start but is supposed to run more efficiently.
*
* Revision 1.19 2004/03/17 22:58:48 dennis
* Added gov.jar to list of jar files on classpath. This was needed
* due to splitting the view, math and utilities from ISAW into the
* gov.anl.ipns package.
* Also changed reference from /IPNShome/pfpeterson/packup to
* /IPNShome/IsawMake/packup
*
* Revision 1.18 2004/01/08 17:58:17 bouzekc
* Removed unused local variables.
*
* Revision 1.17 2003/06/17 21:52:56 pfpeterson
* Added quotes around the classpath when writing windows batch files.
*
* Revision 1.16 2003/04/17 14:48:49 pfpeterson
* Update skip(String) function to do more than the default with jnilib.
*
* Revision 1.15 2002/12/09 20:29:36 pfpeterson
* Added jhall.jar to the classpath in generated batch file.
*
* Revision 1.14 2002/11/27 23:11:55 pfpeterson
* standardized header
*
* Revision 1.13 2002/09/27 20:04:18 pfpeterson
* Small modification on exec script written for sun os.
*
* Revision 1.12 2002/08/16 15:18:56 pfpeterson
* Fixed bug where you couldn't install from a directory with
* spaces in the name.
*
* Revision 1.11 2002/08/15 18:40:41 pfpeterson
* Fixed the windows and mac batch file creation.
*
* Revision 1.10 2002/05/29 21:14:57 pfpeterson
* Now determines the name of the jar file through reflection. Also
* added functionality for testing which uses the information as
* well.
*
* Revision 1.9 2002/04/12 15:17:53 pfpeterson
* Prints message about moving properties file only when sucessful.
*
* Revision 1.8 2002/04/04 20:48:50 pfpeterson
* changed command line switch to '-mx128m'.
*
* Revision 1.7 2002/03/26 20:47:08 pfpeterson
* More mac updates:
* - Set default file extension to 'applescript' (uncompiled code).
* - Extension for compiled code is 'scpt'.
*
* Revision 1.6 2002/03/26 16:42:12 pfpeterson
* Changed batch file to be an apple script.
*
* Revision 1.5 2002/03/25 23:46:52 pfpeterson
* Changed exiting information dialog. Location of java no longer
* needed for mac clients.
*
* Revision 1.4 2002/03/04 20:29:54 pfpeterson
* Updated mac support.
*
* Revision 1.3 2002/02/18 21:57:09 pfpeterson
* Fixed nexus and windows problem.
*
* Revision 1.2 2002/02/18 16:33:27 pfpeterson
* Changes the permission of Isaw_exec.sh to executable using the "chmod +x"
* system call. New line character is now System.getProperty("line.separator").
*
* Revision 1.1 2002/02/13 20:42:19 pfpeterson
* First version of unified installer in CVS.
*/
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.zip.*;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
/*
* This installer is based on the ZipSelfExtractor utility by Z. Steve
* Jin and John D. Mitchell as found at
* http://www.javaworld.com/javaworld/javatips/jw-javatip120.html.
*
* The intent is to find information about where to place the new
* version of ISAW then put it there.
*/
public class IsawInstaller extends JFrame
{
private String myClassName;
static String MANIFEST = "META-INF/MANIFEST.MF";
static JFrame mw;
private Boolean injar;
// global variables so text can be changed
JTextField location;
String jarFileName;
JTextField os;
JTextField batch;
JTextField java;
String operating_system;
// buttons
JButton installDir,
batchFile,
javaLoc,
cancelBut,
installBut;
// progress bar
JProgressBar progress;
// fields
private static final String WIN_ID = "windows";
private static final String LIN_ID = "linux";
private static final String SUN_ID = "sunos";
private static final String MAC_ID = "mac";
private static final String UNKNOWN_ID = "unknown";
// button and label stuff
private static final String UNPACK_ARCH = "Unpack Archive:";
private static final String INSTALL_LOC = "Install Directory:";
private static final String BATCH_FILE = "Isaw Batch File:";
private static final String JAVA_LOC = "Java Location:";
private static final String CANCEL_BUT = "Cancel";
private static final String CHANGE = "Change";
private static final String START_BUT = "Install";
private static final String NO_BATCH = "not creating batch file";
private static final String NA = "n/a";
/* =========================== main =========================== */
/**
* This method is what is called when the jar is executed assuming
* that the MANIFEST points at this class. The technique is to
* draw the installer with meaningful default values (depending on
* operating system) then extract the archive and create the batch
* file once the install button is pressed.
*/
public static void main(String[] args){
IsawInstaller zse = new IsawInstaller();
// get the operating system
zse.getOS();
// find the name of archive
zse.jarFileName=zse.getJarFileName();
// set up the GUI
zse.init();
} // end of main
/* ======================== constructor ======================= */
/**
* The constructor is empty.
*/
public IsawInstaller(){
}
/**
* Method to determine if running from a jar file.
*/
private boolean inJar(){
if(injar==null){
String className=this.getClass().getName().replace('.','/');
String classJar=this.getClass().getResource("/"+className
+".class").toString();
if(classJar.startsWith("jar:")){
injar=Boolean.TRUE;
}else{
injar=Boolean.FALSE;
}
}
return injar.booleanValue();
}
/* ====================== operating system ==================== */
/**
* Determine the operating system. If the operating system is
* something other than WIN_ID or LIN_ID then it defaults to
* UNKNOWN_ID. This information is used to build the GUI with the
* appropriate options available and produce the correct system
* dependent batch file.
*/
private String getOS(){
String osS=System.getProperty("os.name");
osS=osS.trim();
if( osS != null ){
int index=osS.indexOf(" ");
if(index>0){
osS=osS.substring(0,index);
}
osS=osS.toLowerCase();
if(osS.startsWith(WIN_ID)){
operating_system=WIN_ID;
}else if(osS.startsWith(LIN_ID)){
operating_system=LIN_ID;
}else if(osS.startsWith(SUN_ID)){
operating_system=SUN_ID;
}else if(osS.startsWith(MAC_ID)){
operating_system=MAC_ID;
}else{
System.err.println("OS ("+osS+") not known");
operating_system=UNKNOWN_ID;
}
}else{
operating_system=UNKNOWN_ID;
}
//operating_system=WIN_ID;
//operating_system=MAC_ID;
//operating_system=UNKNOWN_ID;
return operating_system;
}
/* =================== installation directory ================= */
/**
* This method sets the current_working_directory/ISAW as the
* default installation directory.
*/
private String getDefaultDir(){
File result=new File(".","ISAW");
try{
result=result.getCanonicalFile();
}catch(Exception e){
System.err.println("Exception in getDefaultDir:"+e);
}
return result.toString();
}
/**
* Pops up a dialog to determine where the user would like ISAW
* installed. This changes the value of the location JTextField.
*/
private String getInstallDir(){
JFileChooser fc = new JFileChooser();
File result=new File(location.getText());
fc.setCurrentDirectory(result);
// set title
fc.setDialogTitle("Select destination directory for installing ISAW");
// turn off multiple selection
fc.setMultiSelectionEnabled(false);
// set selection mode to files and directories
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
//fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
boolean keepgoing=true;
while(keepgoing){
switch(fc.showDialog(IsawInstaller.this, "Select")){
case JFileChooser.CANCEL_OPTION:
return null;
case JFileChooser.APPROVE_OPTION:
// do nothing
}
result=fc.getSelectedFile();
if(result.exists()){
if(result.isDirectory()){
keepgoing=false;
}else{
System.out.println(result+" is a file");
}
}else{ // should we create the directory?
String msg="'"+result+"'"+" does not exist.\n"
+"Create?";
switch(JOptionPane.showConfirmDialog(IsawInstaller.this,msg,
"Create New Directory?",JOptionPane.YES_NO_OPTION)){
case JOptionPane.YES_OPTION:
if(result.mkdir()){
keepgoing=false;
break;
}
case JOptionPane.NO_OPTION:
// don't do anything
}
}
}
String filename=fc.getSelectedFile().toString();
location.setText(filename);
String batchfile=batch.getText();
if(batchfile.equals(NO_BATCH)){
// do nothing
}else{
batchfile=batchfile.substring(batchfile.lastIndexOf(File.separator));
batch.setText(filename+batchfile);
}
return filename;
}
/**
* Fix the separator in a director/file listing to contain only
* forward slashes.
*/
private static String fixSeparator(String filename){
String separator = "/";
String result = null;
result = replace(filename, "\\\\", separator);
result = replace(result, "\\", separator);
result = replace(result, "//", separator);
return result;
}
private static String replace( String in_string, String old_chars,
String new_chars ){
if( in_string==null || old_chars==null || new_chars==null ) return null;
if(old_chars.equals(new_chars)) return in_string;
int start;
String result=in_string;
int from_index=0;
while( result.indexOf(old_chars,from_index)>=0 ){
start=result.indexOf( old_chars, from_index );
result=result.substring(0,start)+new_chars
+result.substring(start+old_chars.length());
from_index=start+new_chars.length();
}
return result;
}
/* =================== make the batch file ==================== */
/**
* Determine whether or not the user wants to make a batch
* file. If cancel is selected then it does nothing and returns
* false, otherwise will invoke either "noBatch" or "yesBatch".
*/
private boolean makeBatch(){
String msg = "Create a batch files?";
switch(JOptionPane.showConfirmDialog(IsawInstaller.this,msg,
"Batch Files",JOptionPane.YES_NO_CANCEL_OPTION)){
case JOptionPane.CANCEL_OPTION:
if((batch.getText()).equals(NO_BATCH)){
return false;
}else{
return false;
}
case JOptionPane.YES_OPTION:
this.yesBatch(null);
return true;
case JOptionPane.NO_OPTION:
this.noBatch();
return false;
}
return true;
}
/**
* Determine what the default name of the batch file should be
* according to the operating system.
*/
private String getDefaultBatch(){
String filename=this.location.getText()+File.separator;
String bt="";
if(batch!=null){
bt=batch.getText();
if(bt==null) bt="";
}
if(operating_system.equals(WIN_ID)){
filename=filename+"Isaw_exec.bat";
}else if(operating_system.equals(LIN_ID)){
filename=filename+"Isaw_exec.sh";
}else if(operating_system.equals(SUN_ID)){
filename=filename+"Isaw_exec.sh";
}else if(operating_system.equals(MAC_ID)){
filename=filename+"Isaw_exec.applescript";
}else{
return null;
}
return filename;
}
/**
* Pop up a dialog to determine what the batch file should be
* called. This changes the value of the batch JTextField through
* the use of "noBatch" and "yesBatch".
*/
private String getBatchName(){
String filename=this.batch.getText();
if(filename.indexOf(NO_BATCH)>=0){
filename=getDefaultBatch();
}
if(filename==null){
return null;
}
filename=ISAWgetFile("Select Name of Isaw Batch File",filename);
if(filename==null) return null;
/* if((new File(filename)).exists()){
switch(JOptionPane.showConfirmDialog(IsawInstaller.this,
"Overwrite Existing batch file?",
"Batch File",JOptionPane.YES_NO_CANCEL_OPTION)){
case JOptionPane.NO_OPTION:
this.noBatch();
case JOptionPane.CANCEL_OPTION:
return null;
case JOptionPane.YES_OPTION:
// do nothing
}
} */
yesBatch(filename);
return filename;
}
/**
* Pop up a dialog to let the user specify the location of the
* java executable. This modifies the JTextField java.
*/
private String getJavaExec(){
String filename=java.getText();
if(operating_system.equals(WIN_ID)){
java.setText("n/a");
return null;
}
if(operating_system.equals(MAC_ID)){
java.setText("n/a");
return null;
}
filename=ISAWgetFile("Select Java Executable",this.findJavaExec());
if(filename==null){
return null;
}else{
java.setText(filename);
return filename;
}
}
/**
* Finds the java executable from the "java.home" system property.
*/
private String findJavaExec(){
String filename=System.getProperty("java.home");
if(filename!=null){
filename=filename.substring(0,filename.lastIndexOf(System.getProperty("file.separator")))
+System.getProperty("file.separator")+"bin"
+System.getProperty("file.separator")+"java";
}else{
filename=".";
}
return filename;
}
/**
* Sets the text of batch to NO_BATCH and the text of java to NA.
*/
private void noBatch(){
batch.setText(NO_BATCH);
java.setText(NA);
return;
}
/**
* Sets the text of batch to batchfile and resets the text of
* java.
*
* @param batchfile New name of the batchfile.
*/
private void yesBatch(String batchfile){
if(batchfile!=null){
if((batch.getText()).equals(batchfile)){
// do nothing
}else{
batch.setText(batchfile);
}
}
if(operating_system.equals(WIN_ID)){
// do nothing
}else{
if((java.getText()).equals(NA)){
java.setText(null);
}
}
return;
}
/**
* Writes out the system dependent batch files.
*/
private void writeBatch()
{
writeBatch(null);
writeBatch("EventTools.ShowEventsApp.IsawEV");
writeBatch("Wizard.TOF_SCD.InitialPeaksWizard_SNS");
writeBatch("Wizard.TOF_SCD.InitialPeaksWizard_SNS1");
writeBatch("Wizard.TOF_SCD.DailyPeaksWizard_SNS");
writeBatch("devTools.Method2OperatorWizard");
writeBatch("EventTools.ShowEventsApp.DataHandlers.SocketServerTest");
writeBatch("Operators.TOF_SCD.IntegrateNorm");
}
private void writeBatch( String className){
String filename=batch.getText();
if((filename==null)||(filename.equals(NO_BATCH)))return;
String memory ="256";
if( className != null )
{
int k = filename.lastIndexOf( "Isaw" );
if( k < 0 )
return;
String Subs = className.substring( 1 + className.lastIndexOf( '.' ) );
filename = filename.substring( 0 , k ) + Subs
+ filename.substring( k + 4 );
if( Subs.equals("IsawEV"))
memory ="1200";
}else
className = "IsawGUI.Isaw";
File batchF=new File(filename);
if(batchF.exists()){
int last=filename.lastIndexOf(".");
File newName=new File(filename.substring(0,last)+".old");
batchF.renameTo(newName);
String msg="Renaming existing batch file from\n"
+filename+"\n"
+"to\n"
+newName;
JOptionPane.showMessageDialog(IsawInstaller.this,msg,
"Renaming Batchfile",
JOptionPane.INFORMATION_MESSAGE);
}
String isaw_home=location.getText();
if( (new File(isaw_home)).exists() ){
//System.out.println("isaw_home exists");
}else{
(new File(isaw_home)).mkdir();
String msg="Creating new directory:\n"
+isaw_home;
JOptionPane.showMessageDialog(IsawInstaller.this,msg,
"Creating Directory",
JOptionPane.INFORMATION_MESSAGE);
}
String lib_home=isaw_home+File.separator+"lib";
String java_home=java.getText();
if(java_home==null || java_home.equals(NA) || java_home.length()<=0
) java_home="java";
String content="";
String newline=System.getProperty("line.separator"); // "\n";
if(operating_system.equals(WIN_ID)){
content="rem The '-mx' option specifies initial memory"
+" allocation."+newline
+"rem If you have less than 256 MB of memory, you might"
+" need to ask for less."+newline
+"rem The '-cp' option specifies the class path\n"
+"rem --"+newline
+"rem The following command is used to run from jar files\n"
+"rem --"+newline
+"cd "+isaw_home+newline
+"path ./lib;%PATH%"+newline
+"java -mx"+memory+"m -cp \""+fixSeparator(isaw_home)
+";Isaw.jar;sgt_v2.jar;gov.jar;IPNS.jar;ISIS.jar;jnexus.jar;sdds.jar;SSG_Tools.jar;jogl.jar;gluegen-rt.jar;"
+"jhall.jar;jython.jar;.\" "+ className+newline
+"rem --"+newline
+"rem The following command is used to run from Isaw folder"
+ newline
+"rem --"+newline
+"rem java -mx"+memory+"m -cp Isaw.jar;sgt_v2.jar;gov.jar;IPNS.jar;ISIS.jar;jnexus.jar;sdds.jar;SSG_Tools.jar;jogl.jar;gluegen-rt.jar;"
+"jhall.jar;jython.jar;.\" -Dsun.awt.noerasebackground=true -Dsun.java2d.noddraw=true -Dsun.java2d.opengl=true "
+"-Duser.language=en -Duser.region=US " +className+newline;
}else if(operating_system.equals(LIN_ID)){
content="#!/bin/sh"+newline
+"ISAW="+isaw_home+newline
+"JAVA="+java_home+newline
+"export LD_LIBRARY_PATH="+lib_home+newline
+"cd $ISAW"+newline
+"$JAVA -mx"+memory+"m -server -cp $ISAW:$ISAW/Isaw.jar:$ISAW/gov.jar:$ISAW/IPNS.jar:$ISAW/ISIS.jar:"
+"$ISAW/jnexus.jar:$ISAW/sgt_v2.jar:$ISAW/sdds.jar:$ISAW/SSG_Tools.jar:$ISAW/jogl.jar:$ISAW/gluegen-rt.jar:"
+"$ISAW/jhall.jar:$ISAW/jython.jar:. -Dsun.awt.noerasebackground=true "
+"-Duser.language=en -Duser.region=US " +className+newline;
}else if(operating_system.equals(SUN_ID)){
content="#!/bin/sh"+newline
+"ISAW="+isaw_home+newline
+"JAVA="+java_home+newline
+"LD_LIBRARY_PATH="+lib_home+newline
+"cd $ISAW"+newline
+"$JAVA -mx"+memory+"m -cp $ISAW:$ISAW/Isaw.jar:$ISAW/gov.jar:$ISAW/IPNS.jar:$ISAW/ISIS.jar:"+
"$ISAW/jnexus.jar:$ISAW/sgt_v2.jar:$ISAW/sdds.jar:$ISAW/SSG_Tools.jar:$ISAW/jogl.jar:$ISAW/gluegen-rt.jar:"
+"$ISAW/jhall.jar:$ISAW/jython.jar:. -Dsun.awt.noerasebackground=true "
+"-Duser.language=en -Duser.region=US " +className+newline;
}else if(operating_system.equals(MAC_ID)){
content="tell application \"Terminal\""+newline
+" do script with command \"java -mx"+memory+"m -cp "
+isaw_home+":"
+isaw_home+"/Isaw.jar:"
+isaw_home+"/sgt_v2.jar:"
+isaw_home+"/gov.jar:"
+isaw_home+"/IPNS.jar:"
+isaw_home+"/ISIS.jar:"
+isaw_home+"/jnexus.jar:"
+isaw_home+"/sdds.jar:"
+isaw_home+"/SSG_Tools.jar:"
+isaw_home+"/jogl.jar:"
+isaw_home+"/gluegen-rt.jar:"
+isaw_home+"/jython.jar:"
+isaw_home+"/jhall.jar:. -Dsun.awt.noerasebackground=true "
+"-Duser.language=en -Duser.region=US "
+className+"\""+newline
+"end tell"+newline;
}else{
System.err.println("Unknown operating system: "+operating_system);
return;
}
//System.out.print(content);
try{
FileWriter outfile=new FileWriter(filename);
outfile.write(content);
outfile.flush();
outfile.close();
}catch(Exception e){
System.err.println("Exception in writeBatch: "+e);
}
if(operating_system.equals(LIN_ID) || operating_system.equals(SUN_ID)){
Process proc = null;
try{
proc=Runtime.getRuntime().exec("chmod +x "+filename);
proc.waitFor();
}catch(InterruptedException e){
System.err.println("Could not change access of batch file: "+e);
}catch(IOException e){
System.err.println("Could not change access of batch file: "+e);
}finally{
if(proc!=null)proc.destroy();
}
}
return;
}
/**
* Make all files in the ISAW/bin directory executable on Linux or Sun.
*/
private void makeBinExecutable()
{
if ( operating_system.equals(LIN_ID) || operating_system.equals(SUN_ID) )
{
String bin_dir = location.getText() + "/bin";
Process proc = null;
try
{
String command = "chmod -R +x " + bin_dir;
proc=Runtime.getRuntime().exec( command );
proc.waitFor();
}
catch ( Exception e )
{
System.err.println("Could not make binaries executable: "+e);
}
finally
{
if ( proc != null )
proc.destroy();
}
}
}
/* ======================== extraction ======================== */
/**
* Determine the name of the jar file.
*/
private String getJarFileName(){
String urlStr=null;
if(inJar()){
myClassName = this.getClass().getName()+".class";
urlStr = this.getClass().getResource(myClassName).toString();
if(urlStr!=null){
urlStr=fixSeparator(urlStr);
urlStr=URLDecoder.decode(urlStr);
int from = "jar:file:".length();
int to = urlStr.indexOf("!");
if( from<to && from!=-1 ){
if(operating_system.equals(WIN_ID)) from++;
return urlStr.substring(from, to);
}else{
System.err.println("'"+urlStr+"' not an archive("
+from+","+to+")");
}
}else{
System.err.println("Name of archive not found");
}
}else{
File dir=new File("/IPNShome/IsawMake/packup/");
if(dir.isDirectory() && dir.exists() ){
File F[];
F = dir.listFiles();
for( int i=0 ; i<F.length ; i++){
if(F[i].isFile()){
if(F[i].getName().endsWith(".jar")){
if(F[i].getName().startsWith("Isaw-")){
return F[i].getAbsolutePath();
}
}
}
}
System.err.println("Name of archive not found");
}else{
System.err.println(dir.getAbsolutePath()+" does not exist");
}
}
System.exit(-1);
return "";
}
/**
* Move the existing IsawProps.dat if it exists.
*/
private void moveIsawProps(){
String filename=System.getProperty("user.home");
if(filename.endsWith(File.separator)){
// do nothing
}else{
filename=filename+File.separator;
}
filename=filename+"IsawProps.dat";
//System.out.println(filename);
File props=new File(filename);
if(props.exists()){
int last=filename.lastIndexOf(".");
File newName=new File(filename.substring(0,last)+".old");
props.renameTo(newName);
if(newName.exists()&&!props.exists()){
String msg="Renaming existing IsawProps.dat to\n"
+newName;
JOptionPane.showMessageDialog(IsawInstaller.this,msg,
"Renaming IsawProps.dat",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
/**
* Access point for extracting files from the archive. The actual
* extraction is done from a separate thread. This allows for the
* progress bar to be updated.
*/
public void extract(){
final Extractor worker;
worker=new Extractor(IsawInstaller.this);
worker.init(location.getText(),jarFileName);
worker.start();
}
/* =========================== GUI ============================ */
/**
* Draw the GUI using reasonable start values for all of the
* install information.
*/
private void init(){
mw = new JFrame("Isaw Installer");
mw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// ==================== initialize the grid bag constraints ==
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.anchor = GridBagConstraints.WEST;
// ==================== put text-box on top and fill with readme
JEditorPane leftEdP = new JEditorPane();
leftEdP.setEditable(false);
leftEdP.setText(this.readmetext());
JScrollPane instruct=new JScrollPane(leftEdP);
instruct.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
instruct.setPreferredSize(new Dimension(700,400));
mw.getContentPane().add(instruct, BorderLayout.NORTH);
// ==================== put a generic Panel on the bottom ====
JPanel right=new JPanel();
right.setLayout(new GridBagLayout());
mw.getContentPane().add(right, BorderLayout.SOUTH);
// ==================== create objects to fill bottom panel ==
// ========== stuff for archive name
JLabel unpackL = new JLabel(UNPACK_ARCH);
JTextField unpack=new JTextField();
unpack.setEditable(false);
unpack.setColumns(30);
unpack.setText(jarFileName);
// ========== stuff for install directory
JLabel locationL = new JLabel(INSTALL_LOC);
location=new JTextField(this.getDefaultDir());
location.setEditable(false);
location.setColumns(30);
installDir=new JButton(CHANGE);
// ========== stuff for batch file frame
JPanel batchP = new JPanel(new GridBagLayout());
batchP.setBorder(BorderFactory.createTitledBorder("Create Batch Files"));
// ========== cancel button
cancelBut=new JButton(CANCEL_BUT);
cancelBut.setForeground(Color.red);
// ========== progress meter
progress=new JProgressBar();
//progress.setIndeterminate(true);
// ========== install button
installBut=new JButton(START_BUT);
installBut.setForeground(Color.green.darker());
// ==================== things for batch file frame ==========
// ========== stuff for batch file name
JLabel batchL=new JLabel(BATCH_FILE);
batch=new JTextField(getDefaultBatch());
batch.setEditable(false);
batch.setColumns(30);
batchFile=new JButton(CHANGE);
// ========== stuff for java executable location
JLabel javaL=new JLabel(JAVA_LOC);
if(operating_system.equals(WIN_ID)){
java=new JTextField(NA);
}else{
java=new JTextField(this.findJavaExec());
}
java.setEditable(false);
java.setColumns(30);
javaLoc=new JButton(CHANGE);
// ==================== set size of buttons to be same as installBut
Dimension d=installBut.getSize();
installDir.setSize(d);
batchFile.setSize(d);
javaLoc.setSize(d);
cancelBut.setSize(d);
// ==================== add the listeners ====================
installDir.addActionListener(new MyMouseListener(this));
batchFile.addActionListener(new MyMouseListener(this));
javaLoc.addActionListener( new MyMouseListener(this));
cancelBut.addActionListener( new MyMouseListener(this));
installBut.addActionListener( new MyMouseListener(this));
// ==================== pack the lower panel =================
// ========== add vertical space at the top
gbc.weightx=1.0; gbc.gridwidth=GridBagConstraints.REMAINDER;
right.add(Box.createVerticalStrut(10),gbc);
// ========== stuff for unpack step
gbc.weightx=0.0; gbc.gridwidth=1;
right.add(Box.createHorizontalStrut(2),gbc);
gbc.weightx=0.0; gbc.gridwidth=1;
right.add(unpackL,gbc);
gbc.weightx=1.0; gbc.gridwidth=1;
right.add(Box.createHorizontalGlue(),gbc);
gbc.weightx=2.0; gbc.gridwidth=1;
right.add(unpack,gbc);
gbc.weightx=1.0; gbc.gridwidth=1;
right.add(Box.createHorizontalGlue(),gbc);
gbc.weightx=0.0; gbc.gridwidth=1;
right.add(Box.createRigidArea(d),gbc);
gbc.weightx=0.0; gbc.gridwidth=GridBagConstraints.REMAINDER;
right.add(Box.createHorizontalGlue(),gbc);
// ========== add vertical space
gbc.weightx=1.0; gbc.gridwidth=GridBagConstraints.REMAINDER;
right.add(Box.createVerticalStrut(10),gbc);
// ========== stuff for install directory step
gbc.weightx=0.0; gbc.gridwidth=1;
right.add(Box.createHorizontalStrut(2),gbc);
gbc.weightx=0.0; gbc.gridwidth=1;
right.add(locationL,gbc);
gbc.weightx=1.0; gbc.gridwidth=1;
right.add(Box.createHorizontalGlue(),gbc);
gbc.weightx=2.0; gbc.gridwidth=1;
right.add(location,gbc);