Skip to content

Commit ba3a68c

Browse files
committed
Restructure Artifact Service
1 parent c968e2d commit ba3a68c

File tree

39 files changed

+861
-1215
lines changed

39 files changed

+861
-1215
lines changed

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/ArtifactCoordinates.java

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,43 @@
2424
*/
2525
package org.spongepowered.downloads.artifact.api;
2626

27+
import com.fasterxml.jackson.annotation.JsonCreator;
2728
import com.fasterxml.jackson.annotation.JsonProperty;
2829
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2930

30-
import java.util.Objects;
3131
import java.util.StringJoiner;
3232

3333
@JsonDeserialize
34-
public final class ArtifactCoordinates {
34+
public record ArtifactCoordinates(
35+
@JsonProperty(required = true) String groupId,
36+
@JsonProperty(required = true) String artifactId
37+
) {
38+
@JsonCreator
39+
public ArtifactCoordinates {
40+
}
41+
42+
public MavenCoordinates version(String version) {
43+
return MavenCoordinates.parse(
44+
new StringJoiner(":").add(this.groupId()).add(this.artifactId()).add(version).toString());
45+
}
46+
47+
public String asMavenString() {
48+
return this.groupId() + ":" + this.artifactId();
49+
}
3550

3651
/**
3752
* The group id of an artifact, as defined by the Apache Maven documentation.
3853
* See <a href="https://maven.apache.org/pom.html#Maven_Coordinates">Maven Coordinates</a>.
3954
*/
40-
@JsonProperty(required = true)
41-
public final String groupId;
55+
public String groupId() {
56+
return groupId;
57+
}
58+
4259
/**
4360
* The artifact id of an artifact, as defined by the Apache Maven documentation.
4461
* See <a href="https://maven.apache.org/pom.html#Maven_Coordinates">Maven Coordinates</a>.
4562
*/
46-
@JsonProperty(required = true)
47-
public final String artifactId;
48-
49-
50-
public ArtifactCoordinates(final String groupId, final String artifactId) {
51-
this.groupId = groupId;
52-
this.artifactId = artifactId;
53-
}
54-
55-
@Override
56-
public boolean equals(final Object o) {
57-
if (this == o) {
58-
return true;
59-
}
60-
if (o == null || getClass() != o.getClass()) {
61-
return false;
62-
}
63-
ArtifactCoordinates that = (ArtifactCoordinates) o;
64-
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
65-
}
66-
67-
@Override
68-
public int hashCode() {
69-
return Objects.hash(groupId, artifactId);
70-
}
71-
72-
@Override
73-
public String toString() {
74-
return new StringJoiner(", ", ArtifactCoordinates.class.getSimpleName() + "[", "]")
75-
.add("groupId='" + groupId + "'")
76-
.add("artifactId='" + artifactId + "'")
77-
.toString();
78-
}
79-
80-
public MavenCoordinates version(String version) {
81-
return MavenCoordinates.parse(new StringJoiner(":").add(this.groupId).add(this.artifactId).add(version).toString());
82-
}
83-
84-
public String asMavenString() {
85-
return this.groupId + ":" + this.artifactId;
63+
public String artifactId() {
64+
return artifactId;
8665
}
8766
}

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/Group.java

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,65 +28,15 @@
2828
import com.fasterxml.jackson.annotation.JsonProperty;
2929
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
3030

31-
import java.util.Objects;
32-
import java.util.StringJoiner;
33-
3431
@JsonDeserialize
35-
public final class Group {
36-
37-
@JsonProperty(required = true)
38-
public final String groupCoordinates;
39-
@JsonProperty(required = true)
40-
public final String name;
41-
@JsonProperty(required = true)
42-
public final String website;
32+
public record Group(
33+
@JsonProperty(required = true) String groupCoordinates,
34+
@JsonProperty(required = true) String name,
35+
@JsonProperty(required = true) String website
36+
) {
4337

4438
@JsonCreator
45-
public Group(final String groupCoordinates, final String name, final String website) {
46-
this.groupCoordinates = groupCoordinates;
47-
this.name = name;
48-
this.website = website;
49-
}
50-
51-
public String getGroupCoordinates() {
52-
return this.groupCoordinates;
39+
public Group {
5340
}
5441

55-
public String getName() {
56-
return this.name;
57-
}
58-
59-
public String getWebsite() {
60-
return this.website;
61-
}
62-
63-
@Override
64-
public boolean equals(final Object o) {
65-
if (this == o) {
66-
return true;
67-
}
68-
if (o == null || this.getClass() != o.getClass()) {
69-
return false;
70-
}
71-
final Group group = (Group) o;
72-
return Objects.equals(this.groupCoordinates, group.groupCoordinates) &&
73-
Objects.equals(this.name, group.name) &&
74-
Objects.equals(this.website, group.website);
75-
}
76-
77-
@Override
78-
public int hashCode() {
79-
return Objects.hash(this.groupCoordinates, this.name, this.website);
80-
}
81-
82-
@Override
83-
public String
84-
toString() {
85-
return new StringJoiner(
86-
", ", Group.class.getSimpleName() + "[", "]")
87-
.add("groupCoordinates='" + this.groupCoordinates + "'")
88-
.add("name='" + this.name + "'")
89-
.add("website=" + this.website)
90-
.toString();
91-
}
9242
}

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/MavenCoordinates.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@JsonDeserialize
3838
public final class MavenCoordinates implements Comparable<MavenCoordinates> {
3939

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

4242
/**
4343
* The group id of an artifact, as defined by the Apache Maven documentation.

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/Ordering.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/VersionType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public String asStandardVersionString(final String version) {
5252
stringJoiner.add(split[i]);
5353
}
5454

55-
final var unTimestampedVersion = stringJoiner.add(SNAPSHOT_VERSION).toString();
56-
return unTimestampedVersion;
55+
return stringJoiner.add(SNAPSHOT_VERSION).toString();
5756
}
5857
},
5958

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

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

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

109-
/**
110-
* Gets whether this version is a snapshot of any kind.
111-
*
112-
* @return
113-
*/
114108
public boolean isSnapshot() {
115109
return false;
116110
}

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/event/GroupUpdate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final record ArtifactRegistered(ArtifactCoordinates coordinates) implements Grou
6767

6868
@Override
6969
public String groupId() {
70-
return this.coordinates.groupId;
70+
return this.coordinates.groupId();
7171
}
7272
}
7373

artifact-api/src/main/java/org/spongepowered/downloads/artifact/api/query/ArtifactDetails.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public final class ArtifactDetails {
5151
name = "gitRepository"),
5252
})
5353
@JsonDeserialize
54-
public interface Update<T> {
54+
public sealed interface Update<T> {
5555

5656
Either<BadRequest, T> validate();
5757

58-
final record Website(
58+
record Website(
5959
@JsonProperty(required = true) String website
6060
) implements Update<URL> {
6161

@@ -70,7 +70,7 @@ public Either<BadRequest, URL> validate() {
7070
}
7171
}
7272

73-
final record DisplayName(
73+
record DisplayName(
7474
@JsonProperty(required = true) String display
7575
) implements Update<String> {
7676

@@ -84,7 +84,7 @@ public Either<BadRequest, String> validate() {
8484
}
8585
}
8686

87-
final record Issues(
87+
record Issues(
8888
@JsonProperty(required = true) String issues
8989
) implements Update<URL> {
9090
@JsonCreator
@@ -98,7 +98,7 @@ public Either<BadRequest, URL> validate() {
9898
}
9999
}
100100

101-
final record GitRepository(
101+
record GitRepository(
102102
@JsonProperty(required = true) String gitRepo
103103
) implements Update<URL> {
104104

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

117117
@JsonSerialize
118-
public final record Response(
118+
public record Response(
119119
String name,
120120
String displayName,
121121
String website,

0 commit comments

Comments
 (0)