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

Implement configuration for handling artifact ratings from a file #744

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<suppress checks="AbbreviationAsWordInName"
files="GAV.java"
lines="12"/>
<suppress checks="AbbreviationAsWordInName"
files="AbstractReporter.java"
lines="35"/>
<suppress checks="MemberName"
files="AbstractReporter.java"
lines="35"/>
<suppress checks="LineLength"
files="package-info.java"
lines="142"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import com.sap.oss.phosphor.fosstars.model.Label;
import com.sap.oss.phosphor.fosstars.model.Score;
import com.sap.oss.phosphor.fosstars.model.rating.AbstractRating;
import com.sap.oss.phosphor.fosstars.model.rating.oss.OssSecurityRating.SecurityLabel;
import com.sap.oss.phosphor.fosstars.model.score.oss.OssArtifactSecurityScore;
import com.sap.oss.phosphor.fosstars.model.value.ScoreValue;
import java.util.Objects;

/**
* This is a security rating for artifacts of an open-source project.
* The rating is based on {@link
* This is a security rating for artifacts of an open-source project. The rating is based on {@link
* com.sap.oss.phosphor.fosstars.model.score.oss.OssArtifactSecurityScore}.
*/
public class OssArtifactSecurityRating extends AbstractRating {
Expand All @@ -21,7 +21,6 @@ public class OssArtifactSecurityRating extends AbstractRating {
* A set of labels for the rating.
*/
public enum ArtifactSecurityLabel implements Label {

BAD, MODERATE, GOOD, UNCLEAR, UNKNOWN;
}

Expand All @@ -41,7 +40,7 @@ public OssArtifactSecurityRating() {
* Initializes a new rating.
*
* @param score An instance of
* {@link com.sap.oss.phosphor.fosstars.model.score.oss.OssArtifactSecurityScore}.
* {@link com.sap.oss.phosphor.fosstars.model.score.oss.OssArtifactSecurityScore}.
* @param thresholds Thresholds for labels.
*/
@JsonCreator
Expand All @@ -50,8 +49,7 @@ public OssArtifactSecurityRating(
@JsonProperty("thresholds") Thresholds thresholds) {

super("Security rating for artifact versions of an open-source project", score);
Objects.requireNonNull(thresholds, "Oh no! Thresholds is null!");
this.thresholds = thresholds;
this.thresholds = Objects.requireNonNull(thresholds, "Oh no! Thresholds is null!");
}

@Override
Expand Down Expand Up @@ -84,6 +82,15 @@ protected ArtifactSecurityLabel label(ScoreValue scoreValue) {
return ArtifactSecurityLabel.GOOD;
}

/**
* Return thresholds for the labels.
*
* @return The thresholds for the labels.
*/
public Thresholds thresholds() {
return thresholds;
}

/**
* Holds thresholds for labels.
*/
Expand Down Expand Up @@ -113,8 +120,8 @@ public static class Thresholds {
* Initialize thresholds.
*
* @param moderate A threshold for the moderate label.
* @param good A threshold for the good label.
* @param unclear A threshold for the unclear label.
* @param good A threshold for the good label.
* @param unclear A threshold for the unclear label.
*/
@JsonCreator
public Thresholds(
Expand All @@ -135,6 +142,32 @@ public Thresholds(
this.good = good;
this.unclear = unclear;
}
}

/**
* Returns the threshold for {@link SecurityLabel#MODERATE} label.
*
* @return The threshold.
*/
public double forModerate() {
return moderate;
}

/**
* Returns the threshold for {@link SecurityLabel#GOOD} label.
*
* @return The threshold.
*/
public double forGood() {
return good;
}

/**
* Returns the threshold for {@link SecurityLabel#UNCLEAR} label.
*
* @return The threshold.
*/
public double forUnclear() {
return unclear;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
import java.util.Objects;

/**
* This is a security rating for open-source projects
* that is based on a security score for open-source project.
* This is a security rating for open-source projects that is based on a security score for
* open-source project.
*/
public class OssSecurityRating extends AbstractRating {

/**
* A set of labels for the rating.
*/
public enum SecurityLabel implements Label {

BAD, MODERATE, GOOD, UNCLEAR
}

Expand All @@ -39,7 +38,7 @@ public OssSecurityRating() {
/**
* Initializes a security rating based on a security score for open-source projects.
*
* @param score The security score.
* @param score The security score.
* @param thresholds Thresholds for labels.
*/
@JsonCreator
Expand Down Expand Up @@ -116,8 +115,8 @@ public static class Thresholds {
* Initialize thresholds.
*
* @param moderate A threshold for the moderate label.
* @param good A threshold for the good label.
* @param unclear A threshold for the unclear label.
* @param good A threshold for the good label.
* @param unclear A threshold for the unclear label.
*/
@JsonCreator
public Thresholds(
Expand Down Expand Up @@ -166,5 +165,4 @@ public double forUnclear() {
return unclear;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;

/**
* Maven artifact.
Expand Down Expand Up @@ -40,10 +41,10 @@ public class MavenArtifact extends AbstractSubject implements Artifact {
/**
* Initializes a Maven artifact.
*
* @param group A group id of the artifact.
* @param group A group id of the artifact.
* @param artifact An artifact id of the artifact.
* @param version The version of the artifact. It may be null.
* @param project A {@link GitHubProject}. It may be null.
* @param version The version of the artifact. It may be null.
* @param project A {@link GitHubProject}. It may be null.
*/
@JsonCreator
public MavenArtifact(
Expand Down Expand Up @@ -88,6 +89,16 @@ public Optional<String> version() {
return Optional.ofNullable(version);
}

/**
* Return the artifact in GAV format.
*
* @return GAV format of the artifact.
*/
public String gav() {
String versionPrint = StringUtils.isEmpty(version) ? "" : String.format(":%s", version);
return String.format("%s:%s%s", group, artifact, versionPrint);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -121,4 +132,10 @@ public String purl() {

return format("pkg:maven/%s/%s@%s", group, artifact, version);
}

@Override
public String toString() {
String scmPrint = project == null ? "" : String.format(" -> %s", project);
return String.format("%s%s", gav(), scmPrint);
}
}
Loading