Skip to content

Commit dca2824

Browse files
committed
Begin preparations of maven central upload
1 parent 3f40e17 commit dca2824

File tree

12 files changed

+205
-135
lines changed

12 files changed

+205
-135
lines changed

.github/workflows/gradle-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v5
1818

19-
- name: Set up JDK 17
19+
- name: Set up JDK 11
2020
uses: actions/setup-java@v5
2121
with:
22-
java-version: "17"
22+
java-version: "11"
2323
distribution: "temurin"
2424

2525
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.

.github/workflows/gradle-dependency-submission.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Dependency Submission
33
on:
44
push:
55
branches: [ "main" ]
6+
paths:
7+
- 'build.gradle.kts'
8+
- 'settings.gradle.kts'
9+
- 'gradle/**'
10+
- 'buildSrc/**'
611

712
jobs:
813
dependency-submission:
@@ -12,10 +17,10 @@ jobs:
1217
steps:
1318
- uses: actions/checkout@v5
1419

15-
- name: Set up JDK 17
20+
- name: Set up JDK 11
1621
uses: actions/setup-java@v5
1722
with:
18-
java-version: "17"
23+
java-version: "11"
1924
distribution: "temurin"
2025

2126
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.

.jitpack.yml

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

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public class ExampleClass {
5757

5858
## Usage
5959

60-
This library is available through [Jitpack][jitpack] repository. Add it along with repository in your dependency
61-
manager.
60+
Add library as dependency to Maven or Gradle. See the actual versions on [Maven Central][maven-central]. **Java 11** or higher is required to use this library.
6261

6362
1. Maven:
6463
```xml
@@ -83,7 +82,7 @@ manager.
8382
- [`problem4j-spring-web`][problem4j-spring-web] - Spring Web module extending `ResponseEntityExceptionHandler` for
8483
handling exceptions and returning `Problem` responses.
8584
86-
[jitpack]: https://jitpack.io/#malczuuu/problem4j-core
85+
[maven-central]: https://central.sonatype.com/artifact/io.github.malczuuu.problem4j/problem4j-core
8786
8887
[problem4j]: https://github.com/malczuuu/problem4j
8988

build.gradle.kts

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import com.diffplug.spotless.LineEnding
22

33
plugins {
4-
`java-library`
5-
`maven-publish`
6-
id("com.diffplug.spotless") version "7.2.1"
4+
id("java-library")
5+
id("maven-publish")
6+
id("signing")
7+
id("com.diffplug.spotless").version("7.2.1")
8+
id("com.gradleup.nmcp.aggregation").version("1.1.0")
79
}
810

911
group = "io.github.malczuuu.problem4j"
1012

11-
if (version == "unspecified") {
12-
version = Versioning.getSnapshotVersion(rootProject.rootDir)
13-
}
13+
/**
14+
* In order to avoid hardcoding snapshot versions, we derive the version from the current Git commit hash. For CI/CD add
15+
* -Pversion={releaseVersion} parameter to match Git tag.
16+
*/
17+
version =
18+
if (version == "unspecified")
19+
getSnapshotVersion(rootProject.rootDir)
20+
else
21+
version
1422

1523
java {
16-
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
24+
toolchain.languageVersion = JavaLanguageVersion.of(11)
1725
withSourcesJar()
1826
withJavadocJar()
1927
}
@@ -38,20 +46,57 @@ publishing {
3846
from(components["java"])
3947

4048
pom {
41-
name.set(project.name)
42-
description.set("Core library implementing Problem model according to RFC7807")
43-
url.set("https://github.com/malczuuu/${project.name}")
49+
name = project.name
50+
description = "Core library implementing Problem model according to RFC7807"
51+
url = "https://github.com/malczuuu/${project.name}"
52+
inceptionYear = "2025"
4453
licenses {
4554
license {
46-
name.set("MIT License")
47-
url.set("https://opensource.org/licenses/MIT")
55+
name = "MIT License"
56+
url = "https://opensource.org/licenses/MIT"
4857
}
4958
}
59+
developers {
60+
developer {
61+
id = "malczuuu"
62+
name = "Damian Malczewski"
63+
url = "https://github.com/malczuuu"
64+
}
65+
}
66+
issueManagement {
67+
system = "GitHub Issues"
68+
url = "https://github.com/malczuuu/${project.name}/issues"
69+
}
70+
scm {
71+
connection = "scm:git:git://github.com/malczuuu/${project.name}.git"
72+
developerConnection = "scm:git:[email protected]:malczuuu/${project.name}.git"
73+
url = "https://github.com/malczuuu/${project.name}"
74+
}
5075
}
5176
}
5277
}
5378
}
5479

80+
nmcpAggregation {
81+
centralPortal {
82+
username = System.getenv("PUBLISHING_USERNAME")
83+
password = System.getenv("PUBLISHING_PASSWORD")
84+
85+
publishingType = "USER_MANAGED"
86+
}
87+
publishAllProjectsProbablyBreakingProjectIsolation()
88+
}
89+
90+
signing {
91+
if (project.hasProperty("sign")) {
92+
useInMemoryPgpKeys(
93+
System.getenv("SIGNING_KEY"),
94+
System.getenv("SIGNING_PASSWORD")
95+
)
96+
sign(publishing.publications["maven"])
97+
}
98+
}
99+
55100
spotless {
56101
format("misc") {
57102
target("**/*.gradle.kts", "**/.gitattributes", "**/.gitignore")

buildSrc/src/main/kotlin/Versioning.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,32 @@ import org.eclipse.jgit.revwalk.RevWalk
33
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
44
import java.io.File
55

6-
object Versioning {
76

8-
private const val UNSPECIFIED = "unspecified"
7+
private const val UNSPECIFIED = "unspecified"
98

10-
/**
11-
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD.
12-
* On error, returns "unspecified".
13-
*
14-
* @param projectRootDir the root directory of the project (containing .git)
15-
*/
16-
fun getSnapshotVersion(projectRootDir: File): String {
17-
return try {
18-
val builder = FileRepositoryBuilder()
19-
.setGitDir(File(projectRootDir, ".git"))
20-
.readEnvironment()
21-
.findGitDir()
9+
/**
10+
* Returns a snapshot version string based on the abbreviated Git commit hash of HEAD.
11+
* On error, returns "unspecified".
12+
*
13+
* @param projectRootDir the root directory of the project (containing .git)
14+
*/
15+
fun getSnapshotVersion(projectRootDir: File): String {
16+
return try {
17+
val builder = FileRepositoryBuilder()
18+
.setGitDir(File(projectRootDir, ".git"))
19+
.readEnvironment()
20+
.findGitDir()
2221

23-
builder.build().use { repository ->
24-
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
22+
builder.build().use { repository ->
23+
val headId = repository.resolve("HEAD") ?: return UNSPECIFIED
2524

26-
RevWalk(repository).use { revWalk ->
27-
val headCommit: RevCommit = revWalk.parseCommit(headId)
28-
headCommit.id.name.substring(0, 7)
29-
}
25+
RevWalk(repository).use { revWalk ->
26+
val headCommit: RevCommit = revWalk.parseCommit(headId)
27+
headCommit.id.name.substring(0, 7)
3028
}
31-
} catch (e: Exception) {
32-
System.err.println("Error determining version: $e")
33-
UNSPECIFIED
3429
}
30+
} catch (e: Exception) {
31+
System.err.println("Error determining version: $e")
32+
UNSPECIFIED
3533
}
3634
}

src/main/java/io/github/malczuuu/problem4j/core/JsonEscape.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package io.github.malczuuu.problem4j.core;
22

3-
import java.util.HashMap;
43
import java.util.Map;
54

65
final class JsonEscape {
76

8-
private static final Map<Character, String> REPLACEMENTS = new HashMap<>();
9-
10-
static {
11-
REPLACEMENTS.put('"', "\\\"");
12-
REPLACEMENTS.put('\\', "\\\\");
13-
REPLACEMENTS.put('\b', "\\b");
14-
REPLACEMENTS.put('\f', "\\f");
15-
REPLACEMENTS.put('\n', "\\n");
16-
REPLACEMENTS.put('\r', "\\r");
17-
REPLACEMENTS.put('\t', "\\t");
18-
REPLACEMENTS.put('/', "\\/");
19-
}
7+
private static final Map<Character, String> REPLACEMENTS =
8+
Map.of(
9+
'"', "\\\"",
10+
'\\', "\\\\",
11+
'\b', "\\b",
12+
'\f', "\\f",
13+
'\n', "\\n",
14+
'\r', "\\r",
15+
'\t', "\\t",
16+
'/', "\\/");
2017

2118
static String escape(String value) {
2219
StringBuilder result = new StringBuilder();

src/main/java/io/github/malczuuu/problem4j/core/Problem.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.github.malczuuu.problem4j.core;
22

3-
import java.io.Serial;
43
import java.io.Serializable;
54
import java.net.URI;
65
import java.util.ArrayList;
7-
import java.util.Arrays;
86
import java.util.Collections;
97
import java.util.HashMap;
108
import java.util.List;
@@ -15,7 +13,7 @@
1513

1614
public class Problem implements Serializable {
1715

18-
@Serial private static final long serialVersionUID = 1L;
16+
private static final long serialVersionUID = 1L;
1917

2018
public static final URI BLANK_TYPE = URI.create("about:blank");
2119
public static final String CONTENT_TYPE = "application/problem+json";
@@ -24,22 +22,6 @@ public static ProblemBuilder builder() {
2422
return new ProblemBuilderImpl();
2523
}
2624

27-
public static ProblemBuilder builder(Problem problem) {
28-
ProblemBuilder builder =
29-
builder()
30-
.type(problem.getType())
31-
.title(problem.getTitle())
32-
.status(problem.getStatus())
33-
.detail(problem.getDetail())
34-
.instance(problem.getInstance());
35-
36-
for (String extension : problem.getExtensions()) {
37-
builder = builder.extension(extension, problem.getExtensionValue(extension));
38-
}
39-
40-
return builder;
41-
}
42-
4325
public static Extension extension(String key, Object value) {
4426
return new Extension(key, value);
4527
}
@@ -85,6 +67,22 @@ public Problem(
8567
this(type, title, status, detail, instance, buildMapFromRawArgs(extensions));
8668
}
8769

70+
public ProblemBuilder toBuilder() {
71+
ProblemBuilder builder =
72+
builder()
73+
.type(getType())
74+
.title(getTitle())
75+
.status(getStatus())
76+
.detail(getDetail())
77+
.instance(getInstance());
78+
79+
for (String extension : getExtensions()) {
80+
builder = builder.extension(extension, getExtensionValue(extension));
81+
}
82+
83+
return builder;
84+
}
85+
8886
private static Map<String, Object> buildMapFromExtensions(Set<Extension> extensions) {
8987
Map<String, Object> map = new HashMap<>(extensions.size());
9088
extensions.forEach(e -> map.put(e.getKey(), e.getValue()));
@@ -107,11 +105,6 @@ private static Map<String, Object> buildMapFromRawArgs(Object[] arguments)
107105

108106
Map<String, Object> map = new HashMap<>(arguments.length / 2);
109107

110-
List<Object> valuesAsList = new ArrayList<>(Arrays.asList(arguments));
111-
if (valuesAsList.size() % 2 != 0) {
112-
valuesAsList.add(valuesAsList.size() - 1);
113-
}
114-
115108
for (int i = 0; i < arguments.length; i += 2) {
116109
String key = arguments[i].toString();
117110
Object value = arguments[i + 1];
@@ -155,7 +148,7 @@ public boolean hasExtension(String extension) {
155148

156149
@Override
157150
public boolean equals(Object o) {
158-
if (o == null || getClass() != o.getClass()) {
151+
if (!(o instanceof Problem)) {
159152
return false;
160153
}
161154
Problem problem = (Problem) o;
@@ -176,23 +169,22 @@ public int hashCode() {
176169
public String toString() {
177170
List<String> lines = new ArrayList<>(4);
178171
if (getType() != null) {
179-
lines.add("\"type\": \"" + quote(getType().toString()) + "\"");
172+
lines.add("\"type\" : \"" + quote(getType().toString()) + "\"");
180173
}
181174
if (getTitle() != null) {
182-
lines.add("\"title\": \"" + quote(getTitle()) + "\"");
175+
lines.add("\"title\" : \"" + quote(getTitle()) + "\"");
183176
}
184-
lines.add("\"status\": " + getStatus());
177+
lines.add("\"status\" : " + getStatus());
185178
if (getDetail() != null) {
186-
lines.add("\"detail\": \"" + quote(getDetail()) + "\"");
179+
lines.add("\"detail\" : \"" + quote(getDetail()) + "\"");
180+
}
181+
if (getInstance() != null) {
182+
lines.add("\"instance\" : \"" + quote(getInstance().toString()) + "\"");
187183
}
188184
return lines.stream().collect(Collectors.joining(", ", "{ ", " }"));
189185
}
190186

191-
/**
192-
* @deprecated method was accidentally made public
193-
*/
194-
@Deprecated(since = "3.2.0")
195-
public static String quote(String string) {
187+
private static String quote(String string) {
196188
return JsonEscape.escape(string);
197189
}
198190

src/main/java/io/github/malczuuu/problem4j/core/ProblemBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.github.malczuuu.problem4j.core;
22

33
import java.net.URI;
4+
import java.util.Collection;
5+
import java.util.Map;
46

57
public interface ProblemBuilder {
68

@@ -22,5 +24,11 @@ public interface ProblemBuilder {
2224

2325
ProblemBuilder extension(String name, Object value);
2426

27+
ProblemBuilder extension(Map<String, Object> extensions);
28+
29+
ProblemBuilder extension(Problem.Extension... extensions);
30+
31+
ProblemBuilder extension(Collection<Problem.Extension> extensions);
32+
2533
Problem build();
2634
}

0 commit comments

Comments
 (0)