diff --git a/src/CmdOptions.cpp b/src/CmdOptions.cpp index 5600da4..a92f1ac 100755 --- a/src/CmdOptions.cpp +++ b/src/CmdOptions.cpp @@ -184,6 +184,7 @@ CmdOptions::CmdOptions() CLI::App * installCommand = m_cliApp.add_subcommand("install", "install dependencies for a package from its packagedependencies file(s)"); installCommand->add_option("--alternate-remote-type,-l", m_altRepoType, "alternate remote type: " + getOptionString("--alternate-remote-type")); installCommand->add_option("--alternate-remote-url,-u", m_altRepoUrl, "alternate remote url to use when the declared remote fails to provide a dependency"); + installCommand->add_option("--invert-remote-order", m_invertRepositoryOrder, "invert alternate and base remote search order : alternate remote is searched before packagedependencies declared remote", true); installCommand->add_option("--apiKey,-k", m_apiKey, "Artifactory api key"); installCommand->add_option("file", m_dependenciesFile, "Remaken dependencies files", true); installCommand->add_option("--conan_profile", m_conanProfile, "force conan profile name to use (overrides detected profile)",true); diff --git a/src/CmdOptions.h b/src/CmdOptions.h index 2ec129f..3543786 100755 --- a/src/CmdOptions.h +++ b/src/CmdOptions.h @@ -129,6 +129,10 @@ class CmdOptions return m_moduleSubfolderPath; } + bool invertRepositoryOrder () const { + return m_invertRepositoryOrder; + } + bool useCache() const { return !m_ignoreCache; } @@ -252,6 +256,7 @@ class CmdOptions std::string m_conanProfile = "default"; fs::path m_moduleSubfolderPath; bool m_ignoreCache; + bool m_invertRepositoryOrder = false; bool m_verbose; bool m_recurse; bool m_regex = false; diff --git a/src/Dependency.cpp b/src/Dependency.cpp index 93eb350..6ec68b3 100755 --- a/src/Dependency.cpp +++ b/src/Dependency.cpp @@ -190,6 +190,7 @@ Dependency::Dependency(const std::string & rawFormat, const std::string & mainMo m_bHasOptions = true; } } + m_originalBaseRepository = m_baseRepository; } diff --git a/src/Dependency.h b/src/Dependency.h index b8b6687..7bfafd8 100644 --- a/src/Dependency.h +++ b/src/Dependency.h @@ -72,6 +72,11 @@ class Dependency m_baseRepository = otherRepo; } + inline void resetBaseRepository() { + m_baseRepository = m_originalBaseRepository; + } + + inline const std::string & getMode() const { return m_mode; } @@ -122,6 +127,7 @@ class Dependency std::string m_name; std::string m_version; std::string m_baseRepository; + std::string m_originalBaseRepository; std::string m_identifier; std::string m_repositoryType; std::string m_mode; diff --git a/src/managers/DependencyManager.cpp b/src/managers/DependencyManager.cpp index 4a05eb0..843ac6c 100755 --- a/src/managers/DependencyManager.cpp +++ b/src/managers/DependencyManager.cpp @@ -176,6 +176,14 @@ void DependencyManager::retrieveDependency(Dependency & dependency) { fs::detail::utf8_codecvt_facet utf8; shared_ptr fileRetriever = FileHandlerFactory::instance()->getFileHandler(dependency, m_options); + if (m_options.invertRepositoryOrder() && dependency.getType() == Dependency::Type::REMAKEN) {// what about cache management in this case ? + fileRetriever = FileHandlerFactory::instance()->getAlternateHandler(dependency.getType(),m_options); + if (!fileRetriever) { // no alternate repository found + BOOST_LOG_TRIVIAL(error)<<"==> No alternate repository defined for '"<computeSourcePath(dependency); fs::path outputDirectory = fileRetriever->computeLocalDependencyRootDir(dependency); fs::path libDirectory = fileRetriever->computeRootLibDir(dependency); @@ -186,14 +194,20 @@ void DependencyManager::retrieveDependency(Dependency & dependency) try { outputDirectory = fileRetriever->installArtefact(dependency); } - catch (std::runtime_error & e) { // try alternate repository + catch (std::runtime_error & e) { // try alternate/primary repository shared_ptr fileRetriever = FileHandlerFactory::instance()->getAlternateHandler(dependency.getType(),m_options); + if (m_options.invertRepositoryOrder() && dependency.getType() == Dependency::Type::REMAKEN) {// what about cache management in this case ? + fileRetriever = FileHandlerFactory::instance()->getFileHandler(dependency, m_options); + } if (!fileRetriever) { // no alternate repository found BOOST_LOG_TRIVIAL(error)<<"==> Unable to find '"<computeSourcePath(dependency); try { std::cout<<"==> Trying to find '"<