Skip to content

Commit 49f9e1a

Browse files
committed
Upgrades to JDK 25
- Replaces gpg-plugin by sign-maven-plugin to sign artifact for Maven Central publishing, so that it does not depend on local gpg software. - That fix the warning: Parameter 'passphrase' (user property 'gpg.passphrase') is deprecated: Do not use this configuration, it may leak sensitive information. Rely on gpg-agent or env variables instead. - It also fix the GitHub Action deploy failure: gpg: signing failed: No pinentry - Updates deploy.yml, removing unnecessary signing key obtention step (the key is gotten from the secrets) - Removes Lombok Signed-off-by: Manoel Campos <[email protected]>
1 parent f66a018 commit 49f9e1a

File tree

9 files changed

+61
-134
lines changed

9 files changed

+61
-134
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@ jobs:
1818
server-username: MAVEN_USERNAME
1919
server-password: MAVEN_PASSWORD
2020
cache: 'maven'
21-
- id: install-secret-key
22-
name: Install gpg secret key
23-
run: |
24-
# The key to assing to OSSRH_GPG_SECRET_KEY can be got running on your PC: gpg -a --export-secret-keys KEY_ID
25-
# The KEY_ID can be got from the GPG Keyhain.
26-
# The OSSRH_GPG_SECRET_KEY_PASSWORD is in macOS keychain (GPG Key password)
27-
# OSSRH_USERNAME and OSSRH_TOKEN (password) are available at ~/.m2/settings.xml
28-
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
29-
gpg --list-keys
3021
- name: Publish package
31-
run: mvn --no-transfer-progress -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} --batch-mode -Psonatype deploy
22+
run: SIGN_KEY="${{ secrets.OSSRH_GPG_SIGN_KEY }}" mvn --no-transfer-progress --batch-mode -Psonatype deploy
3223
env:
3324
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
3425
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# A Java client to get real random integers from https://random.org [![build](https://github.com/manoelcampos/random-org-java-client/actions/workflows/build.yml/badge.svg)](https://github.com/manoelcampos/random-org-java-client/actions/workflows/build.yml) [![javadoc](https://javadoc.io/badge2/com.manoelcampos/random-org-client/javadoc.svg)](https://javadoc.io/doc/com.manoelcampos/random-org-client)
1+
# A Java client to get real random integers from https://random.org [![build](https://github.com/manoelcampos/random-org-java-client/actions/workflows/build.yml/badge.svg)](https://github.com/manoelcampos/random-org-java-client/actions/workflows/build.yml) [![javadoc](https://javadoc.io/badge2/com.manoelcampos/random-org-client/javadoc.svg)](https://javadoc.io/doc/com.manoelcampos/random-org-client) [![Maven Central](https://img.shields.io/maven-central/v/io.github.manoelcampos/random-org-client.svg?label=Maven%20Central)](https://central.sonatype.com/search?q=random-org-client&namespace=io.github.manoelcampos)
22

33
## How to use
44

pom.xml

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.manoelcampos</groupId>
88
<artifactId>random-org-client</artifactId>
9-
<version>1.1.3</version>
9+
<version>1.1.5</version>
1010
<name>random.org client</name>
1111
<url>https://github.com/manoelcampos/random-org-java-client</url>
1212
<description>
@@ -15,6 +15,11 @@
1515

1616
<inceptionYear>2023</inceptionYear>
1717

18+
<properties>
19+
<maven.compiler.release>25</maven.compiler.release>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
</properties>
22+
1823
<licenses>
1924
<license>
2025
<name>GPLv3</name>
@@ -42,12 +47,6 @@
4247
<system>GitHub Issues</system>
4348
</issueManagement>
4449

45-
<properties>
46-
<maven.compiler.release>25</maven.compiler.release>
47-
<lombok.version>1.18.42</lombok.version>
48-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
49-
</properties>
50-
5150
<profiles>
5251
<profile>
5352
<id>default</id>
@@ -56,20 +55,6 @@
5655
</activation>
5756
<build>
5857
<plugins>
59-
<plugin>
60-
<groupId>org.apache.maven.plugins</groupId>
61-
<artifactId>maven-compiler-plugin</artifactId>
62-
<configuration>
63-
<annotationProcessorPaths>
64-
<path>
65-
<groupId>org.projectlombok</groupId>
66-
<artifactId>lombok</artifactId>
67-
<version>${lombok.version}</version>
68-
</path>
69-
</annotationProcessorPaths>
70-
</configuration>
71-
</plugin>
72-
7358
<plugin>
7459
<groupId>org.apache.maven.plugins</groupId>
7560
<artifactId>maven-surefire-plugin</artifactId>
@@ -157,28 +142,18 @@
157142
</plugin>
158143

