Class VerificationCodeGenerator


  • public class VerificationCodeGenerator
    extends Object
    Generates a package verification code from a directory of source code or an array of SPDXFiles.

    A class implementing the IFileChecksumGenerator is supplied as a parameter to the constructor. The method getFileChecksum is called for each file in the directory. This can be used as a hook to capture all files in the directory and capture the checksum values at a file level.

    Author:
    Gary O'Neall
    • Constructor Detail

      • VerificationCodeGenerator

        public VerificationCodeGenerator​(IFileChecksumGenerator fileChecksumGenerator)
    • Method Detail

      • generatePackageVerificationCode

        public org.spdx.library.model.v2.SpdxPackageVerificationCode generatePackageVerificationCode​(org.spdx.library.model.v2.SpdxFile[] spdxFiles,
                                                                                                     String[] skippedFilePaths,
                                                                                                     org.spdx.storage.IModelStore modelStore,
                                                                                                     String documentUri)
                                                                                              throws NoSuchAlgorithmException,
                                                                                                     org.spdx.core.InvalidSPDXAnalysisException
        Generate the SPDX Package Verification Code from an array of SPDXFiles
        Parameters:
        spdxFiles - Files to generate the VerificationCode from
        skippedFilePaths - File path names to not include in the VerificationCode
        modelStore - where the resultant VerificationCode is store
        documentUri - document URI where the VerificationCode is stored
        Returns:
        VerificationCode based on all files in spdxFiles minus the skippedFilePaths
        Throws:
        NoSuchAlgorithmException - unexpected checksum calculation error
        org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing error
      • generatePackageVerificationCode

        public org.spdx.library.model.v2.SpdxPackageVerificationCode generatePackageVerificationCode​(File sourceDirectory,
                                                                                                     File[] skippedFiles,
                                                                                                     org.spdx.storage.IModelStore modelStore,
                                                                                                     String documentUri)
                                                                                              throws NoSuchAlgorithmException,
                                                                                                     IOException,
                                                                                                     org.spdx.core.InvalidSPDXAnalysisException
        Generate the SPDX Package Verification Code from a directory of files included in the archive
        Parameters:
        sourceDirectory - source directory for the package verification code
        modelStore - where the resultant VerificationCode is store
        documentUri - document URI where the VerificationCode is stored
        Returns:
        PackageVerificationCode based on the files in the sourceDirectory
        Throws:
        NoSuchAlgorithmException - unexpected error creating checksums
        IOException - on file or directory read errors
        org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing error
      • generatePackageVerificationCode

        protected org.spdx.library.model.v2.SpdxPackageVerificationCode generatePackageVerificationCode​(List<String> fileChecksums,
                                                                                                        String[] skippedFilePaths,
                                                                                                        org.spdx.storage.IModelStore modelStore,
                                                                                                        String documentUri)
                                                                                                 throws NoSuchAlgorithmException,
                                                                                                        org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        fileChecksums - used to create the verification code value
        skippedFilePaths - list of files skipped when calculating the verification code
        modelStore - where the resultant VerificationCode is store
        documentUri - document URI where the VerificationCode is stored
        Returns:
        a PackageVerificationCode with the value created from the fileChecksums
        Throws:
        NoSuchAlgorithmException - unexpected error creating checksums
        org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing error
      • normalizeFilePath

        public static String normalizeFilePath​(String nonNormalizedFilePath)
        Normalizes a file path per the SPDX spec
        Parameters:
        nonNormalizedFilePath - original file path - may be unix or DOS format
        Returns:
        file path normalized per SPDX spec
      • generatePackageVerificationCode

        public org.spdx.library.model.v2.SpdxPackageVerificationCode generatePackageVerificationCode​(File sourceDirectory,
                                                                                                     org.spdx.storage.IModelStore modelStore,
                                                                                                     String documentUri)
                                                                                              throws NoSuchAlgorithmException,
                                                                                                     IOException,
                                                                                                     org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        sourceDirectory - directory to create the verification code for
        modelStore - where the resultant VerificationCode is store
        documentUri - document URI where the VerificationCode is stored
        Returns:
        SPDX package verification code
        Throws:
        NoSuchAlgorithmException - unexpected error creating checksums
        IOException - on IO error reading files or directories
        org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing error