org.spdx.rdfparser.InvalidSPDXAnalysisException Java Examples

The following examples show how to use org.spdx.rdfparser.InvalidSPDXAnalysisException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestPointerFactory.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.pointer.PointerFactory#getSinglePointerFromModel(org.spdx.rdfparser.IModelContainer, org.apache.jena.graph.Node)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testGetSinglePointerFromModelByProperties() throws InvalidSPDXAnalysisException {
	int byteOffset = 14;
	int lineOffset = 1231;
	SinglePointer bop = new ByteOffsetPointer(REFERENCED1, byteOffset);
	Resource bopResource = bop.createResource(modelContainer);
	SinglePointer lcp = new LineCharPointer(REFERENCED2, lineOffset);
	Resource lcpResource = lcp.createResource(modelContainer);

	// remove the types
	Property rdfTypeProperty = modelContainer.getModel().getProperty(SpdxRdfConstants.RDF_NAMESPACE, 
			SpdxRdfConstants.RDF_PROP_TYPE);
	bopResource.removeAll(rdfTypeProperty);
	lcpResource.removeAll(rdfTypeProperty);
	
	SinglePointer result = PointerFactory.getSinglePointerFromModel(modelContainer, bopResource.asNode());
	assertTrue(result instanceof ByteOffsetPointer);
	assertTrue(REFERENCED1.equivalent(result.getReference()));
	assertEquals(new Integer(byteOffset), ((ByteOffsetPointer)result).getOffset());
	
	result = PointerFactory.getSinglePointerFromModel(modelContainer, lcpResource.asNode());
	assertTrue(result instanceof LineCharPointer);
	assertTrue(REFERENCED2.equivalent(result.getReference()));
	assertEquals(new Integer(lineOffset), ((LineCharPointer)result).getLineNumber());
}
 
Example #2
Source File: RdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * @param nameSpace
 * @param propertyName
 * @param checksumValue
 * @return
 * @throws InvalidSPDXAnalysisException 
 */
protected DoapProject[] findMultipleDoapPropertyValues(String nameSpace,
		String propertyName) throws InvalidSPDXAnalysisException {
	if (this.model == null || this.node == null) {
		return new DoapProject[0];
	}
	List<DoapProject> retval = Lists.newArrayList();
	Node p = model.getProperty(nameSpace, propertyName).asNode();
	Triple m = Triple.createMatch(node, p, null);
	ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);	
	while (tripleIter.hasNext()) {
		Triple t = tripleIter.next();
		retval.add(new DoapProject(modelContainer, t.getObject()));
	}
	return retval.toArray(new DoapProject[retval.size()]);
}
 
Example #3
Source File: WithExceptionOperator.java    From tools with Apache License 2.0 6 votes vote down vote up
@Override
public void populateModel() throws InvalidSPDXAnalysisException {
	// License
	// delete any previous created
	Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
	model.removeAll(resource, licProperty, null);

	licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
	Resource licResource = license.createResource(this.modelContainer);
	resource.addProperty(licProperty, licResource);
	// Exception
	// delete any previous created
	Property exceptionProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION);
	model.removeAll(resource, exceptionProperty, null);

	exceptionProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION);
	Resource exceptionResource = exception.createResource(modelContainer);
	resource.addProperty(exceptionProperty, exceptionResource);
}
 
Example #4
Source File: ExternalDocumentRef.java    From tools with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equivalent(IRdfModel compare) {
	if (compare == this) {
		return true;
	}
	if (!(compare instanceof ExternalDocumentRef)) {
		return false;
	}
	ExternalDocumentRef compref = (ExternalDocumentRef)compare;
	try {
           return (Objects.equal(this.getSpdxDocumentNamespace(), compref.getSpdxDocumentNamespace()) &&
                   equivalentConsideringNull(this.getChecksum(), compref.getChecksum()) && Objects.equal(this.getExternalDocumentId(),
                   compref.getExternalDocumentId()));
	} catch (InvalidSPDXAnalysisException e) {
		logger.error("Invald SPDX Analysis exception comparing external document references: "+e.getMessage(),e);
		return false;
	}
}
 