159144
<!--
160-
Signs the generated jar using GPG, as required for deploying at the Maven Central.
145+
Signs the generated jar using, as required for deploying at the Maven Central.
161146
Configurations are defined into the local repo settings.xml
162147
-->
163148
<plugin>
164-
<groupId>org.apache.maven.plugins</groupId>
165-
<artifactId>maven-gpg-plugin</artifactId>
166-
<version>3.2.8</version>
149+
<groupId>org.simplify4u.plugins</groupId>
150+
<artifactId>sign-maven-plugin</artifactId>
151+
<version>1.1.0</version>
167152
<executions>
168153
<execution>
169-
<id>sign-artifacts</id>
170-
<phase>verify</phase>
171154
<goals>
172155
<goal>sign</goal>
173156
</goals>
174-
<configuration>
175-
<!-- Prevent `gpg` from using pinentry programs
176-
and avoid "gpg: signing failed: Inappropriate ioctl for device" error. -->
177-
<gpgArguments>
178-
<arg>--pinentry-mode</arg>
179-
<arg>loopback</arg>
180-
</gpgArguments>
181-
</configuration>
182157
</execution>
183158
</executions>
184159
</plugin>
@@ -238,11 +213,5 @@
238213
<artifactId>jackson-datatype-jsr310</artifactId>
239214
<version>2.19.1</version>
240215
</dependency>
241-
<dependency>
242-
<groupId>org.projectlombok</groupId>
243-
<artifactId>lombok</artifactId>
244-
<version>${lombok.version}</version>
245-
<scope>provided</scope>
246-
</dependency>
247216
</dependencies>
248217
</project>
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.manoelcampos.randomorg;
22

