@@ -162,13 +162,9 @@ pub fn get_jvm_dyn_lib_file_name() -> &'static str {
162
162
/// If `JAVA_HOME` is not defined, the function tries to locate it using the `java` executable.
163
163
pub fn locate_java_home ( ) -> errors:: Result < String > {
164
164
match & env:: var ( "JAVA_HOME" ) {
165
- Ok ( s) if s. is_empty ( ) => {
166
- do_locate_java_home ( )
167
- }
165
+ Ok ( s) if s. is_empty ( ) => do_locate_java_home ( ) ,
168
166
Ok ( java_home_env_var) => Ok ( java_home_env_var. clone ( ) ) ,
169
- Err ( _) => {
170
- do_locate_java_home ( )
171
- }
167
+ Err ( _) => do_locate_java_home ( ) ,
172
168
}
173
169
}
174
170
@@ -189,25 +185,31 @@ fn do_locate_java_home() -> errors::Result<String> {
189
185
}
190
186
191
187
let output = command. output ( ) . map_err ( |error| {
192
- let message = format ! ( "Command '{}' is not found in the system PATH ({})" , command_str, error) ;
188
+ let message = format ! (
189
+ "Command '{}' is not found in the system PATH ({})" ,
190
+ command_str, error
191
+ ) ;
193
192
errors:: JavaLocatorError :: new ( & message)
194
193
} ) ?;
195
- let java_exec_path = String :: from_utf8 ( output. stdout )
196
- . map ( |jp| {
197
- let mut lines: Vec < & str > = jp. lines ( ) . collect ( ) ;
198
- if lines. len ( ) > 1 {
199
- println ! ( "WARNING: java_locator found {} possible java locations: {}. Using the last one." ,
200
- lines. len( ) ,
201
- lines. join( ", " ) ) ;
202
- lines. remove ( lines. len ( ) - 1 ) . to_string ( )
203
- } else {
204
- jp
205
- }
206
- } ) ?;
194
+ let java_exec_path = String :: from_utf8 ( output. stdout ) . map ( |jp| {
195
+ let mut lines: Vec < & str > = jp. lines ( ) . collect ( ) ;
196
+ if lines. len ( ) > 1 {
197
+ println ! (
198
+ "WARNING: java_locator found {} possible java locations: {}. Using the last one." ,
199
+ lines. len( ) ,
200
+ lines. join( ", " )
201
+ ) ;
202
+ lines. remove ( lines. len ( ) - 1 ) . to_string ( )
203
+ } else {
204
+ jp
205
+ }
206
+ } ) ?;
207
207
208
208
// Return early in case that the java executable is not found
209
209
if java_exec_path. is_empty ( ) {
210
- Err ( errors:: JavaLocatorError :: new ( "Java is not installed or not added in the system PATH" ) ) ?
210
+ Err ( errors:: JavaLocatorError :: new (
211
+ "Java is not installed or not added in the system PATH" ,
212
+ ) ) ?
211
213
}
212
214
213
215
let mut test_path = PathBuf :: from ( java_exec_path. trim ( ) ) ;
@@ -230,17 +232,16 @@ fn do_locate_java_home() -> errors::Result<String> {
230
232
231
233
match test_path. to_str ( ) {
232
234
Some ( s) => Ok ( String :: from ( s) ) ,
233
- None => Err ( errors:: JavaLocatorError :: new ( & format ! ( "Could not convert path {:?} to String" , test_path) ) ) ,
235
+ None => Err ( errors:: JavaLocatorError :: new ( & format ! (
236
+ "Could not convert path {:?} to String" ,
237
+ test_path
238
+ ) ) ) ,
234
239
}
235
240
}
236
241
237
242
/// Returns the path that contains the `libjvm.so` (or `jvm.dll` in windows).
238
243
pub fn locate_jvm_dyn_library ( ) -> errors:: Result < String > {
239
- let jvm_dyn_lib_file_name = if is_windows ( ) {
240
- "jvm.dll"
241
- } else {
242
- "libjvm.*"
243
- } ;
244
+ let jvm_dyn_lib_file_name = if is_windows ( ) { "jvm.dll" } else { "libjvm.*" } ;
244
245
245
246
locate_file ( jvm_dyn_lib_file_name)
246
247
}
@@ -265,7 +266,10 @@ pub fn locate_file(file_name: &str) -> errors::Result<String> {
265
266
. collect ( ) ;
266
267
267
268
if paths_vec. is_empty ( ) {
268
- Err ( errors:: JavaLocatorError :: new ( & format ! ( "Could not find the {} library in any subdirectory of {}" , file_name, java_home) ) )
269
+ Err ( errors:: JavaLocatorError :: new ( & format ! (
270
+ "Could not find the {} library in any subdirectory of {}" ,
271
+ file_name, java_home
272
+ ) ) )
269
273
} else {
270
274
Ok ( paths_vec[ 0 ] . clone ( ) )
271
275
}
@@ -278,11 +282,14 @@ mod unit_tests {
278
282
#[ test]
279
283
fn locate_java_home_test ( ) {
280
284
println ! ( "locate_java_home: {}" , locate_java_home( ) . unwrap( ) ) ;
281
- println ! ( "locate_jvm_dyn_library: {}" , locate_jvm_dyn_library( ) . unwrap( ) ) ;
285
+ println ! (
286
+ "locate_jvm_dyn_library: {}" ,
287
+ locate_jvm_dyn_library( ) . unwrap( )
288
+ ) ;
282
289
}
283
290
284
291
#[ test]
285
292
fn locate_java_from_exec_test ( ) {
286
293
println ! ( "do_locate_java_home: {}" , do_locate_java_home( ) . unwrap( ) ) ;
287
294
}
288
- }
295
+ }
0 commit comments