[platform] cross-platform launcher: better encapsulation of remote dev stuff

GitOrigin-RevId: e9267e2bec85b16fa453eddf802e51a64b47cbf1
This commit is contained in:
Roman Shevchenko
2023-04-24 09:40:59 +02:00
committed by intellij-monorepo-bot
parent fdc4da73b8
commit 440d7ffa32
2 changed files with 42 additions and 50 deletions

View File

@@ -113,19 +113,19 @@ fn main_impl(remote_dev: bool, verbose: bool) -> Result<()> {
std::process::exit(1);
}));
debug!("** Preparing configuration");
let configuration = &get_configuration(remote_dev)?;
debug!("** Preparing launch configuration");
let configuration = get_configuration(remote_dev)?;
debug!("** Locating runtime");
let java_home = &configuration.prepare_for_launch()?;
let java_home = configuration.prepare_for_launch()?;
debug!("Resolved runtime: {java_home:?}");
debug!("** Resolving VM options");
let vm_options = get_full_vm_options(configuration)?;
let vm_options = get_full_vm_options(&configuration)?;
debug!("** Launching JVM");
let args = configuration.get_args();
let result = java::run_jvm_and_event_loop(java_home, vm_options, args.to_vec());
let result = java::run_jvm_and_event_loop(&java_home, vm_options, args.to_vec());
log::logger().flush();
@@ -150,7 +150,7 @@ pub struct ProductInfoLaunchField {
pub additionalJvmArguments: Vec<String>
}
trait LaunchConfiguration {
pub trait LaunchConfiguration {
fn get_args(&self) -> &[String];
fn get_intellij_vm_options(&self) -> Result<Vec<String>>;
@@ -162,30 +162,13 @@ trait LaunchConfiguration {
fn get_configuration(is_remote_dev: bool) -> Result<Box<dyn LaunchConfiguration>> {
let cmd_args: Vec<String> = env::args().collect();
debug!("args={:?}", &cmd_args[1..]);
let (remote_dev_project_path, jvm_args) = match is_remote_dev {
true => {
let remote_dev_args = RemoteDevLaunchConfiguration::parse_remote_dev_args(&cmd_args)?;
(remote_dev_args.project_path, remote_dev_args.ij_args)
},
false => (None, cmd_args[1..].to_vec())
};
debug!("args={:?}", &cmd_args);
if is_remote_dev {
// required for the most basic launch (e.g. showing help)
// as there may be nothing on user system and we'll crash
RemoteDevLaunchConfiguration::setup_font_config()?;
}
let default = DefaultLaunchConfiguration::new(jvm_args)?;
match remote_dev_project_path {
None => Ok(Box::new(default)),
Some(x) => {
let config = RemoteDevLaunchConfiguration::new(&x, default)?;
Ok(Box::new(config))
}
RemoteDevLaunchConfiguration::new(cmd_args)
} else {
let configuration = DefaultLaunchConfiguration::new(cmd_args[1..].to_vec())?;
Ok(Box::new(configuration))
}
}

View File

@@ -142,8 +142,26 @@ impl DefaultLaunchConfiguration {
}
impl RemoteDevLaunchConfiguration {
pub fn new(args: Vec<String>) -> Result<Box<dyn LaunchConfiguration>> {
let (project_path, default_cfg_args) = Self::parse_remote_dev_args(&args)?;
// required for the most basic launch (e.g. showing help)
// as there may be nothing on user system and we'll crash
Self::setup_font_config()?;
let default_cfg = DefaultLaunchConfiguration::new(default_cfg_args)?;
match project_path {
Some(path) => {
let configuration = Self::create(&path, default_cfg)?;
Ok(Box::new(configuration))
},
None => Ok(Box::new(default_cfg))
}
}
// remote-dev-server.exe ij_command_name /path/to/project args
pub fn parse_remote_dev_args(args: &[String]) -> Result<RemoteDevArgs> {
fn parse_remote_dev_args(args: &[String]) -> Result<(Option<PathBuf>, Vec<String>)> {
debug!("Parsing remote dev command-line arguments");
if args.len() < 2 {
@@ -173,16 +191,12 @@ impl RemoteDevLaunchConfiguration {
let project_path = if args.len() > 2 {
let arg = args[2].as_str();
if arg == "-h" || arg == "--help" {
return Ok(
RemoteDevArgs {
project_path: None,
ij_args: vec![
args[0].to_string(),
"remoteDevShowHelp".to_string(),
ij_starter_command.ij_command
]
}
);
let args = vec![
args[0].to_string(),
"remoteDevShowHelp".to_string(),
ij_starter_command.ij_command
];
return Ok((None, args));
}
Some(Self::get_project_path(arg)?)
@@ -213,7 +227,7 @@ impl RemoteDevLaunchConfiguration {
}
}.concat();
Ok(RemoteDevArgs { project_path, ij_args })
Ok((project_path, ij_args))
}
fn get_project_path(argument: &str) -> Result<PathBuf> {
@@ -229,7 +243,7 @@ impl RemoteDevLaunchConfiguration {
return Ok(project_path);
}
pub fn new(project_path: &Path, default: DefaultLaunchConfiguration) -> Result<Self> {
fn create(project_path: &Path, default: DefaultLaunchConfiguration) -> Result<Self> {
// prevent opening of 2 backends for the same directory via symlinks
let canonical_project_path = canonical_non_unc(project_path)?;
@@ -434,13 +448,13 @@ impl RemoteDevLaunchConfiguration {
Ok(trust_file_path)
}
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub fn setup_font_config() -> Result<()> {
#[cfg(not(target_os = "linux"))]
fn setup_font_config() -> Result<()> {
Ok(())
}
#[cfg(any(target_os = "linux"))]
pub fn setup_font_config() -> Result<()> {
#[cfg(target_os = "linux")]
fn setup_font_config() -> Result<()> {
// TODO: implement
Ok(())
}
@@ -522,11 +536,6 @@ struct IdeProperty {
value: String
}
pub struct RemoteDevArgs {
pub project_path: Option<PathBuf>,
pub ij_args: Vec<String>
}
fn print_help() {
let remote_dev_commands = &get_known_intellij_commands();
let mut remote_dev_commands_message = String::from("\nExamples:\n");