Example #5
Source File: TestPackageSheet.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelationshipsCol() throws InvalidSPDXAnalysisException, SpdxCompareException {
	SpdxElement relatedElement = getDescribedPackage(doc3).getFiles()[0];
	Relationship[] different = new Relationship[] {
			new Relationship(relatedElement, RelationshipType.CONTAINED_BY, "Comment")};
	getDescribedPackage(doc3).setRelationships(different);
	comparer.compare(new SpdxDocument[] {doc1, doc2, doc3});
	pkgSheet.importCompareResults(comparer, docNames);
	Row row = findRow(PackageSheet.RELATIONSHIPS_FIELD_TEXT);
	assertEquals(PackageSheet.DIFFERENT_STRING, getEqualCellValue(row));
	String expected = CompareHelper.relationshipToString(getDescribedPackage(doc1).getRelationships()[0]);
	assertEquals(expected, getDocCellValue(0, row));
	expected = CompareHelper.relationshipToString(getDescribedPackage(doc2).getRelationships()[0]);
	assertEquals(expected, getDocCellValue(1, row));
	assertEquals(CompareHelper.relationshipToString(different[0]), getDocCellValue(2, row));
	comparer.compare(new SpdxDocument[] {doc1, doc2});
	pkgSheet.importCompareResults(comparer, new String[] {docNames[0], docNames[1]});
	row = findRow(PackageSheet.RELATIONSHIPS_FIELD_TEXT);
	assertEquals(PackageSheet.EQUAL_STRING, getEqualCellValue(row));
}
 
Example #6
Source File: Relationship.java    From tools with Apache License 2.0 6 votes vote down vote up
@Override
public void getPropertiesFromModel() throws InvalidSPDXAnalysisException {
	this.relatedSpdxElement = findElementPropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, 
			SpdxRdfConstants.PROP_RELATED_SPDX_ELEMENT);
	this.comment = findSinglePropertyValue(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT);
	String relationshipTypeUri = findUriPropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, 
			SpdxRdfConstants.PROP_RELATIONSHIP_TYPE);
	if (relationshipTypeUri != null) {
		String relationshipString = relationshipTypeUri.substring(SpdxRdfConstants.SPDX_NAMESPACE.length());
		try {
			this.relationshipType = RelationshipType.fromString(relationshipString);
		}catch (Exception ex) {
			logger.error("Invalid relationship type found in the model - " + relationshipString);
			throw(new InvalidSPDXAnalysisException("Invalid relationship type: " + relationshipString));
		}
	}
}
 
Example #7
Source File: CommonCode.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * @param externalDocumentRef
 * @param out
 * @param constants
 * @throws InvalidSPDXAnalysisException 
 */
private static void printExternalDocumentRef(
		ExternalDocumentRef externalDocumentRef, PrintWriter out,
		Properties constants) throws InvalidSPDXAnalysisException {
	String uri = externalDocumentRef.getSpdxDocumentNamespace();
	if (uri == null || uri.isEmpty()) {
		uri = "[UNSPECIFIED]";
	}
	String sha1 = "[UNSPECIFIED]";
	Checksum checksum = externalDocumentRef.getChecksum();
	if (checksum != null && checksum.getValue() != null && !checksum.getValue().isEmpty()) {
		sha1 = checksum.getValue();
	}
	String id = externalDocumentRef.getExternalDocumentId();
	if (id == null || id.isEmpty()) {
		id = "[UNSPECIFIED]";
	}
	println(out, constants.getProperty("PROP_EXTERNAL_DOC_URI") +
				id + " " + uri + " SHA1: " + sha1);	
}
 
