Class SpdxFileCollector

java.lang.Object
org.spdx.maven.utils.SpdxFileCollector

public class SpdxFileCollector extends Object
Collects SPDX file information from directories.

The method collectFilesInDirectory(FileSet[] filesets) will scan and create SPDX File information for all files in the filesets.

Author:
Gary O'Neall
  • Constructor Details

    • SpdxFileCollector

      public SpdxFileCollector()
      SpdxFileCollector collects SPDX file information for files
  • Method Details

    • collectFiles

      public void collectFiles(List<org.apache.maven.shared.model.fileset.FileSet> fileSets, String baseDir, SpdxDefaultFileInformation defaultFileInformation, Map<String,SpdxDefaultFileInformation> pathSpecificInformation, SpdxPackage projectPackage, RelationshipType relationshipType, SpdxDocument spdxDoc, Set<ChecksumAlgorithm> algorithms) throws SpdxCollectionException
      Collect file information in the directory (including subdirectories).
      Parameters:
      fileSets - FileSets containing the description of the directory to be scanned
      baseDir - project base directory used to construct the relative paths for the SPDX files
      defaultFileInformation - Information on default SPDX field data for the files
      pathSpecificInformation - Map of path to file information used to override the default file information
      relationshipType - Type of relationship to the project package
      projectPackage - Package to which the files belong
      spdxDoc - SPDX document which contains the extracted license infos that may be needed for license parsing
      Throws:
      SpdxCollectionException
    • isSourceFile

      protected boolean isSourceFile(Collection<FileType> fileTypes)
      Parameters:
      fileTypes -
      Returns:
      true if the fileTypes contain a source file type
    • convertFilePathToSpdxFileName

      public String convertFilePathToSpdxFileName(String filePath)
      Create the SPDX file name from a system specific path name
      Parameters:
      filePath - system specific file path relative to the top of the archive root to the top of the archive directory where the file is stored.
      Returns:
    • getExtension

      public String getExtension(File file)
    • extensionToFileType

      protected static FileType extensionToFileType(String fileExtension)
    • getFiles

      public Collection<SpdxFile> getFiles()
      Returns:
      SPDX Files which have been acquired through the collectFilesInDirectory method
    • getSnippets

      public List<SpdxSnippet> getSnippets()
      Returns:
      SPDX Snippets collected through the collectFilesInDirectory method
    • getLicenseInfoFromFiles

      public Collection<AnyLicenseInfo> getLicenseInfoFromFiles()
      Returns:
      all license information used in the SPDX files
    • getVerificationCode

      public SpdxPackageVerificationCode getVerificationCode(String spdxFilePath, SpdxDocument spdxDoc) throws NoSuchAlgorithmException, InvalidSPDXAnalysisException
      Create a verification code from all SPDX files collected
      Parameters:
      spdxFilePath - Complete file path for the SPDX file - this will be excluded from the verification code
      spdxDoc - SPDX document which will contain the package verification code.
      Returns:
      Throws:
      NoSuchAlgorithmException
      InvalidSPDXAnalysisException
    • convertChecksumToString

      public static String convertChecksumToString(byte[] digestBytes)
      Converts an array of bytes to a string compliant with the SPDX sha1 representation
      Parameters:
      digestBytes -
      Returns:
    • generateSha1

      public static String generateSha1(File file, SpdxDocument spdxDoc) throws SpdxCollectionException, InvalidSPDXAnalysisException
      Generate the Sha1 for a given file. Must have read access to the file. This method is equivalent to calling SpdxFileCollector.generateChecksum(file, "SHA-1").
      Parameters:
      file - file to generate checksum for
      spdxDoc - SPDX document which will contain the checksum
      Returns:
      SHA1 checksum of the input file
      Throws:
      SpdxCollectionException - if the algorithm is unavailable or the file cannot be read
      InvalidSPDXAnalysisException
    • generateChecksum

      public static Set<Checksum> generateChecksum(File file, Set<ChecksumAlgorithm> algorithms, SpdxDocument spdxDoc) throws SpdxCollectionException, InvalidSPDXAnalysisException
      Generate checksums for a given file using each algorithm supplied. Must have read access to the file.
      Parameters:
      file - file whose checksum is to be generated
      algorithms - algorithms to generate the checksums
      spdxDoc - SPDX document which will contain the checksum
      Returns:
      Set of checksums for file using each algorithm specified
      Throws:
      SpdxCollectionException - if the input algorithm is invalid or unavailable or if the file cannot be read
      InvalidSPDXAnalysisException