45 #include "compatibility.hpp"
53 #define return_sched(retval) \
56 fo_scheduler_disconnect((retval)); \
69 const string& rule_loc,
bool json,
70 const string& lic_result_json,
71 const string& main_license)
73 bool printComma =
false;
75 set<string> all_license_list;
76 const unordered_map<string, string>& license_map =
78 const map<tuple<string, string, string, string>,
bool>& rule_list =
80 map<tuple<string, string>,
bool> compatibility_results;
90 std::ifstream ifs(lic_result_json.c_str());
94 for (
const auto& fileItems : root[
"results"])
96 const string fileName = fileItems[
"file"].asString();
97 set<string> file_license_set = set<string>(main_license_set);
98 for (
const auto&
license : fileItems[
"licenses"])
101 string str =
license.asString();
102 if (str ==
"Dual-license" || str ==
"No_license_found" || str ==
"Void")
106 file_license_set.insert(str);
107 all_license_list.insert(str);
109 if (file_license_set.size() > 1)
111 vector<tuple<string, string, bool>> result;
113 compatibility_results);
124 vector<tuple<string, string, bool>> result;
125 string name =
"null";
127 compatibility_results);
143 int main(
int argc,
char** argv)
146 vector<string> licenseNames;
147 string lic_types, rule, jFile, mainLicense;
200 catch (invalid_argument& e)
217 const set<string>& license_set,
218 const unordered_map<string, string>& license_map,
219 const map<tuple<string, string, string, string>,
bool>& rule_list,
220 map<tuple<string, string>,
bool>& scan_results)
222 string first_name, first_type, second_name, second_type;
223 vector<tuple<string, string, bool>> res;
224 vector<string> license_list = vector<string>(license_set.begin(),
227 unsigned int license_len = license_list.size();
228 for (
unsigned int i = 0; i < (license_len - 1); i++)
230 first_name = license_list[i];
233 first_type = license_map.at(first_name);
235 catch (out_of_range&)
239 for (
unsigned int j = (i + 1); j < license_len; j++)
241 second_name = license_list[j];
244 second_type = license_map.at(second_name);
246 catch (out_of_range&)
251 auto existing_result = scan_results.find(
252 make_tuple(first_name, second_name));
253 if (existing_result == scan_results.end())
255 existing_result = scan_results.find(
256 make_tuple(second_name, first_name));
259 if (existing_result != scan_results.end())
261 res.emplace_back(first_name, second_name, existing_result->second);
266 second_name, second_type,
268 res.emplace_back(first_name, second_name, compatibility);
269 scan_results[make_tuple(first_name, second_name)] = compatibility;
map< tuple< string, string, string, string >, bool > initialize_rule_list(const string &file_location)
Read YAML file of rules and parse it as map.
unordered_map< string, string > initialize_license_map(const string &file_location)
Parse license type CSV and create a map.
bool processUploadId(const CompatibilityState &state, int uploadId, CompatibilityDatabaseHandler &databaseHandler, int groupId)
bool parseCliOptions(int argc, char **argv, CompatibilityCliOptions &dest, std::string &types, std::string &rules, string &jFile, string &mainLicense)
Parse the options sent by CLI to CliOptions object.
void printResultToStdout(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName)
CompatibilityState getState(DbManager &dbManager, CompatibilityCliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
int writeARS(const CompatibilityState &state, int arsId, int uploadId, int success, DbManager &dbManager)
int queryAgentId(DbManager &dbManager)
std::set< std::string > mainLicenseToSet(const string &mainLicense)
void appendToJson(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName, bool &printComma)
bool are_licenses_compatible(const string &first_name, const string &first_type, const string &second_name, const string &second_type, const map< tuple< string, string, string, string >, bool > &rule_list)
Check the licenses against rules and get the compatibility result.
Store the options sent through the CLI.
bool doJsonOutput() const
Check if JSON output is required.
Store the state of the agent.
void setAgentId(const int agentId)
#define return_sched(retval)
vector< tuple< string, string, bool > > checkCompatibility(const set< string > &license_set, const unordered_map< string, string > &license_map, const map< tuple< string, string, string, string >, bool > &rule_list, map< tuple< string, string >, bool > &scan_results)
find the compatibility for cli mode
void check_file_compatibility(const string &lic_type_loc, const string &rule_loc, bool json, const string &lic_result_json, const string &main_license)
Check and print license compatibility of scan result.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
int fo_scheduler_groupID()
Gets the id of the group that created the job that the agent is running.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.