Example #8
Source File: TestByteOffsetPointer.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.pointer.ByteOffsetPointer#verify()}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testVerify() throws InvalidSPDXAnalysisException {
	ByteOffsetPointer bop = new ByteOffsetPointer(REFERENCED1, 15);
	bop.createResource(modelContainer);
	List<String> result = bop.verify();
	assertEquals(0, result.size());
	// Null referenced
	ByteOffsetPointer bop2 = new ByteOffsetPointer(null, 15);
	bop2.createResource(modelContainer);
	result = bop2.verify();
	assertEquals(1, result.size());
	ByteOffsetPointer bop3 = new ByteOffsetPointer(REFERENCED1, -1);
	bop3.createResource(modelContainer);
	result = bop3.verify();
	assertEquals(1, result.size());
}
 
Example #9
Source File: TestSpdxPackage.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetFilesAnalyzed() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1};
	Checksum[] checksums = new Checksum[] {CHECKSUM1, CHECKSUM2};
	SpdxFile[] files = new SpdxFile[] {FILE1, FILE2};
	AnyLicenseInfo[] licenseFromFiles = new AnyLicenseInfo[] {LICENSE2};

	SpdxPackage pkg = new SpdxPackage(PKG_NAME1, PKG_COMMENT1, 
			annotations, relationships,	LICENSE1, licenseFromFiles, 
			COPYRIGHT_TEXT1, LICENSE_COMMENT1, LICENSE3, checksums,
			DESCRIPTION1, DOWNLOAD_LOCATION1, files,
			HOMEPAGE1, ORIGINATOR1, PACKAGEFILENAME1, 
			VERIFICATION_CODE1, SOURCEINFO1, SUMMARY1, SUPPLIER1, VERSION1,
			false, new ExternalRef[0]);
	
	assertFalse(pkg.isFilesAnalyzed());
	Resource r = pkg.createResource(modelContainer);
	assertFalse(pkg.isFilesAnalyzed());
	SpdxPackage pkg2 = new SpdxPackage(modelContainer, r.asNode());
	assertFalse(pkg2.isFilesAnalyzed());
	pkg.setFilesAnalyzed(true);
	assertTrue(pkg2.isFilesAnalyzed());
	assertTrue(pkg.isFilesAnalyzed());
}
 
Example #10
Source File: SpdxFile.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Converts URI's for the different file types to file types
 * @param uris
 * @param ignoreErrors If true, any URI's that don't correspond to a know file type will not be included.  If true, an exception is thrown.
 * @return
 * @throws InvalidSPDXAnalysisException 
 */
private FileType[] urisToFileType(String[] uris, boolean ignoreErrors) throws InvalidSPDXAnalysisException {
	List<FileType> retval = Lists.newArrayList();
	for (int i = 0; i < uris.length; i++) {
		if (uris[i] != null && !uris[i].isEmpty()) {
			if (!uris[i].startsWith(SpdxRdfConstants.SPDX_NAMESPACE)) {
				throw(new InvalidSPDXAnalysisException("Invalid file type: "+uris[i]));
			}
			String fileTypeS = uris[i].substring(SpdxRdfConstants.SPDX_NAMESPACE.length());
			try {
				retval.add(FileType.valueOf(fileTypeS));
			} catch (Exception ex) {
				logger.error("Invalid file type in the model - "+fileTypeS);
				if (!ignoreErrors) {
					throw(new InvalidSPDXAnalysisException("Invalid file type: "+uris[i]));
				}
			}
		}
	}
	return retval.toArray(new FileType[retval.size()]);
}
 
Example #11
Source File: TestWithExceptionOperator.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.license.WithExceptionOperator#setException(org.spdx.rdfparser.license.LicenseException)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetException() throws InvalidSPDXAnalysisException {
	WithExceptionOperator weo1 = new WithExceptionOperator(license1, exception1);
	model = ModelFactory.createDefaultModel();
	weo1.createResource(modelContainer);
	ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)weo1.getLicense();
	LicenseException le1 = weo1.getException();
	assertEquals(LICENSE_ID1, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT1, lic1.getExtractedText());
	assertEquals(EXCEPTION_ID1, le1.getLicenseExceptionId());
	assertEquals(EXCEPTION_TEXT1, le1.getLicenseExceptionText());
	assertEquals(EXCEPTION_NAME1, le1.getName());
	weo1.setException(exception2);
	lic1 = (ExtractedLicenseInfo)weo1.getLicense();
	le1 = weo1.getException();
	assertEquals(LICENSE_ID1, lic1.getLicenseId());
	assertEquals(LICENSE_TEXT1, lic1.getExtractedText());
	assertEquals(EXCEPTION_ID2, le1.getLicenseExceptionId());
	assertEquals(EXCEPTION_TEXT2, le1.getLicenseExceptionText());
	assertEquals(EXCEPTION_NAME2, le1.getName());
}
 
