Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SPDX Spec Version 3 #171

Merged
merged 10 commits into from
Jan 22, 2025
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
<tag>master</tag>
</scm>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<distributionManagement>
<repository>
<id>ossrh</id>
Expand Down Expand Up @@ -98,17 +105,17 @@
<dependency>
<groupId>org.spdx</groupId>
<artifactId>java-spdx-library</artifactId>
<version>1.1.12</version>
<version>2.0.0-RC1</version>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-rdf-store</artifactId>
<version>1.1.9</version>
<version>2.0.0-RC1</version>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-jackson-store</artifactId>
<version>1.1.9</version>
<version>2.0.0-RC1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -147,6 +154,11 @@
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spdx</groupId>
<artifactId>spdx-v3jsonld-store</artifactId>
<version>1.0.0-RC1</version>
</dependency>
</dependencies>

<build>
Expand Down
40 changes: 2 additions & 38 deletions src/main/java/org/spdx/maven/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
*/
package org.spdx.maven;

import org.apache.maven.plugin.MojoExecutionException;
import org.spdx.library.InvalidSPDXAnalysisException;
import org.spdx.library.model.SpdxDocument;
import org.spdx.library.model.enumerations.AnnotationType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -28,9 +23,8 @@
* Simple class to hold an SPDX Annotation.
*
* @author Gary O'Neall
* @see org.spdx.library.model.Annotation
* @see AnnotationType
*/
@SuppressWarnings("unused")
public class Annotation
{
private static final Logger LOG = LoggerFactory.getLogger( Annotation.class );
Expand Down Expand Up @@ -125,38 +119,8 @@ public void setAnnotationComment( String annotationComment )
this.annotationComment = annotationComment;
}


/**
* @param spdxDoc SPDX document which will contain the annotation
* @return an SPDX model version of the annotation
*/
public org.spdx.library.model.Annotation toSpdxAnnotation( SpdxDocument spdxDoc ) throws MojoExecutionException
{
AnnotationType annotationType = AnnotationType.OTHER;
try
{
annotationType = AnnotationType.valueOf( this.annotationType );
}
catch ( Exception ex )
{
throw new MojoExecutionException( "Invalid annotation type "+this.annotationType );
}
try
{
return spdxDoc.createAnnotation( this.annotator,
annotationType,
annotationDate,
annotationComment );
}
catch ( InvalidSPDXAnalysisException e )
{
throw new MojoExecutionException( "Error creating annotation.", e );
}
}

public void logInfo()
{
LOG.debug(
"Annotator: " + this.annotator + ", Date: " + this.annotationDate + ", Type: " + this.annotationType );
LOG.debug( "Annotator: {}, Date: {}, Type: {}", this.annotator, this.annotationDate, this.annotationType );
}
}
82 changes: 82 additions & 0 deletions src/main/java/org/spdx/maven/Checksum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.maven;

import java.util.Objects;

/**
* Holds the value and algorithm of a checksum used in the SPDX document
*
* @author Gary O'Neall
*
*/
public class Checksum
{

private String value;
private String algorithm;

/**
* @param algorithm checksum algorithm
* @param value checksum result
*/
public Checksum( String algorithm, String value )
{
this.algorithm = algorithm;
this.value = value;
}

/**
* @return the value
*/
public String getValue()
{
return value;
}

/**
* @param value the value to set
*/
public void setValue( String value )
{
this.value = value;
}

/**
* @return the algorithm
*/
public String getAlgorithm()
{
return algorithm;
}

/**
* @param algorithm the algorithm to set
*/
@SuppressWarnings("unused")
public void setAlgorithm( String algorithm )
{
this.algorithm = algorithm;
}

@Override
public boolean equals(Object o)
{
if ( !( o instanceof Checksum ) )
{
return false;
}
Checksum compare = (Checksum)o;
return Objects.equals( compare.getAlgorithm(), this.getAlgorithm() ) &&
Objects.equals( compare.getValue(), this.getValue() );
}

@Override
public int hashCode()
{
return ( Objects.isNull( algorithm ) ? 11 : algorithm.hashCode() ) ^ ( Objects.isNull( value ) ? 17 : value.hashCode() );
}

}
Loading
Loading