1 #include "classpath.hpp"
11 #include <system_error>
13 #include <sys/types.h>
20 template <
typename TContainer,
typename TSep>
21 void join(std::ostream& os,
const TContainer& src, TSep sep)
24 for (
const auto& x : src)
26 if (!std::exchange(first,
false))
32 static bool file_exists(ptr<const char> path)
40 throw std::system_error(errno, std::system_category());
48 static classpath find_system_default()
50 string_view locations[] =
53 "/usr/local/share/java",
55 string_view requirements[] =
62 std::vector<std::string> components;
63 std::vector<string_view> unfound;
64 for (
auto jar : requirements)
67 for (
auto base_loc : locations)
69 auto potential_sz = base_loc.size() + jar.size() + 4;
70 char potential[potential_sz];
71 std::snprintf(potential, potential_sz,
"%s/%s", base_loc.data(), jar.data());
73 if (file_exists(potential))
76 components.emplace_back(std::string(potential));
82 unfound.emplace_back(jar);
87 return classpath(std::move(components));
91 std::ostringstream os;
92 os <<
"Could not find requirement" << ((unfound.size() == 1U) ?
"" :
"s") <<
": ";
93 join(os, unfound,
", ");
94 os <<
". Searched paths: ";
95 join(os, locations,
", ");
96 throw std::runtime_error(os.str());
103 static const auto instance = find_system_default();
108 _components(std::move(components))
113 std::ostringstream os;
118 std::ostream& operator<<(std::ostream& os,
const classpath&
self)
120 join(os,
self._components,
':');
Represents a collection of JARs or other Java entities that should be provided as the --classpath to ...
Imports the string_view type as std::string_view.
classpath(std::vector< std::string > components) noexcept
Create a classpath specification from the provided components.
std::string command_line() const
Get the command-line representation of this classpath. This puts ':' characters between the component...
static classpath system_default()
Load the system-default classpath for ZooKeeper.