Skip to content

Commit

Permalink
Add Support For License
Browse files Browse the repository at this point in the history
 - The update allows the model to handle all types of licenses.
 - Removed all methods identified as unused.

Signed-off-by: RishabhBhatnagar <bhatnagarrishabh4@gmail.com>
  • Loading branch information
RishabhBhatnagar committed Aug 20, 2020
1 parent f609198 commit 2998728
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 349 deletions.
37 changes: 27 additions & 10 deletions rdfloader/parser2v2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ var (
SPDX_SUPPLIER = NS_SPDX + "supplier"
SPDX_ORIGINATOR = NS_SPDX + "originator"
SPDX_DOWNLOAD_LOCATION = NS_SPDX + "downloadLocation"
SPDX_NOASSERTION = NS_SPDX + "noassertion"
SPDX_NONE = NS_SPDX + "none"
SPDX_FILES_ANALYZED = NS_SPDX + "filesAnalyzed"
SPDX_PACKAGE_VERIFICATION_CODE = NS_SPDX + "packageVerificationCode"
SPDX_SOURCE_INFO = NS_SPDX + "sourceInfo"
Expand Down Expand Up @@ -84,14 +82,33 @@ var (
SPDX_REFERENCE_CATEGORY_SECURITY = NS_SPDX + "referenceCategory_security"
SPDX_REFERENCE_CATEGORY_OTHER = NS_SPDX + "referenceCategory_other"

SPDX_REFERENCE_TYPE = NS_SPDX + "referenceType"
SPDX_REFERENCE_LOCATOR = NS_SPDX + "referenceLocator"
SPDX_ANNOTATION_DATE = NS_SPDX + "annotationDate"
SPDX_ANNOTATOR = NS_SPDX + "annotator"
SPDX_MEMBER = NS_SPDX + "member"
SPDX_DISJUNCTIVE_LICENSE_SET = NS_SPDX + "DisjunctiveLicenseSet"
SPDX_CONJUNCTIVE_LICENSE_SET = NS_SPDX + "ConjunctiveLicenseSet"
SPDX_EXTRACTED_LICENSING_INFO = NS_SPDX + "ExtractedLicensingInfo"
SPDX_REFERENCE_TYPE = NS_SPDX + "referenceType"
SPDX_REFERENCE_LOCATOR = NS_SPDX + "referenceLocator"
SPDX_ANNOTATION_DATE = NS_SPDX + "annotationDate"
SPDX_ANNOTATOR = NS_SPDX + "annotator"
SPDX_MEMBER = NS_SPDX + "member"
SPDX_DISJUNCTIVE_LICENSE_SET = NS_SPDX + "DisjunctiveLicenseSet"
SPDX_CONJUNCTIVE_LICENSE_SET = NS_SPDX + "ConjunctiveLicenseSet"
SPDX_EXTRACTED_LICENSING_INFO = NS_SPDX + "ExtractedLicensingInfo"
SPDX_NONE_CAPS = NS_SPDX + "NONE"
SPDX_NOASSERTION_CAPS = NS_SPDX + "NOASSERTION"
SPDX_NONE_SMALL = NS_SPDX + "none"
SPDX_NOASSERTION_SMALL = NS_SPDX + "noassertion"
SPDX_LICENSE = NS_SPDX + "License"
SPDX_LISTED_LICENSE = NS_SPDX + "ListedLicense"
SPDX_EXAMPLE = NS_SPDX + "example"
SPDX_IS_OSI_APPROVED = NS_SPDX + "isOsiApproved"
SPDX_STANDARD_LICENSE_TEMPLATE = NS_SPDX + "standardLicenseTemplate"
SPDX_IS_DEPRECATED_LICENSE_ID = NS_SPDX + "isDeprecatedLicenseId"
SPDX_IS_FSF_LIBRE = NS_SPDX + "isFsfLibre"
SPDX_LICENSE_TEXT = NS_SPDX + "licenseText"
SPDX_STANDARD_LICENSE_HEADER = NS_SPDX + "standardLicenseHeader"
SPDX_LICENSE_EXCEPTION_ID = NS_SPDX + "licenseExceptionId"
SPDX_LICENSE_EXCEPTION_TEXT = NS_SPDX + "licenseExceptionText"
SPDX_LICENSE_EXCEPTION = NS_SPDX + "licenseException"
SPDX_WITH_EXCEPTION_OPERATOR = NS_SPDX + "WithExceptionOperator"
SPDX_OR_LATER_OPERATOR = NS_SPDX + "OrLaterOperator"
SPDX_STANDARD_LICENSE_HEADER_TEMPLATE = NS_SPDX + "standardLicenseHeaderTemplate"

// RDFS properties
RDFS_COMMENT = NS_RDFS + "comment"
Expand Down
2 changes: 1 addition & 1 deletion rdfloader/parser2v2/parse_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// The newly created annotation is appended to the doc.
func (parser *rdfParser2_2) parseAnnotationFromNode(node *gordfParser.Node) (err error) {
ann := &spdx.Annotation2_2{}
for _, subTriple := range parser.nodeToTriples[node.String()] {
for _, subTriple := range parser.nodeToTriples(node) {
switch subTriple.Predicate.ID {
case SPDX_ANNOTATOR:
// cardinality: exactly 1
Expand Down
2 changes: 1 addition & 1 deletion rdfloader/parser2v2/parse_creation_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Cardinality: Mandatory, one.
func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *spdx.CreationInfo2_2, node *gordfParser.Node) error {
for _, triple := range parser.nodeToTriples[node.String()] {
for _, triple := range parser.nodeToTriples(node) {
switch triple.Predicate.ID {
case SPDX_LICENSE_LIST_VERSION: // 2.7
// cardinality: max 1
Expand Down
10 changes: 7 additions & 3 deletions rdfloader/parser2v2/parse_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *s
return nil, err
}

for _, subTriple := range parser.nodeToTriples[fileNode.String()] {
for _, subTriple := range parser.nodeToTriples(fileNode) {
switch subTriple.Predicate.ID {
case SPDX_FILE_NAME: // 4.1
// cardinality: exactly 1
Expand All @@ -38,7 +38,11 @@ func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *s
err = parser.setFileChecksumFromNode(file, subTriple.Object)
case SPDX_LICENSE_CONCLUDED: // 4.5
// cardinality: (exactly 1 anyLicenseInfo) or (None) or (Noassertion)
file.LicenseConcluded, err = parser.getLicenseFromTriple(subTriple)
anyLicense, err := parser.getAnyLicenseFromNode(subTriple.Object)
if err != nil {
return nil, fmt.Errorf("error parsing licenseConcluded: %v", err)
}
file.LicenseConcluded = anyLicense.ToLicenseString()
case SPDX_LICENSE_INFO_IN_FILE: // 4.6
// cardinality: min 1
lastPart := getLastPartOfURI(subTriple.Object.ID)
Expand Down Expand Up @@ -117,7 +121,7 @@ func (parser *rdfParser2_2) getArtifactFromNode(node *gordfParser.Node) (*spdx.A
artifactOf.URI = node.ID
}
// parsing rest triples and attributes of the artifact.
for _, triple := range parser.nodeToTriples[node.String()] {
for _, triple := range parser.nodeToTriples(node) {
switch triple.Predicate.ID {
case RDF_TYPE:
case DOAP_HOMEPAGE:
Expand Down

0 comments on commit 2998728

Please sign in to comment.