Skip to content

Commit

Permalink
fix(atarashi): Fix the wrapper for atarashi
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
  • Loading branch information
GMishx authored and hastagAB committed Jul 23, 2019
1 parent a6c3fed commit 5a03a4e
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ install/defconf/Db.conf
install/defconf/fossology.conf
install/fo-postinstall
src/adj2nest/agent/adj2nest
src/atarashi/agent/atarashiWrapper
src/buckets/agent/buckets
src/cli/cp2foss
src/cli/cp2foss.1
Expand Down Expand Up @@ -151,8 +152,6 @@ src/reportImport/agent/reportImport
/install/scripts/php.ini
/install/scripts/php.ini.orig
/install/db/dbmigrate_pfile_calculate_sha256.php
/src/ninka/agent/atarashiWrapper
/src/ninka/agent/atarashi

# Add all the Ubuntu consol log file
ubuntu-*
1 change: 1 addition & 0 deletions src/Makefile
Expand Up @@ -11,6 +11,7 @@ include $(VARS)
DIRS = \
adj2nest \
buckets \
atarashi \
cli \
copyright \
debug \
Expand Down
4 changes: 1 addition & 3 deletions src/atarashi/Makefile
Expand Up @@ -16,11 +16,10 @@ TESTDIR = agent_tests

DIR_LOOP = @set -e; for dir in $(DIRS); do $(MAKE) -s -C $$dir $(1); done

all: VERSIONFILE atarashi-all
all: VERSIONFILE
$(call DIR_LOOP, )

test: all
# $(TOP)/install/scripts/install-atarashi.sh
$(MAKE) -C $(TESTDIR) test

coverage: all
Expand Down Expand Up @@ -48,4 +47,3 @@ clean:
rm -f VERSION

.PHONY: all test coverage VERSIONFILE install uninstall clean
.PHONY: atarashi-all atarashi-install atarashi-uninstall atarashi-clean atarashi-Makefile
Binary file added src/atarashi/agent/atarashiWrapper
Binary file not shown.
27 changes: 26 additions & 1 deletion src/atarashi/agent/atarashiwrapper.cc
Expand Up @@ -44,5 +44,30 @@ string scanFileWithAtarashi(const State& state, const fo::File& file)
bail(1);
}

return result;
int jsonStart = result.find("{");
return result.substr(jsonStart, string::npos);
}

vector<LicenseMatch> extractLicensesFromAtarashiResult(string atarashiResult)
{
Json::Reader reader;
Json::Value atarashiResultobj;
bool parseSuccess = reader.parse(atarashiResult, atarashiResultobj);

if (!parseSuccess)
{
cout << "Failed to parse" << reader.getFormattedErrorMessages();
bail(-30);
}

vector<LicenseMatch> matches;
Json::Value resultArray = atarashiResultobj["results"];
for (unsigned int index = 0; index < resultArray.size(); ++index)
{
Json::Value resultObject = resultArray[index];
LicenseMatch m(resultObject["shortname"].asString(),
(unsigned)(resultObject["sim_score"].asDouble() * 100.0));
matches.push_back(m);
}
return matches;
}
8 changes: 3 additions & 5 deletions src/atarashi/agent/atarashiwrapper.hpp
Expand Up @@ -18,18 +18,16 @@
#ifndef ATARASHI_AGENT_ATARASHI_WRAPPER_HPP
#define ATARASHI_AGENT_ATARASHI_WRAPPER_HPP

#define AGENT_NAME "atarashi"
#define AGENT_DESC "atarashi agent"
#define AGENT_ARS "atarashi_ars"

#include <string>
#include <vector>
#include <jsoncpp/json/json.h>

#include "files.hpp"
#include "licensematch.hpp"
#include "state.hpp"

using namespace std;

string scanFileWithAtarashi(const State& state, const fo::File& file);

vector<LicenseMatch> extractLicensesFromAtarashiResult(string atarashiResult);
#endif // ATARASHI_AGENT_ATARASHI_WRAPPER_HPP
11 changes: 1 addition & 10 deletions src/atarashi/agent/utils.cc
Expand Up @@ -18,7 +18,6 @@
#include <iostream>
#include "atarashiwrapper.hpp"
#include "utils.hpp"
#include <jsoncpp/json/json.h>

using namespace fo;

