Package org.spdx.maven.utils
Class SpdxFileCollector
java.lang.Object
org.spdx.maven.utils.SpdxFileCollector
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 Summary
ConstructorDescriptionSpdxFileCollector collects SPDX file information for files -
Method Summary
Modifier and TypeMethodDescriptionvoid
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) Collect file information in the directory (including subdirectories).static String
convertChecksumToString
(byte[] digestBytes) Converts an array of bytes to a string compliant with the SPDX sha1 representationconvertFilePathToSpdxFileName
(String filePath) Create the SPDX file name from a system specific path nameprotected static FileType
extensionToFileType
(String fileExtension) generateChecksum
(File file, Set<ChecksumAlgorithm> algorithms, SpdxDocument spdxDoc) Generate checksums for a given file using each algorithm supplied.static String
generateSha1
(File file, SpdxDocument spdxDoc) Generate the Sha1 for a given file.getExtension
(File file) getFiles()
getVerificationCode
(String spdxFilePath, SpdxDocument spdxDoc) Create a verification code from all SPDX files collectedprotected boolean
isSourceFile
(Collection<FileType> fileTypes)
-
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 SpdxCollectionExceptionCollect file information in the directory (including subdirectories).- Parameters:
fileSets
- FileSets containing the description of the directory to be scannedbaseDir
- project base directory used to construct the relative paths for the SPDX filesdefaultFileInformation
- Information on default SPDX field data for the filespathSpecificInformation
- Map of path to file information used to override the default file informationrelationshipType
- Type of relationship to the project packageprojectPackage
- Package to which the files belongspdxDoc
- SPDX document which contains the extracted license infos that may be needed for license parsing- Throws:
SpdxCollectionException
-
isSourceFile
- Parameters:
fileTypes
-- Returns:
- true if the fileTypes contain a source file type
-
convertFilePathToSpdxFileName
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
-
extensionToFileType
-
getFiles
- Returns:
- SPDX Files which have been acquired through the collectFilesInDirectory method
-
getSnippets
- Returns:
- SPDX Snippets collected through the collectFilesInDirectory method
-
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 codespdxDoc
- SPDX document which will contain the package verification code.- Returns:
- Throws:
NoSuchAlgorithmException
InvalidSPDXAnalysisException
-
convertChecksumToString
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 callingSpdxFileCollector.generateChecksum(file, "SHA-1")
.- Parameters:
file
- file to generate checksum forspdxDoc
- 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 readInvalidSPDXAnalysisException
-
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 generatedalgorithms
- algorithms to generate the checksumsspdxDoc
- 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 readInvalidSPDXAnalysisException
-