Example #12
Source File: ExternalRef.java    From tools with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equivalent(IRdfModel compare) {
	if (compare == this) {
		return true;
	}
	if (!(compare instanceof ExternalRef)) {
		return false;
	}
	// Note - we consider references equiv. even if the comments differ
	ExternalRef erCompare = (ExternalRef)compare;
	try {
		return Objects.equal(this.getReferenceCategory(), erCompare.getReferenceCategory()) &&
				Objects.equal(this.getReferenceLocator(), erCompare.getReferenceLocator()) &&
				this.equivalentConsideringNull(this.getReferenceType(), erCompare.getReferenceType());
	} catch (InvalidSPDXAnalysisException e) {
		logger.error("Error getting equiv. data",e);
		return false;
	}
}
 
Example #13
Source File: DisjunctiveLicenseSet.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Disjunctive license sets can contain other conjunctive license sets as members.  Logically,
 * the members of these "sub-disjunctive license sets" could be direct members and have the same
 * meaning.
 * @return all members "flattening out" disjunctive license sets which are members of this set
 */
protected AnyLicenseInfo[] getFlattenedMembers() {
	if (this.resource != null && this.refreshOnGet) {
		try {
			getPropertiesFromModel();
		} catch (InvalidSPDXAnalysisException e) {
			logger.warn("Error getting properites from model, using stored values.",e);
		}
	}
	HashSet<AnyLicenseInfo> retval = new HashSet<AnyLicenseInfo>();	// Use a set since any duplicated elements would be still considered equal
	Iterator<AnyLicenseInfo> iter = this.licenseInfos.iterator();
	while (iter.hasNext()) {
		AnyLicenseInfo li = iter.next();
		if (li instanceof DisjunctiveLicenseSet) {
			// we need to flatten this out
			AnyLicenseInfo[] members = ((DisjunctiveLicenseSet)li).getFlattenedMembers();
			for (int i = 0; i < members.length; i++) {
				retval.add(members[i]);
			}
		} else {
			retval.add(li);
		}
	}
	return retval.toArray(new AnyLicenseInfo[retval.size()]);
}
 
Example #14
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.RdfModelObject#findMultiplePropertyValues(java.lang.String, java.lang.String)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetFindMultipePropertyValues() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	String[] result = empty.findMultiplePropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(0, result.length);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, new String[] {TEST_PROPVALUE1, TEST_PROPVALUE2});
	result = empty.findMultiplePropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	if (result[0].equals(TEST_PROPVALUE1)) {
		assertEquals(TEST_PROPVALUE2, result[1]);
	} else if (result[0].equals(TEST_PROPVALUE2)) {
		assertEquals(TEST_PROPVALUE1, result[1]);
	} else {
		fail("Wrong values");
	}
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, new String[] {TEST_PROPVALUE3, TEST_PROPVALUE4});
	result = empty.findMultiplePropertyValues(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(2, result.length);
	if (result[0].equals(TEST_PROPVALUE3)) {
		assertEquals(TEST_PROPVALUE4, result[1]);
	} else if (result[0].equals(TEST_PROPVALUE4)) {
		assertEquals(TEST_PROPVALUE3, result[1]);
	} else {
		fail("Wrong values");
	}
}
 
Example #15
Source File: BuildLegacyDocument.java    From tools with Apache License 2.0 5 votes vote down vote up
public BuildLegacyDocument(Model model, SPDXDocument spdxDocument, Properties constants) {
	this.constants = constants;
	analysis = spdxDocument;
	try {
		analysis.createSpdxAnalysis("http://www.uri.com" + "#SPDXANALYSIS");
		analysis.createSpdxPackage();
	} catch (InvalidSPDXAnalysisException ex) {
		System.out
				.print("Error creating SPDX Analysis: " + ex.getMessage());
		return;
	}
}
 
