Package org.spdx.compare
Class SpdxComparer
java.lang.Object
org.spdx.compare.SpdxComparer
public class SpdxComparer extends Object
Performs a comparison between two or more SPDX documents and holds the results of the comparison
The main function to perform the comparison is
compare(spdxdoc1, spdxdoc2)
For reviewers, the comparison results are separated into unique reviewers for a give document
which can be obtained by the method getUniqueReviewers(index1, index2). The
uniqueness is determined by the reviewer name. If two documents contain reviewers with the
same name but different dates or comments, the reviews are considered to be the same review
with different data. The differences for these reviews can be obtained through the method
getReviewerDifferences(index1, index2)
For files, the comparison results are separated into unique files based on the file names
which can be obtained by the method getUniqueFiles(index1, index2). If two
documents contain files with the same name, but different data, the differences for these
files can be obtained through the method getFileDifferences(index1, index2)
Multi-threading considerations: This class is "mostly" threadsafe in that the calls to
perform the comparison are synchronized and a flag is used to throw an error for any
calls to getters when a compare is in progress. There is a small theoretical window in the
getters where the compare operation is started in the middle of a get operation.- Author:
- Gary O'Neall
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpdxComparer.SPDXReviewDifferenceContains the results of a comparison between two SPDXReviews where the reviewer name is the same but there is a difference in the reviewer comment or the reviewer date -
Constructor Summary
Constructors Constructor Description SpdxComparer() -
Method Summary
Modifier and Type Method Description static booleanarraysEqual(Object[] a1, Object[] a2)Compare two object arraysprotected SpdxFile[]collectAllFiles(SpdxDocument spdxDocument)Collect all of the files present in the SPDX document including files within documents and files embedded in packagesprotected SpdxPackage[]collectAllPackages(SpdxDocument spdxDocument)Collect all of the packages present in the SPDX document including packages embedded in other relationships within documentsvoidcompare(SpdxDocument[] spdxDocuments)Compares multiple SPDX documentsvoidcompare(SpdxDocument spdxDoc1, SpdxDocument spdxDoc2)Compares 2 SPDX documentsbooleancompareLicense(int doc1, AnyLicenseInfo license1, int doc2, AnyLicenseInfo license2)Compares two licenses from two different SPDX documents taking into account the extracted license infos who's ID's may be different between the two documents Note: The ExtracedLicenseIDMap must be initialized before this method is invokedstatic intcompareStrings(String stringA, String stringB)Compares two strings including trimming the string and taking into account they may be null.static booleanelementsEquivalent(RdfModelObject[] elementsA, RdfModelObject[] elementsB)Returns true if two arrays of SPDX elements contain equivalent elementsstatic booleanelementsEquivalent(RdfModelObject elementA, RdfModelObject elementB)static Annotation[]findUniqueAnnotations(Annotation[] annotationsA, Annotation[] annotationsB)Find any SPDX annotations which are in annotationsA but not in annotationsBstatic Checksum[]findUniqueChecksums(Checksum[] checksumsA, Checksum[] checksumsB)Find any SPDX checksums which are in elementsA but not in elementsBstatic ExternalDocumentRef[]findUniqueExternalDocumentRefs(ExternalDocumentRef[] externalDocRefsA, ExternalDocumentRef[] externalDocRefsB)Find unique relationships that are present in relationshipsA but not relationshipsBstatic Relationship[]findUniqueRelationships(Relationship[] relationshipsA, Relationship[] relationshipsB)Find unique relationships that are present in relationshipsA but not relationshipsBSpdxLicenseDifference[]getExtractedLicenseDifferences(int docIndexA, int docIndexB)Retrieves any licenses which where the text matches in both documents but other fields are differentSpdxFileDifference[]getFileDifferences(int docindex1, int docindex2)Returns any file differences found between the first and second SPDX documents as specified by the document indexintgetNumSpdxDocs()SpdxPackageComparer[]getPackageComparers()SpdxPackageComparer[]getPackageDifferences()SpdxComparer.SPDXReviewDifference[]getReviewerDifferences(int docindex1, int docindex2)Get all reviewer differences between two documents.SpdxSnippetComparer[]getSnippetComparers()SpdxDocumentgetSpdxDoc(int docIndex)SpdxDocument[]getSpdxDocuments()String[]getUniqueCreators(int doc1index, int doc2index)Returns any creators which are in the SPDX document 1 which are not in document 2Annotation[]getUniqueDocumentAnnotations(int docindex1, int docindex2)Return any document annotations which are in spdx document index 1 but not in spdx document index 2Relationship[]getUniqueDocumentRelationship(int docindex1, int docindex2)Return any document annotations which are in spdx document index 1 but not in spdx document index 2ExternalDocumentRef[]getUniqueExternalDocumentRefs(int docindex1, int docindex2)Return any external document references which are in spdx document index 1 but not in spdx document index 2ExtractedLicenseInfo[]getUniqueExtractedLicenses(int docIndexA, int docIndexB)Retrieves any unique extracted licenses fromt the first SPDX document index relative to the second - unique is determined by the license text matchingSpdxFile[]getUniqueFiles(int docindex1, int docindex2)Return any files which are in spdx document index 1 but not in spdx document index 2SpdxPackage[]getUniquePackages(int docindex1, int docindex2)Return any files which are in spdx document index 1 but not in spdx document index 2SPDXReview[]getUniqueReviewers(int docindex1, int docindex2)Get all unique reviewers in SPDX document at index 1 relative to reviewers in SPDX Document at index 2booleanisCreatorInformationEqual()booleanisDataLicenseEqual()booleanisDifferenceFound()booleanisDocumentAnnotationsEquals()booleanisDocumentCommentsEqual()booleanisDocumentContentsEquals()booleanisDocumentRelationshipsEquals()booleanisExternalDcoumentRefsEquals()booleanisExtractedLicensingInfosEqual()booleanisfilesEquals()booleanisLicenseListVersionEqual()booleanisPackagesEquals()booleanisReviewersEqual()booleanisSnippetsEqual()booleanisSpdxVersionEqual()static booleanobjectsEqual(Object o1, Object o2)returns true if the two objects are equal considering nullsstatic booleanstringsEqual(String stringA, String stringB)Compares two strings returning true if they are equal considering null values and trimming the strings.
-
Constructor Details
-
SpdxComparer
public SpdxComparer()
-
-
Method Details
-
compare
public void compare(SpdxDocument spdxDoc1, SpdxDocument spdxDoc2) throws InvalidSPDXAnalysisException, SpdxCompareExceptionCompares 2 SPDX documents- Parameters:
spdxDoc1-spdxDoc2-- Throws:
InvalidSPDXAnalysisExceptionSpdxCompareException
-
compare
public void compare(SpdxDocument[] spdxDocuments) throws InvalidSPDXAnalysisException, SpdxCompareExceptionCompares multiple SPDX documents- Parameters:
spdxDocuments-- Throws:
SpdxCompareExceptionInvalidSPDXAnalysisException
-
collectAllPackages
protected SpdxPackage[] collectAllPackages(SpdxDocument spdxDocument) throws InvalidSPDXAnalysisExceptionCollect all of the packages present in the SPDX document including packages embedded in other relationships within documents- Parameters:
spdxDocument-- Returns:
- Throws:
InvalidSPDXAnalysisException
-
collectAllFiles
protected SpdxFile[] collectAllFiles(SpdxDocument spdxDocument) throws InvalidSPDXAnalysisExceptionCollect all of the files present in the SPDX document including files within documents and files embedded in packages- Parameters:
spdxDocument-- Returns:
- Throws:
InvalidSPDXAnalysisException
-
compareLicense
public boolean compareLicense(int doc1, AnyLicenseInfo license1, int doc2, AnyLicenseInfo license2) throws SpdxCompareExceptionCompares two licenses from two different SPDX documents taking into account the extracted license infos who's ID's may be different between the two documents Note: The ExtracedLicenseIDMap must be initialized before this method is invoked- Parameters:
doc1- Index of the SPDX document for license1license1-doc2- Index of the SPDX document for license2license2-- Returns:
- true if the licenses are equivalent
- Throws:
SpdxCompareException
-
objectsEqual
returns true if the two objects are equal considering nulls- Parameters:
o1-o2-- Returns:
-
elementsEquivalent
-
arraysEqual
Compare two object arrays- Parameters:
a1-a2-- Returns:
-
stringsEqual
Compares two strings returning true if they are equal considering null values and trimming the strings. and normalizing linefeeds. Empty strings are treated as the same as null values.- Parameters:
stringA-stringB-- Returns:
-
compareStrings
Compares two strings including trimming the string and taking into account they may be null. Null is considered a smaller value- Parameters:
stringA-stringB-- Returns:
-
isDifferenceFound
public boolean isDifferenceFound()- Returns:
-
isSpdxVersionEqual
- Returns:
- Throws:
SpdxCompareException
-
getSpdxDoc
- Parameters:
docIndex- Reference to which document number - 0 is the first document parameter in compare- Returns:
- Throws:
SpdxCompareException
-
isDataLicenseEqual
- Returns:
- Throws:
SpdxCompareException
-
isDocumentCommentsEqual
- Returns:
- Throws:
SpdxCompareException
-
isReviewersEqual
- Returns:
- Throws:
SpdxCompareException
-
isExternalDcoumentRefsEquals
- Throws:
SpdxCompareException
-
isExtractedLicensingInfosEqual
- Throws:
SpdxCompareException
-
getUniqueReviewers
Get all unique reviewers in SPDX document at index 1 relative to reviewers in SPDX Document at index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getReviewerDifferences
public SpdxComparer.SPDXReviewDifference[] getReviewerDifferences(int docindex1, int docindex2) throws SpdxCompareExceptionGet all reviewer differences between two documents. A reviewer difference is where the reviewer name is the same but the reviewer date and/or the reviewer comment is different- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getUniqueExtractedLicenses
public ExtractedLicenseInfo[] getUniqueExtractedLicenses(int docIndexA, int docIndexB) throws SpdxCompareExceptionRetrieves any unique extracted licenses fromt the first SPDX document index relative to the second - unique is determined by the license text matching- Parameters:
docIndexA-docIndexB-- Returns:
- Throws:
SpdxCompareException
-
getExtractedLicenseDifferences
public SpdxLicenseDifference[] getExtractedLicenseDifferences(int docIndexA, int docIndexB) throws SpdxCompareExceptionRetrieves any licenses which where the text matches in both documents but other fields are different- Parameters:
docIndexA-docIndexB-- Returns:
- Throws:
SpdxCompareException
-
isCreatorInformationEqual
- Returns:
- Throws:
SpdxCompareException
-
getUniqueCreators
Returns any creators which are in the SPDX document 1 which are not in document 2- Parameters:
doc1index-doc2index-- Returns:
- Throws:
SpdxCompareException
-
isfilesEquals
- Returns:
- Throws:
SpdxCompareException
-
isPackagesEquals
- Returns:
- Throws:
SpdxCompareException
-
isDocumentAnnotationsEquals
- Returns:
- Throws:
SpdxCompareException
-
isDocumentRelationshipsEquals
- Returns:
- Throws:
SpdxCompareException
-
getUniqueFiles
Return any files which are in spdx document index 1 but not in spdx document index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getFileDifferences
public SpdxFileDifference[] getFileDifferences(int docindex1, int docindex2) throws SpdxCompareExceptionReturns any file differences found between the first and second SPDX documents as specified by the document index- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getUniquePackages
Return any files which are in spdx document index 1 but not in spdx document index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getUniqueExternalDocumentRefs
public ExternalDocumentRef[] getUniqueExternalDocumentRefs(int docindex1, int docindex2) throws SpdxCompareExceptionReturn any external document references which are in spdx document index 1 but not in spdx document index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getUniqueDocumentAnnotations
public Annotation[] getUniqueDocumentAnnotations(int docindex1, int docindex2) throws SpdxCompareExceptionReturn any document annotations which are in spdx document index 1 but not in spdx document index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getUniqueDocumentRelationship
public Relationship[] getUniqueDocumentRelationship(int docindex1, int docindex2) throws SpdxCompareExceptionReturn any document annotations which are in spdx document index 1 but not in spdx document index 2- Parameters:
docindex1-docindex2-- Returns:
- Throws:
SpdxCompareException
-
getPackageDifferences
- Returns:
- Package comparers where there is at least one difference
- Throws:
SpdxCompareException
-
getPackageComparers
- Returns:
- all package comparers
-
getNumSpdxDocs
public int getNumSpdxDocs()- Returns:
-
isLicenseListVersionEqual
- Returns:
- Throws:
SpdxCompareException
-
findUniqueChecksums
Find any SPDX checksums which are in elementsA but not in elementsB- Parameters:
checksumsA-checksumsB-- Returns:
-
findUniqueAnnotations
public static Annotation[] findUniqueAnnotations(Annotation[] annotationsA, Annotation[] annotationsB)Find any SPDX annotations which are in annotationsA but not in annotationsB- Parameters:
annotationsA-annotationsB-- Returns:
-
elementsEquivalent
Returns true if two arrays of SPDX elements contain equivalent elements- Parameters:
elementsA-elementsB-- Returns:
-
findUniqueRelationships
public static Relationship[] findUniqueRelationships(Relationship[] relationshipsA, Relationship[] relationshipsB)Find unique relationships that are present in relationshipsA but not relationshipsB- Parameters:
relationshipsA-relationshipsB-- Returns:
-
findUniqueExternalDocumentRefs
public static ExternalDocumentRef[] findUniqueExternalDocumentRefs(ExternalDocumentRef[] externalDocRefsA, ExternalDocumentRef[] externalDocRefsB) throws InvalidSPDXAnalysisExceptionFind unique relationships that are present in relationshipsA but not relationshipsB- Parameters:
externalDocRefsA-externalDocRefsB-- Returns:
- Throws:
InvalidSPDXAnalysisException
-
getSpdxDocuments
- Returns:
-
isDocumentContentsEquals
- Returns:
- Throws:
SpdxCompareException
-
isSnippetsEqual
- Returns:
- Throws:
SpdxCompareException
-
getSnippetComparers
- Returns:
- all snippet comparers
-