|
4 | 4 |
|
5 | 5 | namespace automation |
6 | 6 | { |
7 | | - namespace interpreter |
8 | | - { |
9 | | - CInformation::CInformation(const boost::filesystem::path& interpreterPath) |
10 | | - : m_isSupportedOnThisPlatform(true), |
11 | | - m_package(shared::CDataContainer::make()), |
12 | | - m_path(interpreterPath) |
13 | | - { |
14 | | - try |
15 | | - { |
16 | | - boost::filesystem::path packageFile; |
17 | | - packageFile = m_path / "package.json"; |
18 | | - m_package->deserializeFromFile(packageFile.string()); |
19 | | - } |
20 | | - catch (shared::exception::CException& e) |
21 | | - { |
22 | | - throw std::runtime_error(m_path.stem().string() + std::string(" : Error reading package.json : ") + e.what()); |
23 | | - } |
24 | | - |
25 | | - try |
26 | | - { |
27 | | - // Get and check data |
28 | | - |
29 | | - m_type = m_path.stem().string(); |
30 | | - |
31 | | - m_name = m_package->get<std::string>("name"); |
32 | | - if (m_name.empty()) |
33 | | - throw std::invalid_argument("Error reading package.json : interpreter name can not be empty"); |
34 | | - |
35 | | - if (m_package->containsValue("description")) |
36 | | - m_description = m_package->get<std::string>("description"); |
37 | | - |
38 | | - m_version = shared::versioning::CSemVer(m_package->get<std::string>("version")); |
39 | | - |
40 | | - m_author = m_package->get<std::string>("author"); |
41 | | - if (m_author.empty()) |
42 | | - throw std::invalid_argument("Error reading package.json : interpreter author can not be empty"); |
43 | | - |
44 | | - if (m_package->containsValue("url")) |
45 | | - m_url = m_package->get<std::string>("url"); // No check on URL |
46 | | - |
47 | | - if (m_package->containsValue("credits")) |
48 | | - m_credits = m_package->get<std::string>("credits"); |
49 | | - |
50 | | - if (m_package->containsValue("supportedPlatforms") || m_package->containsChild("supportedPlatforms")) |
51 | | - m_isSupportedOnThisPlatform = tools::CSupportedPlatformsChecker::isSupported(m_package->get<shared::CDataContainer>("supportedPlatforms")); |
52 | | - else |
53 | | - m_isSupportedOnThisPlatform = true; |
54 | | - } |
55 | | - catch (shared::exception::CException& e) |
56 | | - { |
57 | | - // Set interpreter as not supported |
58 | | - m_isSupportedOnThisPlatform = false; |
59 | | - throw std::invalid_argument(m_path.stem().string() + std::string(" : Error reading package.json : data not found : ") + e.what()); |
60 | | - } |
61 | | - |
62 | | - auto interpreterFolder = m_path.filename().string(); |
63 | | - if (!boost::equal(interpreterFolder, m_type)) |
64 | | - { |
65 | | - // Set interpreter as not supported |
66 | | - m_isSupportedOnThisPlatform = false; |
67 | | - throw std::runtime_error((boost::format("The interpreter folder '%1%' does not match interpreter type '%2%'") % interpreterFolder % m_type).str()); |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - CInformation::~CInformation() |
72 | | - { |
73 | | - } |
74 | | - |
75 | | - const std::string& CInformation::getType() const |
76 | | - { |
77 | | - return m_type; |
78 | | - } |
79 | | - |
80 | | - const std::string& CInformation::getName() const |
81 | | - { |
82 | | - return m_name; |
83 | | - } |
84 | | - |
85 | | - const std::string& CInformation::getDescription() const |
86 | | - { |
87 | | - return m_description; |
88 | | - } |
89 | | - |
90 | | - const shared::versioning::CSemVer& CInformation::getVersion() const |
91 | | - { |
92 | | - return m_version; |
93 | | - } |
94 | | - |
95 | | - const std::string& CInformation::getAuthor() const |
96 | | - { |
97 | | - return m_author; |
98 | | - } |
99 | | - |
100 | | - const std::string& CInformation::getUrl() const |
101 | | - { |
102 | | - return m_url; |
103 | | - } |
104 | | - |
105 | | - const std::string& CInformation::getCredits() const |
106 | | - { |
107 | | - return m_credits; |
108 | | - } |
109 | | - |
110 | | - bool CInformation::isSupportedOnThisPlatform() const |
111 | | - { |
112 | | - return m_isSupportedOnThisPlatform; |
113 | | - } |
114 | | - |
115 | | - boost::shared_ptr<const shared::CDataContainer> CInformation::getPackage() const |
116 | | - { |
117 | | - return m_package; |
118 | | - } |
119 | | - |
120 | | - const boost::filesystem::path& CInformation::getPath() const |
121 | | - { |
122 | | - return m_path; |
123 | | - } |
124 | | - } |
| 7 | + namespace interpreter |
| 8 | + { |
| 9 | + CInformation::CInformation(const boost::filesystem::path& interpreterPath) |
| 10 | + : m_isSupportedOnThisPlatform(true), |
| 11 | + m_package(shared::CDataContainer::make()), |
| 12 | + m_path(interpreterPath) |
| 13 | + { |
| 14 | + try |
| 15 | + { |
| 16 | + boost::filesystem::path packageFile; |
| 17 | + packageFile = m_path / "package.json"; |
| 18 | + m_package->deserializeFromFile(packageFile.string()); |
| 19 | + } |
| 20 | + catch (shared::exception::CException& e) |
| 21 | + { |
| 22 | + throw std::runtime_error(m_path.stem().string() + std::string(" : Error reading package.json : ") + e.what()); |
| 23 | + } |
| 24 | + |
| 25 | + try |
| 26 | + { |
| 27 | + // Get and check data |
| 28 | + |
| 29 | + m_type = m_path.stem().string(); |
| 30 | + |
| 31 | + m_name = m_package->get<std::string>("name"); |
| 32 | + if (m_name.empty()) |
| 33 | + throw std::invalid_argument("Error reading package.json : interpreter name can not be empty"); |
| 34 | + |
| 35 | + if (m_package->containsValue("description")) |
| 36 | + m_description = m_package->get<std::string>("description"); |
| 37 | + |
| 38 | + m_version = shared::versioning::CSemVer(m_package->get<std::string>("version")); |
| 39 | + |
| 40 | + m_author = m_package->get<std::string>("author"); |
| 41 | + if (m_author.empty()) |
| 42 | + throw std::invalid_argument("Error reading package.json : interpreter author can not be empty"); |
| 43 | + |
| 44 | + if (m_package->containsValue("url")) |
| 45 | + m_url = m_package->get<std::string>("url"); // No check on URL |
| 46 | + |
| 47 | + if (m_package->containsValue("credits")) |
| 48 | + m_credits = m_package->get<std::string>("credits"); |
| 49 | + |
| 50 | + if (m_package->containsValue("supportedPlatforms") || m_package->containsChild("supportedPlatforms")) |
| 51 | + m_isSupportedOnThisPlatform = tools::CSupportedPlatformsChecker::isSupported(m_package->get<shared::CDataContainer>("supportedPlatforms")); |
| 52 | + else |
| 53 | + m_isSupportedOnThisPlatform = true; |
| 54 | + } |
| 55 | + catch (shared::exception::CException& e) |
| 56 | + { |
| 57 | + // Set interpreter as not supported |
| 58 | + m_isSupportedOnThisPlatform = false; |
| 59 | + throw std::invalid_argument(m_path.stem().string() + std::string(" : Error reading package.json : data not found : ") + e.what()); |
| 60 | + } |
| 61 | + |
| 62 | + auto interpreterFolder = m_path.filename().string(); |
| 63 | + if (!boost::equal(interpreterFolder, m_type)) |
| 64 | + { |
| 65 | + // Set interpreter as not supported |
| 66 | + m_isSupportedOnThisPlatform = false; |
| 67 | + throw std::runtime_error(std::string("The interpreter folder '") |
| 68 | + + interpreterFolder |
| 69 | + + "' does not match interpreter type '" |
| 70 | + + m_type |
| 71 | + + "'"); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + CInformation::~CInformation() |
| 76 | + { |
| 77 | + } |
| 78 | + |
| 79 | + const std::string& CInformation::getType() const |
| 80 | + { |
| 81 | + return m_type; |
| 82 | + } |
| 83 | + |
| 84 | + const std::string& CInformation::getName() const |
| 85 | + { |
| 86 | + return m_name; |
| 87 | + } |
| 88 | + |
| 89 | + const std::string& CInformation::getDescription() const |
| 90 | + { |
| 91 | + return m_description; |
| 92 | + } |
| 93 | + |
| 94 | + const shared::versioning::CSemVer& CInformation::getVersion() const |
| 95 | + { |
| 96 | + return m_version; |
| 97 | + } |
| 98 | + |
| 99 | + const std::string& CInformation::getAuthor() const |
| 100 | + { |
| 101 | + return m_author; |
| 102 | + } |
| 103 | + |
| 104 | + const std::string& CInformation::getUrl() const |
| 105 | + { |
| 106 | + return m_url; |
| 107 | + } |
| 108 | + |
| 109 | + const std::string& CInformation::getCredits() const |
| 110 | + { |
| 111 | + return m_credits; |
| 112 | + } |
| 113 | + |
| 114 | + bool CInformation::isSupportedOnThisPlatform() const |
| 115 | + { |
| 116 | + return m_isSupportedOnThisPlatform; |
| 117 | + } |
| 118 | + |
| 119 | + boost::shared_ptr<const shared::CDataContainer> CInformation::getPackage() const |
| 120 | + { |
| 121 | + return m_package; |
| 122 | + } |
| 123 | + |
| 124 | + const boost::filesystem::path& CInformation::getPath() const |
| 125 | + { |
| 126 | + return m_path; |
| 127 | + } |
| 128 | + } |
125 | 129 | } // namespace automation::interpreter |
126 | 130 |
|
127 | 131 |
|
0 commit comments