Expand Down Expand Up @@ -142,15 +141,7 @@ vector<LicenseMatch> createMatches(std::string liscenceName, unsigned percentage
bool matchFileWithLicenses(const State& state, const fo::File& file, AtarashiDatabaseHandler& databaseHandler)
{
string atarashiResult = scanFileWithAtarashi(state, file);
Json::Reader reader;
Json::Value obj;
reader.parse(atarashiResult, obj);

Json::StreamWriterBuilder builder;
builder.settings_["indentation"] = "";
std::string liscenceName = Json::writeString(builder, obj['results'][0]['shortname']);
unsigned percentage = obj['results'][0]['sim_score'].asInt();
vector<LicenseMatch> matches = createMatches(liscenceName, percentage);
vector<LicenseMatch> matches = extractLicensesFromAtarashiResult(atarashiResult);
return saveLicenseMatchesToDatabase(state, matches, file.getId(), databaseHandler);
}

Expand Down
4 changes: 2 additions & 2 deletions src/atarashi/agent/utils.hpp
Expand Up @@ -18,9 +18,9 @@
#ifndef ATARASHI_AGENT_UTILS_HPP
#define ATARASHI_AGENT_UTILS_HPP

#define AGENT_NAME "atarashi"
#define AGENT_NAME "atarashiWrapper"
#define AGENT_DESC "atarashi agent"
#define AGENT_ARS "atarashi_ars"
#define AGENT_ARS "atarashiWrapper_ars"

#include <string>
#include <vector>
Expand Down
7 changes: 3 additions & 4 deletions src/atarashi/ui/agent-atarashi.php
Expand Up @@ -26,7 +26,6 @@ public function __construct() {
$this->Name = "agent_atarashi";
$this->Title = _("atarashi License Analysis");
$this->AgentName = "atarashiWrapper";


parent::__construct();
}
Expand All @@ -35,19 +34,19 @@ function AgentHasResults($uploadId=0)
{
return CheckARS($uploadId, $this->AgentName, "atarashi agent", "atarashi_ars");
}

function preInstall()
{
if ($this->isAtarashiInstalled()) {
menu_insert("Agents::" . $this->Title, 0, $this->Name);
}
}

public function isAtarashiInstalled()
{
exec('which atarashi', $lines, $returnVar);
return (0==$returnVar);
}
}

register_plugin(new AtarashiAgentPlugin());
register_plugin(new AtarashiAgentPlugin());
2 changes: 1 addition & 1 deletion src/www/ui/async/AjaxExplorer.php
Expand Up @@ -64,7 +64,7 @@ class AjaxExplorer extends DefaultPlugin
/** @var array [uploadtree_id]=>cnt */
private $filesToBeCleared;
/** @var array */
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I');
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I', 'atarashiWrapper' => 'A');

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/async/AjaxFileBrowser.php
Expand Up @@ -52,7 +52,7 @@ class AjaxFileBrowser extends DefaultPlugin
/** @var LicenseMap */
private $licenseProjector;
/** @var array */
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I');
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I', 'atarashiWrapper' => 'A');

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/template/browse_file.js.twig
Expand Up @@ -27,7 +27,7 @@ function createDirlistTable() {
}
},
"aoColumns": [{"sTitle":"Files","sClass":"left"},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport)","sClass":"left","bSortable":false},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport, A: atarashiWrapper)","sClass":"left","bSortable":false},
{"sTitle":"Edited Results","sClass":"left","bSortable":false},
{"sTitle":"Clearing Status","sClass":"clearingStatus center","bSortable":false,"bSearchable":false,"sWidth":"5%","mRender":function ( data, type, full ) {
if(type!='display') return data;
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/template/file-browse.js.twig
Expand Up @@ -25,7 +25,7 @@ function createDirlistTable() {
}
},
"aoColumns": [{"sTitle":"Files","sClass":"left"},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport)","sClass":"left","bSortable":false},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport, A: atarashiWrapper)","sClass":"left","bSortable":false},
{"sTitle":"Actions","sClass":"left","bSortable":false,"bSearchable":false}],
"sPaginationType": "listbox",
"iDisplayLength": 25,
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/template/ui-browse-license_file-list.js.twig
Expand Up @@ -8,7 +8,7 @@ function createDirlistTable() {
$('#dirlist').dataTable( {
"aaData": {{ aaData }},
"aoColumns":[{"sTitle":"Files","sClass":"left"},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport)","sClass":"left"},
{"sTitle":"Scanner Results (N: nomos, M: monk, Nk: ninka, I: reportImport, A: atarashiWrapper)","sClass":"left"},
{"sTitle":"Edited Results","sClass":"left"},
{"sTitle":"Clearing Status","sClass":"clearingStatus center","bSearchable":false,"sWidth":"5%","mRender":function ( data, type, full ) {
if(type!='display') return data;
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/ui-browse-license.php
Expand Up @@ -55,7 +55,7 @@ class ui_browse_license extends DefaultPlugin
/** @var LicenseMap */
private $licenseProjector;
/** @var array */
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I');
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I', 'atarashiWrapper' => 'A');

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/ui-file-browse.php
Expand Up @@ -48,7 +48,7 @@ class ui_file_browse extends DefaultPlugin
/** @var LicenseMap */
private $licenseProjector;
/** @var array */
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I');
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I', 'atarashiWrapper' => 'A');

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/www/ui/ui-license-list-files.php
Expand Up @@ -45,7 +45,7 @@ class LicenseListFiles extends FO_Plugin
private $agentDao;

/** @var Array */
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I');
protected $agentNames = array('nomos' => 'N', 'monk' => 'M', 'ninka' => 'Nk', 'reportImport' => 'I', 'atarashiWrapper' => 'A');

function __construct()
{
Expand Down

0 comments on commit 5a03a4e

Please sign in to comment.