From 497745ad31c90545b288e2845049e0ce474bcbe2 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 19 10月 2019 10:10:45 +0800 Subject: [PATCH] Merge branch 'feature/code_review_and_refactor' into develop --- src/library/locate/EnvironmentVarLocation.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/library/locate/EnvironmentVarLocation.cpp b/src/library/locate/EnvironmentVarLocation.cpp new file mode 100644 index 0000000..a904b9a --- /dev/null +++ b/src/library/locate/EnvironmentVarLocation.cpp @@ -0,0 +1,46 @@ +/* + * EnvironmentVarLocation.cpp + * + * Created on: Oct 12, 2019 + * Author: Gabriele Contini + */ + +#include <build_properties.h> + +#include "../base/FileUtils.hpp" +#include "../base/StringUtils.h" +#include "EnvironmentVarLocation.hpp" + +namespace license { +namespace locate { +using namespace std; + +EnvironmentVarLocation::EnvironmentVarLocation() : + LocatorStrategy("EnvironmentVarLocation") { +} + +EnvironmentVarLocation::~EnvironmentVarLocation() { +} + +const vector<string> EnvironmentVarLocation::license_locations( + EventRegistry &eventRegistry) { + vector<string> licenseFileFoundWithEnvVariable; + + const string varName(LICENSE_LOCATION_ENV_VAR); + if (varName.length() > 0) { + //var name is defined in header files. + char *env_var_value = getenv(LICENSE_LOCATION_ENV_VAR); + if (env_var_value != nullptr && env_var_value[0] != '\0') { + const vector<string> declared_positions = license::split_string( + string(env_var_value), ';'); + licenseFileFoundWithEnvVariable = license::filter_existing_files( + declared_positions, eventRegistry, LICENSE_LOCATION_ENV_VAR); + } else { + eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED); + } + } + return licenseFileFoundWithEnvVariable; +} + +} +} -- Gitblit v1.9.1