3-
import lombok.AllArgsConstructor;
4-
import lombok.Getter;
5-
import lombok.Setter;
6-
73
/**
8-
* @author Manoel Campos da Silva Filho
4+
* @author Manoel Campos da Silva Filho
95
*/
10-
@Getter @Setter @AllArgsConstructor
11-
class GenerateIntegersRequestData {
6+
record GenerateIntegersRequestData(int id, String jsonrpc, String method, GenerateIntegersRequestParams params)
7+
{
128
public static final String API_PATH = "https://api.random.org/json-rpc/4/invoke";
13-
private final int id = 42;
14-
private final String jsonrpc = RandomOrgClient.JSONRPC_VERSION;
15-
private final String method = "generateIntegers";
16-
private final GenerateIntegersRequestParams params;
9+
10+
public GenerateIntegersRequestData(GenerateIntegersRequestParams params, final String apiKey) {
11+
this(params.of(apiKey));
12+
}
13+
14+
public GenerateIntegersRequestData(GenerateIntegersRequestParams params) {
15+
this(42, RandomOrgClient.JSONRPC_VERSION, "generateIntegers", params);
16+
}
1717
}
Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
package com.manoelcampos.randomorg;
22

3-
import lombok.AccessLevel;
4-
import lombok.Getter;
5-
import lombok.Setter;
6-
import lombok.experimental.Accessors;
7-
83
/**
9-
* @author Manoel Campos da Silva Filho
4+
* @param n The number of random integers to generate
5+
* @param min The minimum value for a generated random int.
6+
* @param max The maximum value for a generated random int.
7+
* @param replacement Enable generation of duplicated integers (true) or not (false).
8+
* @author Manoel Campos da Silva Filho
109
*/
11-
@Getter @Setter @Accessors(chain = true)
12-
class GenerateIntegersRequestParams {
10+
record GenerateIntegersRequestParams(int n, int min, int max, boolean replacement, String apiKey)
11+
{
1312
public static final int MIN_VALUE = -100000000;
14-
public static final int MAX_VALUE = 100000000;
15-
16-
@Setter(AccessLevel.PROTECTED)
17-
private String apiKey;
13+
public static final int MAX_VALUE = 100000000;
1814

19-
/** The number of random integers to generate */
20-
private final int n;
15+
GenerateIntegersRequestParams {
16+
if(n <= 0)
17+
throw new IllegalArgumentException("n must be greater than 0");
2118

22-
/** The minimum value for a generated random int. */
23-
private final int min;
19+
if(min < GenerateIntegersRequestParams.MIN_VALUE)
20+
throw new IllegalArgumentException("minValue cannot be smaller than " + MIN_VALUE);
2421

25-
/** The maximum value for a generated random int. */
26-
private final int max;
22+
if(max > GenerateIntegersRequestParams.MAX_VALUE)
23+
throw new IllegalArgumentException("minValue cannot be higher than " + MAX_VALUE);
24+
}
2725

2826
/**
29-
* Enable generation of duplicated integers (true) or not (false).
27+
* Clones the object, copying all fields from the source object,
28+
* except the {@link #apiKey}, that is set to the informed value.
29+
*
30+
* @param apiKey the API key to set in the new object
3031
*/
31-
private boolean replacement;
32+
GenerateIntegersRequestParams of(final String apiKey){
33+
return new GenerateIntegersRequestParams(n, min, max, replacement, apiKey);
34+
}
3235

3336
/**
3437
* Instantiates a GenerateIntegersRequestParams that indicates to
@@ -64,27 +67,7 @@ class GenerateIntegersRequestParams {
6467
this(n, min, max, true);
6568
}
6669

67-
/**
68-
* Instantiates a GenerateIntegersRequestParams that indicates to
69-
* generate random integers between a given [min .. max] interval.
70-
* @param n the number of random integers to generate
71-
* @param min the minimum value for a generated random int
72-
* @param max the maximum value for a generated random int
73-
* @param replacement Enable generation of duplicated integers (true) or not (false).
74-
*/
75-
GenerateIntegersRequestParams(final int n, final int min, final int max, final boolean replacement) {
76-
if(n <= 0)
77-
throw new IllegalArgumentException("n must be greater than 0");
78-
79-
if(min < GenerateIntegersRequestParams.MIN_VALUE)
80-
throw new IllegalArgumentException("minValue cannot be smaller than " + MIN_VALUE);
81-
82-
if(max > GenerateIntegersRequestParams.MAX_VALUE)
83-
throw new IllegalArgumentException("minValue cannot be higher than " + MAX_VALUE);
84-
85-
this.n = n;
86-
this.min = min;
87-
this.max = max;
88-
this.replacement = replacement;
70+
GenerateIntegersRequestParams(final int n, final int min, final int max, final boolean replacement){
71+
this(n, min, max, replacement, "");
8972
}
9073
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package com.manoelcampos.randomorg;
22

3-
import lombok.Getter;
4-
import lombok.Setter;
5-
63
/**
7-
* @author Manoel Campos da Silva Filho
4+
* @author Manoel Campos da Silva Filho
85
*/
9-
@Getter @Setter
10-
class GenerateIntegersResponse {
11-
private String jsonrpc;
12-
private int id;
13-
private Result result;
6+
//@JsonIgnoreProperties(ignoreUnknown = true)
7+
record GenerateIntegersResponse(String jsonrpc, int id, Result result, Object error) {
148
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package com.manoelcampos.randomorg;
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
4-
import lombok.Getter;
5-
import lombok.Setter;
64

75
import java.time.LocalDateTime;
86

97
/**
10-
* @author Manoel Campos da Silva Filho
8+
* @author Manoel Campos da Silva Filho
119
*/
12-
@Getter @Setter
13-
class RandomData {
14-
private int[] data;
10+
record RandomData(
11+
int[] data,
1512

1613
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss'Z'")
17-
private LocalDateTime completionTime;
14+
LocalDateTime completionTime)
15+
{
1816
}

src/main/java/com/manoelcampos/randomorg/RandomOrgClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public int[] generateNonDuplicatedIntegers(final int n, final int minValue, fina
7575
}
7676

7777
private int[] generateIntegers(final GenerateIntegersRequestParams params) {
78-
final var data = new GenerateIntegersRequestData(params.setApiKey(API_KEY));
78+
final var data = new GenerateIntegersRequestData(params, API_KEY);
7979
try {
8080
final var json = objectMapper.writeValueAsString(data);
8181
final var req =
@@ -87,7 +87,8 @@ private int[] generateIntegers(final GenerateIntegersRequestParams params) {
8787

8888
final String res = client.send(req, HttpResponse.BodyHandlers.ofString()).body();
8989
final var generateIntegersResponse = objectMapper.readValue(res, GenerateIntegersResponse.class);
90-
return generateIntegersResponse.getResult().getRandom().getData();
90+
System.out.println(generateIntegersResponse);
91+
return generateIntegersResponse.result().random().data();
9192
} catch (URISyntaxException | InterruptedException | IOException e) {
9293
throw new RuntimeException(e);
9394
}
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
package com.manoelcampos.randomorg;
22

3-
import lombok.Getter;
4-
import lombok.Setter;
5-
63
/**
7-
* @author Manoel Campos da Silva Filho
4+
* @author Manoel Campos da Silva Filho
85
*/
9-
@Getter @Setter
10-
class Result {
11-
private long bitsUsed;
12-
private long bitsLeft;
13-
private int requestsLeft;
14-
private int advisoryDelay;
15-
private RandomData random;
6+
record Result(long bitsUsed, long bitsLeft, int requestsLeft, int advisoryDelay, RandomData random) {
167
}

0 commit comments

Comments
 (0)