Example #16
Source File: CreatorInfoContext.java    From tools with Apache License 2.0 5 votes vote down vote up
public List<String> creator() {
	List<String> creators = Lists.newArrayList();
	try {
		SPDXCreatorInformation creatorInfo = doc.getCreationInfo();
		if (creatorInfo != null) {
			String[] creatorArray = creatorInfo.getCreators();
			for (int i = 0; i < creatorArray.length; i++) {
				creators.add(creatorArray[i]);
			}
		}
	} catch(InvalidSPDXAnalysisException ex) {
		creators.add("Error getting creators: "+ex.getMessage());
	}
	return creators;
}
 
Example #17
Source File: RdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
protected void addPropertyValue(String nameSpace, String propertyName,
		Annotation annotation) throws InvalidSPDXAnalysisException {
	if (model != null && resource != null) {
		Property p = model.createProperty(nameSpace, propertyName);
		if (annotation != null) {
				this.resource.addProperty(p, annotation.createResource(modelContainer));
		}
	}
}
 
Example #18
Source File: SpreadsheetToRDF.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Copy snippet information from the spreadsheet to the analysis document
 * @param snippetSheet
 * @param analysis
 * @param fileIdToFile
 * @throws InvalidSPDXAnalysisException 
 * @throws SpreadsheetException 
 */
private static void copyPerSnippetInfo(SnippetSheet snippetSheet,
		SpdxDocument analysis, Map<String, SpdxFile> fileIdToFile) throws InvalidSPDXAnalysisException, SpreadsheetException {
	int i = snippetSheet.getFirstDataRow();
	SpdxSnippet snippet = snippetSheet.getSnippet(i, analysis.getDocumentContainer());
	while (snippet != null) {
		analysis.getDocumentContainer().addElement(snippet);
		i = i + 1;
		snippet = snippetSheet.getSnippet(i, analysis.getDocumentContainer());
	}
}
 
Example #19
Source File: SpdxItem.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
private void getMyPropertiesFromModel() throws InvalidSPDXAnalysisException {
	this.copyrightText = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_COPYRIGHT_TEXT);
	this.licenseComments = findSinglePropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LIC_COMMENTS);
	this.licenseConcluded = findAnyLicenseInfoPropertyValue(SpdxRdfConstants.SPDX_NAMESPACE, 
			SpdxRdfConstants.PROP_LICENSE_CONCLUDED);
	this.licenseInfoFromFiles = findAnyLicenseInfoPropertyValues(SpdxRdfConstants.SPDX_NAMESPACE, 
			getLicenseInfoFromFilesPropertyName());
	this.attributionText = findMultiplePropertyValues(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_ATTRIBUTION_TEXT);
}
 
Example #20
Source File: SpdxComparer.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @throws SpdxCompareException 
 * 
 */
private void compareDataLicense() throws SpdxCompareException {
	try {
		AnyLicenseInfo lic1 = this.spdxDocs[0].getDataLicense();
		this.dataLicenseEqual = true;
		for (int i = 1; i < spdxDocs.length; i++) {
			if (!lic1.equals(spdxDocs[i].getDataLicense())) {
				this.dataLicenseEqual = false;
				break;
			}
		}
	} catch (InvalidSPDXAnalysisException e) {
		throw(new SpdxCompareException("SPDX analysis error during compare data license: "+e.getMessage(),e));
	}
}
 
Example #21
Source File: TestExternalDocumentRef.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.ExternalDocumentRef#verify()}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testVerify() throws InvalidSPDXAnalysisException {
	ExternalDocumentRef edf = new ExternalDocumentRef(DOCUMENT_URI1, CHECKSUM1,
			DOCUMENT_ID1);
	assertEquals(0, edf.verify().size());
	Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	edf.createResource(modelContainer);
	assertEquals(0, edf.verify().size());
	edf.setChecksum(null);
	assertEquals(1, edf.verify().size());
	edf.setSpdxDocumentNamespace(null);
	assertEquals(2, edf.verify().size());
}
 
