use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class SPDXParserTest method testGetLicenseInfo.
@Test
@UseDataProvider("dataProviderAdd")
public void testGetLicenseInfo(String exampleFile, List<String> expectedLicenses, int numberOfCoyprights, String exampleCopyright) throws Exception {
Attachment attachment = makeAttachment(exampleFile, Arrays.stream(AttachmentType.values()).filter(SW360Constants.LICENSE_INFO_ATTACHMENT_TYPES::contains).findAny().get());
LicenseInfoParsingResult result = parser.getLicenseInfos(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachment.getAttachmentContentId())))).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
assertLicenseInfoParsingResult(result);
assertIsResultOfExample(result.getLicenseInfo(), exampleFile, expectedLicenses, numberOfCoyprights, exampleCopyright);
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class SPDXParserTest method testAddSPDXContentToCLI.
@Test
@UseDataProvider("dataProviderAdd")
public void testAddSPDXContentToCLI(String exampleFile, List<String> expectedLicenses, int numberOfCoyprights, String exampleCopyright) throws Exception {
AttachmentContent attachmentContent = new AttachmentContent().setFilename(exampleFile);
InputStream input = makeAttachmentContentStream(exampleFile);
SpdxDocument spdxDocument = SPDXDocumentFactory.createSpdxDocument(input, parser.getUriOfAttachment(attachmentContentStore.get(exampleFile)), FILETYPE_SPDX_INTERNAL);
LicenseInfoParsingResult result = SPDXParserTools.getLicenseInfoFromSpdx(attachmentContent, spdxDocument);
assertIsResultOfExample(result.getLicenseInfo(), exampleFile, expectedLicenses, numberOfCoyprights, exampleCopyright);
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class DocxGenerator method fillLicenseList.
private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
XWPFRun licenseHeaderRun = document.createParagraph().createRun();
addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
addNewLines(document, 0);
for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
XWPFParagraph licenseParagraph = document.createParagraph();
licenseParagraph.setStyle(STYLE_HEADING);
String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
addBookmark(licenseParagraph, licenseName, licenseName);
addNewLines(document, 0);
setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
addNewLines(document, 1);
}
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class DocxGenerator method generateOutputFile.
@Override
public byte[] generateOutputFile(Collection<LicenseInfoParsingResult> projectLicenseInfoResults, String projectName, String projectVersion, String licenseInfoHeaderText) throws SW360Exception {
ByteArrayOutputStream docxOutputStream = new ByteArrayOutputStream();
Optional<byte[]> docxTemplateFile = CommonUtils.loadResource(DocxGenerator.class, DOCX_TEMPLATE_FILE);
if (docxTemplateFile.isPresent()) {
try {
XWPFDocument xwpfDocument = new XWPFDocument(new ByteArrayInputStream(docxTemplateFile.get()));
switch(getOutputVariant()) {
case DISCLOSURE:
fillDocument(xwpfDocument, projectLicenseInfoResults, projectName, projectVersion, licenseInfoHeaderText, false);
break;
case REPORT:
fillDocument(xwpfDocument, projectLicenseInfoResults, projectName, projectVersion, licenseInfoHeaderText, true);
break;
default:
throw new IllegalArgumentException("Unknown generator variant type: " + getOutputVariant());
}
xwpfDocument.write(docxOutputStream);
docxOutputStream.close();
} catch (XmlException e) {
throw new SW360Exception("Got XmlException while generating docx document: " + e.getMessage());
} catch (IOException e) {
throw new SW360Exception("Got IOException when generating docx document: " + e.getMessage());
} catch (TException e) {
throw new SW360Exception("Error reading sw360 licenses: " + e.getMessage());
}
return docxOutputStream.toByteArray();
} else {
throw new SW360Exception("Could not load the template for xwpf document: " + DOCX_TEMPLATE_FILE);
}
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult in project sw360portal by sw360.
the class DocxGenerator method fillReleaseDetailList.
private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
addNewLines(document, 0);
for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
addReleaseTitle(document, parsingResult);
if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
addCopyrights(document, parsingResult);
addLicenses(document, parsingResult, includeObligations);
} else {
XWPFRun errorRun = document.createParagraph().createRun();
String errorText = nullToEmptyString(parsingResult.getMessage());
String filename = getFilename(parsingResult);
addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
}
addNewLines(document, 1);
}
addPageBreak(document);
}
Aggregations