diff --git a/examples/10-jsonloader/example_json_loader.go b/examples/10-jsonloader/example_json_loader.go new file mode 100644 index 00000000..96f47fd0 --- /dev/null +++ b/examples/10-jsonloader/example_json_loader.go @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +// Example for: *jsonparser2v2* + +// This example demonstrates loading an SPDX json from disk into memory, +// and then logging out some attributes to the console . + +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/spdx/tools-golang/jsonloader" +) + +func main() { + + // check that we've received the right number of arguments + args := os.Args + if len(args) != 3 { + fmt.Printf("Usage: %v \n", args[0]) + fmt.Printf(" Load SPDX 2.2 tag-value file , and\n") + fmt.Printf(" save it out to .\n") + return + } + + // open the SPDX file + fileIn := args[1] + r, err := os.Open(fileIn) + if err != nil { + fmt.Printf("Error while opening %v for reading: %v", fileIn, err) + return + } + defer r.Close() + + // try to load the SPDX file's contents as a json file, version 2.2 + doc, err := jsonloader.Load2_2(r) + if err != nil { + fmt.Printf("Error while parsing %v: %v", args[1], err) + return + } + + // if we got here, the file is now loaded into memory. + fmt.Printf("Successfully loaded %s\n", args[1]) + + fmt.Println(strings.Repeat("=", 80)) + fmt.Println("Some Attributes of the Document:") + fmt.Printf("Document Name: %s\n", doc.CreationInfo.DocumentName) + fmt.Printf("DataLicense: %s\n", doc.CreationInfo.DataLicense) + fmt.Printf("Document NameSpace: %s\n", doc.CreationInfo.DocumentNamespace) + fmt.Printf("SPDX Document Version: %s\n", doc.CreationInfo.SPDXVersion) + fmt.Println(strings.Repeat("=", 80)) +} diff --git a/examples/8-jsonloader/result.txt b/examples/8-jsonloader/result.txt deleted file mode 100644 index 7909ccf2..00000000 --- a/examples/8-jsonloader/result.txt +++ /dev/null @@ -1,346 +0,0 @@ -SPDXVersion: SPDX-2.2 -DataLicense: CC0-1.0 -SPDXID: SPDXRef-DOCUMENT -DocumentName: SPDX-Tools-v2.0 -DocumentNamespace: http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301 -ExternalDocumentRef: DocumentRef-spdx-tool-1.2 http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301 SHA1:d6a770ba38583ed4bb4525bd96e50461655d2759 -LicenseListVersion: 3.9 -Creator: Person: Jane Doe -Creator: Organization: ExampleCodeInspect -Creator: Tool: LicenseFind-1.0 -Created: 2010-01-29T18:30:22Z -CreatorComment: This package has been shipped in source and binary form. -The binaries were created with gcc 4.5.1 and expect to link to -compatible system run time libraries. -DocumentComment: This document was created using SPDX 2.0 using licenses from the web site. - -##### Unpackaged files - -FileName: ./package/foo.c -SPDXID: SPDXRef-File -FileType: SOURCE -FileChecksum: SHA1: d6a770ba38583ed4bb4525bd96e50461655d2758 -FileChecksum: MD5: 624c1abb3664f4b35547e7c73864ad24 -LicenseConcluded: (LGPL-2.0-only OR LicenseRef-2) -LicenseInfoInFile: GPL-2.0-only -LicenseInfoInFile: LicenseRef-2 -LicenseComments: The concluded license was taken from the package level that the file was included in. -FileCopyrightText: Copyright 2008-2010 John Smith -FileComment: The concluded license was taken from the package level that the file was included in. -This information was found in the COPYING.txt file in the xyz directory. -FileNotice: Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.com - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED �AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -FileContributor: The Regents of the University of California -FileContributor: Modified by Paul Mundt lethal@linux-sh.org -FileContributor: IBM Corporation -FileAttributionText: The Regents of the University of California -FileAttributionText: Modified by Paul Mundt lethal@linux-sh.org -FileAttributionText: IBM Corporation - -##### Package: glibc - -PackageName: glibc -SPDXID: SPDXRef-Package -PackageVersion: 2.11.1 -PackageFileName: glibc-2.11.1.tar.gz -PackageSupplier: Person: Jane Doe (jane.doe@example.com) -PackageOriginator: Organization: ExampleCodeInspect (contact@example.com) -PackageDownloadLocation: http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz -FilesAnalyzed: true -PackageVerificationCode: d6a770ba38583ed4bb4525bd96e50461655d2758 (excludes: ./package.spdx) -PackageChecksum: SHA1: 85ed0817af83a24ad8da68c2b5094de69833983c -PackageChecksum: SHA256: 11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd -PackageChecksum: MD5: 624c1abb3664f4b35547e7c73864ad24 -PackageHomePage: http://ftp.gnu.org/gnu/glibc -PackageSourceInfo: uses glibc-2_11-branch from git://sourceware.org/git/glibc.git. -PackageLicenseConcluded: (LGPL-2.0-only OR LicenseRef-3) -PackageLicenseInfoFromFiles: GPL-2.0-only -PackageLicenseInfoFromFiles: LicenseRef-2 -PackageLicenseInfoFromFiles: LicenseRef-1 -PackageLicenseDeclared: (LGPL-2.0-only AND LicenseRef-3) -PackageLicenseComments: The license for this project changed with the release of version x.y. The version of the project included here post-dates the license change. -PackageCopyrightText: Copyright 2008-2010 John Smith -PackageSummary: GNU C library. -PackageDescription: The GNU C Library defines functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to GNU systems. -ExternalRef: SECURITY cpe23Type cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:* -ExternalRef: OTHER http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge acmecorp/acmenator/4.1.3-alpha -ExternalRefComment: This is the external ref for Acme -PackageAttributionText: The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually. - -FileName: ./lib-source/commons-lang3-3.1-sources.jar -SPDXID: SPDXRef-CommonsLangSrc -FileType: ARCHIVE -FileChecksum: SHA1: c2b4e1c67a2d28fced849ee1bb76e7391b93f125 -LicenseConcluded: Apache-2.0 -LicenseInfoInFile: Apache-2.0 -FileCopyrightText: Copyright 2001-2011 The Apache Software Foundation -FileComment: This file is used by Jena -FileNotice: Apache Commons Lang -Copyright 2001-2011 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - -This product includes software from the Spring Framework, -under the Apache License 2.0 (see: StringUtils.containsWhitespace()) -FileContributor: Apache Software Foundation -FileAttributionText: Apache Software Foundation - -FileName: ./src/org/spdx/parser/DOAPProject.java -SPDXID: SPDXRef-DoapSource -FileType: SOURCE -FileChecksum: SHA1: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 -LicenseConcluded: Apache-2.0 -LicenseInfoInFile: Apache-2.0 -FileCopyrightText: Copyright 2010, 2011 Source Auditor Inc. -FileContributor: Protecode Inc. -FileContributor: SPDX Technical Team Members -FileContributor: Open Logic Inc. -FileContributor: Source Auditor Inc. -FileContributor: Black Duck Software In.c -FileAttributionText: Protecode Inc. -FileAttributionText: SPDX Technical Team Members -FileAttributionText: Open Logic Inc. -FileAttributionText: Source Auditor Inc. -FileAttributionText: Black Duck Software In.c - -SnippetSPDXIdentifier: SPDXRef-Snippet -SnippetFromFileSPDXID: SPDXRef-DoapSource -SnippetByteRange: 310:420 -SnippetLineRange: 5:23 -SnippetLicenseConcluded: GPL-2.0-only -LicenseInfoInSnippet: GPL-2.0-only -SnippetLicenseComments: The concluded license was taken from package xyz, from which the snippet was copied into the current file. The concluded license information was found in the COPYING.txt file in package xyz. -SnippetCopyrightText: Copyright 2008-2010 John Smith -SnippetComment: This snippet was identified as significant and highlighted in this Apache-2.0 file, when a commercial scanner identified it as being derived from file foo.c in package xyz which is licensed under GPL-2.0. -SnippetName: from linux kernel - -FileName: ./lib-source/jena-2.6.3-sources.jar -SPDXID: SPDXRef-JenaLib -FileType: ARCHIVE -FileChecksum: SHA1: 3ab4e1c67a2d28fced849ee1bb76e7391b93f125 -LicenseConcluded: LicenseRef-1 -LicenseInfoInFile: LicenseRef-1 -LicenseComments: This license is used by Jena -FileCopyrightText: (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP -FileComment: This file belongs to Jena -FileContributor: Apache Software Foundation -FileContributor: Hewlett Packard Inc. -FileAttributionText: Apache Software Foundation -FileAttributionText: Hewlett Packard Inc. - -##### Package: Saxon - -PackageName: Saxon -SPDXID: SPDXRef-Saxon -PackageVersion: 8.8 -PackageFileName: saxonB-8.8.zip -PackageDownloadLocation: https://sourceforge.net/projects/saxon/files/Saxon-B/8.8.0.7/saxonb8-8-0-7j.zip/download -FilesAnalyzed: false -PackageChecksum: SHA1: 85ed0817af83a24ad8da68c2b5094de69833983c -PackageHomePage: http://saxon.sourceforge.net/ -PackageLicenseConcluded: MPL-1.0 -PackageLicenseDeclared: MPL-1.0 -PackageLicenseComments: Other versions available for a commercial license -PackageCopyrightText: Copyright Saxonica Ltd -PackageDescription: The Saxon package is a collection of tools for processing XML documents. - -##### Package: Jena - -PackageName: Jena -SPDXID: SPDXRef-fromDoap-0 -PackageVersion: 3.12.0 -PackageDownloadLocation: https://search.maven.org/remotecontent?filepath=org/apache/jena/apache-jena/3.12.0/apache-jena-3.12.0.tar.gz -FilesAnalyzed: false -PackageHomePage: http://www.openjena.org/ -PackageLicenseConcluded: NOASSERTION -PackageLicenseDeclared: NOASSERTION -PackageCopyrightText: NOASSERTION -ExternalRef: PACKAGE_MANAGER purl pkg:maven/org.apache.jena/apache-jena@3.12.0 - -##### Package: Apache Commons Lang - -PackageName: Apache Commons Lang -SPDXID: SPDXRef-fromDoap-1 -PackageDownloadLocation: NOASSERTION -FilesAnalyzed: false -PackageHomePage: http://commons.apache.org/proper/commons-lang/ -PackageLicenseConcluded: NOASSERTION -PackageLicenseDeclared: NOASSERTION -PackageCopyrightText: NOASSERTION - -##### Other Licenses - -LicenseID: LicenseRef-1 -ExtractedText: /* - * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -LicenseID: LicenseRef-2 -ExtractedText: This package includes the GRDDL parser developed by Hewlett Packard under the following license: -� Copyright 2007 Hewlett-Packard Development Company, LP - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -LicenseID: LicenseRef-4 -ExtractedText: /* - * (c) Copyright 2009 University of Bristol - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -LicenseID: LicenseRef-Beerware-4.2 -ExtractedText: "THE BEER-WARE LICENSE" (Revision 42): -phk@FreeBSD.ORG wrote this file. As long as you retain this notice you -can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp - -LicenseID: LicenseRef-3 -ExtractedText: The CyberNeko Software License, Version 1.0 - - -(C) Copyright 2002-2005, Andy Clark. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - -3. The end-user documentation included with the redistribution, - if any, must include the following acknowledgment: - "This product includes software developed by Andy Clark." - Alternately, this acknowledgment may appear in the software itself, - if and wherever such third-party acknowledgments normally appear. - -4. The names "CyberNeko" and "NekoHTML" must not be used to endorse - or promote products derived from this software without prior - written permission. For written permission, please contact - andyc@cyberneko.net. - -5. Products derived from this software may not be called "CyberNeko", - nor may "CyberNeko" appear in their name, without prior written - permission of the author. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -LicenseName: CyberNeko License -LicenseCrossReference: http://people.apache.org/~andyc/neko/LICENSE -LicenseCrossReference: http://justasample.url.com -LicenseComment: This is tye CyperNeko License - -##### Relationships - -Relationship: SPDXRef-DOCUMENT CONTAINS SPDXRef-Package -Relationship: SPDXRef-DOCUMENT COPY_OF DocumentRef-spdx-tool-1.2:SPDXRef-ToolsElement -Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-File -Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package -Relationship: SPDXRef-Package CONTAINS SPDXRef-JenaLib -Relationship: SPDXRef-Package DYNAMIC_LINK SPDXRef-Saxon -Relationship: SPDXRef-CommonsLangSrc GENERATED_FROM NOASSERTION -Relationship: SPDXRef-JenaLib CONTAINS SPDXRef-Package -Relationship: SPDXRef-File GENERATED_FROM SPDXRef-fromDoap-0 - -##### Annotations - -Annotator: Person: File Commenter -AnnotationDate: 2011-01-29T18:30:22Z -AnnotationType: OTHER -SPDXREF: SPDXRef-File -AnnotationComment: File level annotation - -Annotator: Person: Package Commenter -AnnotationDate: 2011-01-29T18:30:22Z -AnnotationType: OTHER -SPDXREF: SPDXRef-Package -AnnotationComment: Package level annotation - -Annotator: Person: Jane Doe () -AnnotationDate: 2010-01-29T18:30:22Z -AnnotationType: OTHER -SPDXREF: SPDXRef-DOCUMENT -AnnotationComment: Document level annotation - -Annotator: Person: Joe Reviewer -AnnotationDate: 2010-02-10T00:00:00Z -AnnotationType: REVIEW -SPDXREF: SPDXRef-DOCUMENT -AnnotationComment: This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses - -Annotator: Person: Suzanne Reviewer -AnnotationDate: 2011-03-13T00:00:00Z -AnnotationType: REVIEW -SPDXREF: SPDXRef-DOCUMENT -AnnotationComment: Another example reviewer. - diff --git a/examples/8-jsonloader/examplejsontotv.go b/examples/8-jsontotv/examplejsontotv.go similarity index 100% rename from examples/8-jsonloader/examplejsontotv.go rename to examples/8-jsontotv/examplejsontotv.go diff --git a/examples/9-jsonsaver/sample.json b/examples/9-jsonsaver/sample.json deleted file mode 100644 index b02dc5b0..00000000 --- a/examples/9-jsonsaver/sample.json +++ /dev/null @@ -1,417 +0,0 @@ -{ - "SPDXID": "SPDXRef-DOCUMENT", - "spdxVersion": "SPDX-2.2", - "creationInfo": { - "comment": "This package has been shipped in source and binary form.\nThe binaries were created with gcc 4.5.1 and expect to link to\ncompatible system run time libraries.", - "created": "2010-01-29T18:30:22Z", - "creators": [ - "Person: Jane Doe", - "Organization: ExampleCodeInspect", - "Tool: LicenseFind-1.0" - ], - "licenseListVersion": "3.9" - }, - "name": "SPDX-Tools-v2.0", - "dataLicense": "CC0-1.0", - "comment": "This document was created using SPDX 2.0 using licenses from the web site.", - "externalDocumentRefs": [ - { - "checksum": { - "algorithm": "SHA1", - "checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2759" - }, - "externalDocumentId": "DocumentRef-spdx-tool-1.2", - "spdxDocument": "http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301" - } - ], - "hasExtractedLicensingInfos": [ - { - "extractedText": "/*\n * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote products\n * derived from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/", - "licenseId": "LicenseRef-1" - }, - { - "extractedText": "This package includes the GRDDL parser developed by Hewlett Packard under the following license:\n� Copyright 2007 Hewlett-Packard Development Company, LP\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: \n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. \nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. \nThe name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. \nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", - "licenseId": "LicenseRef-2" - }, - { - "extractedText": "/*\n * (c) Copyright 2009 University of Bristol\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote products\n * derived from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/", - "licenseId": "LicenseRef-4" - }, - { - "extractedText": "\"THE BEER-WARE LICENSE\" (Revision 42):\nphk@FreeBSD.ORG wrote this file. As long as you retain this notice you\ncan do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp \u003c/\nLicenseName: Beer-Ware License (Version 42)\nLicenseCrossReference: http://people.freebsd.org/~phk/\nLicenseComment: \nThe beerware license has a couple of other standard variants.", - "licenseId": "LicenseRef-Beerware-4.2" - }, - { - "comment": "This is tye CyperNeko License", - "extractedText": "The CyberNeko Software License, Version 1.0\n\n \n(C) Copyright 2002-2005, Andy Clark. All rights reserved.\n \nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n\n1. Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer. \n\n2. Redistributions in binary form must reproduce the above copyright\n notice, this list of conditions and the following disclaimer in\n the documentation and/or other materials provided with the\n distribution.\n\n3. The end-user documentation included with the redistribution,\n if any, must include the following acknowledgment: \n \"This product includes software developed by Andy Clark.\"\n Alternately, this acknowledgment may appear in the software itself,\n if and wherever such third-party acknowledgments normally appear.\n\n4. The names \"CyberNeko\" and \"NekoHTML\" must not be used to endorse\n or promote products derived from this software without prior \n written permission. For written permission, please contact \n andyc@cyberneko.net.\n\n5. Products derived from this software may not be called \"CyberNeko\",\n nor may \"CyberNeko\" appear in their name, without prior written\n permission of the author.\n\nTHIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED\nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\nOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS\nBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, \nOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT \nOF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR \nBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE \nOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", - "licenseId": "LicenseRef-3", - "name": "CyberNeko License", - "seeAlsos": [ - "http://people.apache.org/~andyc/neko/LICENSE", - "http://justasample.url.com" - ] - } - ], - "annotations": [ - { - "annotationDate": "2010-01-29T18:30:22Z", - "annotationType": "OTHER", - "annotator": "Person: Jane Doe ()", - "comment": "Document level annotation" - }, - { - "annotationDate": "2010-02-10T00:00:00Z", - "annotationType": "REVIEW", - "annotator": "Person: Joe Reviewer", - "comment": "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses" - }, - { - "annotationDate": "2011-03-13T00:00:00Z", - "annotationType": "REVIEW", - "annotator": "Person: Suzanne Reviewer", - "comment": "Another example reviewer." - } - ], - "documentNamespace": "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", - "documentDescribes": [ - "SPDXRef-File", - "SPDXRef-Package" - ], - "packages": [ - { - "SPDXID": "SPDXRef-Package", - "annotations": [ - { - "annotationDate": "2011-01-29T18:30:22Z", - "annotationType": "OTHER", - "annotator": "Person: Package Commenter", - "comment": "Package level annotation" - } - ], - "attributionTexts": [ - "The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually." - ], - "checksums": [ - { - "algorithm": "MD5", - "checksumValue": "624c1abb3664f4b35547e7c73864ad24" - }, - { - "algorithm": "SHA1", - "checksumValue": "85ed0817af83a24ad8da68c2b5094de69833983c" - }, - { - "algorithm": "SHA256", - "checksumValue": "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd" - } - ], - "copyrightText": "Copyright 2008-2010 John Smith", - "description": "The GNU C Library defines functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to GNU systems.", - "downloadLocation": "http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz", - "externalRefs": [ - { - "referenceCategory": "SECURITY", - "referenceLocator": "cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:*", - "referenceType": "cpe23Type" - }, - { - "comment": "This is the external ref for Acme", - "referenceCategory": "OTHER", - "referenceLocator": "acmecorp/acmenator/4.1.3-alpha", - "referenceType": "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301#LocationRef-acmeforge" - } - ], - "filesAnalyzed": true, - "hasFiles": [ - "SPDXRef-DoapSource", - "SPDXRef-CommonsLangSrc", - "SPDXRef-JenaLib" - ], - "homepage": "http://ftp.gnu.org/gnu/glibc", - "licenseComments": "The license for this project changed with the release of version x.y. The version of the project included here post-dates the license change.", - "licenseConcluded": "(LGPL-2.0-only OR LicenseRef-3)", - "licenseDeclared": "(LGPL-2.0-only AND LicenseRef-3)", - "licenseInfoFromFiles": [ - "GPL-2.0-only", - "LicenseRef-2", - "LicenseRef-1" - ], - "name": "glibc", - "originator": "Organization: ExampleCodeInspect (contact@example.com)", - "packageFileName": "glibc-2.11.1.tar.gz", - "packageVerificationCode": { - "packageVerificationCodeExcludedFiles": [ - "./package.spdx" - ], - "packageVerificationCodeValue": "d6a770ba38583ed4bb4525bd96e50461655d2758" - }, - "sourceInfo": "uses glibc-2_11-branch from git://sourceware.org/git/glibc.git.", - "summary": "GNU C library.", - "supplier": "Person: Jane Doe (jane.doe@example.com)", - "versionInfo": "2.11.1" - }, - { - "SPDXID": "SPDXRef-fromDoap-1", - "copyrightText": "NOASSERTION", - "downloadLocation": "NOASSERTION", - "filesAnalyzed": false, - "homepage": "http://commons.apache.org/proper/commons-lang/", - "licenseConcluded": "NOASSERTION", - "licenseDeclared": "NOASSERTION", - "name": "Apache Commons Lang" - }, - { - "SPDXID": "SPDXRef-fromDoap-0", - "copyrightText": "NOASSERTION", - "downloadLocation": "https://search.maven.org/remotecontent?filepath=org/apache/jena/apache-jena/3.12.0/apache-jena-3.12.0.tar.gz", - "externalRefs": [ - { - "referenceCategory": "PACKAGE_MANAGER", - "referenceLocator": "pkg:maven/org.apache.jena/apache-jena@3.12.0", - "referenceType": "purl" - } - ], - "filesAnalyzed": false, - "homepage": "http://www.openjena.org/", - "licenseConcluded": "NOASSERTION", - "licenseDeclared": "NOASSERTION", - "name": "Jena", - "versionInfo": "3.12.0" - }, - { - "SPDXID": "SPDXRef-Saxon", - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "85ed0817af83a24ad8da68c2b5094de69833983c" - } - ], - "copyrightText": "Copyright Saxonica Ltd", - "description": "The Saxon package is a collection of tools for processing XML documents.", - "downloadLocation": "https://sourceforge.net/projects/saxon/files/Saxon-B/8.8.0.7/saxonb8-8-0-7j.zip/download", - "filesAnalyzed": false, - "homepage": "http://saxon.sourceforge.net/", - "licenseComments": "Other versions available for a commercial license", - "licenseConcluded": "MPL-1.0", - "licenseDeclared": "MPL-1.0", - "name": "Saxon", - "packageFileName": "saxonB-8.8.zip", - "versionInfo": "8.8" - } - ], - "files": [ - { - "SPDXID": "SPDXRef-DoapSource", - "attributionTexts": [ - "Protecode Inc.", - "SPDX Technical Team Members", - "Open Logic Inc.", - "Source Auditor Inc.", - "Black Duck Software In.c" - ], - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" - } - ], - "copyrightText": "Copyright 2010, 2011 Source Auditor Inc.", - "fileContributors": [ - "Protecode Inc.", - "SPDX Technical Team Members", - "Open Logic Inc.", - "Source Auditor Inc.", - "Black Duck Software In.c" - ], - "fileName": "./src/org/spdx/parser/DOAPProject.java", - "fileTypes": [ - "SOURCE" - ], - "licenseConcluded": "Apache-2.0", - "licenseInfoInFiles": [ - "Apache-2.0" - ] - }, - { - "SPDXID": "SPDXRef-CommonsLangSrc", - "attributionTexts": [ - "Apache Software Foundation" - ], - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "c2b4e1c67a2d28fced849ee1bb76e7391b93f125" - } - ], - "comment": "This file is used by Jena", - "copyrightText": "Copyright 2001-2011 The Apache Software Foundation", - "fileContributors": [ - "Apache Software Foundation" - ], - "fileName": "./lib-source/commons-lang3-3.1-sources.jar", - "fileTypes": [ - "ARCHIVE" - ], - "licenseConcluded": "Apache-2.0", - "licenseInfoInFiles": [ - "Apache-2.0" - ], - "noticeText": "Apache Commons Lang\nCopyright 2001-2011 The Apache Software Foundation\n\nThis product includes software developed by\nThe Apache Software Foundation (http://www.apache.org/).\n\nThis product includes software from the Spring Framework,\nunder the Apache License 2.0 (see: StringUtils.containsWhitespace())" - }, - { - "SPDXID": "SPDXRef-JenaLib", - "attributionTexts": [ - "Apache Software Foundation", - "Hewlett Packard Inc." - ], - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "3ab4e1c67a2d28fced849ee1bb76e7391b93f125" - } - ], - "comment": "This file belongs to Jena", - "copyrightText": "(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP", - "fileContributors": [ - "Apache Software Foundation", - "Hewlett Packard Inc." - ], - "fileName": "./lib-source/jena-2.6.3-sources.jar", - "fileTypes": [ - "ARCHIVE" - ], - "licenseComments": "This license is used by Jena", - "licenseConcluded": "LicenseRef-1", - "licenseInfoInFiles": [ - "LicenseRef-1" - ] - }, - { - "SPDXID": "SPDXRef-File", - "annotations": [ - { - "annotationDate": "2011-01-29T18:30:22Z", - "annotationType": "OTHER", - "annotator": "Person: File Commenter", - "comment": "File level annotation" - } - ], - "attributionTexts": [ - "The Regents of the University of California", - "Modified by Paul Mundt lethal@linux-sh.org", - "IBM Corporation" - ], - "checksums": [ - { - "algorithm": "MD5", - "checksumValue": "624c1abb3664f4b35547e7c73864ad24" - }, - { - "algorithm": "SHA1", - "checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2758" - } - ], - "comment": "The concluded license was taken from the package level that the file was included in.\nThis information was found in the COPYING.txt file in the xyz directory.", - "copyrightText": "Copyright 2008-2010 John Smith", - "fileContributors": [ - "The Regents of the University of California", - "Modified by Paul Mundt lethal@linux-sh.org", - "IBM Corporation" - ], - "fileName": "./package/foo.c", - "fileTypes": [ - "SOURCE" - ], - "licenseComments": "The concluded license was taken from the package level that the file was included in.", - "licenseConcluded": "(LGPL-2.0-only OR LicenseRef-2)", - "licenseInfoInFiles": [ - "GPL-2.0-only", - "LicenseRef-2" - ], - "noticeText": "Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: \nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED �AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." - } - ], - "snippets": [ - { - "SPDXID": "SPDXRef-Snippet", - "comment": "This snippet was identified as significant and highlighted in this Apache-2.0 file, when a commercial scanner identified it as being derived from file foo.c in package xyz which is licensed under GPL-2.0.", - "copyrightText": "Copyright 2008-2010 John Smith", - "licenseComments": "The concluded license was taken from package xyz, from which the snippet was copied into the current file. The concluded license information was found in the COPYING.txt file in package xyz.", - "licenseConcluded": "GPL-2.0-only", - "licenseInfoInSnippets": [ - "GPL-2.0-only" - ], - "name": "from linux kernel", - "ranges": [ - { - "endPointer": { - "offset": 420, - "reference": "SPDXRef-DoapSource" - }, - "startPointer": { - "offset": 310, - "reference": "SPDXRef-DoapSource" - } - }, - { - "endPointer": { - "lineNumber": 23, - "reference": "SPDXRef-DoapSource" - }, - "startPointer": { - "lineNumber": 5, - "reference": "SPDXRef-DoapSource" - } - } - ], - "snippetFromFile": "SPDXRef-DoapSource" - } - ], - "relationships": [ - { - "relatedSpdxElement": "SPDXRef-Package", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-DOCUMENT" - }, - { - "relatedSpdxElement": "DocumentRef-spdx-tool-1.2:SPDXRef-ToolsElement", - "relationshipType": "COPY_OF", - "spdxElementId": "SPDXRef-DOCUMENT" - }, - { - "relatedSpdxElement": "SPDXRef-File", - "relationshipType": "DESCRIBES", - "spdxElementId": "SPDXRef-DOCUMENT" - }, - { - "relatedSpdxElement": "SPDXRef-Package", - "relationshipType": "DESCRIBES", - "spdxElementId": "SPDXRef-DOCUMENT" - }, - { - "relatedSpdxElement": "SPDXRef-JenaLib", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-Package" - }, - { - "relatedSpdxElement": "SPDXRef-Saxon", - "relationshipType": "DYNAMIC_LINK", - "spdxElementId": "SPDXRef-Package" - }, - { - "relatedSpdxElement": "NOASSERTION", - "relationshipType": "GENERATED_FROM", - "spdxElementId": "SPDXRef-CommonsLangSrc" - }, - { - "relatedSpdxElement": "SPDXRef-Package", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-JenaLib" - }, - { - "relatedSpdxElement": "SPDXRef-fromDoap-0", - "relationshipType": "GENERATED_FROM", - "spdxElementId": "SPDXRef-File" - } - ] -} \ No newline at end of file diff --git a/examples/9-jsonsaver/exampletvtojson.go b/examples/9-tvtojson/exampletvtojson.go similarity index 82% rename from examples/9-jsonsaver/exampletvtojson.go rename to examples/9-tvtojson/exampletvtojson.go index 79816c18..2c6ec7ef 100644 --- a/examples/9-jsonsaver/exampletvtojson.go +++ b/examples/9-tvtojson/exampletvtojson.go @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later -// Example for: *tvloader*, *tvsaver* +// Example for: *tvloader*, *jsonsaver* // This example demonstrates loading an SPDX tag-value file from disk into memory, -// and re-saving it to a different file on disk. +// and re-saving it to a different json file on disk. package main @@ -11,8 +11,8 @@ import ( "fmt" "os" - "github.com/spdx/tools-golang/jsonloader" "github.com/spdx/tools-golang/jsonsaver" + "github.com/spdx/tools-golang/tvloader" ) func main() { @@ -36,7 +36,7 @@ func main() { defer r.Close() // try to load the SPDX file's contents as a tag-value file, version 2.2 - doc, err := jsonloader.Load2_2(r) + doc, err := tvloader.Load2_2(r) if err != nil { fmt.Printf("Error while parsing %v: %v", args[1], err) return @@ -45,7 +45,7 @@ func main() { // if we got here, the file is now loaded into memory. fmt.Printf("Successfully loaded %s\n", args[1]) - // we can now save it back to disk, using tvsaver. + // we can now save it back to disk, using jsonsaver. // create a new file for writing fileOut := args[2] @@ -56,7 +56,7 @@ func main() { } defer w.Close() - // try to save the document to disk as an SPDX tag-value file, version 2.2 + // try to save the document to disk as an SPDX json file, version 2.2 err = jsonsaver.Save2_2(doc, w) if err != nil { fmt.Printf("Error while saving %v: %v", fileOut, err) diff --git a/examples/README.md b/examples/README.md index 7cd80a06..bd4b3d3e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -64,9 +64,23 @@ the same identifier in both documents. This example demonstrates loading an SPDX rdf file from disk into memory and then printing the corresponding spdx struct for the document. -## 8-jsonloader +## 8-jsontotv *jsonloader*, *tvsaver* This example demonstrates loading an SPDX json from disk into memory and then re-saving it to a different file on disk in tag-value format. + +## 9-tvtojson + +*jsonsaver*, *tvloader* + +This example demonstrates loading an SPDX tag-value from disk into memory +and then re-saving it to a different file on disk in json format. + +## 10-jsonloader + +*jsonloader* + +This example demonstrates loading an SPDX json from disk into memory +and then logging some of the attributes to the console. diff --git a/jsonloader/jsonloader_test.go b/jsonloader/jsonloader_test.go index 2ce87502..e90a6a58 100644 --- a/jsonloader/jsonloader_test.go +++ b/jsonloader/jsonloader_test.go @@ -3,6 +3,7 @@ package jsonloader import ( + "bytes" "fmt" "io" "os" @@ -45,6 +46,14 @@ func TestLoad2_2(t *testing.T) { }, wantErr: false, }, + { + name: "fail - invalidjson ", + args: args{ + content: bytes.NewReader([]byte(`{"Hello":"HI",}`)), + }, + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -53,7 +62,7 @@ func TestLoad2_2(t *testing.T) { t.Errorf("Load2_2() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got.CreationInfo, tt.want.CreationInfo) { + if !tt.wantErr && !reflect.DeepEqual(got.CreationInfo, tt.want.CreationInfo) { t.Errorf("Load2_2() = %v, want %v", got.CreationInfo, tt.want.CreationInfo) } }) diff --git a/jsonloader/parser2v2/parse_annotations_test.go b/jsonloader/parser2v2/parse_annotations_test.go index 6ef5693c..014c3dde 100644 --- a/jsonloader/parser2v2/parse_annotations_test.go +++ b/jsonloader/parser2v2/parse_annotations_test.go @@ -31,6 +31,26 @@ func TestJSONSpdxDocument_parseJsonAnnotations2_2(t *testing.T) { } ] } `) + data2 := []byte(`{ + "annotations" : [ { + "annotationDate" : "2010-02-10T00:00:00Z", + "annotationType" : "REVIEW", + "annotator" : "Person: Joe Reviewer", + "comment" : "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses", + "Hello":"hellp" + }] +} +`) + data3 := []byte(`{ + "annotations" : [ { + "annotationDate" : "2010-02-10T00:00:00Z", + "annotationType" : "REVIEW", + "annotator" : "Fasle: Joe Reviewer", + "comment" : "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses", + "Hello":"hellp" + }] +} +`) annotationstest1 := []*spdx.Annotation2_2{ { @@ -60,7 +80,12 @@ func TestJSONSpdxDocument_parseJsonAnnotations2_2(t *testing.T) { } var specs JSONSpdxDocument + var specs2 JSONSpdxDocument + var specs3 JSONSpdxDocument + json.Unmarshal(data, &specs) + json.Unmarshal(data2, &specs2) + json.Unmarshal(data3, &specs3) type args struct { key string @@ -88,16 +113,41 @@ func TestJSONSpdxDocument_parseJsonAnnotations2_2(t *testing.T) { want: annotationstest1, wantErr: false, }, + { + name: "failure test - invaid creator type", + spec: specs2, + args: args{ + key: "annotations", + value: specs2["annotations"], + doc: &spdxDocument2_2{}, + SPDXElementID: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"}, + }, + want: nil, + wantErr: true, + }, + { + name: "failure test - invalid tag", + spec: specs3, + args: args{ + key: "annotations", + value: specs3["annotations"], + doc: &spdxDocument2_2{}, + SPDXElementID: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"}, + }, + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := tt.spec.parseJsonAnnotations2_2(tt.args.key, tt.args.value, tt.args.doc, tt.args.SPDXElementID); (err != nil) != tt.wantErr { t.Errorf("JSONSpdxDocument.parseJsonAnnotations2_2() error = %v, wantErr %v", err, tt.wantErr) } - - for i := 0; i < len(tt.want); i++ { - if !reflect.DeepEqual(tt.args.doc.Annotations[i], tt.want[i]) { - t.Errorf("Load2_2() = %v, want %v", tt.args.doc.Annotations[i], tt.want[i]) + if !tt.wantErr { + for i := 0; i < len(tt.want); i++ { + if !reflect.DeepEqual(tt.args.doc.Annotations[i], tt.want[i]) { + t.Errorf("Load2_2() = %v, want %v", tt.args.doc.Annotations[i], tt.want[i]) + } } } diff --git a/jsonloader/parser2v2/parse_creation_info_test.go b/jsonloader/parser2v2/parse_creation_info_test.go index ae62cba1..280775ac 100644 --- a/jsonloader/parser2v2/parse_creation_info_test.go +++ b/jsonloader/parser2v2/parse_creation_info_test.go @@ -153,6 +153,64 @@ func TestJSONSpdxDocument_parseJsonCreationInfo2_2(t *testing.T) { }, wantErr: false, }, + { + name: "failure : Invalid tag ", + spec: specs, + args: args{ + key: "invalid", + value: "This document was created using SPDX 2.0 using licenses from the web site.", + doc: &spdxDocument2_2{}, + }, + want: &spdx.CreationInfo2_2{ExternalDocumentReferences: map[string]spdx.ExternalDocumentRef2_2{}}, + wantErr: true, + }, + { + name: "failure : DocRef missing in ExternalRefs", + spec: specs, + args: args{ + key: "externalDocumentRefs", + value: []map[string]interface{}{ + { + "externalDocumentId": "spdx-tool-1.2", + "spdxDocument": "http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301", + "checksum": map[string]interface{}{ + "algorithm": "SHA1", + "checksumValue": "d6a770ba38583ed4bb4525bd96e50461655d2759", + }, + }, + }, + doc: &spdxDocument2_2{}, + }, + want: nil, + wantErr: true, + }, + { + name: "failure : invalid SPDXID", + spec: specs, + args: args{ + key: "SPDXID", + value: "DOCUMENT", + doc: &spdxDocument2_2{}, + }, + want: &spdx.CreationInfo2_2{ExternalDocumentReferences: map[string]spdx.ExternalDocumentRef2_2{}}, + wantErr: true, + }, + { + name: "failure - invalid creator type", + spec: specs, + args: args{ + key: "creationInfo", + value: map[string]interface{}{ + "comment": "This package has been shipped in source and binary form.\nThe binaries were created with gcc 4.5.1 and expect to link to\ncompatible system run time libraries.", + "created": "2010-01-29T18:30:22Z", + "creators": []string{"Invalid: LicenseFind-1.0", "Organization: ExampleCodeInspect ()", "Person: Jane Doe ()"}, + "licenseListVersion": "3.8", + }, + doc: &spdxDocument2_2{}, + }, + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -160,7 +218,7 @@ func TestJSONSpdxDocument_parseJsonCreationInfo2_2(t *testing.T) { if err := tt.spec.parseJsonCreationInfo2_2(tt.args.key, tt.args.value, tt.args.doc); (err != nil) != tt.wantErr { t.Errorf("JSONSpdxDocument.parseJsonCreationInfo2_2() error = %v, wantErr %v", err, tt.wantErr) } - if !reflect.DeepEqual(tt.args.doc.CreationInfo, tt.want) { + if !tt.wantErr && !reflect.DeepEqual(tt.args.doc.CreationInfo, tt.want) { t.Errorf("Load2_2() = %v, want %v", tt.args.doc.CreationInfo, tt.want) } diff --git a/jsonloader/parser2v2/parse_files_test.go b/jsonloader/parser2v2/parse_files_test.go index 196cb605..30f1bdc4 100644 --- a/jsonloader/parser2v2/parse_files_test.go +++ b/jsonloader/parser2v2/parse_files_test.go @@ -27,6 +27,7 @@ func TestJSONSpdxDocument_parseJsonFiles2_2(t *testing.T) { "fileName" : "./src/org/spdx/parser/DOAPProject.java", "fileTypes" : [ "SOURCE" ], "licenseConcluded" : "Apache-2.0", + "attributionTexts":["text1"], "licenseInfoInFiles" : [ "Apache-2.0" ] }, { "SPDXID" : "SPDXRef-CommonsLangSrc", @@ -97,13 +98,14 @@ func TestJSONSpdxDocument_parseJsonFiles2_2(t *testing.T) { Value: "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", }, }, - FileCopyrightText: "Copyright 2010, 2011 Source Auditor Inc.", - FileContributor: []string{"Protecode Inc.", "SPDX Technical Team Members", "Open Logic Inc.", "Source Auditor Inc.", "Black Duck Software In.c"}, - FileDependencies: []string{"SPDXRef-JenaLib", "SPDXRef-CommonsLangSrc"}, - FileName: "./src/org/spdx/parser/DOAPProject.java", - FileType: []string{"SOURCE"}, - LicenseConcluded: "Apache-2.0", - LicenseInfoInFile: []string{"Apache-2.0"}, + FileCopyrightText: "Copyright 2010, 2011 Source Auditor Inc.", + FileContributor: []string{"Protecode Inc.", "SPDX Technical Team Members", "Open Logic Inc.", "Source Auditor Inc.", "Black Duck Software In.c"}, + FileDependencies: []string{"SPDXRef-JenaLib", "SPDXRef-CommonsLangSrc"}, + FileName: "./src/org/spdx/parser/DOAPProject.java", + FileType: []string{"SOURCE"}, + LicenseConcluded: "Apache-2.0", + FileAttributionTexts: []string{"text1"}, + LicenseInfoInFile: []string{"Apache-2.0"}, }, "CommonsLangSrc": { FileSPDXIdentifier: "CommonsLangSrc", diff --git a/jsonloader/parser2v2/parse_snippets_test.go b/jsonloader/parser2v2/parse_snippets_test.go index e72599e4..b25bee55 100644 --- a/jsonloader/parser2v2/parse_snippets_test.go +++ b/jsonloader/parser2v2/parse_snippets_test.go @@ -21,6 +21,7 @@ func TestJSONSpdxDocument_parseJsonSnippets2_2(t *testing.T) { "licenseComments" : "The concluded license was taken from package xyz, from which the snippet was copied into the current file. The concluded license information was found in the COPYING.txt file in package xyz.", "licenseConcluded" : "GPL-2.0-only", "licenseInfoInSnippets" : [ "GPL-2.0-only" ], + "attributionTexts":["text1"], "name" : "from linux kernel", "ranges" : [ { "endPointer" : { @@ -52,6 +53,7 @@ func TestJSONSpdxDocument_parseJsonSnippets2_2(t *testing.T) { Snippets: map[spdx.ElementID]*spdx.Snippet2_2{ "Snippet": { SnippetSPDXIdentifier: "Snippet", + SnippetAttributionTexts: []string{"text1"}, SnippetFromFileSPDXIdentifier: spdx.DocElementID{ElementRefID: "DoapSource"}, SnippetComment: "This snippet was identified as significant and highlighted in this Apache-2.0 file, when a commercial scanner identified it as being derived from file foo.c in package xyz which is licensed under GPL-2.0.", SnippetCopyrightText: "Copyright 2008-2010 John Smith", diff --git a/jsonsaver/jsonsaver.go b/jsonsaver/jsonsaver.go index 35898ad5..11ee58d7 100644 --- a/jsonsaver/jsonsaver.go +++ b/jsonsaver/jsonsaver.go @@ -14,10 +14,10 @@ import ( func Save2_2(doc *spdx.Document2_2, w io.Writer) error { var b []byte buf := bytes.NewBuffer(b) - result, err := saver2v2.RenderDocument2_2(doc, buf) + err := saver2v2.RenderDocument2_2(doc, buf) if err != nil { return err } - w.Write(result.Bytes()) + w.Write(buf.Bytes()) return nil } diff --git a/jsonsaver/jsonsaver_test.go b/jsonsaver/jsonsaver_test.go new file mode 100644 index 00000000..79926067 --- /dev/null +++ b/jsonsaver/jsonsaver_test.go @@ -0,0 +1,226 @@ +package jsonsaver + +import ( + "bytes" + "testing" + + "github.com/spdx/tools-golang/spdx" +) + +func TestSave2_2(t *testing.T) { + type args struct { + doc *spdx.Document2_2 + } + test1 := &spdx.Document2_2{ + CreationInfo: &spdx.CreationInfo2_2{ + DataLicense: "CC0-1.0", + SPDXVersion: "SPDX-2.2", + SPDXIdentifier: "DOCUMENT", + DocumentComment: "This document was created using SPDX 2.0 using licenses from the web site.", + LicenseListVersion: "3.8", + Created: "2010-01-29T18:30:22Z", + CreatorPersons: []string{"Jane Doe ()"}, + CreatorOrganizations: []string{"ExampleCodeInspect ()"}, + CreatorTools: []string{"LicenseFind-1.0"}, + DocumentName: "SPDX-Tools-v2.0", + DocumentNamespace: "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", + CreatorComment: "This package has been shipped in source and binary form.\nThe binaries were created with gcc 4.5.1 and expect to link to\ncompatible system run time libraries.", + ExternalDocumentReferences: map[string]spdx.ExternalDocumentRef2_2{ + "spdx-tool-1.2": { + DocumentRefID: "spdx-tool-1.2", + URI: "http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301", + Alg: "SHA1", + Checksum: "d6a770ba38583ed4bb4525bd96e50461655d2759", + }, + }, + }, + OtherLicenses: []*spdx.OtherLicense2_2{ + { + ExtractedText: "\"THE BEER-WARE LICENSE\" (Revision 42):\nphk@FreeBSD.ORG wrote this file. As long as you retain this notice you\ncan do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp