From a9bb49c7d685dd82feaf4050f756fdf590315200 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 17 May 2026 13:56:15 +0900 Subject: fix(compile): implement abstract class traits across all types Implement BaseCommand trait and other abstract class traits across all command, downloader, io, package, and VCS driver types. Also fix trait method signatures for composer_mut and io_mut to return mutable references to Option rather than Option of mutable references. --- crates/shirabe/src/command/about_command.rs | 32 +++++++- crates/shirabe/src/command/archive_command.rs | 31 +++++++- crates/shirabe/src/command/audit_command.rs | 35 +++++++- crates/shirabe/src/command/base_command.rs | 4 +- crates/shirabe/src/command/bump_command.rs | 32 +++++++- .../src/command/check_platform_reqs_command.rs | 33 +++++++- crates/shirabe/src/command/clear_cache_command.rs | 33 +++++++- crates/shirabe/src/command/config_command.rs | 90 ++++++++++++++++++++- .../shirabe/src/command/create_project_command.rs | 32 +++++++- crates/shirabe/src/command/depends_command.rs | 38 ++++++++- crates/shirabe/src/command/diagnose_command.rs | 33 +++++++- .../shirabe/src/command/dump_autoload_command.rs | 33 +++++++- crates/shirabe/src/command/exec_command.rs | 33 +++++++- crates/shirabe/src/command/fund_command.rs | 33 +++++++- crates/shirabe/src/command/global_command.rs | 33 +++++++- crates/shirabe/src/command/home_command.rs | 33 +++++++- crates/shirabe/src/command/init_command.rs | 33 +++++++- crates/shirabe/src/command/install_command.rs | 33 +++++++- crates/shirabe/src/command/licenses_command.rs | 33 +++++++- crates/shirabe/src/command/outdated_command.rs | 33 +++++++- crates/shirabe/src/command/prohibits_command.rs | 38 ++++++++- crates/shirabe/src/command/reinstall_command.rs | 33 +++++++- crates/shirabe/src/command/remove_command.rs | 33 +++++++- crates/shirabe/src/command/repository_command.rs | 92 +++++++++++++++++++++- crates/shirabe/src/command/require_command.rs | 33 +++++++- crates/shirabe/src/command/run_script_command.rs | 34 +++++++- crates/shirabe/src/command/script_alias_command.rs | 35 +++++++- crates/shirabe/src/command/search_command.rs | 34 +++++++- crates/shirabe/src/command/self_update_command.rs | 31 +++++++- crates/shirabe/src/command/show_command.rs | 32 +++++++- crates/shirabe/src/command/status_command.rs | 33 +++++++- crates/shirabe/src/command/suggests_command.rs | 37 ++++++++- crates/shirabe/src/command/update_command.rs | 30 ++++++- crates/shirabe/src/command/validate_command.rs | 32 +++++++- .../src/dependency_resolver/generic_rule.rs | 57 ++++++++++++-- .../src/dependency_resolver/multi_conflict_rule.rs | 47 ++++++++++- .../src/dependency_resolver/rule2_literals.rs | 47 ++++++++++- crates/shirabe/src/downloader/fossil_downloader.rs | 4 +- crates/shirabe/src/downloader/git_downloader.rs | 6 +- crates/shirabe/src/downloader/gzip_downloader.rs | 5 +- crates/shirabe/src/downloader/hg_downloader.rs | 4 +- .../shirabe/src/downloader/perforce_downloader.rs | 4 +- crates/shirabe/src/downloader/phar_downloader.rs | 5 +- crates/shirabe/src/downloader/rar_downloader.rs | 5 +- crates/shirabe/src/downloader/svn_downloader.rs | 4 +- crates/shirabe/src/downloader/tar_downloader.rs | 5 +- crates/shirabe/src/downloader/vcs_downloader.rs | 28 +++++++ crates/shirabe/src/downloader/xz_downloader.rs | 5 +- crates/shirabe/src/downloader/zip_downloader.rs | 3 +- crates/shirabe/src/io/console_io.rs | 17 +++- crates/shirabe/src/io/null_io.rs | 16 +++- crates/shirabe/src/package/alias_package.rs | 52 +++++++++++- .../src/package/archiver/base_exclude_filter.rs | 67 ++++++++++++++++ .../package/archiver/composer_exclude_filter.rs | 6 +- .../src/package/archiver/git_exclude_filter.rs | 10 +-- crates/shirabe/src/package/package.rs | 53 ++++++++++++- .../shirabe/src/repository/vcs/forgejo_driver.rs | 6 +- crates/shirabe/src/repository/vcs/fossil_driver.rs | 4 +- .../src/repository/vcs/git_bitbucket_driver.rs | 4 +- crates/shirabe/src/repository/vcs/git_driver.rs | 4 +- crates/shirabe/src/repository/vcs/github_driver.rs | 4 +- crates/shirabe/src/repository/vcs/gitlab_driver.rs | 4 +- crates/shirabe/src/repository/vcs/hg_driver.rs | 4 +- .../shirabe/src/repository/vcs/perforce_driver.rs | 4 +- crates/shirabe/src/repository/vcs/svn_driver.rs | 4 +- crates/shirabe/src/repository/vcs/vcs_driver.rs | 61 ++++++++++++++ 66 files changed, 1670 insertions(+), 96 deletions(-) (limited to 'crates') diff --git a/crates/shirabe/src/command/about_command.rs b/crates/shirabe/src/command/about_command.rs index 3b16b0e2..583482be 100644 --- a/crates/shirabe/src/command/about_command.rs +++ b/crates/shirabe/src/command/about_command.rs @@ -2,11 +2,15 @@ use crate::command::base_command::BaseCommand; use crate::composer::Composer; +use crate::io::io_interface::IOInterface; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct AboutCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl AboutCommand { @@ -29,3 +33,29 @@ impl AboutCommand { 0 } } + +impl BaseCommand for AboutCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 867b0101..1a85df49 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -4,6 +4,7 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{LogicException, get_debug_type}; @@ -33,7 +34,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct ArchiveCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for ArchiveCommand {} @@ -319,3 +322,29 @@ impl ArchiveCommand { Ok(Some(package.into_complete())) } } + +impl BaseCommand for ArchiveCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/audit_command.rs b/crates/shirabe/src/command/audit_command.rs index 7fb6c5f2..2331f8dd 100644 --- a/crates/shirabe/src/command/audit_command.rs +++ b/crates/shirabe/src/command/audit_command.rs @@ -5,13 +5,16 @@ use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::repository::installed_repository::InstalledRepository; use crate::repository::repository_set::RepositorySet; use crate::repository::repository_utils::RepositoryUtils; use anyhow::Result; -use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; +use shirabe_external_packages::symfony::{ + component::console::command::command::Command, console::input::input_interface::InputInterface, +}; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_fill_keys, array_merge, implode, in_array, @@ -19,7 +22,9 @@ use shirabe_php_shim::{ #[derive(Debug)] pub struct AuditCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl AuditCommand { @@ -154,3 +159,29 @@ impl AuditCommand { Ok(installed_repo.get_packages()) } } + +impl BaseCommand for AuditCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 7f9a8606..c9f79b75 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -38,9 +38,9 @@ pub trait BaseCommand { fn inner(&self) -> &Command; fn inner_mut(&mut self) -> &mut Command; fn composer(&self) -> Option<&Composer>; - fn composer_mut(&mut self) -> Option<&mut Composer>; + fn composer_mut(&mut self) -> &mut Option; fn io(&self) -> Option<&dyn IOInterface>; - fn io_mut(&mut self) -> Option<&mut dyn IOInterface>; + fn io_mut(&mut self) -> &mut Option>; /// Gets the application instance for this command. fn get_application(&self) -> Result { diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs index ddb17c24..03822467 100644 --- a/crates/shirabe/src/command/bump_command.rs +++ b/crates/shirabe/src/command/bump_command.rs @@ -2,12 +2,14 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, file_get_contents, file_put_contents, is_writable, strtolower}; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; @@ -23,7 +25,9 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct BumpCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for BumpCommand {} @@ -368,3 +372,29 @@ impl BumpCommand { } } } + +impl BaseCommand for BumpCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs index fcf10aa9..62cde820 100644 --- a/crates/shirabe/src/command/check_platform_reqs_command.rs +++ b/crates/shirabe/src/command/check_platform_reqs_command.rs @@ -2,13 +2,16 @@ use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, strip_tags}; use shirabe_semver::constraint::constraint::Constraint; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::link::Link; use crate::repository::installed_repository::InstalledRepository; @@ -25,7 +28,9 @@ struct CheckResult { #[derive(Debug)] pub struct CheckPlatformReqsCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CheckPlatformReqsCommand { @@ -316,3 +321,29 @@ impl CheckPlatformReqsCommand { } } } + +impl BaseCommand for CheckPlatformReqsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/clear_cache_command.rs b/crates/shirabe/src/command/clear_cache_command.rs index 06026a4e..1d495028 100644 --- a/crates/shirabe/src/command/clear_cache_command.rs +++ b/crates/shirabe/src/command/clear_cache_command.rs @@ -2,15 +2,20 @@ use crate::cache::Cache; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; #[derive(Debug)] pub struct ClearCacheCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl ClearCacheCommand { @@ -116,3 +121,29 @@ impl ClearCacheCommand { Ok(0) } } + +impl BaseCommand for ClearCacheCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 5237b627..62e630ad 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -3,6 +3,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::input::input_option::InputOption; @@ -17,7 +18,9 @@ use shirabe_php_shim::{ }; use crate::advisory::auditor::Auditor; +use crate::command::base_command::BaseCommand; use crate::command::base_config_command::BaseConfigCommand; +use crate::composer::Composer; use crate::config::Config; use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; @@ -32,7 +35,14 @@ use shirabe_semver::version_parser::VersionParser; #[derive(Debug)] pub struct ConfigCommand { - inner: BaseConfigCommand, + inner: Command, + composer: Option, + io: Option>, + + config: Option, + config_file: Option, + config_source: Option, + pub(crate) auth_config_file: Option, pub(crate) auth_config_source: Option, } @@ -2170,3 +2180,81 @@ fn key_first_key(value: &PhpMixed) -> Option { } None } + +impl BaseCommand for ConfigCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> Option<&mut Composer> { + self.composer.as_mut() + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_ref() + } + + fn io_mut(&mut self) -> Option<&mut dyn IOInterface> { + self.io.as_mut() + } +} + +impl BaseCommand for ConfigCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} + +impl BaseConfigCommand for ConfigCommand { + fn config(&self) -> Option<&Config> { + self.config.as_ref() + } + + fn config_mut(&mut self) -> Option<&mut Config> { + self.config.as_mut() + } + + fn config_file(&self) -> Option<&JsonFile> { + self.config_file.as_ref() + } + + fn config_file_mut(&mut self) -> Option<&mut JsonFile> { + self.config_file.as_mut() + } + + fn config_source(&self) -> Option<&JsonConfigSource> { + self.config_source.as_ref() + } + + fn config_source_mut(&mut self) -> Option<&mut JsonConfigSource> { + self.config_source.as_mut() + } +} diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index c6498482..c0902d46 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -3,6 +3,7 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::seld::signal::signal_handler::SignalHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::finder::finder::Finder; @@ -48,7 +49,10 @@ use crate::util::process_executor::ProcessExecutor; /// Install a package as new project into new directory. #[derive(Debug)] pub struct CreateProjectCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + /// @var SuggestedPackagesReporter pub(crate) suggested_packages_reporter: Option, } @@ -895,3 +899,29 @@ impl CreateProjectCommand { self.inner.create_audit_config(config, input) } } + +impl BaseCommand for CreateProjectCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/depends_command.rs b/crates/shirabe/src/command/depends_command.rs index 9ec3ddeb..f83fe00f 100644 --- a/crates/shirabe/src/command/depends_command.rs +++ b/crates/shirabe/src/command/depends_command.rs @@ -8,7 +8,7 @@ use shirabe_external_packages::symfony::console::input::input_interface::InputIn use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct DependsCommand { - inner: BaseDependencyCommand, + colors: Vec, } impl CompletionTrait for DependsCommand {} @@ -58,3 +58,39 @@ impl DependsCommand { self.inner.do_execute(input, output) } } + +impl BaseCommand for DependsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} + +impl BaseDependencyCommand for DependsCommand { + fn colors(&self) -> &[String] { + &self.colors + } + + fn colors_mut(&mut self) -> &mut [String] { + &mut self.colors + } +} diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 07e367f1..23c0cd04 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::xdebug_handler::xdebug_handler::XdebugHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::process::executable_finder::ExecutableFinder; @@ -25,6 +26,7 @@ use crate::config::Config; use crate::downloader::transport_exception::TransportException; use crate::factory::Factory; use crate::io::buffer_io::BufferIO; +use crate::io::io_interface::IOInterface; use crate::io::null_io::NullIO; use crate::json::json_file::JsonFile; use crate::json::json_validation_exception::JsonValidationException; @@ -51,7 +53,10 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct DiagnoseCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + pub(crate) http_downloader: Option, pub(crate) process: Option, pub(crate) exit_code: i64, @@ -1364,3 +1369,29 @@ impl DiagnoseCommand { PhpMixed::Bool(true) } } + +impl BaseCommand for DiagnoseCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/dump_autoload_command.rs b/crates/shirabe/src/command/dump_autoload_command.rs index 295f1c04..471b353f 100644 --- a/crates/shirabe/src/command/dump_autoload_command.rs +++ b/crates/shirabe/src/command/dump_autoload_command.rs @@ -1,18 +1,23 @@ //! ref: composer/src/Composer/Command/DumpAutoloadCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, PhpMixed, file_exists}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; #[derive(Debug)] pub struct DumpAutoloadCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl DumpAutoloadCommand { @@ -197,3 +202,29 @@ impl DumpAutoloadCommand { Ok(0) } } + +impl BaseCommand for DumpAutoloadCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs index 5602e853..82c90bcf 100644 --- a/crates/shirabe/src/command/exec_command.rs +++ b/crates/shirabe/src/command/exec_command.rs @@ -1,17 +1,22 @@ //! ref: composer/src/Composer/Command/ExecCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, RuntimeException, basename, chdir, getcwd, glob}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; #[derive(Debug)] pub struct ExecCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl ExecCommand { @@ -186,3 +191,29 @@ impl ExecCommand { Ok(binaries) } } + +impl BaseCommand for ExecCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs index 398efd9a..0d0c2ec4 100644 --- a/crates/shirabe/src/command/fund_command.rs +++ b/crates/shirabe/src/command/fund_command.rs @@ -5,6 +5,7 @@ use std::any::Any; use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -12,7 +13,9 @@ use shirabe_php_shim::PhpMixed; use shirabe_semver::constraint::match_all_constraint::MatchAllConstraint; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::alias_package::AliasPackage; use crate::package::base_package::BasePackage; @@ -21,7 +24,9 @@ use crate::repository::composite_repository::CompositeRepository; #[derive(Debug)] pub struct FundCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl FundCommand { @@ -201,3 +206,29 @@ impl FundCommand { Ok(()) } } + +impl BaseCommand for FundCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs index 695232c3..a5423f52 100644 --- a/crates/shirabe/src/command/global_command.rs +++ b/crates/shirabe/src/command/global_command.rs @@ -4,6 +4,7 @@ use std::path::Path; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::completion::completion_suggestions::CompletionSuggestions; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; @@ -12,14 +13,18 @@ use shirabe_external_packages::symfony::console::output::output_interface::Outpu use shirabe_php_shim::{LogicException, RuntimeException, chdir}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use crate::util::filesystem::Filesystem; use crate::util::platform::Platform; #[derive(Debug)] pub struct GlobalCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl GlobalCommand { @@ -157,3 +162,29 @@ impl GlobalCommand { true } } + +impl BaseCommand for GlobalCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs index 142f8688..dd8a81c1 100644 --- a/crates/shirabe/src/command/home_command.rs +++ b/crates/shirabe/src/command/home_command.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Command/HomeCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{FILTER_VALIDATE_URL, filter_var}; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::complete_package_interface::CompletePackageInterface; use crate::repository::repository_factory::RepositoryFactory; use crate::repository::repository_interface::RepositoryInterface; @@ -18,7 +21,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct HomeCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for HomeCommand {} @@ -216,3 +221,29 @@ impl HomeCommand { )) } } + +impl BaseCommand for HomeCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index e61b7a6d..d8f01135 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -4,6 +4,7 @@ use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::spdx_licenses::spdx_licenses::SpdxLicenses; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::helper::formatter_helper::FormatterHelper; use shirabe_external_packages::symfony::component::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; @@ -19,6 +20,7 @@ use shirabe_php_shim::{ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; use crate::command::package_discovery_trait::PackageDiscoveryTrait; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; use crate::factory::Factory; use crate::io::io_interface::IOInterface; @@ -34,7 +36,10 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct InitCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + /// @var array git_config: Option>, } @@ -1152,3 +1157,29 @@ impl InitCommand { None } } + +impl BaseCommand for InitCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs index 264b58c2..04d630be 100644 --- a/crates/shirabe/src/command/install_command.rs +++ b/crates/shirabe/src/command/install_command.rs @@ -1,6 +1,7 @@ //! ref: composer/src/Composer/Command/InstallCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::PhpMixed; @@ -8,16 +9,20 @@ use shirabe_php_shim::PhpMixed; use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::installer::Installer; +use crate::io::io_interface::IOInterface; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; use crate::util::http_downloader::HttpDownloader; #[derive(Debug)] pub struct InstallCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for InstallCommand {} @@ -174,3 +179,29 @@ impl InstallCommand { install.run() } } + +impl BaseCommand for InstallCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs index ddb7b32e..4cebc07f 100644 --- a/crates/shirabe/src/command/licenses_command.rs +++ b/crates/shirabe/src/command/licenses_command.rs @@ -4,6 +4,7 @@ use std::any::Any; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::helper::table::Table; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; @@ -12,7 +13,9 @@ use shirabe_external_packages::symfony::console::style::symfony_style::SymfonySt use shirabe_php_shim::{PhpMixed, RuntimeException, UnexpectedValueException}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::complete_package::CompletePackage; use crate::package::complete_package_interface::CompletePackageInterface; @@ -24,7 +27,9 @@ use crate::util::package_sorter::PackageSorter; #[derive(Debug)] pub struct LicensesCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl LicensesCommand { @@ -281,3 +286,29 @@ impl LicensesCommand { Ok(0) } } + +impl BaseCommand for LicensesCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/outdated_command.rs b/crates/shirabe/src/command/outdated_command.rs index ed927b78..1a199311 100644 --- a/crates/shirabe/src/command/outdated_command.rs +++ b/crates/shirabe/src/command/outdated_command.rs @@ -2,10 +2,13 @@ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -13,7 +16,9 @@ use shirabe_php_shim::PhpMixed; #[derive(Debug)] pub struct OutdatedCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for OutdatedCommand {} @@ -133,3 +138,29 @@ impl OutdatedCommand { true } } + +impl BaseCommand for OutdatedCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/prohibits_command.rs b/crates/shirabe/src/command/prohibits_command.rs index accfcf08..c8aa89d0 100644 --- a/crates/shirabe/src/command/prohibits_command.rs +++ b/crates/shirabe/src/command/prohibits_command.rs @@ -8,7 +8,7 @@ use shirabe_external_packages::symfony::console::input::input_interface::InputIn use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct ProhibitsCommand { - inner: BaseDependencyCommand, + colors: Vec, } impl CompletionTrait for ProhibitsCommand {} @@ -65,3 +65,39 @@ impl ProhibitsCommand { self.inner.do_execute(input, output, true) } } + +impl BaseCommand for ProhibitsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} + +impl BaseDependencyCommand for ProhibitsCommand { + fn colors(&self) -> &[String] { + &self.colors + } + + fn colors_mut(&mut self) -> &mut [String] { + &mut self.colors + } +} diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index 3fb26a2f..e0a8843c 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -4,17 +4,20 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::InvalidArgumentException; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::operation::install_operation::InstallOperation; use crate::dependency_resolver::operation::uninstall_operation::UninstallOperation; use crate::dependency_resolver::transaction::Transaction; +use crate::io::io_interface::IOInterface; use crate::package::alias_package::AliasPackage; use crate::package::base_package::BasePackage; use crate::plugin::command_event::CommandEvent; @@ -24,7 +27,9 @@ use crate::util::platform::Platform; #[derive(Debug)] pub struct ReinstallCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for ReinstallCommand {} @@ -264,3 +269,29 @@ impl ReinstallCommand { Ok(0) } } + +impl BaseCommand for ReinstallCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs index b7f83787..da1da090 100644 --- a/crates/shirabe/src/command/remove_command.rs +++ b/crates/shirabe/src/command/remove_command.rs @@ -2,6 +2,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::exception::invalid_argument_exception::InvalidArgumentException; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; @@ -10,18 +11,22 @@ use shirabe_php_shim::{PhpMixed, UnexpectedValueException, array_map, strtolower use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::request::Request; use crate::factory::Factory; use crate::installer::Installer; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::base_package::BasePackage; #[derive(Debug)] pub struct RemoveCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl RemoveCommand { @@ -672,3 +677,29 @@ impl RemoveCommand { Ok(status) } } + +impl BaseCommand for RemoveCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs index cfe9065f..86afe80a 100644 --- a/crates/shirabe/src/command/repository_command.rs +++ b/crates/shirabe/src/command/repository_command.rs @@ -2,6 +2,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -9,15 +10,26 @@ use shirabe_php_shim::{ InvalidArgumentException, PHP_URL_HOST, PhpMixed, RuntimeException, parse_url, strtolower, }; +use crate::command::base_command::BaseCommand; use crate::command::base_config_command::BaseConfigCommand; +use crate::composer::Composer; +use crate::config::Config; +use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; #[derive(Debug)] pub struct RepositoryCommand { - inner: BaseConfigCommand, + inner: Command, + composer: Option, + io: Option>, + + config: Option, + config_file: Option, + config_source: Option, } impl RepositoryCommand { @@ -436,3 +448,81 @@ impl RepositoryCommand { }) } } + +impl BaseCommand for RepositoryCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> Option<&mut Composer> { + self.composer.as_mut() + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_ref() + } + + fn io_mut(&mut self) -> Option<&mut dyn IOInterface> { + self.io.as_mut() + } +} + +impl BaseCommand for RepositoryCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} + +impl BaseConfigCommand for RepositoryCommand { + fn config(&self) -> Option<&Config> { + self.config.as_ref() + } + + fn config_mut(&mut self) -> Option<&mut Config> { + self.config.as_mut() + } + + fn config_file(&self) -> Option<&JsonFile> { + self.config_file.as_ref() + } + + fn config_file_mut(&mut self) -> Option<&mut JsonFile> { + self.config_file.as_mut() + } + + fn config_source(&self) -> Option<&JsonConfigSource> { + self.config_source.as_ref() + } + + fn config_source_mut(&mut self) -> Option<&mut JsonConfigSource> { + self.config_source.as_mut() + } +} diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index 738790de..24dda7e8 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -4,6 +4,7 @@ use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::seld::signal::signal_handler::SignalHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_php_shim::{ @@ -17,6 +18,7 @@ use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; use crate::command::package_discovery_trait::PackageDiscoveryTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::request::Request; @@ -45,7 +47,10 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct RequireCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + newly_created: bool, first_require: bool, json: Option, @@ -1132,3 +1137,29 @@ impl RequireCommand { } } } + +impl BaseCommand for RequireCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs index 09624af9..fac896a0 100644 --- a/crates/shirabe/src/command/run_script_command.rs +++ b/crates/shirabe/src/command/run_script_command.rs @@ -1,13 +1,16 @@ //! ref: composer/src/Composer/Command/RunScriptCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, PhpMixed, RuntimeException}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::script::event::Event as ScriptEvent; use crate::script::script_events::ScriptEvents; use crate::util::platform::Platform; @@ -15,7 +18,10 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct RunScriptCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + script_events: Vec<&'static str>, } @@ -249,3 +255,29 @@ impl RunScriptCommand { Ok(result) } } + +impl BaseCommand for RunScriptCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs index c5bacc4e..a02d646d 100644 --- a/crates/shirabe/src/command/script_alias_command.rs +++ b/crates/shirabe/src/command/script_alias_command.rs @@ -1,17 +1,22 @@ //! ref: composer/src/Composer/Command/ScriptAliasCommand.php -use crate::command::base_command::BaseCommand; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::util::platform::Platform; +use crate::{command::base_command::BaseCommand, composer::Composer}; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string}; pub struct ScriptAliasCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + script: String, description: String, aliases: Vec, @@ -125,3 +130,29 @@ impl ScriptAliasCommand { )?) } } + +impl BaseCommand for ScriptAliasCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs index 2e9de048..28f4fd1b 100644 --- a/crates/shirabe/src/command/search_command.rs +++ b/crates/shirabe/src/command/search_command.rs @@ -1,16 +1,18 @@ //! ref: composer/src/Composer/Command/SearchCommand.php -use crate::command::base_command::BaseCommand; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; use crate::repository::composite_repository::CompositeRepository; use crate::repository::platform_repository::PlatformRepository; use crate::repository::repository_interface::RepositoryInterface; +use crate::{command::base_command::BaseCommand, composer::Composer}; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -18,7 +20,9 @@ use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, pr #[derive(Debug)] pub struct SearchCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl SearchCommand { @@ -177,3 +181,29 @@ impl SearchCommand { Ok(0) } } + +impl BaseCommand for SearchCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/self_update_command.rs b/crates/shirabe/src/command/self_update_command.rs index f69476d1..b1b0c06e 100644 --- a/crates/shirabe/src/command/self_update_command.rs +++ b/crates/shirabe/src/command/self_update_command.rs @@ -2,6 +2,7 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::finder::finder::Finder; @@ -32,7 +33,9 @@ use crate::util::platform::Platform; #[derive(Debug)] pub struct SelfUpdateCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl SelfUpdateCommand { @@ -1178,3 +1181,29 @@ RGv89BPD+2DLnJysngsvVaUCAwEAAQ==\n\ result } } + +impl BaseCommand for SelfUpdateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index 8b5e9678..52d2bd74 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::semver::semver::Semver; use shirabe_external_packages::composer::spdx_licenses::spdx_licenses::SpdxLicenses; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::formatter::output_formatter_style::OutputFormatterStyle; @@ -50,7 +51,10 @@ const _INPUT_OPTION_REF: i64 = InputOption::VALUE_NONE; #[derive(Debug)] pub struct ShowCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + pub(crate) version_parser: VersionParser, pub(crate) colors: Vec, repository_set: Option, @@ -2640,6 +2644,32 @@ impl ShowCommand { impl CompletionTrait for ShowCommand {} +impl BaseCommand for ShowCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} + #[derive(Debug)] pub enum PackageOrName { Pkg(Box), diff --git a/crates/shirabe/src/command/status_command.rs b/crates/shirabe/src/command/status_command.rs index ff6675d9..e4f25cdc 100644 --- a/crates/shirabe/src/command/status_command.rs +++ b/crates/shirabe/src/command/status_command.rs @@ -2,11 +2,14 @@ use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::dumper::array_dumper::ArrayDumper; use crate::package::version::version_guesser::VersionGuesser; use crate::package::version::version_parser::VersionParser; @@ -17,7 +20,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct StatusCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl StatusCommand { @@ -301,3 +306,29 @@ impl StatusCommand { Ok(exit_code) } } + +impl BaseCommand for StatusCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs index efa0ce2c..317b9c4b 100644 --- a/crates/shirabe/src/command/suggests_command.rs +++ b/crates/shirabe/src/command/suggests_command.rs @@ -2,20 +2,27 @@ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::installer::suggested_packages_reporter::SuggestedPackagesReporter; +use crate::io::io_interface::IOInterface; use crate::repository::installed_repository::InstalledRepository; use crate::repository::platform_repository::PlatformRepository; use crate::repository::root_package_repository::RootPackageRepository; use anyhow::Result; -use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; +use shirabe_external_packages::symfony::{ + component::console::command::command::Command, console::input::input_interface::InputInterface, +}; use shirabe_php_shim::{PhpMixed, empty, in_array}; #[derive(Debug)] pub struct SuggestsCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, + completion_trait: CompletionTrait, } @@ -112,3 +119,29 @@ impl SuggestsCommand { Ok(0) } } + +impl BaseCommand for SuggestsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 0311cec2..aeeb7ba8 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -37,7 +37,9 @@ use crate::util::http_downloader::HttpDownloader; #[derive(Debug)] pub struct UpdateCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl CompletionTrait for UpdateCommand {} @@ -623,3 +625,29 @@ impl UpdateCommand { VersionSelector::new(repository_set) } } + +impl BaseCommand for UpdateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs index e95e5cad..5906aaa4 100644 --- a/crates/shirabe/src/command/validate_command.rs +++ b/crates/shirabe/src/command/validate_command.rs @@ -1,10 +1,12 @@ //! ref: composer/src/Composer/Command/ValidateCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; @@ -17,7 +19,9 @@ use crate::util::filesystem::Filesystem; #[derive(Debug)] pub struct ValidateCommand { - inner: BaseCommand, + inner: Command, + composer: Option, + io: Option>, } impl ValidateCommand { @@ -330,3 +334,29 @@ impl ValidateCommand { } } } + +impl BaseCommand for ValidateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option> { + &mut self.io + } +} diff --git a/crates/shirabe/src/dependency_resolver/generic_rule.rs b/crates/shirabe/src/dependency_resolver/generic_rule.rs index f30d6125..23d1e3c3 100644 --- a/crates/shirabe/src/dependency_resolver/generic_rule.rs +++ b/crates/shirabe/src/dependency_resolver/generic_rule.rs @@ -2,19 +2,16 @@ use crate::dependency_resolver::rule::Rule; use anyhow::Result; -use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw, implode, unpack}; +use shirabe_php_shim::{PHP_VERSION_ID, PhpMixed, RuntimeException, hash_raw, implode, unpack}; + +use super::{request::Request, rule::ReasonData}; pub struct GenericRule { - inner: Rule, pub(crate) literals: Vec, } impl GenericRule { - pub fn new( - mut literals: Vec, - reason: shirabe_php_shim::PhpMixed, - reason_data: shirabe_php_shim::PhpMixed, - ) -> Self { + pub fn new(mut literals: Vec, reason: PhpMixed, reason_data: PhpMixed) -> Self { let inner = Rule::new(reason, reason_data); literals.sort(); Self { inner, literals } @@ -96,3 +93,49 @@ impl RuleLiterals for GenericRule { &self.literals } } + +impl Rule for GenericRule { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs index b15434e0..981a5225 100644 --- a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs +++ b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs @@ -7,7 +7,6 @@ use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw}; #[derive(Debug)] pub struct MultiConflictRule { - inner: Rule, pub(crate) literals: Vec, } @@ -118,3 +117,49 @@ impl RuleLiterals for MultiConflictRule { true } } + +impl Rule for MultiConflictRule { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/dependency_resolver/rule2_literals.rs b/crates/shirabe/src/dependency_resolver/rule2_literals.rs index e86c93d6..50ae77b2 100644 --- a/crates/shirabe/src/dependency_resolver/rule2_literals.rs +++ b/crates/shirabe/src/dependency_resolver/rule2_literals.rs @@ -5,7 +5,6 @@ use crate::dependency_resolver::rule::Rule; #[derive(Debug)] pub struct Rule2Literals { - inner: Rule, pub(crate) literal1: i64, pub(crate) literal2: i64, literals: Vec, @@ -71,3 +70,49 @@ impl RuleLiterals for Rule2Literals { &self.literals } } + +impl Rule for Rule2Literals { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs index a686177d..5314e102 100644 --- a/crates/shirabe/src/downloader/fossil_downloader.rs +++ b/crates/shirabe/src/downloader/fossil_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/FossilDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; @@ -9,7 +9,7 @@ use shirabe_php_shim::RuntimeException; #[derive(Debug)] pub struct FossilDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, } impl FossilDownloader { diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 97d0ee90..1bc0ff1b 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -13,7 +13,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::downloader::dvcs_downloader_interface::DvcsDownloaderInterface; -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::util::filesystem::Filesystem; @@ -24,7 +24,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct GitDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, /// @var array has_stashed_changes: IndexMap, /// @var array @@ -41,7 +41,7 @@ impl GitDownloader { process: Option, fs: Option, ) -> Self { - let inner = VcsDownloader::new(io, config, process, fs); + let inner = VcsDownloaderBase::new(io, config, process, fs); let git_util = GitUtil::new(&*inner.io, &inner.config, &inner.process, &inner.filesystem); Self { inner, diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs index 81fdbeda..ca508276 100644 --- a/crates/shirabe/src/downloader/gzip_downloader.rs +++ b/crates/shirabe/src/downloader/gzip_downloader.rs @@ -1,9 +1,11 @@ //! ref: composer/src/Composer/Downloader/GzipDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use crate::util::platform::Platform; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{ DIRECTORY_SEPARATOR, PATHINFO_FILENAME, PHP_URL_PATH, RuntimeException, extension_loaded, @@ -11,7 +13,8 @@ use shirabe_php_shim::{ }; pub struct GzipDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, } impl GzipDownloader { diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs index ff068065..1b4204f2 100644 --- a/crates/shirabe/src/downloader/hg_downloader.rs +++ b/crates/shirabe/src/downloader/hg_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/HgDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use crate::util::hg::Hg as HgUtils; use anyhow::Result; @@ -9,7 +9,7 @@ use shirabe_php_shim::RuntimeException; #[derive(Debug)] pub struct HgDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, } impl HgDownloader { diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs index 8674b3d0..b10e27f6 100644 --- a/crates/shirabe/src/downloader/perforce_downloader.rs +++ b/crates/shirabe/src/downloader/perforce_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/PerforceDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use crate::repository::vcs_repository::VcsRepository; use crate::util::perforce::Perforce; @@ -12,7 +12,7 @@ use std::any::Any; #[derive(Debug)] pub struct PerforceDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, pub(crate) perforce: Option, } diff --git a/crates/shirabe/src/downloader/phar_downloader.rs b/crates/shirabe/src/downloader/phar_downloader.rs index 8fea6790..5316fc1e 100644 --- a/crates/shirabe/src/downloader/phar_downloader.rs +++ b/crates/shirabe/src/downloader/phar_downloader.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Downloader/PharDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::Phar; #[derive(Debug)] pub struct PharDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, } impl PharDownloader { diff --git a/crates/shirabe/src/downloader/rar_downloader.rs b/crates/shirabe/src/downloader/rar_downloader.rs index 1b4767fd..308b6fa9 100644 --- a/crates/shirabe/src/downloader/rar_downloader.rs +++ b/crates/shirabe/src/downloader/rar_downloader.rs @@ -1,17 +1,20 @@ //! ref: composer/src/Composer/Downloader/RarDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use crate::util::ini_helper::IniHelper; use crate::util::platform::Platform; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{ RarArchive, RuntimeException, UnexpectedValueException, class_exists, implode, }; pub struct RarDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, } impl RarDownloader { diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index 30a64f26..ef006f3d 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -5,7 +5,7 @@ use shirabe_external_packages::react::promise; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, version_compare}; -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::repository::vcs_repository::VcsRepository; @@ -13,7 +13,7 @@ use crate::util::svn::Svn as SvnUtil; #[derive(Debug)] pub struct SvnDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, pub(crate) cache_credentials: bool, } diff --git a/crates/shirabe/src/downloader/tar_downloader.rs b/crates/shirabe/src/downloader/tar_downloader.rs index c327ca09..d8531e00 100644 --- a/crates/shirabe/src/downloader/tar_downloader.rs +++ b/crates/shirabe/src/downloader/tar_downloader.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Downloader/TarDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::PharData; #[derive(Debug)] pub struct TarDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, } impl TarDownloader { diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs index b76c242e..9ec86ff2 100644 --- a/crates/shirabe/src/downloader/vcs_downloader.rs +++ b/crates/shirabe/src/downloader/vcs_downloader.rs @@ -23,6 +23,34 @@ use crate::package::version::version_parser::VersionParser; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; +#[derive(Debug)] +pub struct VcsDownloaderBase { + pub io: Box, + pub config: Config, + pub process: ProcessExecutor, + pub filesystem: Filesystem, + pub has_cleaned_changes: IndexMap, +} + +impl VcsDownloaderBase { + pub fn new( + io: Box, + config: Config, + process: Option, + fs: Option, + ) -> Self { + let process = process.unwrap_or_else(|| ProcessExecutor::new(None, None)); + let filesystem = fs.unwrap_or_else(|| Filesystem::new(None)); + Self { + io, + config, + process, + filesystem, + has_cleaned_changes: IndexMap::new(), + } + } +} + pub trait VcsDownloader: DownloaderInterface + ChangeReportInterface + VcsCapableDownloaderInterface { diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs index 0c5d876a..1ad0bb17 100644 --- a/crates/shirabe/src/downloader/xz_downloader.rs +++ b/crates/shirabe/src/downloader/xz_downloader.rs @@ -1,13 +1,16 @@ //! ref: composer/src/Composer/Downloader/XzDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::{Result, bail}; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; #[derive(Debug)] pub struct XzDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, } impl XzDownloader { diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index ecb7821e..90e56398 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -24,7 +24,8 @@ static IS_WINDOWS: Mutex> = Mutex::new(None); #[derive(Debug)] pub struct ZipDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap, // @phpstan-ignore property.onlyRead (helper property that is set via reflection for testing purposes) zip_archive_object: Option, } diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs index 0794ca5d..f2c09acd 100644 --- a/crates/shirabe/src/io/console_io.rs +++ b/crates/shirabe/src/io/console_io.rs @@ -24,7 +24,8 @@ use crate::util::silencer::Silencer; /// The Input/Output helper. #[derive(Debug)] pub struct ConsoleIO { - pub(crate) inner: BaseIO, + authentications: index::IndexMap>>, + pub(crate) input: Box, pub(crate) output: Box, pub(crate) helper_set: HelperSet, @@ -567,3 +568,17 @@ impl ConsoleIO { } } } + +impl BaseIO for ConsoleIO { + fn authentications( + &self, + ) -> &indexmap::IndexMap>> { + &self.authentications + } + + fn authentications_mut( + &mut self, + ) -> &mut indexmap::IndexMap>> { + &mut self.authentications + } +} diff --git a/crates/shirabe/src/io/null_io.rs b/crates/shirabe/src/io/null_io.rs index 42183988..af0296d0 100644 --- a/crates/shirabe/src/io/null_io.rs +++ b/crates/shirabe/src/io/null_io.rs @@ -6,7 +6,7 @@ use shirabe_php_shim::PhpMixed; #[derive(Debug)] pub struct NullIO { - inner: BaseIO, + authentications: index::IndexMap>>, } impl IOInterface for NullIO { @@ -79,3 +79,17 @@ impl IOInterface for NullIO { default } } + +impl BaseIO for NullIO { + fn authentications( + &self, + ) -> &indexmap::IndexMap>> { + &self.authentications + } + + fn authentications_mut( + &mut self, + ) -> &mut indexmap::IndexMap>> { + &mut self.authentications + } +} diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index a101a1fa..a4279131 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -13,7 +13,11 @@ use crate::repository::repository_interface::RepositoryInterface; #[derive(Debug)] pub struct AliasPackage { - pub(crate) inner: BasePackage, + id: i64, + name: String, + pretty_name: String, + repository: Option>, + /// @var string pub(crate) version: String, /// @var string @@ -427,3 +431,49 @@ impl PackageInterface for AliasPackage { self.inner.get_repository() } } + +impl BasePackage for AliasPackage { + fn id(&self) -> i64 { + self.id + } + + fn id_mut(&mut self) -> &mut i64 { + &mut self.id + } + + fn name(&self) -> &str { + &self.name + } + + fn name_mut(&mut self) -> &mut String { + &mut self.name + } + + fn pretty_name(&self) -> &str { + &self.pretty_name + } + + fn pretty_name_mut(&mut self) -> &mut String { + &mut self.pretty_name + } + + fn repository_opt(&self) -> Option<&dyn RepositoryInterface> { + self.repository.as_ref() + } + + fn set_repository_box(&mut self, repository: Box) { + todo!() + } + + fn take_repository(&mut self) -> Option> { + todo!() + } + + fn as_any(&self) -> &dyn std::any::Any { + todo!() + } + + fn clone_box(&self) -> Box { + todo!() + } +} diff --git a/crates/shirabe/src/package/archiver/base_exclude_filter.rs b/crates/shirabe/src/package/archiver/base_exclude_filter.rs index 6522d797..c7d2557d 100644 --- a/crates/shirabe/src/package/archiver/base_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/base_exclude_filter.rs @@ -3,6 +3,73 @@ use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::symfony::component::finder::glob::Glob; +#[derive(Debug)] +pub struct BaseExcludeFilterBase { + pub source_path: String, + pub exclude_patterns: Vec<(String, bool, bool)>, +} + +impl BaseExcludeFilterBase { + pub fn new(source_path: String) -> Self { + Self { + source_path, + exclude_patterns: Vec::new(), + } + } + + pub fn parse_lines(&self, lines: Vec, line_parser: F) -> Vec<(String, bool, bool)> + where + F: Fn(&str) -> Option<(String, bool, bool)>, + { + lines + .into_iter() + .filter_map(|line| { + let line = line.trim().to_string(); + if line.is_empty() || line.starts_with('#') { + return None; + } + line_parser(&line) + }) + .collect() + } + + pub fn generate_patterns(&self, rules: Vec) -> Vec<(String, bool, bool)> { + rules + .into_iter() + .map(|rule| Self::generate_pattern(&rule)) + .collect() + } + + pub fn generate_pattern(rule: &str) -> (String, bool, bool) { + let mut negate = false; + let mut pattern = String::new(); + + let mut rule = rule.to_string(); + if !rule.is_empty() && rule.starts_with('!') { + negate = true; + rule = rule.trim_start_matches('!').to_string(); + } + + let first_slash_position = rule.find('/'); + if first_slash_position == Some(0) { + pattern = "^/".to_string(); + } else if first_slash_position.is_none() || first_slash_position == Some(rule.len() - 1) { + pattern = "/".to_string(); + } + + let rule = rule.trim_matches('/'); + + let glob_regex = Glob::to_regex(rule); + let rule_regex = &glob_regex[2..glob_regex.len() - 2]; + + ( + format!("{{{}{}(?=$|/)}}", pattern, rule_regex), + negate, + false, + ) + } +} + pub trait BaseExcludeFilter { fn source_path(&self) -> &str; fn exclude_patterns(&self) -> &[(String, bool, bool)]; diff --git a/crates/shirabe/src/package/archiver/composer_exclude_filter.rs b/crates/shirabe/src/package/archiver/composer_exclude_filter.rs index b9a32f49..979e67ea 100644 --- a/crates/shirabe/src/package/archiver/composer_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/composer_exclude_filter.rs @@ -1,15 +1,15 @@ //! ref: composer/src/Composer/Package/Archiver/ComposerExcludeFilter.php -use super::base_exclude_filter::BaseExcludeFilter; +use super::base_exclude_filter::BaseExcludeFilterBase; #[derive(Debug)] pub struct ComposerExcludeFilter { - inner: BaseExcludeFilter, + inner: BaseExcludeFilterBase, } impl ComposerExcludeFilter { pub fn new(source_path: String, exclude_rules: Vec) -> Self { - let mut inner = BaseExcludeFilter::new(source_path); + let mut inner = BaseExcludeFilterBase::new(source_path); inner.exclude_patterns = inner.generate_patterns(exclude_rules); Self { inner } } diff --git a/crates/shirabe/src/package/archiver/git_exclude_filter.rs b/crates/shirabe/src/package/archiver/git_exclude_filter.rs index 8028c156..dddad122 100644 --- a/crates/shirabe/src/package/archiver/git_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/git_exclude_filter.rs @@ -1,16 +1,16 @@ //! ref: composer/src/Composer/Package/Archiver/GitExcludeFilter.php -use crate::package::archiver::base_exclude_filter::BaseExcludeFilter; +use crate::package::archiver::base_exclude_filter::BaseExcludeFilterBase; use shirabe_external_packages::composer::pcre::preg::Preg; use std::path::Path; pub struct GitExcludeFilter { - inner: BaseExcludeFilter, + inner: BaseExcludeFilterBase, } impl GitExcludeFilter { pub fn new(source_path: String) -> Self { - let inner = BaseExcludeFilter::new(source_path.clone()); + let inner = BaseExcludeFilterBase::new(source_path.clone()); let mut filter = Self { inner }; let gitattributes_path = format!("{}/.gitattributes", source_path); @@ -37,11 +37,11 @@ impl GitExcludeFilter { let parts = Preg::split(r"\s+", line); if parts.len() == 2 && parts[1] == "export-ignore" { - return BaseExcludeFilter::generate_pattern(&parts[0]); + return Some(BaseExcludeFilterBase::generate_pattern(&parts[0])); } if parts.len() == 2 && parts[1] == "-export-ignore" { - return BaseExcludeFilter::generate_pattern(&format!("!{}", parts[0])); + return BaseExcludeFilterBase::generate_pattern(&format!("!{}", parts[0])); } None diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs index 81d61311..ae94a202 100644 --- a/crates/shirabe/src/package/package.rs +++ b/crates/shirabe/src/package/package.rs @@ -9,6 +9,7 @@ use shirabe_php_shim::{E_USER_DEPRECATED, PhpMixed, strpos, trigger_error}; use crate::package::base_package::BasePackage; use crate::package::link::Link; use crate::package::version::version_parser::VersionParser; +use crate::repository::repository_interface::RepositoryInterface; /// Mirror entry, e.g. `['url' => 'https://...', 'preferred' => true]`. #[derive(Debug, Clone)] @@ -20,7 +21,11 @@ pub struct Mirror { /// Core package definitions that are needed to resolve dependencies and install packages #[derive(Debug)] pub struct Package { - pub(crate) inner: BasePackage, + id: i64, + name: String, + pretty_name: String, + repository: Option>, + pub(crate) r#type: Option, pub(crate) target_dir: Option, /// `'source'` | `'dist'` | `null` @@ -523,3 +528,49 @@ impl Package { new_links } } + +impl BasePackage for Package { + fn id(&self) -> i64 { + self.id + } + + fn id_mut(&mut self) -> &mut i64 { + &mut self.id + } + + fn name(&self) -> &str { + &self.name + } + + fn name_mut(&mut self) -> &mut String { + &mut self.name + } + + fn pretty_name(&self) -> &str { + &self.pretty_name + } + + fn pretty_name_mut(&mut self) -> &mut String { + &mut self.pretty_name + } + + fn repository_opt(&self) -> Option<&dyn RepositoryInterface> { + self.repository.as_ref() + } + + fn set_repository_box(&mut self, repository: Box) { + todo!() + } + + fn take_repository(&mut self) -> Option> { + todo!() + } + + fn as_any(&self) -> &dyn std::any::Any { + todo!() + } + + fn clone_box(&self) -> Box { + todo!() + } +} diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 74f1e119..c03f2177 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -13,7 +13,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::forgejo::Forgejo; use crate::util::forgejo_repository_data::ForgejoRepositoryData; use crate::util::forgejo_url::ForgejoUrl; @@ -21,7 +21,7 @@ use crate::util::http::response::Response; #[derive(Debug)] pub struct ForgejoDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) forgejo_url: Option, pub(crate) repository_data: Option, pub(crate) git_driver: Option, @@ -500,7 +500,7 @@ impl ForgejoDriver { fn setup_git_driver(&mut self, url: &str) -> Result<()> { let mut git_driver = GitDriver { - inner: VcsDriver::new( + inner: VcsDriverBase::new( { let mut m = IndexMap::new(); m.insert("url".to_string(), PhpMixed::String(url.to_string())); diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 6e99f5f1..f1e6a89a 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -8,13 +8,13 @@ use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct FossilDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option>, pub(crate) branches: Option>, pub(crate) root_identifier: Option, diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index dc3b5f3c..0e16ced9 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -16,14 +16,14 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::repository::vcs::vcs_driver_interface::VcsDriverInterface; use crate::util::bitbucket::Bitbucket; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitBitbucketDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) owner: String, /// @var string diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 0f8f841e..48aa4c17 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -12,7 +12,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::git::Git as GitUtil; use crate::util::process_executor::ProcessExecutor; @@ -20,7 +20,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct GitDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option>, pub(crate) branches: Option>, pub(crate) root_identifier: Option, diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index bd2e2ade..233e3ea5 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -16,13 +16,13 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::github::GitHub; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitHubDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) owner: String, pub(crate) repository: String, /// @var array Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index cb0d0a2d..583f2218 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -16,7 +16,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::gitlab::GitLab; use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; @@ -24,7 +24,7 @@ use crate::util::http_downloader::HttpDownloader; /// Driver for GitLab API, use the Git driver for local checkouts. #[derive(Debug)] pub struct GitLabDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @phpstan-var 'https'|'http' scheme: String, namespace: String, diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 6b32a0ac..a8fc70af 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -3,7 +3,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::hg::Hg as HgUtils; use crate::util::url::Url; @@ -14,7 +14,7 @@ use shirabe_php_shim::{RuntimeException, dirname, is_dir, is_writable}; #[derive(Debug)] pub struct HgDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option>, pub(crate) branches: Option>, pub(crate) root_identifier: Option, diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs index cd3b32b5..ee09deed 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -7,14 +7,14 @@ use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException}; use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::http::response::Response; use crate::util::perforce::Perforce; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct PerforceDriver { - inner: VcsDriver, + inner: VcsDriverBase, pub(crate) depot: String, pub(crate) branch: String, pub(crate) perforce: Option, diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 7c32e4ab..0a05d844 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -14,7 +14,7 @@ use crate::config::Config; use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; use crate::util::svn::Svn as SvnUtil; @@ -22,7 +22,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct SvnDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) base_url: String, /// @var array Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 3195822d..162792e7 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -17,6 +17,67 @@ use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; use crate::util::process_executor::ProcessExecutor; +#[derive(Debug)] +pub struct VcsDriverBase { + pub url: String, + pub origin_url: String, + pub repo_config: IndexMap, + pub io: Box, + pub config: Config, + pub process: ProcessExecutor, + pub http_downloader: HttpDownloader, + pub info_cache: IndexMap>>, + pub cache: Option, +} + +impl VcsDriverBase { + pub fn new( + repo_config: IndexMap, + io: Box, + config: Config, + http_downloader: HttpDownloader, + process: ProcessExecutor, + ) -> Self { + let url = repo_config + .get("url") + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); + let origin_url = url.clone(); + Self { + url, + origin_url, + repo_config, + io, + config, + process, + http_downloader, + info_cache: IndexMap::new(), + cache: None, + } + } + + pub fn should_cache(&self, identifier: &str) -> bool { + self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier).unwrap_or(false) + } + + pub fn get_scheme(&self) -> &str { + if extension_loaded("openssl") { + return "https"; + } + "http" + } + + pub fn get_contents(&self, url: &str) -> anyhow::Result { + let options = self + .repo_config + .get("options") + .cloned() + .unwrap_or(PhpMixed::Array(IndexMap::new())); + self.http_downloader.get(url, &options) + } +} + // TODO(phase-b): the constructor is `final` in PHP; concrete implementations must replicate the // initialization logic (local-path normalization etc.) from the original new() body. pub trait VcsDriver: VcsDriverInterface { -- cgit v1.3.1