MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / determineMinifiHome

Function determineMinifiHome

main/MainHelper.cpp:93–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93std::string determineMinifiHome(const std::shared_ptr<logging::Logger>& logger){
94 /* Try to determine MINIFI_HOME */
95 std::string minifiHome = [&logger]() -> std::string {
96 /* If MINIFI_HOME is set as an environment variable, we will use that */
97 bool minifiHomeSet = false;
98 std::string minifiHome;
99 std::tie(minifiHomeSet, minifiHome) = utils::Environment::getEnvironmentVariable(MINIFI_HOME_ENV_KEY);
100 if (minifiHomeSet) {
101 logger->log_info("Found " MINIFI_HOME_ENV_KEY "=%s in environment", minifiHome);
102 return minifiHome;
103 } else {
104 logger->log_info(MINIFI_HOME_ENV_KEY " is not set; trying to infer it");
105 }
106
107 /* Try to determine MINIFI_HOME relative to the location of the minifi executable */
108 std::string executablePath = utils::file::FileUtils::get_executable_path();
109 if (executablePath.empty()) {
110 logger->log_error("Failed to determine location of the minifi executable");
111 } else {
112 std::string minifiPath, minifiFileName;
113 std::tie(minifiPath, minifiFileName) = minifi::utils::file::FileUtils::split_path(executablePath);
114 logger->log_info("Inferred " MINIFI_HOME_ENV_KEY "=%s based on the minifi executable location %s", minifiPath, executablePath);
115 return minifiPath;
116 }
117
118#ifndef WIN32
119 /* Try to determine MINIFI_HOME relative to the current working directory */
120 std::string cwd = utils::Environment::getCurrentWorkingDirectory();
121 if (cwd.empty()) {
122 logger->log_error("Failed to determine current working directory");
123 } else {
124 logger->log_info("Inferred " MINIFI_HOME_ENV_KEY "=%s based on the current working directory %s", cwd, cwd);
125 return cwd;
126 }
127#endif
128
129 return "";
130 }();
131
132 if (minifiHome.empty()) {
133 logger->log_error("No " MINIFI_HOME_ENV_KEY " could be inferred. "
134 "Please set " MINIFI_HOME_ENV_KEY " or run minifi from a valid location.");
135 return "";
136 }
137
138 /* Verify that MINIFI_HOME is valid */
139 bool minifiHomeValid = false;
140 if (validHome(minifiHome)) {
141 minifiHomeValid = true;
142 } else {
143 logger->log_info("%s is not a valid " MINIFI_HOME_ENV_KEY ", because there is no " DEFAULT_NIFI_PROPERTIES_FILE " file in it.", minifiHome);
144
145 std::string minifiHomeWithoutBin, binDir;
146 std::tie(minifiHomeWithoutBin, binDir) = minifi::utils::file::FileUtils::split_path(minifiHome);
147 if (minifiHomeWithoutBin != "" && (binDir == "bin" || binDir == std::string("bin") + minifi::utils::file::FileUtils::get_separator())) {
148 if (validHome(minifiHomeWithoutBin)) {
149 logger->log_info("%s is a valid " MINIFI_HOME_ENV_KEY ", falling back to it.", minifiHomeWithoutBin);
150 minifiHomeValid = true;

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 8

get_executable_pathFunction · 0.85
split_pathFunction · 0.85
validHomeFunction · 0.85
log_infoMethod · 0.80
log_errorMethod · 0.80
c_strMethod · 0.80
get_separatorFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected