diff --git a/src/phpunit.xml b/src/phpunit.xml
index 05613df4..fb454103 100644
--- a/src/phpunit.xml
+++ b/src/phpunit.xml
@@ -1,43 +1,43 @@
www/ui_tests/startUpTest.php
lib/php
cli/tests/test_fo_copyright_list.php
copyright/agent_tests/Functional
decider/agent_tests
deciderjob/agent_tests/Functional
monk/agent_tests/Functional
ninka/agent_tests/Functional
- spdx2/agent_tests/Functional
+ spdx2/agent_tests
.
.
./phpunit-bootstrap.php
lib/php/tests
lib/c
*/*tests
testing
tutorials
vendor
diff --git a/src/spdx2/agent/Makefile b/src/spdx2/agent/Makefile
index ed23e8b4..78fe8c57 100644
--- a/src/spdx2/agent/Makefile
+++ b/src/spdx2/agent/Makefile
@@ -1,56 +1,56 @@
# Copyright Siemens AG 2015
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
TOP=../../..
VARS=$(TOP)/Makefile.conf
DEPS=$(TOP)/Makefile.deps
include $(VARS)
MOD_NAME = spdx2
MOD_SUBDIR = agent
MOD_NAMES = spdx2 spdx2tv dep5
-EXE=spdx2.php version.php services.php
+EXE=spdx2.php version.php services.php spdx2utils.php
all: version.php spdx2
version.php: version-process_php
# include the preprocessing stuff
include $(TOP)/Makefile.process
spdx2:
@echo "making locally runnable report (only for testing)"
$(MAKE) -C $(FOCLIDIR) fo_wrapper
ln -sf $(FOCLIDIR)/fo_wrapper.php $(MOD_NAME)
install: all
for MOD in $(MOD_NAMES); do \
$(INSTALL_PROGRAM) -d $(DESTDIR)$(MODDIR)/$$MOD/$(MOD_SUBDIR)/; \
done
for file in $(EXE); do \
echo "installing $$file"; \
$(INSTALL_PROGRAM) $$file $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR)/$$file; \
done
echo "Making wrapper for $(MOD_NAME)"
ln -sf $(LIBEXECDIR)/fo_wrapper $(DESTDIR)$(MODDIR)/$(MOD_NAME)/agent/$(MOD_NAME)
find template/ -type f -exec $(INSTALL_DATA) {} $(DESTDIR)$(MODDIR)/$(MOD_NAME)/$(MOD_SUBDIR)/{} \;
for MOD in $(MOD_NAMES); do \
$(INSTALL_PROGRAM) agent.sh $(DESTDIR)$(MODDIR)/$$MOD/$(MOD_SUBDIR)/$$MOD.sh; \
done
uninstall:
for MOD in $(MOD_NAMES); do \
rm -rf $(DESTDIR)$(MODDIR)/$$MOD/$(MOD_SUBDIR); \
done
clean:
rm -f core version.php $(MOD_NAME)
.PHONY: all install uninstall clean
include $(DEPS)
diff --git a/src/spdx2/agent/spdx2.php b/src/spdx2/agent/spdx2.php
index 9b975508..bcd33a0e 100644
--- a/src/spdx2/agent/spdx2.php
+++ b/src/spdx2/agent/spdx2.php
@@ -1,703 +1,663 @@
'N', 'monk' => 'M');
/** @var array */
protected $includedLicenseIds = array();
/** @var string */
protected $uri;
/** @var string */
protected $outputFormat = self::DEFAULT_OUTPUT_FORMAT;
function __construct()
{
parent::__construct('spdx2', AGENT_VERSION, AGENT_REV);
$this->uploadDao = $this->container->get('dao.upload');
$this->clearingDao = $this->container->get('dao.clearing');
$this->dbManager = $this->container->get('db.manager');
$this->renderer = $this->container->get('twig.environment');
$this->renderer->setCache(false);
$this->agentSpecifLongOptions[] = self::UPLOAD_ADDS.':';
$this->agentSpecifLongOptions[] = self::OUTPUT_FORMAT_KEY.':';
}
- /**
- * @param string[] $args
- * @param string $key1
- * @param string $key2
- *
- * @return string[] $args
- */
- protected function preWorkOnArgsFlp($args,$key1,$key2)
- {
- $needle = ' --'.$key2.'=';
- if (strpos($args[$key1],$needle) !== false) {
- $exploded = explode($needle,$args[$key1]);
- $args[$key1] = trim($exploded[0]);
- $args[$key2] = trim($exploded[1]);
- }
- return $args;
- }
-
/**
* @param string[] $args
*
* @return string[] $args
*/
protected function preWorkOnArgs($args)
{
if ((!array_key_exists(self::OUTPUT_FORMAT_KEY,$args)
|| $args[self::OUTPUT_FORMAT_KEY] === "")
&& array_key_exists(self::UPLOAD_ADDS,$args))
{
- $args = $this->preWorkOnArgsFlp($args,self::UPLOAD_ADDS,self::OUTPUT_FORMAT_KEY);
+ $args = SpdxTwoUtils::preWorkOnArgsFlp($args,self::UPLOAD_ADDS,self::OUTPUT_FORMAT_KEY);
}
else
{
if (!array_key_exists(self::UPLOAD_ADDS,$args) || $args[self::UPLOAD_ADDS] === "")
{
- $args = $this->preWorkOnArgsFlp($args,self::UPLOAD_ADDS,self::OUTPUT_FORMAT_KEY);
+ $args = SpdxTwoUtils::preWorkOnArgsFlp($args,self::UPLOAD_ADDS,self::OUTPUT_FORMAT_KEY);
}
}
return $args;
}
/**
* @param int $uploadId
* @return bool
*/
function processUploadId($uploadId)
{
$args = $this->preWorkOnArgs($this->args);
if(array_key_exists(self::OUTPUT_FORMAT_KEY,$args))
{
$possibleOutputFormat = trim($args[self::OUTPUT_FORMAT_KEY]);
if(in_array($possibleOutputFormat, explode(',',self::AVAILABLE_OUTPUT_FORMATS)))
{
$this->outputFormat = $possibleOutputFormat;
}
}
$this->licenseMap = new LicenseMap($this->dbManager, $this->groupId, LicenseMap::REPORT, true);
$this->computeUri($uploadId);
$packageNodes = $this->renderPackage($uploadId);
$additionalUploadIds = array_key_exists(self::UPLOAD_ADDS,$args) ? explode(',',$args[self::UPLOAD_ADDS]) : array();
$packageIds = array($uploadId);
foreach($additionalUploadIds as $additionalId)
{
$packageNodes .= $this->renderPackage($additionalId);
$packageIds[] = $additionalId;
}
$this->writeReport($packageNodes, $packageIds, $uploadId);
return true;
}
/**
* @param string $partname
* @return string
*/
protected function getTemplateFile($partname)
{
$prefix = $this->outputFormat . "-";
$postfix = ".twig";
switch ($this->outputFormat)
{
case "spdx2":
$postfix = ".xml" . $postfix;
break;
case "spdx2tv":
break;
case "dep5":
$prefix = $prefix . "copyright-";
break;
}
return $prefix . $partname . $postfix;
}
/**
* @param string $fileBase
* @param string $packageName
* @return string
*/
protected function getUri($fileBase,$packageName)
{
$fileName = $fileBase. strtoupper($this->outputFormat)."_".$packageName.'_'.time();
switch ($this->outputFormat)
{
case "spdx2":
$fileName = $fileName .".rdf" ;
break;
case "spdx2tv":
$fileName = $fileName .".spdx" ;
break;
case "dep5":
$fileName = $fileName .".txt" ;
break;
}
return $fileName;
}
- /**
- * @param string[] $licenses
- * @return string
- */
- protected function implodeLicenses($licenses)
- {
- sort($licenses);
- if(count($licenses) == 3 &&
- ($index = array_search("Dual-license",$licenses)) !== false)
- {
- return $licenses[$index===0?1:0] . " or " . $licenses[$index===1?2:1];
- }
- else
- {
- $licenses = array_map(function ($license){
- if(strpos($license, " or ") !== false){
- return "(" . $license . ")";
- }else{
- return $license;
- }
- },$licenses);
- return implode(" and ", $licenses);
- }
- }
-
/**
* @param int $uploadId
* @return string
*/
protected function renderPackage($uploadId)
{
$uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
$itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId,$uploadTreeTableName);
$this->heartbeat(0);
$filesWithLicenses = $this->getFilesWithLicensesFromClearings($itemTreeBounds);
$this->heartbeat(0);
$this->addClearingStatus($filesWithLicenses,$itemTreeBounds);
$this->heartbeat(0);
$licenseComment = $this->addScannerResults($filesWithLicenses, $itemTreeBounds);
$this->heartbeat(0);
$this->addCopyrightResults($filesWithLicenses, $uploadId);
$this->heartbeat(0);
$upload = $this->uploadDao->getUpload($uploadId);
$fileNodes = $this->generateFileNodes($filesWithLicenses, $upload->getTreeTableName());
$mainLicenseIds = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
$mainLicenses = array();
foreach($mainLicenseIds as $licId)
{
$reportedLicenseId = $this->licenseMap->getProjectedId($licId);
$this->includedLicenseIds[$reportedLicenseId] = true;
$mainLicenses[] = $this->licenseMap->getProjectedShortname($reportedLicenseId);
}
$hashes = $this->uploadDao->getUploadHashes($uploadId);
return $this->renderString($this->getTemplateFile('package'),array(
'uploadId'=>$uploadId,
'uri'=>$this->uri,
'packageName'=>$upload->getFilename(),
'uploadName'=>$upload->getFilename(),
'sha1'=>$hashes['sha1'],
'md5'=>$hashes['md5'],
'verificationCode'=>$this->getVerificationCode($upload),
'mainLicenses'=>$mainLicenses,
- 'mainLicense'=>$this->implodeLicenses($mainLicenses),
+ 'mainLicense'=>SpdxTwoUtils::implodeLicenses($mainLicenses, "LicenseRef-"),
'licenseComments'=>$licenseComment,
'fileNodes'=>$fileNodes)
);
}
/**
* @param ItemTreeBounds $itemTreeBounds
* @return string[][][] $filesWithLicenses mapping item->'concluded'->(array of shortnames)
*/
protected function getFilesWithLicensesFromClearings(ItemTreeBounds $itemTreeBounds)
{
$clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $this->groupId);
$filesWithLicenses = array();
$clearingsProceeded = 0;
foreach ($clearingDecisions as $clearingDecision)
{
$clearingsProceeded += 1;
if(($clearingsProceeded&2047)==0)
{
$this->heartbeat(0);
}
if($clearingDecision->getType() == DecisionTypes::IRRELEVANT)
{
continue;
}
foreach ($clearingDecision->getClearingEvents() as $clearingEvent)
{
$clearingLicense = $clearingEvent->getClearingLicense();
if ($clearingLicense->isRemoved())
{
continue;
}
if($clearingEvent->getReportinfo())
{
$customLicenseText = $clearingEvent->getReportinfo();
$reportedLicenseShortname = $this->licenseMap->getProjectedShortname($this->licenseMap->getProjectedId($clearingLicense->getLicenseId())) .
'-' . md5($customLicenseText);
$this->includedLicenseIds[$reportedLicenseShortname] = $customLicenseText;
$filesWithLicenses[$clearingDecision->getUploadTreeId()]['concluded'][] = $reportedLicenseShortname;
}
else
{
$reportedLicenseId = $this->licenseMap->getProjectedId($clearingLicense->getLicenseId());
$this->includedLicenseIds[$reportedLicenseId] = true;
$filesWithLicenses[$clearingDecision->getUploadTreeId()]['concluded'][] =
$this->licenseMap->getProjectedShortname($reportedLicenseId);
}
}
}
return $filesWithLicenses;
}
/**
* @param string[][][] $filesWithLicenses
* @param string[] $licenses
* @param string[] $copyrights
* @param string $file
* @param string $fullPath
*/
protected function toLicensesWithFilesAdder(&$filesWithLicenses, $licenses, $copyrights, $file, $fullPath)
{
- $key = $this->implodeLicenses($licenses);
+ $key = SpdxTwoUtils::implodeLicenses($licenses);
if (!array_key_exists($key, $filesWithLicenses))
{
$filesWithLicenses[$key]['files']=array();
$filesWithLicenses[$key]['copyrights']=array();
}
$filesWithLicenses[$key]['files'][$file] = $fullPath;
foreach ($copyrights as $copyright) {
if (!in_array($copyright, $filesWithLicenses[$key]['copyrights'])) {
$filesWithLicenses[$key]['copyrights'][] = $copyright;
}
}
}
/**
* @param string[][][] $filesWithLicenses
* @param string $treeTableName
*/
protected function toLicensesWithFiles(&$filesWithLicenses, $treeTableName)
{
$licensesWithFiles = array();
$treeDao = $this->container->get('dao.tree');
$filesProceeded = 0;
foreach($filesWithLicenses as $fileId=>$licenses)
{
$filesProceeded += 1;
if(($filesProceeded&2047)==0)
{
$this->heartbeat(0);
}
$fullPath = $treeDao->getFullPath($fileId,$treeTableName);
if(!empty($licenses['concluded']) && count($licenses['concluded'])>0)
{
$this->toLicensesWithFilesAdder($licensesWithFiles,$licenses['concluded'],$licenses['copyrights'],$fileId,$fullPath);
}
else
{
if(!empty($licenses['scanner']) && count($licenses['scanner'])>0)
{
- $implodedLicenses = $this->implodeLicenses($licenses['scanner']);
+ $implodedLicenses = SpdxTwoUtils::implodeLicenses($licenses['scanner']);
if($licenses['isCleared'])
{
$msgLicense = "None (scanners found: " . $implodedLicenses . ")";
}
else
{
$msgLicense = "NoLicenseConcluded (scanners found: " . $implodedLicenses . ")";
}
}
else
{
if($licenses['isCleared'])
{
$msgLicense = "None";
}
else
{
$msgLicense = "NoLicenseConcluded";
}
}
$this->toLicensesWithFilesAdder($licensesWithFiles,array($msgLicense),$licenses['copyrights'],$fileId,$fullPath);
}
}
return $licensesWithFiles;
}
/**
* @param string[][][] &$filesWithLicenses
* @param ItemTreeBounds $itemTreeBounds
*/
protected function addScannerResults(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds)
{
$uploadId = $itemTreeBounds->getUploadId();
$scannerAgents = array_keys($this->agentNames);
$scanJobProxy = new ScanJobProxy($this->container->get('dao.agent'), $uploadId);
$scanJobProxy->createAgentStatus($scannerAgents);
$scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
if(empty($scannerIds))
{
return;
}
$selectedScanners = '{'.implode(',',$scannerIds).'}';
$tableName = $itemTreeBounds->getUploadTreeTableName();
$stmt = __METHOD__ .'.scanner_findings';
$sql = "SELECT DISTINCT uploadtree_pk,rf_fk FROM $tableName ut, license_file
WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any($1)";
$param = array($selectedScanners);
if ($tableName == 'uploadtree_a') {
$param[] = $uploadId;
$sql .= " AND upload_fk=$".count($param);
$stmt .= $tableName;
}
$sql .= " GROUP BY uploadtree_pk,rf_fk";
$this->dbManager->prepare($stmt, $sql);
$res = $this->dbManager->execute($stmt,$param);
while($row=$this->dbManager->fetchArray($res))
{
$reportedLicenseId = $this->licenseMap->getProjectedId($row['rf_fk']);
$shortName = $this->licenseMap->getProjectedShortname($reportedLicenseId);
if ($shortName != 'No_license_found' && $shortName != 'Void') {
$filesWithLicenses[$row['uploadtree_pk']]['scanner'][] = $shortName;
$this->includedLicenseIds[$reportedLicenseId] = true;
}
}
$this->dbManager->freeResult($res);
return "licenseInfoInFile determined by Scanners $selectedScanners";
}
/**
* @param string[][][] &$filesWithLicenses
* @param int $uploadId
* @return string
*/
protected function addCopyrightResults(&$filesWithLicenses, $uploadId)
{
/* @var $copyrightDao CopyrightDao */
$copyrightDao = $this->container->get('dao.copyright');
$uploadtreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
$allEntries = $copyrightDao->getAllEntries('copyright', $uploadId, $uploadtreeTable, $type='statement');
foreach ($allEntries as $finding) {
$filesWithLicenses[$finding['uploadtree_pk']]['copyrights'][] = \convertToUTF8($finding['content'],false);
}
}
/**
* @param string[][][] &$filesWithLicenses
* @param ItemTreeBounds $itemTreeBounds
*/
protected function addClearingStatus(&$filesWithLicenses,ItemTreeBounds $itemTreeBounds)
{
$alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(),
array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED,
UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN ".$itemTreeBounds->getLeft()." AND ".$itemTreeBounds->getRight().")",
UploadTreeProxy::OPT_GROUP_ID => $this->groupId),
$itemTreeBounds->getUploadTreeTableName(),
'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
$alreadyClearedUploadTreeView->materialize();
$filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
$alreadyClearedUploadTreeView->unmaterialize();
$uploadTreeIds = array_keys($filesWithLicenses);
foreach($uploadTreeIds as $uploadTreeId)
{
$filesWithLicenses[$uploadTreeId]['isCleared'] = false == array_key_exists($uploadTreeId,$filesThatShouldStillBeCleared);
}
}
/**
* @param int $uploadId
*/
protected function computeUri($uploadId)
{
global $SysConf;
$upload = $this->uploadDao->getUpload($uploadId);
$packageName = $upload->getFilename();
$fileBase = $SysConf['FOSSOLOGY']['path']."/report/";
$this->uri = $this->getUri($fileBase,$packageName);
}
/**
* @param string[] $packageNodes
* @param int[] $packageIds
* @param int $uploadId
*/
protected function writeReport(&$packageNodes, $packageIds, $uploadId)
{
$fileBase = dirname($this->uri);
if(!is_dir($fileBase)) {
mkdir($fileBase, 0777, true);
}
umask(0133);
$message = $this->renderString($this->getTemplateFile('document'),array(
'documentName'=>$fileBase,
'uri'=>$this->uri,
'userName'=>$this->container->get('dao.user')->getUserName($this->userId),
'organisation'=>'',
'packageNodes'=>$packageNodes,
'packageIds'=>$packageIds,
'licenseTexts'=>$this->getLicenseTexts())
);
// To ensure the file is valid, replace any non-printable characters with a question mark.
// 'Non-printable' is ASCII < 0x20 (excluding \r, \n and tab) and 0x7F (delete).
$message = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/','?',$message);
file_put_contents($this->uri, $message);
$this->updateReportTable($uploadId, $this->jobId, $this->uri);
}
/**
* @param int $uploadId
* @param int $jobId
* @param string $fileName
*/
protected function updateReportTable($uploadId, $jobId, $fileName){
$this->dbManager->insertTableRow('reportgen',
array('upload_fk'=>$uploadId, 'job_fk'=>$jobId, 'filepath'=>$fileName),
__METHOD__);
}
/**
* @param string $templateName
* @param array $vars
* @return string
*/
protected function renderString($templateName, $vars)
{
return $this->renderer->loadTemplate($templateName)->render($vars);
}
protected function generateFileNodes($filesWithLicenses, $treeTableName)
{
if (strcmp($this->outputFormat, "dep5")!==0)
{
return $this->generateFileNodesByFiles($filesWithLicenses, $treeTableName);
}
else
{
return $this->generateFileNodesByLicenses($filesWithLicenses, $treeTableName);
}
}
/**
* @param string[][][] &$filesWithLicenses
* @param string $treeTableName
* @return string
*/
protected function generateFileNodesByFiles($filesWithLicenses, $treeTableName)
{
/* @var $treeDao TreeDao */
$treeDao = $this->container->get('dao.tree');
$filesProceeded = 0;
$lastValue = 0;
$content = '';
foreach($filesWithLicenses as $fileId=>$licenses)
{
$filesProceeded += 1;
if(($filesProceeded&2047)==0)
{
$this->heartbeat($filesProceeded - $lastValue);
$lastValue = $filesProceeded;
}
$hashes = $treeDao->getItemHashes($fileId);
$fileName = $treeDao->getFullPath($fileId,$treeTableName);
$content .= $this->renderString($this->getTemplateFile('file'),array(
'fileId'=>$fileId,
'sha1'=>$hashes['sha1'],
'md5'=>$hashes['md5'],
'uri'=>$this->uri,
'fileName'=>$fileName,
'fileDirName'=>dirname($fileName),
'fileBaseName'=>basename($fileName),
'isCleared'=>$licenses['isCleared'],
+ 'concludedLicense'=>SpdxTwoUtils::implodeLicenses($licenses['concluded'], "LicenseRef-"),
'concludedLicenses'=>$licenses['concluded'],
'scannerLicenses'=>$licenses['scanner'],
'copyrights'=>$licenses['copyrights']));
}
$this->heartbeat($filesProceeded - $lastValue);
return $content;
}
/**
* @param string[][][] &$filesWithLicenses
* @param string $treeTableName
* @return string
*/
protected function generateFileNodesByLicenses($filesWithLicenses, $treeTableName)
{
$licensesWithFiles = $this->toLicensesWithFiles($filesWithLicenses, $treeTableName);
$content = '';
$filesProceeded = 0;
$lastStep = 0;
$lastValue = 0;
foreach($licensesWithFiles as $licenseId=>$entry)
{
$filesProceeded += count($entry['files']);
if($filesProceeded&(~2047) > $lastStep)
{
$this->heartbeat($filesProceeded - $lastValue);
$lastStep = $filesProceeded&(~2047) + 2048;
$lastValue = $filesProceeded;
}
$comment = "";
if (strrpos($licenseId, "NoLicenseConcluded (scanners found: ", -strlen($licenseId)) !== false)
{
$comment = substr($licenseId,20,strlen($licenseId)-21);
$licenseId = "NoLicenseConcluded";
}
elseif (strrpos($licenseId, "None (scanners found: ", -strlen($licenseId)) !== false)
{
$comment = substr($licenseId,6,strlen($licenseId)-7);
$licenseId = "None";
}
$content .= $this->renderString($this->getTemplateFile('file'),array(
'fileNames'=>$entry['files'],
'license'=>$licenseId,
'copyrights'=>$entry['copyrights'],
'comment'=>$comment));
}
$this->heartbeat($filesProceeded - $lastValue);
return $content;
}
/**
* @return string[] with keys being shortname
*/
protected function getLicenseTexts() {
$licenseTexts = array();
$licenseViewProxy = new LicenseViewProxy($this->groupId,array(LicenseViewProxy::OPT_COLUMNS=>array('rf_pk','rf_shortname','rf_text')));
$this->dbManager->prepare($stmt=__METHOD__, $licenseViewProxy->getDbViewQuery());
$res = $this->dbManager->execute($stmt);
while($row=$this->dbManager->fetchArray($res))
{
if (array_key_exists($row['rf_pk'], $this->includedLicenseIds))
{
$licenseTexts[$row['rf_shortname']] = $row['rf_text'];
}
}
foreach($this->includedLicenseIds as $license => $customText)
{
if (true !== $customText)
{
$licenseTexts[$license] = $customText;
}
}
$this->dbManager->freeResult($res);
return $licenseTexts;
}
/**
* @param UploadTree $upload
* @return string
*/
protected function getVerificationCode(Upload $upload)
{
$stmt = __METHOD__;
$param = array();
if ($upload->getTreeTableName()=='uploadtree_a')
{
$sql = $upload->getTreeTableName().' WHERE upload_fk=$1 AND';
$param[] = $upload->getId();
}
else
{
$sql = $upload->getTreeTableName().' WHERE';
$stmt .= '.'.$upload->getTreeTableName();
}
$sql = "SELECT STRING_AGG(lower_sha1,'') concat_sha1 FROM
(SELECT LOWER(pfile_sha1) lower_sha1 FROM pfile, $sql pfile_fk=pfile_pk ORDER BY pfile_sha1) templist";
$filelistPack = $this->dbManager->getSingleRow($sql,$param,$stmt);
return sha1($filelistPack['concat_sha1']);
}
}
$agent = new SpdxTwoAgent();
$agent->scheduler_connect();
$agent->run_scheduler_event_loop();
$agent->scheduler_disconnect(0);
diff --git a/src/spdx2/agent/spdx2utils.php b/src/spdx2/agent/spdx2utils.php
new file mode 100644
index 00000000..f97a6935
--- /dev/null
+++ b/src/spdx2/agent/spdx2utils.php
@@ -0,0 +1,86 @@
+ {{ copyrights|join('\n')
|replace({'':'<text>','':'</text>'})
|replace({'\f':''}) }}
{% endif %}
diff --git a/src/spdx2/agent/template/spdx2tv-package.twig b/src/spdx2/agent/template/spdx2tv-package.twig
index 259c1f5c..af283e26 100644
--- a/src/spdx2/agent/template/spdx2tv-package.twig
+++ b/src/spdx2/agent/template/spdx2tv-package.twig
@@ -1,37 +1,33 @@
{# Copyright 2015 Siemens AG
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright notice and this notice are preserved.
This file is offered as-is, without any warranty.
#}
{# RelationshipComment: #}
PackageName: {{ packageName }}
PackageFileName: {{ uploadName }}
SPDXID: SPDXRef-upload{{ uploadId }}
PackageDownloadLocation: NOASSERTION
PackageVerificationCode: {{ verificationCode }}
PackageChecksum: SHA1: {{ sha1 }}
{# PackageChecksum: SHA256: #}
PackageChecksum: MD5: {{ md5 }}
{# PackageChecksum: SSDEEP: #}
{% if mainLicenses|default is empty %}
PackageLicenseConcluded: NOASSERTION
PackageLicenseDeclared: NOASSERTION
{% else %}
-PackageLicenseConcluded: (LicenseRef-{{ mainLicenses|join('UNIQUESTRINGTOREPLACE')
- |replace({' ':'-'})
- |replace({'UNIQUESTRINGTOREPLACE':' OR LicenseRef-'}) }})
-PackageLicenseDeclared: (LicenseRef-{{ mainLicenses|join('UNIQUESTRINGTOREPLACE')
- |replace({' ':'-'})
- |replace({'UNIQUESTRINGTOREPLACE':' OR LicenseRef-'}) }})
+PackageLicenseConcluded: {{ mainLicense }}
+PackageLicenseDeclared: {{ mainLicense }}
{% endif %}
{% if licenseComments %}PackageLicenseComments: {{ licenseComments|replace({'':'<text>','':'</text>'}) }}
{% endif %}
PackageLicenseInfoFromFiles: NOASSERTION
PackageCopyrightText: NOASSERTION
##--------------------------
## File Information
##--------------------------
{{ fileNodes }}
diff --git a/src/spdx2/agent_tests/Unit/Makefile b/src/spdx2/agent_tests/Unit/Makefile
new file mode 100644
index 00000000..87cd7bf5
--- /dev/null
+++ b/src/spdx2/agent_tests/Unit/Makefile
@@ -0,0 +1,23 @@
+# Copyright Siemens AG 2014
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved. This file is offered as-is,
+# without any warranty.
+
+TOP = ../../../..
+VARS = $(TOP)/Makefile.conf
+include $(VARS)
+
+LOCALAGENTDIR = ../../agent
+
+all:
+
+test:
+ $(PHPUNIT) --bootstrap $(PHPUNIT_BOOT) *.php
+
+coverage: test
+
+clean:
+
+.PHONY: all test coverage clean
diff --git a/src/spdx2/agent_tests/Unit/spdx2utilTest.php b/src/spdx2/agent_tests/Unit/spdx2utilTest.php
new file mode 100644
index 00000000..ccb779b0
--- /dev/null
+++ b/src/spdx2/agent_tests/Unit/spdx2utilTest.php
@@ -0,0 +1,86 @@
+assertCountBefore = \Hamcrest\MatcherAssert::getCount();
+ }
+
+ protected function tearDown()
+ {
+ $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
+ }
+
+ public function testPreWorkOnArgsFlpZero()
+ {
+ $args = array();
+ assertThat(SpdxTwoUtils::preWorkOnArgsFlp($args,"key1","key2"), equalTo($args));
+ }
+
+ public function testPreWorkOnArgsFlpId()
+ {
+ $args = array("key1" => "value");
+ assertThat(SpdxTwoUtils::preWorkOnArgsFlp($args,"key1","key2"), equalTo($args));
+ }
+
+ public function testPreWorkOnArgsFlpRealWork()
+ {
+ $args = array("key1" => "value --key2=anotherValue");
+ $result = SpdxTwoUtils::preWorkOnArgsFlp($args,"key1","key2");
+ assertThat($result["key1"], equalTo("value"));
+ assertThat($result["key2"], equalTo("anotherValue"));
+ }
+
+ public function provideLicenseSet()
+ {
+ return array(
+ 'null' => array(null, '', ''),
+ 'empty array' => array(array(), '', ''),
+ 'empty array but prefix' => array(array(), 'pre', ''),
+ 'single license'=>array(array("LIC1"), '', 'LIC1'),
+ 'multiple licenses' => array(array("LIC1","LIC2","LIC3"), '', 'LIC1 AND LIC2 AND LIC3'),
+ 'dual license 1st pos' => array(array("Dual-license", "LIC2", "LIC3"), '', 'LIC2 OR LIC3'),
+ 'dual license 2nd pos' => array(array("LIC1", "Dual-license", "LIC3"), '', 'LIC1 OR LIC3'),
+ 'dual license 3rd pos' => array(array("LIC1", "LIC2", "Dual-license"), '', 'LIC1 OR LIC2'),
+ 'dual license with prefix' => array(array("LIC1","LIC2", "Dual-license"), 'pre-', 'pre-LIC1 OR pre-LIC2'),
+ 'multiple dualLicense' => array(array("LIC1","LIC2 OR LIC3"), '', '(LIC2 OR LIC3) AND LIC1'),
+ 'multiple dualLicense with prefix' => array(array("LIC1","LIC2 OR LIC3"), 'pre-', '(LIC2 OR LIC3) AND pre-LIC1'),
+ 'dual multi license' => array(array("LIC1","LIC2 OR LIC3", "Dual-license"), '', '(LIC2 OR LIC3) OR LIC1'),
+ 'dual multi license with prefix' => array(array("LIC1","LIC2 OR LIC3", "Dual-license"), 'pre-', '(LIC2 OR LIC3) OR pre-LIC1'),
+ );
+ }
+
+ /**
+ * @dataProvider provideLicenseSet
+ * @param array $lics
+ * @param string $prefix
+ * @param string $expected
+ */
+ public function testImplodeLicenses($lics, $prefix, $expected)
+ {
+ assertThat(SpdxTwoUtils::implodeLicenses($lics, $prefix), equalTo($expected));
+ }
+}