-
Notifications
You must be signed in to change notification settings - Fork 55
/
Main.java
2817 lines (2588 loc) · 100 KB
/
Main.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
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 301226
* Red Hat Inc. - bug 373640, 379102
* Ericsson AB (Pascal Rapicault) - bug 304132
* Rapicorp, Inc - Default the configuration to Application Support (bug 461725)
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 221969
*******************************************************************************/
package org.eclipse.equinox.launcher;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.net.URLStreamHandlerFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
* The launcher for Eclipse.
*
* <b>Note:</b> This class should not be referenced programmatically by
* other Java code. This class exists only for the purpose of launching Eclipse
* from the command line. To launch Eclipse programmatically, use
* org.eclipse.core.runtime.adaptor.EclipseStarter. The fields and methods
* on this class are not API.
*
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class Main {
/**
* Indicates whether this instance is running in debug mode.
*/
protected boolean debug = false;
/**
* The location of the launcher to run.
*/
protected String bootLocation = null;
/**
* The location of the install root
*/
protected URL installLocation = null;
/**
* The location of the configuration information for this instance
*/
protected URL configurationLocation = null;
/**
* The location of the configuration information in the install root
*/
protected String parentConfigurationLocation = null;
/**
* The id of the bundle that will contain the framework to run. Defaults to org.eclipse.osgi.
*/
protected String framework = OSGI;
/**
* The extra development time class path entries for the framework.
*/
protected String devClassPath = null;
/*
* The extra development time class path entries for all bundles.
*/
private Properties devClassPathProps = null;
/**
* Indicates whether this instance is running in development mode.
*/
protected boolean inDevelopmentMode = false;
/**
* Indicates which OS was passed in with -os
*/
protected String os = null;
protected String ws = null;
protected String arch = null;
// private String name = null; // The name to brand the launcher
// private String launcher = null; // The full path to the launcher
private String library = null;
private String exitData = null;
private String vm = null;
private String[] vmargs = null;
private String[] commands = null;
String[] extensionPaths = null;
JNIBridge bridge = null;
// splash handling
private boolean showSplash = false;
private String splashLocation = null;
private String endSplash = null;
private boolean initialize = false;
protected boolean splashDown = false;
public final class SplashHandler extends Thread {
@Override
public void run() {
takeDownSplash();
}
public void updateSplash() {
if (bridge != null && !splashDown) {
bridge.updateSplash();
}
}
}
private final Thread splashHandler = new SplashHandler();
//splash screen system properties
public static final String SPLASH_HANDLE = "org.eclipse.equinox.launcher.splash.handle"; //$NON-NLS-1$
public static final String SPLASH_LOCATION = "org.eclipse.equinox.launcher.splash.location"; //$NON-NLS-1$
// command line args
private static final String FRAMEWORK = "-framework"; //$NON-NLS-1$
private static final String INSTALL = "-install"; //$NON-NLS-1$
private static final String INITIALIZE = "-initialize"; //$NON-NLS-1$
private static final String VM = "-vm"; //$NON-NLS-1$
private static final String VMARGS = "-vmargs"; //$NON-NLS-1$
private static final String DEBUG = "-debug"; //$NON-NLS-1$
private static final String DEV = "-dev"; //$NON-NLS-1$
private static final String CONFIGURATION = "-configuration"; //$NON-NLS-1$
private static final String NOSPLASH = "-nosplash"; //$NON-NLS-1$
private static final String SHOWSPLASH = "-showsplash"; //$NON-NLS-1$
private static final String EXITDATA = "-exitdata"; //$NON-NLS-1$
private static final String NAME = "-name"; //$NON-NLS-1$
private static final String LAUNCHER = "-launcher"; //$NON-NLS-1$
private static final String PROTECT = "-protect"; //$NON-NLS-1$
//currently the only level of protection we care about.
private static final String PROTECT_MASTER = "master"; //$NON-NLS-1$
private static final String PROTECT_BASE = "base"; //$NON-NLS-1$
private static final String LIBRARY = "--launcher.library"; //$NON-NLS-1$
private static final String APPEND_VMARGS = "--launcher.appendVmargs"; //$NON-NLS-1$
private static final String OVERRIDE_VMARGS = "--launcher.overrideVmargs"; //$NON-NLS-1$
private static final String NL = "-nl"; //$NON-NLS-1$
private static final String ENDSPLASH = "-endsplash"; //$NON-NLS-1$
private static final String[] SPLASH_IMAGES = {"splash.png", //$NON-NLS-1$
"splash.jpg", //$NON-NLS-1$
"splash.jpeg", //$NON-NLS-1$
"splash.gif", //$NON-NLS-1$
"splash.bmp", //$NON-NLS-1$
};
private static final String CLEAN = "-clean"; //$NON-NLS-1$
private static final String NOEXIT = "-noExit"; //$NON-NLS-1$
private static final String OS = "-os"; //$NON-NLS-1$
private static final String WS = "-ws"; //$NON-NLS-1$
private static final String ARCH = "-arch"; //$NON-NLS-1$
private static final String STARTUP = "-startup"; //$NON-NLS-1$
private static final String OSGI = "org.eclipse.osgi"; //$NON-NLS-1$
private static final String STARTER = "org.eclipse.core.runtime.adaptor.EclipseStarter"; //$NON-NLS-1$
private static final String PLATFORM_URL = "platform:/base/"; //$NON-NLS-1$
private static final String ECLIPSE_PROPERTIES = "eclipse.properties"; //$NON-NLS-1$
private static final String FILE_SCHEME = "file:"; //$NON-NLS-1$
protected static final String REFERENCE_SCHEME = "reference:"; //$NON-NLS-1$
protected static final String JAR_SCHEME = "jar:"; //$NON-NLS-1$
// constants: configuration file location
private static final String CONFIG_DIR = "configuration/"; //$NON-NLS-1$
private static final String CONFIG_FILE = "config.ini"; //$NON-NLS-1$
private static final String CONFIG_FILE_TEMP_SUFFIX = ".tmp"; //$NON-NLS-1$
private static final String CONFIG_FILE_BAK_SUFFIX = ".bak"; //$NON-NLS-1$
private static final String ECLIPSE = "eclipse"; //$NON-NLS-1$
private static final String PRODUCT_SITE_MARKER = ".eclipseproduct"; //$NON-NLS-1$
private static final String PRODUCT_SITE_ID = "id"; //$NON-NLS-1$
private static final String PRODUCT_SITE_VERSION = "version"; //$NON-NLS-1$
// constants: System property keys and/or configuration file elements
private static final String PROP_USER_HOME = "user.home"; //$NON-NLS-1$
private static final String PROP_USER_DIR = "user.dir"; //$NON-NLS-1$
private static final String PROP_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$
private static final String PROP_CONFIG_AREA = "osgi.configuration.area"; //$NON-NLS-1$
private static final String PROP_CONFIG_AREA_DEFAULT = "osgi.configuration.area.default"; //$NON-NLS-1$
private static final String PROP_BASE_CONFIG_AREA = "osgi.baseConfiguration.area"; //$NON-NLS-1$
private static final String PROP_SHARED_CONFIG_AREA = "osgi.sharedConfiguration.area"; //$NON-NLS-1$
private static final String PROP_CONFIG_CASCADED = "osgi.configuration.cascaded"; //$NON-NLS-1$
protected static final String PROP_FRAMEWORK = "osgi.framework"; //$NON-NLS-1$
private static final String PROP_SPLASHPATH = "osgi.splashPath"; //$NON-NLS-1$
private static final String PROP_SPLASHLOCATION = "osgi.splashLocation"; //$NON-NLS-1$
private static final String PROP_CLASSPATH = "osgi.frameworkClassPath"; //$NON-NLS-1$
private static final String PROP_EXTENSIONS = "osgi.framework.extensions"; //$NON-NLS-1$
private static final String PROP_FRAMEWORK_SYSPATH = "osgi.syspath"; //$NON-NLS-1$
private static final String PROP_FRAMEWORK_SHAPE = "osgi.framework.shape"; //$NON-NLS-1$
private static final String PROP_LOGFILE = "osgi.logfile"; //$NON-NLS-1$
private static final String PROP_REQUIRED_JAVA_VERSION = "osgi.requiredJavaVersion"; //$NON-NLS-1$
private static final String PROP_PARENT_CLASSLOADER = "osgi.parentClassloader"; //$NON-NLS-1$
private static final String PROP_FRAMEWORK_PARENT_CLASSLOADER = "osgi.frameworkParentClassloader"; //$NON-NLS-1$
private static final String PROP_NL = "osgi.nl"; //$NON-NLS-1$
static final String PROP_NOSHUTDOWN = "osgi.noShutdown"; //$NON-NLS-1$
private static final String PROP_DEBUG = "osgi.debug"; //$NON-NLS-1$
private static final String PROP_OS = "osgi.os"; //$NON-NLS-1$
private static final String PROP_WS = "osgi.ws"; //$NON-NLS-1$
private static final String PROP_ARCH = "osgi.arch"; //$NON-NLS-1$
private static final String PROP_EXITCODE = "eclipse.exitcode"; //$NON-NLS-1$
private static final String PROP_EXITDATA = "eclipse.exitdata"; //$NON-NLS-1$
private static final String PROP_LAUNCHER = "eclipse.launcher"; //$NON-NLS-1$
private static final String PROP_LAUNCHER_NAME = "eclipse.launcher.name"; //$NON-NLS-1$
private static final String PROP_VM = "eclipse.vm"; //$NON-NLS-1$
private static final String PROP_VMARGS = "eclipse.vmargs"; //$NON-NLS-1$
private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$
private static final String PROP_ECLIPSESECURITY = "eclipse.security"; //$NON-NLS-1$
// Suffix for location properties - see LocationManager.
private static final String READ_ONLY_AREA_SUFFIX = ".readOnly"; //$NON-NLS-1$
// Data mode constants for user, configuration and data locations.
private static final String NONE = "@none"; //$NON-NLS-1$
private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$
private static final String USER_HOME = "@user.home"; //$NON-NLS-1$
private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$
// Placeholder for hashcode of installation directory
private static final String INSTALL_HASH_PLACEHOLDER = "@install.hash"; //$NON-NLS-1$
private static final String LAUNCHER_DIR = "@launcher.dir"; //$NON-NLS-1$
// types of parent classloaders the framework can have
private static final String PARENT_CLASSLOADER_APP = "app"; //$NON-NLS-1$
private static final String PARENT_CLASSLOADER_EXT = "ext"; //$NON-NLS-1$
private static final String PARENT_CLASSLOADER_BOOT = "boot"; //$NON-NLS-1$
private static final String PARENT_CLASSLOADER_CURRENT = "current"; //$NON-NLS-1$
// log file handling
protected static final String SESSION = "!SESSION"; //$NON-NLS-1$
protected static final String ENTRY = "!ENTRY"; //$NON-NLS-1$
protected static final String MESSAGE = "!MESSAGE"; //$NON-NLS-1$
protected static final String STACK = "!STACK"; //$NON-NLS-1$
protected static final int ERROR = 4;
protected static final String PLUGIN_ID = "org.eclipse.equinox.launcher"; //$NON-NLS-1$
protected File logFile = null;
protected BufferedWriter log = null;
protected boolean newSession = true;
private boolean protectBase = false;
// for variable substitution
public static final String VARIABLE_DELIM_STRING = "$"; //$NON-NLS-1$
public static final char VARIABLE_DELIM_CHAR = '$';
//for change detection in the base when running in shared install mode
private static final long NO_TIMESTAMP = -1;
private static final String BASE_TIMESTAMP_FILE_CONFIGINI = ".baseConfigIniTimestamp"; //$NON-NLS-1$
private static final String KEY_CONFIGINI_TIMESTAMP = "configIniTimestamp"; //$NON-NLS-1$
private static final String PROP_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$
/**
* A structured form for a version identifier.
*
* @see "http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html for information on valid version strings"
* @see "http://openjdk.java.net/jeps/223 for information on the JavaSE-9 version JEP 223"
*/
static class Identifier {
private static final String DELIM = ". _-"; //$NON-NLS-1$
private int major, minor, service;
Identifier(int major, int minor, int service) {
super();
this.major = major;
this.minor = minor;
this.service = service;
}
/**
* @throws NumberFormatException if cannot parse the major and minor version components
*/
Identifier(String versionString) {
super();
StringTokenizer tokenizer = new StringTokenizer(versionString, DELIM);
// major
if (tokenizer.hasMoreTokens())
major = Integer.parseInt(tokenizer.nextToken());
try {
// minor
if (tokenizer.hasMoreTokens())
minor = Integer.parseInt(tokenizer.nextToken());
// service
if (tokenizer.hasMoreTokens())
service = Integer.parseInt(tokenizer.nextToken());
} catch (NumberFormatException nfe) {
// ignore the minor and service qualifiers in that case and default to 0
// this will allow us to tolerate other non-conventional version numbers
}
}
/**
* Returns true if this id is considered to be greater than or equal to the given baseline.
* e.g.
* 1.2.9 >= 1.3.1 -> false
* 1.3.0 >= 1.3.1 -> false
* 1.3.1 >= 1.3.1 -> true
* 1.3.2 >= 1.3.1 -> true
* 2.0.0 >= 1.3.1 -> true
*/
boolean isGreaterEqualTo(Identifier minimum) {
if (major < minimum.major)
return false;
if (major > minimum.major)
return true;
// major numbers are equivalent so check minor
if (minor < minimum.minor)
return false;
if (minor > minimum.minor)
return true;
// minor numbers are equivalent so check service
return service >= minimum.service;
}
}
private String getWS() {
if (ws != null)
return ws;
String osgiWs = System.getProperty(PROP_WS);
if (osgiWs != null) {
ws = osgiWs;
return ws;
}
String osName = getOS();
if (osName.equals(Constants.OS_WIN32))
return Constants.WS_WIN32;
if (osName.equals(Constants.OS_LINUX))
return Constants.WS_GTK;
if (osName.equals(Constants.OS_MACOSX))
return Constants.WS_COCOA;
if (osName.equals(Constants.OS_HPUX))
return Constants.WS_GTK;
if (osName.equals(Constants.OS_AIX))
return Constants.WS_GTK;
if (osName.equals(Constants.OS_SOLARIS))
return Constants.WS_GTK;
if (osName.equals(Constants.OS_QNX))
return Constants.WS_PHOTON;
return Constants.WS_UNKNOWN;
}
private String getOS() {
if (os != null)
return os;
String osgiOs = System.getProperty(PROP_OS);
if (osgiOs != null) {
os = osgiOs;
return os;
}
String osName = System.getProperty("os.name"); //$NON-NLS-1$
if (osName.regionMatches(true, 0, Constants.OS_WIN32, 0, 3))
return Constants.OS_WIN32;
// EXCEPTION: All mappings of SunOS convert to Solaris
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_SUNOS))
return Constants.OS_SOLARIS;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_LINUX))
return Constants.OS_LINUX;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_QNX))
return Constants.OS_QNX;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_AIX))
return Constants.OS_AIX;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_HPUX))
return Constants.OS_HPUX;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_OS400))
return Constants.OS_OS400;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_OS390))
return Constants.OS_OS390;
if (osName.equalsIgnoreCase(Constants.INTERNAL_OS_ZOS))
return Constants.OS_ZOS;
// os.name on Mac OS can be either Mac OS or Mac OS X
if (osName.regionMatches(true, 0, Constants.INTERNAL_OS_MACOSX, 0, Constants.INTERNAL_OS_MACOSX.length()))
return Constants.OS_MACOSX;
return Constants.OS_UNKNOWN;
}
private String getArch() {
if (arch != null)
return arch;
String osgiArch = System.getProperty(PROP_ARCH);
if (osgiArch != null) {
arch = osgiArch;
return arch;
}
String name = System.getProperty("os.arch");//$NON-NLS-1$
// Map amd64 architecture to x86_64
if (name.equalsIgnoreCase(Constants.INTERNAL_AMD64))
return Constants.ARCH_X86_64;
return name;
}
private String getFragmentString(String fragmentOS, String fragmentWS, String fragmentArch) {
StringJoiner buffer = new StringJoiner("."); //$NON-NLS-1$
buffer.add(PLUGIN_ID).add(fragmentWS).add(fragmentOS);
if (!(fragmentOS.equals(Constants.OS_MACOSX) && !Constants.ARCH_X86_64.equals(fragmentArch))) {
buffer.add(fragmentArch);
}
return buffer.toString();
}
/**
* Sets up the JNI bridge to native calls
*/
private void setupJNI(URL[] defaultPath) {
if (bridge != null)
return;
String libPath = null;
if (library != null) {
File lib = new File(library);
if (lib.isDirectory()) {
libPath = searchFor("eclipse", lib.getAbsolutePath()); //$NON-NLS-1$
} else if (lib.exists()) {
libPath = lib.getAbsolutePath();
}
}
if (libPath == null) {
//find our fragment name
String fragmentOS = getOS();
String fragmentWS = getWS();
String fragmentArch = getArch();
libPath = getLibraryPath(getFragmentString(fragmentOS, fragmentWS, fragmentArch), defaultPath);
}
library = libPath;
if (library != null)
bridge = new JNIBridge(library);
}
private String getLibraryPath(String fragmentName, URL[] defaultPath) {
String libPath = null;
String fragment = null;
if (inDevelopmentMode && devClassPathProps != null) {
String devPathList = devClassPathProps.getProperty(PLUGIN_ID);
String[] locations = getArrayFromList(devPathList);
if (locations.length > 0) {
File location = new File(locations[0]);
if (location.isAbsolute()) {
String dir = location.getParent();
fragment = searchFor(fragmentName, dir);
if (fragment != null)
libPath = getLibraryFromFragment(fragment);
}
}
}
if (libPath == null && bootLocation != null) {
URL[] urls = defaultPath;
if (urls != null && urls.length > 0) {
//the last one is most interesting
for (int i = urls.length - 1; i >= 0 && libPath == null; i--) {
File entryFile = new File(urls[i].getFile());
String dir = entryFile.getParent();
if (inDevelopmentMode) {
String devDir = dir + "/" + PLUGIN_ID + "/fragments"; //$NON-NLS-1$ //$NON-NLS-2$
fragment = searchFor(fragmentName, devDir);
}
if (fragment == null)
fragment = searchFor(fragmentName, dir);
if (fragment != null)
libPath = getLibraryFromFragment(fragment);
}
}
}
if (libPath == null) {
URL install = getInstallLocation();
String location = install.getFile();
location += "/plugins/"; //$NON-NLS-1$
fragment = searchFor(fragmentName, location);
if (fragment != null)
libPath = getLibraryFromFragment(fragment);
}
return libPath;
}
private String getLibraryFromFragment(String fragment) {
if (fragment.startsWith(FILE_SCHEME))
fragment = fragment.substring(5);
File frag = new File(fragment);
if (!frag.exists())
return null;
if (frag.isDirectory())
return searchFor("eclipse", fragment); //$NON-NLS-1$;
try (ZipFile fragmentJar = new ZipFile(frag)) {
Enumeration<? extends ZipEntry> entries = fragmentJar.entries();
String entry = null;
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
if (zipEntry.getName().startsWith("eclipse_")) { //$NON-NLS-1$
entry = zipEntry.getName();
break;
}
}
if (entry != null) {
String lib = extractFromJAR(fragment, entry);
if (!getOS().equals("win32")) { //$NON-NLS-1$
try {
Runtime.getRuntime().exec(new String[] {"chmod", "755", lib}).waitFor(); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Throwable e) {
//ignore
}
}
return lib;
}
} catch (IOException e) {
log("Exception opening JAR file: " + fragment); //$NON-NLS-1$
log(e);
return null;
}
return null;
}
/**
* Executes the launch.
*
* @param args command-line arguments
* @exception Exception thrown if a problem occurs during the launch
*/
protected void basicRun(String[] args) throws Exception {
System.setProperty("eclipse.startTime", Long.toString(System.currentTimeMillis())); //$NON-NLS-1$
commands = args;
String[] passThruArgs = processCommandLine(args);
if (!debug)
// debug can be specified as system property as well
debug = System.getProperty(PROP_DEBUG) != null;
setupVMProperties();
processConfiguration();
if (protectBase && (System.getProperty(PROP_SHARED_CONFIG_AREA) == null)) {
System.err.println("This application is configured to run in a cascaded mode only."); //$NON-NLS-1$
System.setProperty(PROP_EXITCODE, Integer.toString(14));
return;
}
// need to ensure that getInstallLocation is called at least once to initialize the value.
// Do this AFTER processing the configuration to allow the configuration to set
// the install location.
getInstallLocation();
// locate boot plugin (may return -dev mode variations)
URL[] bootPath = getBootPath(bootLocation);
//Set up the JNI bridge. We need to know the install location to find the shared library
setupJNI(bootPath);
//ensure minimum Java version, do this after JNI is set up so that we can write an error message
//with exitdata if we fail.
if (!checkVersion(System.getProperty("java.version"), System.getProperty(PROP_REQUIRED_JAVA_VERSION))) //$NON-NLS-1$
return;
// verify configuration location is writable
if (!checkConfigurationLocation(configurationLocation))
return;
setSecurityPolicy(bootPath);
// splash handling is done here, because the default case needs to know
// the location of the boot plugin we are going to use
handleSplash(bootPath);
beforeFwkInvocation();
invokeFramework(passThruArgs, bootPath);
}
protected void beforeFwkInvocation() {
//Nothing to do.
}
protected void setSecurityPolicy(URL[] bootPath) {
String eclipseSecurity = System.getProperty(PROP_ECLIPSESECURITY);
if (eclipseSecurity != null) {
// setup a policy that grants the launcher and path for the framework AllPermissions.
// Do not set the security manager, this will be done by the framework itself.
ProtectionDomain domain = Main.class.getProtectionDomain();
CodeSource source = null;
if (domain != null)
source = Main.class.getProtectionDomain().getCodeSource();
if (domain == null || source == null) {
log("Can not automatically set the security manager. Please use a policy file."); //$NON-NLS-1$
return;
}
// get the list of codesource URLs to grant AllPermission to
URL[] rootURLs = new URL[bootPath.length + 1];
rootURLs[0] = source.getLocation();
System.arraycopy(bootPath, 0, rootURLs, 1, bootPath.length);
// replace the security policy
Policy eclipsePolicy = new EclipsePolicy(Policy.getPolicy(), rootURLs);
Policy.setPolicy(eclipsePolicy);
}
}
private void invokeFramework(String[] passThruArgs, URL[] bootPath) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, Error, Exception, InvocationTargetException {
String type = PARENT_CLASSLOADER_BOOT;
try {
String javaVersion = System.getProperty("java.version"); //$NON-NLS-1$
if (javaVersion != null && new Identifier(javaVersion).isGreaterEqualTo(new Identifier("1.9"))) { //$NON-NLS-1$
// Workaround for bug 466683. Some org.w3c.dom.* packages that used to be available from
// JavaSE's boot classpath are only available from the extension path in Java 9 b62.
// Workaround for bug 489958. javax.annotation.* types are only available from
// JavaSE-9's extension path in Java 9-ea+108. The identifier "1.9" could be changed to "9", but "1.9" works just as well.
type = PARENT_CLASSLOADER_EXT;
}
} catch (SecurityException | NumberFormatException e) {
// If the security manager won't allow us to get the system property, continue for
// now and let things fail later on their own if necessary.
// If the version string was in a format that we don't understand, continue and
// let things fail later on their own if necessary.
}
type = System.getProperty(PROP_PARENT_CLASSLOADER, type);
type = System.getProperty(PROP_FRAMEWORK_PARENT_CLASSLOADER, type);
ClassLoader parent = null;
if (PARENT_CLASSLOADER_APP.equalsIgnoreCase(type))
parent = ClassLoader.getSystemClassLoader();
else if (PARENT_CLASSLOADER_EXT.equalsIgnoreCase(type)) {
ClassLoader appCL = ClassLoader.getSystemClassLoader();
if (appCL != null)
parent = appCL.getParent();
} else if (PARENT_CLASSLOADER_CURRENT.equalsIgnoreCase(type))
parent = this.getClass().getClassLoader();
@SuppressWarnings("resource")
URLClassLoader loader = new StartupClassLoader(bootPath, parent);
Class<?> clazz = loader.loadClass(STARTER);
Method method = clazz.getDeclaredMethod("run", String[].class, Runnable.class); //$NON-NLS-1$
try {
method.invoke(clazz, passThruArgs, splashHandler);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
else if (e.getTargetException() instanceof Exception)
throw (Exception) e.getTargetException();
else
//could be a subclass of Throwable!
throw e;
}
}
/**
* Checks whether the given available version is greater or equal to the
* given required version.
* <p>Will set PROP_EXITCODE/PROP_EXITDATA accordingly if check fails.</p>
*
* @return a boolean indicating whether the checking passed
*/
private boolean checkVersion(String availableVersion, String requiredVersion) {
if (requiredVersion == null || availableVersion == null)
return true;
try {
Identifier required = new Identifier(requiredVersion);
Identifier available = new Identifier(availableVersion);
boolean compatible = available.isGreaterEqualTo(required);
if (!compatible) {
// any non-zero value should do it - 14 used to be used for version incompatibility in Eclipse 2.1
System.setProperty(PROP_EXITCODE, "14"); //$NON-NLS-1$
System.setProperty(PROP_EXITDATA, "<title>Incompatible JVM</title>Version " + availableVersion + " of the JVM is not suitable for this product. Version: " + requiredVersion + " or greater is required."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return compatible;
} catch (SecurityException | NumberFormatException e) {
// If the security manager won't allow us to get the system property, continue for
// now and let things fail later on their own if necessary.
// If the version string was in a format that we don't understand, continue and
// let things fail later on their own if necessary.
return true;
}
}
/**
* Checks whether the given location can be created and is writable.
* If the system property "osgi.configuration.area.readOnly" is set
* the check always succeeds.
* <p>Will set PROP_EXITCODE/PROP_EXITDATA accordingly if check fails.</p>
*
* @param locationUrl configuration area URL, may be <code>null</code>
* @return a boolean indicating whether the checking passed
*/
private boolean checkConfigurationLocation(URL locationUrl) {
if (locationUrl == null || !"file".equals(locationUrl.getProtocol())) //$NON-NLS-1$
return true;
if (Boolean.parseBoolean(System.getProperty(PROP_CONFIG_AREA + READ_ONLY_AREA_SUFFIX))) {
// user wants readonly config area
return true;
}
File configDir = new File(locationUrl.getFile()).getAbsoluteFile();
if (!configDir.exists()) {
configDir.mkdirs();
if (!configDir.exists()) {
System.setProperty(PROP_EXITCODE, "15"); //$NON-NLS-1$
System.setProperty(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$
"' could not be created. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$
return false;
}
}
if (!canWrite(configDir, getOS())) {
System.setProperty(PROP_EXITCODE, "15"); //$NON-NLS-1$
System.setProperty(PROP_EXITDATA, "<title>Invalid Configuration Location</title>The configuration area at '" + configDir + //$NON-NLS-1$
"' is not writable. Please choose a writable location using the '-configuration' command line option."); //$NON-NLS-1$
return false;
}
return true;
}
/**
* Returns a string representation of the given URL String. This converts
* escaped sequences (%..) in the URL into the appropriate characters.
* NOTE: due to class visibility there is a copy of this method
* in InternalBootLoader
*/
protected String decode(String urlString) {
try {
//first encode '+' characters, because URLDecoder incorrectly converts
//them to spaces on certain class library implementations.
if (urlString.indexOf('+') >= 0) {
int len = urlString.length();
StringBuilder buf = new StringBuilder(len);
for (int i = 0; i < len; i++) {
char c = urlString.charAt(i);
if (c == '+')
buf.append("%2B"); //$NON-NLS-1$
else
buf.append(c);
}
urlString = buf.toString();
}
return URLDecoder.decode(urlString, "UTF-8"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
/**
* Returns the result of converting a list of comma-separated tokens into an array
*
* @return the array of string tokens
* @param prop the initial comma-separated string
*/
protected String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals("")) //$NON-NLS-1$
return new String[0];
ArrayList<String> list = new ArrayList<>();
StringTokenizer tokens = new StringTokenizer(prop, ","); //$NON-NLS-1$
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.isEmpty()) {
list.add(token);
}
}
return list.isEmpty() ? new String[0] : list.toArray(new String[list.size()]);
}
/**
* Returns the <code>URL</code>-based class path describing where the boot classes
* are located when running in development mode.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
private URL[] getDevPath(URL base) throws IOException {
ArrayList<URL> result = new ArrayList<>(5);
if (inDevelopmentMode)
addDevEntries(base, result, OSGI);
//The jars from the base always need to be added, even when running in dev mode (bug 46772)
addBaseJars(base, result);
return result.toArray(new URL[result.size()]);
}
URL constructURL(URL url, String name) {
//Recognize the following URLs
//url: file:foo/dir/
//url: file:foo/file.jar
String externalForm = url.toExternalForm();
if (externalForm.endsWith(".jar")) { //$NON-NLS-1$
try {
return new URL(JAR_SCHEME + url + "!/" + name); //$NON-NLS-1$
} catch (MalformedURLException e) {
//Ignore
}
}
try {
return new URL(url, name);
} catch (MalformedURLException e) {
//Ignore
return null;
}
}
private void readFrameworkExtensions(URL base, ArrayList<URL> result) throws IOException {
String[] extensions = getArrayFromList(System.getProperty(PROP_EXTENSIONS));
String parent = new File(base.getFile()).getParent();
ArrayList<String> extensionResults = new ArrayList<>(extensions.length);
for (String extension : extensions) {
//Search the extension relatively to the osgi plugin
String path = searchForBundle(extension, parent);
if (path == null) {
log("Could not find extension: " + extension); //$NON-NLS-1$
continue;
}
if (debug) {
System.out.println("Loading extension: " + extension); //$NON-NLS-1$
}
URL extensionURL = null;
if (installLocation.getProtocol().equals("file")) { //$NON-NLS-1$
extensionResults.add(path);
extensionURL = new File(path).toURL();
} else
extensionURL = new URL(installLocation.getProtocol(), installLocation.getHost(), installLocation.getPort(), path);
//Load a property file of the extension, merge its content, and in case of dev mode add the bin entries
Properties extensionProperties = null;
try {
extensionProperties = loadProperties(constructURL(extensionURL, ECLIPSE_PROPERTIES));
} catch (IOException e) {
if (debug)
System.out.println("\t" + ECLIPSE_PROPERTIES + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
}
String extensionClassPath = null;
if (extensionProperties != null)
extensionClassPath = extensionProperties.getProperty(PROP_CLASSPATH);
else
// this is a "normal" RFC 101 framework extension bundle just put the base path on the classpath
extensionProperties = new Properties();
String[] entries = extensionClassPath == null || extensionClassPath.length() == 0 ? new String[] {""} : getArrayFromList(extensionClassPath); //$NON-NLS-1$
String qualifiedPath;
if (System.getProperty(PROP_CLASSPATH) == null)
qualifiedPath = "."; //$NON-NLS-1$
else
qualifiedPath = ""; //$NON-NLS-1$
for (String entry : entries) {
qualifiedPath += ", " + FILE_SCHEME + path + entry; //$NON-NLS-1$
}
extensionProperties.put(PROP_CLASSPATH, qualifiedPath);
mergeWithSystemProperties(extensionProperties, null);
if (inDevelopmentMode) {
String name = extension;
if (name.startsWith(REFERENCE_SCHEME)) {
// need to extract the BSN from the path
name = new File(path).getName();
// Note that we do not extract any version information.
// We assume the extension is located in the workspace in a project
// that has the same name as the BSN.
// We could add more logic here to support versions in project folder names
// but it will likely be complicated and error prone.
}
addDevEntries(extensionURL, result, name);
}
}
extensionPaths = extensionResults.toArray(new String[extensionResults.size()]);
}
private void addBaseJars(URL base, ArrayList<URL> result) throws IOException {
String baseJarList = System.getProperty(PROP_CLASSPATH);
if (baseJarList == null) {
readFrameworkExtensions(base, result);
baseJarList = System.getProperty(PROP_CLASSPATH);
}
File fwkFile = new File(base.getFile());
boolean fwkIsDirectory = fwkFile.isDirectory();
//We found where the fwk is, remember it and its shape
if (fwkIsDirectory) {
System.setProperty(PROP_FRAMEWORK_SHAPE, "folder");//$NON-NLS-1$
} else {
System.setProperty(PROP_FRAMEWORK_SHAPE, "jar");//$NON-NLS-1$
}
String fwkPath = new File(new File(base.getFile()).getParent()).getAbsolutePath();
if (Character.isUpperCase(fwkPath.charAt(0))) {
char[] chars = fwkPath.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
fwkPath = new String(chars);
}
System.setProperty(PROP_FRAMEWORK_SYSPATH, fwkPath);
String[] baseJars = getArrayFromList(baseJarList);
if (baseJars.length == 0) {
if (!inDevelopmentMode && new File(base.getFile()).isDirectory())
throw new IOException("Unable to initialize " + PROP_CLASSPATH); //$NON-NLS-1$
addEntry(base, result);
return;
}
for (String string : baseJars) {
try {
// if the string is a file: URL then *carefully* construct the
// URL. Otherwisejust try to build a URL. In either case, if we fail, use
// string as something to tack on the end of the base.
if (string.equals(".")) { //$NON-NLS-1$
addEntry(base, result);
}
URL url = null;
if (string.startsWith(FILE_SCHEME))
url = new File(string.substring(5)).toURL();
else
url = new URL(string);
addEntry(url, result);
} catch (MalformedURLException e) {
addEntry(new URL(base, string), result);
}
}
}
protected void addEntry(URL url, List<URL> result) {
if (new File(url.getFile()).exists())
result.add(url);
}
private void addDevEntries(URL base, List<URL> result, String symbolicName) throws MalformedURLException {
if (devClassPathProps == null)
return; // do nothing
String devPathList = devClassPathProps.getProperty(symbolicName);
if (devPathList == null)
devPathList = devClassPathProps.getProperty("*"); //$NON-NLS-1$
String[] locations = getArrayFromList(devPathList);
for (String location : locations) {
File path = new File(location);
URL url;
if (path.isAbsolute())
url = path.toURL();
else {
// dev path is relative, combine with base location
char lastChar = location.charAt(location.length() - 1);
if ((location.endsWith(".jar") || (lastChar == '/' || lastChar == '\\'))) //$NON-NLS-1$
url = new URL(base, location);
else
url = new URL(base, location + "/"); //$NON-NLS-1$
}
addEntry(url, result);
}
}
/**
* Returns the <code>URL</code>-based class path describing where the boot classes are located.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
private URL[] getBootPath(String base) throws IOException {
URL url = null;
if (base != null) {
url = buildURL(base, true);
} else {
// search in the root location
url = getInstallLocation();
String pluginsLocation = new File(url.getFile(), "plugins").toString(); //$NON-NLS-1$
String path = searchFor(framework, pluginsLocation);
if (path == null)