forked from eclipse-equinox/equinox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JNIBridge.java
186 lines (165 loc) · 4.31 KB
/
JNIBridge.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
/*******************************************************************************
* Copyright (c) 2006, 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
* Rapicorp, Inc - Default the configuration to Application Support (bug 461725)
*******************************************************************************/
package org.eclipse.equinox.launcher;
/**
* <b>Note:</b> This class should not be referenced programmatically by
* other Java code. This class exists only for the purpose of interacting with
* a native launcher. To launch Eclipse programmatically, use
* org.eclipse.core.runtime.adaptor.EclipseStarter. This class is not API.
*
*/
class JNIBridge {
private native void _set_exit_data(String sharedId, String data);
private native void _set_launcher_info(String launcher, String name);
private native void _update_splash();
private native long _get_splash_handle();
private native void _show_splash(String bitmap);
private native void _takedown_splash();
private native String _get_os_recommended_folder();
private native int OleInitialize(int reserved);
private native void OleUninitialize();
private String library;
private boolean libraryLoaded = false;
/**
* @param library the given library
*/
public JNIBridge(String library) {
this.library = library;
}
private void loadLibrary() {
if (library != null) {
try {
if (library.contains("wpf")) { //$NON-NLS-1$
int idx = library.indexOf("eclipse_"); //$NON-NLS-1$
if (idx != -1) {
String comLibrary = library.substring(0, idx) + "com_"; //$NON-NLS-1$
comLibrary += library.substring(idx + 8, library.length());
Runtime.getRuntime().load(comLibrary);
OleInitialize(0);
}
}
Runtime.getRuntime().load(library);
} catch (UnsatisfiedLinkError e) {
//failed
}
}
libraryLoaded = true;
}
public boolean setExitData(String sharedId, String data) {
try {
_set_exit_data(sharedId, data);
return true;
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return setExitData(sharedId, data);
}
return false;
}
}
public boolean setLauncherInfo(String launcher, String name) {
try {
_set_launcher_info(launcher, name);
return true;
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return setLauncherInfo(launcher, name);
}
return false;
}
}
public boolean showSplash(String bitmap) {
try {
_show_splash(bitmap);
return true;
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return showSplash(bitmap);
}
return false;
}
}
public boolean updateSplash() {
try {
_update_splash();
return true;
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return updateSplash();
}
return false;
}
}
public long getSplashHandle() {
try {
return _get_splash_handle();
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return getSplashHandle();
}
return -1;
}
}
/**
* Whether or not we loaded the shared library here from java.
* False does not imply the library is not available, it could have
* been loaded natively by the executable.
*
* @return boolean
*/
boolean isLibraryLoadedByJava() {
return libraryLoaded;
}
public boolean takeDownSplash() {
try {
_takedown_splash();
return true;
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return takeDownSplash();
}
return false;
}
}
public boolean uninitialize() {
if (libraryLoaded && library != null) {
if (library.contains("wpf")) { //$NON-NLS-1$
try {
OleUninitialize();
} catch (UnsatisfiedLinkError e) {
// library not loaded
return false;
}
}
}
return true;
}
public String getOSRecommendedFolder() {
try {
return _get_os_recommended_folder();
} catch (UnsatisfiedLinkError e) {
if (!libraryLoaded) {
loadLibrary();
return getOSRecommendedFolder();
}
return null;
}
}
}