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

Refactor aggregates, potentially replacing lagom with pure akka #43

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,43 @@
*/
package org.spongepowered.downloads.artifact.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.Objects;
import java.util.StringJoiner;

@JsonDeserialize
public final class ArtifactCoordinates {
public record ArtifactCoordinates(
@JsonProperty(required = true) String groupId,
@JsonProperty(required = true) String artifactId
) {
@JsonCreator
public ArtifactCoordinates {
}

public MavenCoordinates version(String version) {
return MavenCoordinates.parse(
new StringJoiner(":").add(this.groupId()).add(this.artifactId()).add(version).toString());
}

public String asMavenString() {
return this.groupId() + ":" + this.artifactId();
}

/**
* The group id of an artifact, as defined by the Apache Maven documentation.
* See <a href="https://maven.apache.org/pom.html#Maven_Coordinates">Maven Coordinates</a>.
*/
@JsonProperty(required = true)
public final String groupId;
public String groupId() {
return groupId;
}

/**
* The artifact id of an artifact, as defined by the Apache Maven documentation.
* See <a href="https://maven.apache.org/pom.html#Maven_Coordinates">Maven Coordinates</a>.
*/
@JsonProperty(required = true)
public final String artifactId;


public ArtifactCoordinates(final String groupId, final String artifactId) {
this.groupId = groupId;
this.artifactId = artifactId;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ArtifactCoordinates that = (ArtifactCoordinates) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId);
}

@Override
public String toString() {
return new StringJoiner(", ", ArtifactCoordinates.class.getSimpleName() + "[", "]")
.add("groupId='" + groupId + "'")
.add("artifactId='" + artifactId + "'")
.toString();
}

public MavenCoordinates version(String version) {
return MavenCoordinates.parse(new StringJoiner(":").add(this.groupId).add(this.artifactId).add(version).toString());
}

public String asMavenString() {
return this.groupId + ":" + this.artifactId;
public String artifactId() {
return artifactId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,15 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.Objects;
import java.util.StringJoiner;

@JsonDeserialize
public final class Group {

@JsonProperty(required = true)
public final String groupCoordinates;
@JsonProperty(required = true)
public final String name;
@JsonProperty(required = true)
public final String website;
public record Group(
@JsonProperty(required = true) String groupCoordinates,
@JsonProperty(required = true) String name,
@JsonProperty(required = true) String website
) {

@JsonCreator
public Group(final String groupCoordinates, final String name, final String website) {
this.groupCoordinates = groupCoordinates;
this.name = name;
this.website = website;
}

public String getGroupCoordinates() {
return this.groupCoordinates;
public Group {
}

public String getName() {
return this.name;
}

public String getWebsite() {
return this.website;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
final Group group = (Group) o;
return Objects.equals(this.groupCoordinates, group.groupCoordinates) &&
Objects.equals(this.name, group.name) &&
Objects.equals(this.website, group.website);
}

@Override
public int hashCode() {
return Objects.hash(this.groupCoordinates, this.name, this.website);
}

@Override
public String
toString() {
return new StringJoiner(
", ", Group.class.getSimpleName() + "[", "]")
.add("groupCoordinates='" + this.groupCoordinates + "'")
.add("name='" + this.name + "'")
.add("website=" + this.website)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@JsonDeserialize
public final class MavenCoordinates implements Comparable<MavenCoordinates> {

private static final Pattern MAVEN_REGEX = Pattern.compile("[-\\w.]+");
private static final Pattern MAVEN_REGEX = Pattern.compile("^[-\\w.]+$");

/**
* The group id of an artifact, as defined by the Apache Maven documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public String asStandardVersionString(final String version) {
stringJoiner.add(split[i]);
}

final var unTimestampedVersion = stringJoiner.add(SNAPSHOT_VERSION).toString();
return unTimestampedVersion;
return stringJoiner.add(SNAPSHOT_VERSION).toString();
}
},

Expand Down Expand Up @@ -82,9 +81,9 @@ public boolean isSnapshot() {
Verifies the pattern that the snapshot version is date.time-build formatted,
enables the pattern match for a timestamped snapshot
*/
private static final Pattern VERSION_FILE_PATTERN = Pattern.compile("^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$");
private static final Pattern VERSION_FILE_PATTERN = Pattern.compile("^(.*)-(\\d{8}.\\d{6})-(\\d+)$");

private static final Pattern TIMESTAMP_TO_REPLACE = Pattern.compile("([0-9]{8}.[0-9]{6})-([0-9]+)$");
private static final Pattern TIMESTAMP_TO_REPLACE = Pattern.compile("(\\d{8}.\\d{6})-(\\d+)$");

public static VersionType fromVersion(final String version) {
if (version == null || version.isEmpty()) {
Expand All @@ -106,11 +105,6 @@ public static VersionType fromVersion(final String version) {
return RELEASE;
}

/**
* Gets whether this version is a snapshot of any kind.
*
* @return
*/
public boolean isSnapshot() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final record ArtifactRegistered(ArtifactCoordinates coordinates) implements Grou

@Override
public String groupId() {
return this.coordinates.groupId;
return this.coordinates.groupId();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public final class ArtifactDetails {
name = "gitRepository"),
})
@JsonDeserialize
public interface Update<T> {
public sealed interface Update<T> {

Either<BadRequest, T> validate();

final record Website(
record Website(
@JsonProperty(required = true) String website
) implements Update<URL> {

Expand All @@ -70,7 +70,7 @@ public Either<BadRequest, URL> validate() {
}
}

final record DisplayName(
record DisplayName(
@JsonProperty(required = true) String display
) implements Update<String> {

Expand All @@ -84,7 +84,7 @@ public Either<BadRequest, String> validate() {
}
}

final record Issues(
record Issues(
@JsonProperty(required = true) String issues
) implements Update<URL> {
@JsonCreator
Expand All @@ -98,7 +98,7 @@ public Either<BadRequest, URL> validate() {
}
}

final record GitRepository(
record GitRepository(
@JsonProperty(required = true) String gitRepo
) implements Update<URL> {

Expand All @@ -115,7 +115,7 @@ public Either<BadRequest, URL> validate() {
}

@JsonSerialize
public final record Response(
public record Response(
String name,
String displayName,
String website,
Expand Down
Loading