45 include_once(__DIR__ .
"/version.php");
86 function __construct()
93 parent::__construct(README_AGENT_NAME, AGENT_VERSION, AGENT_REV);
95 $this->uploadDao = $this->container->get(
'dao.upload');
97 $this->agentSpecifLongOptions[] = self::UPLOAD_ADDS.
':';
110 $this->additionalUploadIds = array_key_exists(self::UPLOAD_ADDS,
$args) ? explode(
',',
$args[self::UPLOAD_ADDS]) : array();
112 array_unshift($uploadIds, $uploadId);
115 $licenseStmts = array();
116 $copyrightStmts = array();
117 $licenseStmtsMain = array();
118 $licenseAcknowledgements = array();
120 foreach ($uploadIds as $addUploadId) {
121 if (!$this->uploadDao->isAccessible($addUploadId,
$groupId)) {
124 $moreLicenses = $this->licenseClearedGetter->getCleared($addUploadId, $this,
$groupId,
true,
"license",
false);
125 $licenseStmts = array_merge($licenseStmts, $moreLicenses[
'statements']);
126 $this->
heartbeat(count($moreLicenses[
'statements']));
127 $this->licenseClearedGetter->setOnlyAcknowledgements(
true);
128 $moreAcknowledgements = $this->licenseClearedGetter->getCleared($addUploadId, $this,
$groupId,
true,
"license",
false);
129 $licenseAcknowledgements = array_merge($licenseAcknowledgements, $moreAcknowledgements[
'statements']);
130 $this->
heartbeat(count($moreAcknowledgements[
'statements']));
131 $moreCopyrights = $this->cpClearedGetter->getCleared($addUploadId, $this,
$groupId,
true,
"copyright",
false);
132 $copyrightStmts = array_merge($copyrightStmts, $moreCopyrights[
'statements']);
133 $this->
heartbeat(count($moreCopyrights[
'statements']));
134 $moreMainLicenses = $this->licenseMainGetter->getCleared($addUploadId, $this,
$groupId,
true,
null,
false);
135 $licenseStmtsMain = array_merge($licenseStmtsMain, $moreMainLicenses[
'statements']);
136 $this->
heartbeat(count($moreMainLicenses[
'statements']));
138 list($licenseStmtsMain, $licenseStmts) = $this->licenseClearedGetter->updateIdentifiedGlobalLicenses($licenseStmtsMain, $licenseStmts);
139 $contents = array(
'licensesMain'=>$licenseStmtsMain,
'licenses'=>$licenseStmts,
'copyrights'=>$copyrightStmts,
'licenseAcknowledgements' => $licenseAcknowledgements);
154 $packageName = $this->uploadDao->getUpload($uploadId)->getFilename();
156 $fileBase = $SysConf[
'FOSSOLOGY'][
'path'].
"/report/";
157 $fileName = $fileBase.
"ReadMe_OSS_".$packageName.
".txt" ;
159 foreach ($this->additionalUploadIds as $addUploadId) {
160 $packageName .=
', ' . $this->uploadDao->getUpload($addUploadId)->getFilename();
163 if (!is_dir($fileBase)) {
164 mkdir($fileBase, 0777,
true);
169 file_put_contents($fileName, $message);
182 $this->reportutils->updateOrInsertReportgenEntry($uploadId,
$jobId, $filename);
196 foreach ($dataForReadME as $statements) {
197 if ($extract ==
'text') {
198 $outData .= $statements[
"content"] . $break;
200 $outData .= str_replace(
"\n",
"\r\n", $statements[$extract]) . $break;
201 if (!empty($addSeparator)) {
202 $outData .= $addSeparator . $break;
205 return htmlspecialchars_decode($outData, ENT_DISALLOWED);
217 $separator1 = str_repeat(
"=", 120);
218 $separator2 = str_repeat(
"-", 120);
219 $break = str_repeat(
"\r\n", 2);
220 $output = $separator1 . $break . $packageName . $break . $separator2 . $break;
221 if (!empty($contents[
'licensesMain'])) {
222 $output .= $separator1 . $break .
" MAIN LICENSES " . $break . $separator2 . $break;
225 if (!empty($contents[
'licenses'])) {
226 $output .= $separator1 . $break .
" OTHER LICENSES " . $break . $separator2 . $break;
229 if (!empty($contents[
'licenseAcknowledgements'])) {
230 $output .= $separator1 . $break .
" ACKNOWLEDGEMENTS " . $break . $separator2 . $break;
231 $output .= $this->
createReadMeOSSFormat($separator2, $contents[
'licenseAcknowledgements'],
'text', $break);
234 if (empty($copyrights)) {
235 $output .=
"<Copyright notices>";
237 $output .=
"<notices>";
239 $output .=
"Copyright notices";
241 $output .= $copyrights;
248 $agent->scheduler_connect();
249 $agent->run_scheduler_event_loop();
250 $agent->scheduler_disconnect(0);
Structure of an Agent with all required parameters.
heartbeat($newProcessed)
Send hear beat to the scheduler.
Readme_OSS agent generates list of licenses and copyrights found in an upload.
updateReportTable($uploadId, $jobId, $filename)
Update the report path.
writeReport($contents, $uploadId)
Write data to text file.
generateReport($contents, $packageName)
Gather all the data.
const UPLOAD_ADDS
The HTTP GET parameter name.
processUploadId($uploadId)
Given an upload ID, process the items in it.
createReadMeOSSFormat($addSeparator, $dataForReadME, $extract, $break)
This function lists elements of array.
int jobId
The id of the job.