Example #22
Source File: TestSpdxDocument.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxDocument#setDataLicense(org.spdx.rdfparser.license.AnyLicenseInfo)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetDataLicense() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {
			ANNOTATION1, ANNOTATION2	
		};
		ExternalDocumentRef[] externalDocumentRefs = new ExternalDocumentRef[] {
				EXTERNAL_REF1, EXTERNAL_REF2
		};
		ExtractedLicenseInfo[] extractedLicenseInfos = new ExtractedLicenseInfo[] {
				LICENSE1, LICENSE2
		};
		Relationship[] relationships = new Relationship[] {
				RELATIONSHIP1, RELATIONSHIP2
		};
		SpdxItem[] items = new SpdxItem[] {
				FILE1, FILE2, PACKAGE1, PACKAGE2
		};
		SpdxDocument doc = container.getSpdxDocument();
		doc.setAnnotations(annotations);
		doc.setComment(DOC_COMMENT1);
		doc.setCreationInfo(CREATIONINFO1);
		doc.setDataLicense(CCO_DATALICENSE);
		doc.setExternalDocumentRefs(externalDocumentRefs);
		doc.setExtractedLicenseInfos(extractedLicenseInfos);
		doc.setName(DOC_NAME1);
		doc.setRelationships(relationships);
		for (int i = 0; i < items.length; i++) {
			doc.addRelationship(new Relationship(items[i], 
					Relationship.RelationshipType.DESCRIBES, ""));
		}
		
		assertEquals(CCO_DATALICENSE, doc.getDataLicense());
		SpdxListedLicense lic = LicenseInfoFactory.getListedLicenseById("Apache-2.0");
		doc.setDataLicense(lic);
		assertEquals(lic, doc.getDataLicense());
}
 
Example #23
Source File: TestSpdxSnippet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxSnippet#getType(org.apache.jena.rdf.model.Model)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testGetType() throws InvalidSPDXAnalysisException {
	SpdxSnippet snippet = new SpdxSnippet("snippetName", null, null, null, 
			COMPLEX_LICENSE, NON_STD_LICENSES, SpdxRdfConstants.NOASSERTION_VALUE,
			null, FROM_FILE1, BYTE_RANGE1, LINE_RANGE1);
	snippet.createResource(modelContainer);
	String expected = SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_SNIPPET;
	Resource result = snippet.getType(model);
	assertTrue(result.isURIResource());
	assertEquals(expected, result.getURI());
}
 
Example #24
Source File: TestDocumentSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocumentComment() throws InvalidSPDXAnalysisException, SpdxCompareException {
	doc3.setComment("Different");
	comparer.compare(new SpdxDocument[] {doc1, doc2, doc3});
	docSheet.importCompareResults(comparer, docNames);
	assertEquals(DIFFERENT_STRING, getEqualsValue(docSheet.DOCUMENT_COMMENT_COL));
	SpdxDocument[] comparedDocs = comparer.getSpdxDocuments();
	for (int i = 0; i < comparedDocs.length; i++) {
		assertEquals(comparedDocs[i].getComment(),
				getDataValue(docSheet.DOCUMENT_COMMENT_COL, i));
	}
}
 
Example #25
Source File: TestPackageSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param doc
 * @return
 * @throws InvalidSPDXAnalysisException
 */
private SpdxPackage getDescribedPackage(SpdxDocument doc) throws InvalidSPDXAnalysisException {
	SpdxItem[] items = doc.getDocumentDescribes();
	for (int i = 0; i < items.length; i++) {
		if (items[i] instanceof SpdxPackage) {
			return (SpdxPackage)items[i];
		}
	}
	return null;
}
 
Example #26
Source File: TestSpdxElement.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.SpdxElement#setName(java.lang.String)}.
 * @throws InvalidSPDXAnalysisException
 */
