Package org.spdx.maven.utils
Class AbstractFileCollector
java.lang.Object
org.spdx.maven.utils.AbstractFileCollector
- Direct Known Subclasses:
SpdxV2FileCollector,SpdxV3FileCollector
Collects SPDX file information from directories.
Concrete subclasses implement specific SPDX spec specific formats
- Author:
- Gary O'Neall
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertChecksumToString(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 org.spdx.library.model.v2.enumerations.FileTypeextensionToFileType(String fileExtension) generateChecksum(File file, Set<String> algorithms) Generate checksums for a given file using each algorithm supplied.static ChecksumgenerateSha1(File file) Generate the Sha1 for a given file.getExtension(File file) protected booleanisSourceFile(Collection<org.spdx.library.model.v2.enumerations.FileType> fileTypes) protected static StringtoRelativeFilePath(File file, String baseDir)
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
EXT_TO_FILE_TYPE
-
CHECKSUM_ALGORITHMS
-
-
Constructor Details
-
AbstractFileCollector
public AbstractFileCollector()
-
-
Method Details
-
getExtension
-
isSourceFile
protected boolean isSourceFile(Collection<org.spdx.library.model.v2.enumerations.FileType> fileTypes) - Parameters:
fileTypes- list of file types for the file- 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:
- valid SPDX file name per the spec
-
extensionToFileType
protected static org.spdx.library.model.v2.enumerations.FileType extensionToFileType(String fileExtension) -
convertChecksumToString
Converts an array of bytes to a string compliant with the SPDX sha1 representation- Parameters:
digestBytes- result of a checksum digest calculation- Returns:
- string representation of the checksum per the SPDX specification
-
generateSha1
public static Checksum generateSha1(File file) throws SpdxCollectionException, org.spdx.core.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 for- Returns:
- SHA1 checksum of the input file
- Throws:
SpdxCollectionException- if the algorithm is unavailable or the file cannot be readorg.spdx.core.InvalidSPDXAnalysisException- on SPDX parsing errors
-
generateChecksum
public static Set<Checksum> generateChecksum(File file, Set<String> algorithms) throws SpdxCollectionException, org.spdx.core.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 checksums- Returns:
Setof checksums for file using each algorithm specified- Throws:
SpdxCollectionException- if the input algorithm is invalid or unavailable or if the file cannot be readorg.spdx.core.InvalidSPDXAnalysisException- on SPDX parsing errors
-
toRelativeFilePath
- Parameters:
file- file which is the target for the path stringbaseDir- base directory of the SPDX archive or project containing the file- Returns:
- a file path for the file relative to the baseDir
-