Skip to content

Commit

Permalink
fix(spdx): Add the missing snippet ranges
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 17, 2023
1 parent e8d9c53 commit 40630f4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions utils/spdx/src/main/kotlin/model/SpdxSnippet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,53 @@ data class SpdxSnippet(
@JsonInclude(JsonInclude.Include.NON_EMPTY)
val name: String = "",

/**
* The ranges in the original host file that the snippet information applies to.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
val ranges: List<Range> = emptyList(),

/**
* The SPDX reference referencing the document within the SpdxDocument containing the snippet.
*/
val snippetFromFile: String
) {
data class Range(
/** The start of the snippet range. */
val startPointer: Pointer,

/** The end of the snippet range. */
val endPointer: Pointer
) {
init {
require(
(startPointer.lineNumber != null && endPointer.lineNumber != null) ||
(startPointer.offset != null && endPointer.offset != null)
) {
"Start and end pointers need to be of the same type (line number or byte offset)."
}
}
}

data class Pointer(
/** SPDX ID of the file. */
val reference: String,

/** Line number in the (text) file. */
@JsonInclude(JsonInclude.Include.NON_NULL)
val lineNumber: Int? = null,

/** Byte offset in the (binary) file. */
@JsonInclude(JsonInclude.Include.NON_NULL)
val offset: Int? = null
) {
init {
require((lineNumber != null) xor (offset != null)) {
"Either 'lineNumber' or 'offset' must be set for the '$reference' pointer."
}
}
}

init {
require(spdxId.startsWith(SpdxConstants.REF_PREFIX)) {
"The SPDX ID '$spdxId' has to start with '${SpdxConstants.REF_PREFIX}'."
Expand Down

0 comments on commit 40630f4

Please sign in to comment.