Skip to content

Commit 3c285ae

Browse files
committed
fix(bridge): re-introduce isPackagedElectron flag for java lb
1 parent 379e7ad commit 3c285ae

10 files changed

Lines changed: 27 additions & 20 deletions

File tree

crates/java-bridge/src/node/helpers/arg_convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn call_context_to_java_args<'a>(
2626
Ok(res)
2727
}
2828

29-
pub fn call_results_to_args(args: &[JavaCallResult]) -> Vec<JavaArg> {
29+
pub fn call_results_to_args(args: &'_ [JavaCallResult]) -> Vec<JavaArg<'_>> {
3030
args.iter()
3131
.map(|arg| arg.as_arg())
3232
.collect::<Vec<JavaArg>>()

crates/java-bridge/src/node/java.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ pub struct Java {
3838
impl Java {
3939
/// Create a new JVM instance.
4040
/// @param libPath The path to jvm.(dll|so|dylib)
41-
/// @param version The JVM version to use.
42-
/// @param opts The JVM options to use.
41+
/// @param version The JVM version to use
42+
/// @param opts The JVM options to use
43+
/// @param javaOptions additional options to pass to the jvm
44+
/// @param javaLibPath the path to the java library (JavaBridge.jar)
45+
/// @param nativeLibPath the path to the native library (java.*.\[dll|so|dylib])
4346
#[napi(constructor)]
4447
pub fn new(
4548
lib_path: Option<String>,

crates/java-bridge/src/node/java_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub struct JavaOptions {
66
/// Additional items to add to the class path. This does allow for wildcard imports
77
/// using glob patterns. If a path is unreadable, an error will be thrown.
8-
/// This behaviour can be changed by setting `ignore_unreadable_class_path_entries` to true.
8+
/// This behavior can be changed by setting `ignore_unreadable_class_path_entries` to true.
99
pub classpath: Option<Vec<String>>,
1010
/// Whether to ignore unreadable class path entries
1111
pub ignore_unreadable_class_path_entries: Option<bool>,

crates/java-rs/src/java/java_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> JavaEnv<'a> {
4141
jni_version_to_string(version)
4242
}
4343

44-
pub fn find_class(&self, class_name: &str) -> ResultType<JavaClass> {
44+
pub fn find_class(&'_ self, class_name: &str) -> ResultType<JavaClass<'_>> {
4545
self.0.find_class(class_name, true)
4646
}
4747

crates/java-rs/src/java/java_env_wrapper.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'a> JavaEnvWrapper<'a> {
476476
.as_ref()
477477
.ok_or("The jvm was unset".to_string())?
478478
.lock()
479-
.unwrap()
479+
.map_err(|_| "Could not lock mutex".to_string())?
480480
.class_loader()
481481
.clone()
482482
.unwrap();
@@ -518,7 +518,7 @@ impl<'a> JavaEnvWrapper<'a> {
518518
.as_ref()
519519
.ok_or("The jvm was unset".to_string())?
520520
.lock()
521-
.unwrap()
521+
.map_err(|_| "Could not lock mutex".to_string())?
522522
.class_loader()
523523
.clone()
524524
.unwrap();
@@ -1189,10 +1189,10 @@ impl<'a> JavaEnvWrapper<'a> {
11891189
}
11901190

11911191
pub fn create_object_array(
1192-
&self,
1192+
&'_ self,
11931193
class: &'a JavaClass<'a>,
11941194
len: i32,
1195-
) -> ResultType<JavaObjectArray> {
1195+
) -> ResultType<JavaObjectArray<'_>> {
11961196
let arr = unsafe {
11971197
self.methods.NewObjectArray.unwrap()(self.env, len, class.class(), ptr::null_mut())
11981198
};
@@ -1471,7 +1471,7 @@ impl<'a> JavaEnvWrapper<'a> {
14711471
.as_ref()
14721472
.ok_or("The jvm was unset".to_string())?
14731473
.lock()
1474-
.unwrap()
1474+
.map_err(|_| "Could not lock mutex".to_string())?
14751475
.class_loader()
14761476
.as_ref()
14771477
.unwrap()
@@ -1491,7 +1491,7 @@ impl<'a> JavaEnvWrapper<'a> {
14911491
.as_ref()
14921492
.ok_or("The jvm was unset".to_string())?
14931493
.lock()
1494-
.unwrap()
1494+
.map_err(|_| "Could not lock mutex".to_string())?
14951495
.set_class_loader(loader);
14961496

14971497
Ok(())

crates/java-rs/src/java/java_field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a> JavaObjectField<'a> {
185185
Self(field)
186186
}
187187

188-
pub fn get(&self, object: &JavaObject<'_>) -> ResultType<Option<JavaObject>> {
188+
pub fn get(&'_ self, object: &JavaObject<'_>) -> ResultType<Option<JavaObject<'_>>> {
189189
self.0.class.env().get_object_field(self, object)
190190
}
191191

@@ -257,7 +257,7 @@ impl<'a> StaticJavaObjectField<'a> {
257257
Self(field)
258258
}
259259

260-
pub fn get(&self) -> ResultType<Option<JavaObject>> {
260+
pub fn get(&'_ self) -> ResultType<Option<JavaObject<'_>>> {
261261
self.0
262262
.class
263263
.env()

crates/java-rs/src/java/objects/class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> JavaClass<'a> {
155155
StaticJavaBooleanMethod::new(method)
156156
}
157157

158-
pub fn get_constructor(&self, signature: &str) -> ResultType<JavaConstructor> {
158+
pub fn get_constructor(&'_ self, signature: &str) -> ResultType<JavaConstructor<'_>> {
159159
self.env().get_constructor(self, signature)
160160
}
161161

crates/java-rs/src/java/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ pub trait IsInstanceOf {
3333
}
3434

3535
pub trait GetClass {
36-
fn get_class(&self) -> ResultType<JavaClass>;
36+
fn get_class(&'_ self) -> ResultType<JavaClass<'_>>;
3737
}

ts-src/java.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ export interface JVMOptions extends JavaOptions {
8686
* in an altered classpath in your java application/library if your
8787
* application is using a custom classpath (e.g. Spring Boot).
8888
*
89-
* Also, it is not possible to restart the jvm after is has been started
89+
* Also, it is not possible to restart the jvm after it has been started
9090
* once, in order to alter the startup classpath. This is due to some
9191
* limitations with the destructor feature of the node.js native api,
9292
* which may not call the destructor in time and having two jvm instances
9393
* in the same application is not allowed by java. Additionally, destroying
94-
* the jvm instance may cause *undefined behaviour*, which may or may not
94+
* the jvm instance may cause *undefined behavior*, which may or may not
9595
* cause the application to crash. Let's not do that.
9696
*
9797
* @param options the options to use when creating the jvm
@@ -104,7 +104,7 @@ export function ensureJvm(options?: JVMOptions): boolean {
104104
options?.version,
105105
options?.opts,
106106
options,
107-
getJavaLibPath(),
107+
getJavaLibPath(options?.isPackagedElectron ?? false),
108108
getNativeLibPath(options?.isPackagedElectron ?? false)
109109
);
110110

ts-src/nativeLib.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ export function getNativeLibPath(isPackagedElectron: boolean): string {
9191
}
9292
}
9393

94-
export function getJavaLibPath(): string {
94+
export function getJavaLibPath(isPackagedElectron: boolean): string {
9595
const lib = path.join(__dirname, 'JavaBridge.jar');
9696

9797
if (fs.existsSync(lib) && fs.statSync(lib).isFile()) {
98-
return lib;
98+
if (isPackagedElectron) {
99+
return lib.replace(APP_ASAR_REGEX, APP_ASAR_UNPACKED);
100+
} else {
101+
return lib;
102+
}
99103
} else {
100104
throw new Error('JavaBridge.jar not found');
101105
}

0 commit comments

Comments
 (0)