@Test
public void testSetName() throws InvalidSPDXAnalysisException {
	Annotation[] annotations = new Annotation[] {ANNOTATION1, ANNOTATION2};
	Relationship[] relationships = new Relationship[] {RELATIONSHIP1, RELATIONSHIP2};
	SpdxElement element1 = new SpdxElement(ELEMENT_NAME1, ELEMENT_COMMENT1,
			annotations, relationships);
	assertEquals(ELEMENT_NAME1, element1.getName());
	element1.createResource(modelContainer);
	assertEquals(ELEMENT_NAME1, element1.getName());
	element1.setName(ELEMENT_NAME2);
	assertEquals(ELEMENT_NAME2, element1.getName());
	element1.setName(null);
	assertTrue(element1.getName() == null);
}
 
Example #27
Source File: RdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Create an RDF Model Object based on an existing Node
 * @param modelContainer Container containing the RDF Model
 * @param node Node describing this object
 * @throws InvalidSPDXAnalysisException
 */
public RdfModelObject(IModelContainer modelContainer, Node node) throws InvalidSPDXAnalysisException {
	this.modelContainer = modelContainer;
	this.model = modelContainer.getModel();
	this.node = node;
	this.refreshOnGet = modelContainer.addCheckNodeObject(node, this);
	if (node.isBlank()) {
		resource = model.createResource(new AnonId(node.getBlankNodeId()));
	} else if (node.isURI()) {
		resource = model.createResource(node.getURI());
	} else {
		throw(new InvalidSPDXAnalysisException("Can not have an model node as a literal"));
	}
}
 
Example #28
Source File: OriginsSheetV2d0.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param externalDocumentRef
 * @return
 * @throws InvalidSPDXAnalysisException 
 */
private String externalDocRefToStr(ExternalDocumentRef externalDocumentRef) throws InvalidSPDXAnalysisException {
	if (externalDocumentRef == null) {
		return "";
	}
	return externalDocumentRef.getExternalDocumentId() +
			" " + externalDocumentRef.getSpdxDocumentNamespace() + 
			" " + Checksum.CHECKSUM_ALGORITHM_TO_TAG.get(externalDocumentRef.getChecksum().getAlgorithm()) +
			" " + externalDocumentRef.getChecksum().getValue();
}
 
Example #29
Source File: TestByteOffsetPointer.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.pointer.SinglePointer#setReference(org.spdx.rdfparser.model.SpdxElement)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testSetReference() throws InvalidSPDXAnalysisException {
	ByteOffsetPointer bop = new ByteOffsetPointer(REFERENCED1, 15);
	assertEquals(REFERENCED1.getName(), bop.getReference().getName());
	Resource r = bop.createResource(modelContainer);
	assertEquals(REFERENCED1.getName(), bop.getReference().getName());
	ByteOffsetPointer bop2 = new ByteOffsetPointer(modelContainer, r.asNode());
	assertEquals(REFERENCED1.getName(), bop2.getReference().getName());
	bop.setReference(REFERENCED2);
	assertEquals(REFERENCED2.getName(), bop.getReference().getName());
	assertEquals(REFERENCED2.getName(), bop2.getReference().getName());
}
 
Example #30
Source File: TestLicenseException.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetName() throws InvalidSPDXAnalysisException {
	LicenseException le = new LicenseException(EXCEPTION_ID1,
			EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_SEEALSO1,
			EXCEPTION_COMMENT1);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	le.setName(EXCEPTION_NAME2);
	assertEquals(EXCEPTION_ID1, le.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME2, le.getName());
	assertEquals(EXCEPTION_TEXT1, le.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le.getComment());
	Resource leResource = le.createResource(testContainer);
	LicenseException le2 = new LicenseException(testContainer, leResource.asNode());
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME2, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
	le2.setName(EXCEPTION_NAME1);
	assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId());
	assertEquals(EXCEPTION_NAME1, le2.getName());
	assertEquals(EXCEPTION_TEXT1, le2.getLicenseExceptionText());
	assertStringsEquals(EXCEPTION_SEEALSO1, le2.getSeeAlso());
	assertEquals(EXCEPTION_COMMENT1, le2.getComment());
}