Skip to content

Validate artifactId with PacakgeURL format #47

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

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dev.cdevents</groupId>
<artifactId>cdevents-sdk-java</artifactId>
<version>0.1.0-SNAPSHOT</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this version to 0.1.2 as currently the SDK follows v0.1.2 spec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
As I understand it, this will then be updated to 0.1.2 (without the -SNAPSHOT) when we make a release, and for now 0.1.2-SNAPSHOT is fine.
@aalmiray is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. The convention is to keep -SNAPSHOT while doing development. This tag must go away during release.

<version>0.1.2-SNAPSHOT</version>

<name>cdevents-sdk-java</name>
<description>cdevents java sdk</description>
Expand All @@ -26,6 +26,8 @@
<assertj-core.version>3.22.0</assertj-core.version>
<jackson.version>2.15.0</jackson.version>
<slf4j.version>2.0.7</slf4j.version>
<json.schema.version>1.0.80</json.schema.version>
<packageurl.version>1.4.1</packageurl.version>
<project.github.repository>cdevents/sdk-java</project.github.repository>
<nexus.url>https://s01.oss.sonatype.org</nexus.url>
<repository.url>git@github.com:${project.github.repository}.git</repository.url>
Expand Down Expand Up @@ -111,7 +113,8 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.0.80</version>
<version>${json.schema.version}</version>

</dependency>

<dependency>
Expand All @@ -128,6 +131,12 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.github.package-url</groupId>
<artifactId>packageurl-java</artifactId>
<version>${packageurl.version}</version>
</dependency>

Comment on lines +134 to +139
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is MIT, so it's fine.
@aalmiray @rjalander is there a way to automate license checks for dependencies in pom.xml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a Maven plugin we could use. Let me find out how to configure it.

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.packageurl.PackageURL;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.ArtifactPackagedSubject;
import dev.cdevents.models.CDEvent;
Expand Down Expand Up @@ -169,10 +170,10 @@ public String eventSchema() {

/**
* @param subjectId
* sets the subject Id
* sets the subject Id in the PURL format
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
public void setSubjectId(PackageURL subjectId) {
getSubject().setId(subjectId.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.packageurl.PackageURL;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.ArtifactPublishedSubject;
import dev.cdevents.models.CDEvent;
Expand Down Expand Up @@ -149,10 +150,10 @@ public String eventSchema() {

/**
* @param subjectId
* sets the subject Id
* sets the subject Id in PURL format
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
public void setSubjectId(PackageURL subjectId) {
getSubject().setId(subjectId.toString());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/cdevents/events/BuildFinishedCDEvent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.packageurl.PackageURL;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.BuildFinishedSubject;
import dev.cdevents.models.CDEvent;
Expand Down Expand Up @@ -169,10 +170,10 @@ public void setSubjectSource(URI subjectSource) {

/**
* @param artifactId
* sets the subjects artifactId
* sets the subjects artifactId in PURL format
*/
public void setSubjectArtifactId(String artifactId) {
getSubject().getContent().setArtifactId(artifactId);
public void setSubjectArtifactId(PackageURL artifactId) {
getSubject().getContent().setArtifactId(artifactId.toString());

}

Expand Down
14 changes: 8 additions & 6 deletions src/test/java/dev/cdevents/CDEventsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.cdevents;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.events.*;
import dev.cdevents.exception.CDEventsException;
Expand Down Expand Up @@ -648,14 +650,14 @@ void testInvalidBuildStartedEventWithNoSubject() {
}

@Test
void createBuildFinishedAsCloudEvent() {
void createBuildFinishedAsCloudEvent() throws MalformedPackageURLException {

BuildFinishedCDEvent cdEvent = new BuildFinishedCDEvent();
cdEvent.setSource(URI.create("http://dev.cdevents"));

cdEvent.setSubjectId("test-build");
cdEvent.setSubjectSource(URI.create("/dev/builds/test-build"));
cdEvent.setSubjectArtifactId("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f");
cdEvent.setSubjectArtifactId(new PackageURL("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f"));

String cdEventJson = CDEvents.cdEventAsJson(cdEvent);

Expand Down Expand Up @@ -846,12 +848,12 @@ void testInvalidTestSuiteFinishedEventWithNoSubject() {
}

@Test
void createArtifactPackagedEventAsCloudEvent() {
void createArtifactPackagedEventAsCloudEvent() throws MalformedPackageURLException {

ArtifactPackagedCDEvent cdEvent = new ArtifactPackagedCDEvent();
cdEvent.setSource(URI.create("http://dev.cdevents"));

cdEvent.setSubjectId("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b");
cdEvent.setSubjectId(new PackageURL("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b"));
cdEvent.setSubjectSource(URI.create("/dev/artifact/source"));

cdEvent.setSubjectChangeId("test-feature");
Expand Down Expand Up @@ -882,11 +884,11 @@ void testInvalidArtifactPackagedEventWithNoSubject() {
}

@Test
void createArtifactPublishedEventAsCloudEvent() {
void createArtifactPublishedEventAsCloudEvent() throws MalformedPackageURLException {
ArtifactPublishedCDEvent cdEvent = new ArtifactPublishedCDEvent();
cdEvent.setSource(URI.create("http://dev.cdevents"));

cdEvent.setSubjectId("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b");
cdEvent.setSubjectId(new PackageURL("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b"));
cdEvent.setSubjectSource(URI.create("/dev/artifact/source"));

String cdEventJson = CDEvents.cdEventAsJson(cdEvent);
Expand Down