fn try_launch<P: AsRef<Path>>(installer_jar: &PathBuf, jre_path: P) -> JreLaunchError {
	// Let's see if the jre is valid
	// -version will always return an exit code of 0 if successful.

	println!("Trying JVM located at: {:?}", jre_path.as_ref());

	match Command::new(jre_path.as_ref()).arg("-version").status() {
		Ok(status) => {
			if !status.success() {
				// TODO: Introspect into the status code
				//  None only occurs on unix-like OSes, so macOS could have a signal
				match status.code() {
					None => {
						eprintln!("JVM terminated via signal");
					}
					Some(code) => {
						eprintln!("JVM terminated with exit code {}", code);
					}
				}

				return JreLaunchError::Jre;
			}
		}
		Err(e) => {
			return match e.kind() {
				ErrorKind::NotFound => {
					eprintln!("Could not find JVM at location");
					JreLaunchError::Jre
				}
				ErrorKind::PermissionDenied => {
					eprintln!("Permission denied when trying to launch jvm");
					JreLaunchError::NoPermission
				}
				_ => {
					eprintln!("Failed to launch JVM with error {:?}", e);
					JreLaunchError::Os(e)
				}
			}
		}
	}

	println!("Running JVM located at {:?}", jre_path.as_ref());

	// We have successfully run -version, so now we launch the installer.
	let result = Command::new(jre_path.as_ref())
		.arg("-jar")
		.arg(installer_jar.as_os_str())
		.status();

	match result {
		Ok(status) => {
			if status.success() {
				println!("Success, terminating bootstrapper");
				// Our job here is done
				exit(0);
			}

			// What happened?
			//
			// If the Java Virtual Machine was not successfully created, the exit code is 1.
			// The installer having a non-zero return code is not a good sign though.
			match status.code() {
				None => {
					// TODO: Signal
					eprintln!("JVM killed via signal");
					JreLaunchError::Jre
				}
				Some(code) => {
					// JVM failed to start
					eprintln!("JVM terminated with exit code {}", code);
					JreLaunchError::Jre
				}
			}
		}
		Err(e) => match e.kind() {
			ErrorKind::NotFound => {
				eprintln!("Could not find JVM at location");
				JreLaunchError::Jre
			}
			ErrorKind::PermissionDenied => {
				eprintln!("Permission denied when trying to launch jvm");
				JreLaunchError::NoPermission
			}
			_ => {
				eprintln!("Failed to launch JVM with error {:?}", e);
				JreLaunchError::Os(e)
			}
		},
	}
}
/// Try to launch the installer
///
/// This will terminate the process if the java installer was successfully launched.
Try to launch the installer
This will terminate the process if the java installer was successfully launched.
Try to launch the installer This will terminate the process if the java installer was successfully launched .
fn try_launch<P: AsRef<Path>>(installer_jar: &PathBuf, jre_path: P) -> JreLaunchError {
	// Let's see if the jre is valid
	// -version will always return an exit code of 0 if successful.
	println!("Trying JVM located at: {:?}", jre_path.as_ref());
	match Command::new(jre_path.as_ref()).arg("-version").status() {
		Ok(status) => {
			if !status.success() {
				// TODO: Introspect into the status code
				//  None only occurs on unix-like OSes, so macOS could have a signal
				match status.code() {
					None => {
						eprintln!("JVM terminated via signal");
					}
					Some(code) => {
						eprintln!("JVM terminated with exit code {}", code);
					}
				}
				return JreLaunchError::Jre;
			}
		}
		Err(e) => {
			return match e.kind() {
				ErrorKind::NotFound => {
					eprintln!("Could not find JVM at location");
					JreLaunchError::Jre
				}
				ErrorKind::PermissionDenied => {
					eprintln!("Permission denied when trying to launch jvm");
					JreLaunchError::NoPermission
				}
				_ => {
					eprintln!("Failed to launch JVM with error {:?}", e);
					JreLaunchError::Os(e)
				}
			}
		}
	}
	println!("Running JVM located at {:?}", jre_path.as_ref());
	// We have successfully run -version, so now we launch the installer.
	let result = Command::new(jre_path.as_ref())
		.arg("-jar")
		.arg(installer_jar.as_os_str())
		.status();
	match result {
		Ok(status) => {
			if status.success() {
				println!("Success, terminating bootstrapper");
				// Our job here is done
				exit(0);
			}
			// What happened?
			//
			// If the Java Virtual Machine was not successfully created, the exit code is 1.
			// The installer having a non-zero return code is not a good sign though.
			match status.code() {
				None => {
					// TODO: Signal
					eprintln!("JVM killed via signal");
					JreLaunchError::Jre
				}
				Some(code) => {
					// JVM failed to start
					eprintln!("JVM terminated with exit code {}", code);
					JreLaunchError::Jre
				}
			}
		}
		Err(e) => match e.kind() {
			ErrorKind::NotFound => {
				eprintln!("Could not find JVM at location");
				JreLaunchError::Jre
			}
			ErrorKind::PermissionDenied => {
				eprintln!("Permission denied when trying to launch jvm");
				JreLaunchError::NoPermission
			}
			_ => {
				eprintln!("Failed to launch JVM with error {:?}", e);
				JreLaunchError::Os(e)
			}
		},
	}
}
fn try_launch < P : AsRef < Path > > ( installer_jar : & PathBuf , jre_path : P ) -> JreLaunchError { // Let's see if the jre is valid // -version will always return an exit code of 0 if successful. println ! ( " " jre_path as_ref ( ) ) ; match Command :: new ( jre_path . as_ref ( ) ) . arg ( " " ) . status ( ) { Ok ( status ) => { if ! status . success ( ) { // TODO: Introspect into the status code //  None only occurs on unix-like OSes, so macOS could have a signal match status . code ( ) { None => { eprintln ! ( " " ) ; } Some ( code ) => { eprintln ! ( " " code ) ; } } return JreLaunchError :: Jre ; } } Err ( e ) => { return match e . kind ( ) { ErrorKind :: NotFound => { eprintln ! ( " " ) ; JreLaunchError :: Jre } ErrorKind :: PermissionDenied => { eprintln ! ( " " ) ; JreLaunchError :: NoPermission } _ => { eprintln ! ( " " e ) ; JreLaunchError :: Os ( e ) } } } } println ! ( " " jre_path as_ref ( ) ) ; // We have successfully run -version, so now we launch the installer. let result = Command :: new ( jre_path . as_ref ( ) ) . arg ( " " ) . arg ( installer_jar . as_os_str ( ) ) . status ( ) ; match result { Ok ( status ) => { if status . success ( ) { println ! ( " " ) ; // Our job here is done exit ( 0 ) ; } // What happened? // // If the Java Virtual Machine was not successfully created, the exit code is 1. // The installer having a non-zero return code is not a good sign though. match status . code ( ) { None => { // TODO: Signal eprintln ! ( " " ) ; JreLaunchError :: Jre } Some ( code ) => { // JVM failed to start eprintln ! ( " " code ) ; JreLaunchError :: Jre } } } Err ( e ) => match e . kind ( ) { ErrorKind :: NotFound => { eprintln ! ( " " ) ; JreLaunchError :: Jre } ErrorKind :: PermissionDenied => { eprintln ! ( " " ) ; JreLaunchError :: NoPermission } _ => { eprintln ! ( " " e ) ; JreLaunchError :: Os ( e ) } } , } }
Try to launch the installer
This will terminate the process if the java installer was successfully launched.
Try to launch the installer This will terminate the process if the java installer was successfully launched .
installer_jar
&PathBuf
jre_path
P
installer_jar
&PathBuf
jre_path
P