Skip to content

Commit

Permalink
Merge pull request #21 from Emkas/java-11
Browse files Browse the repository at this point in the history
Full compatibility with Java 11
  • Loading branch information
mkurzydlowski authored Jul 30, 2024
2 parents 312b74c + 1ca037a commit 054b9d3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release notes
=============

1.10.0
------

*Released on 2024-07-31*

* Require at least Java 8
* Java 11 compatibility without any hidden dependencies
* Removed depracated getters in `ClientImpl`

1.9.1
-----
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tools and specifications [here][develhub].
Installation and Documentation
------------------------------

Requires **Java 7 SE**. Apart from that, and a tiny [SLF4J](http://slf4j.org/)
Requires at least **Java 8 SE**. Apart from that, and a tiny [SLF4J](http://slf4j.org/)
API library, *no other dependencies are required*. The resulting JAR is only
`49kB` in size (as of version `1.8.0`).

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>eu.erasmuswithoutpaper</groupId>
<artifactId>ewp-registry-client</artifactId>
<version>1.9.1</version>
<version>1.10.0</version>
<packaging>jar</packaging>

<name>EWP Registry Client</name>
Expand Down Expand Up @@ -54,7 +54,7 @@
</distributionManagement>

<properties>
<java.version>1.7</java.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -83,9 +83,9 @@
<!-- Scope: TEST -->

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
Expand All @@ -20,7 +21,6 @@
import java.util.Map;
import java.util.Set;

import javax.xml.bind.DatatypeConverter;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.xpath.XPath;
Expand Down Expand Up @@ -399,7 +399,7 @@ public Iterator<String> getPrefixes(String namespaceUri) {

for (Element keyElem : keyElems) {
String fingerprint = keyElem.getAttribute("sha-256");
byte[] data = DatatypeConverter.parseBase64Binary(keyElem.getTextContent());
byte[] data = Base64.getMimeDecoder().decode(keyElem.getTextContent());
X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
RSAPublicKey value;
try {
Expand Down Expand Up @@ -834,6 +834,8 @@ public boolean isStale() {
}

static class CatalogueParserException extends RegistryClientException {
private static final long serialVersionUID = 8536812850006770409L;

CatalogueParserException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Http200RegistryResponse extends RegistryResponse {
* Thrown by {@link Http200RegistryResponse#deserialize(byte[])} when the raw data could not be
* deserialized into a valid {@link Http200RegistryResponse} object.
*/
@SuppressWarnings("serial")
static class CouldNotDeserialize extends Exception {
private static final long serialVersionUID = -3124583265761204268L;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ public ClientImplOptions() {
this.timeBetweenRetries = 180000;
}

/**
* @return Same as {@link #isAutoRefreshing()}.
* @deprecated As of release 1.2.0, replaced by {@link #isAutoRefreshing()}.
*/
@Deprecated
public boolean getAutoRefreshing() { // NOPMD
return this.isAutoRefreshing();
}

/**
* @return The {@link CatalogueFetcher} instance which will be used by the client. See
* {@link #setCatalogueFetcher(CatalogueFetcher)}.
Expand Down Expand Up @@ -75,15 +66,6 @@ public Map<String, byte[]> getPersistentCacheMap() {
return this.persistentCacheMap;
}

/**
* @return The cache instance to be used. See {@link #setPersistentCacheMap(Map)}.
* @deprecated As of release 1.4.0, replaced by {@link #getPersistentCacheMap()}.
*/
@Deprecated
public Map<String, byte[]> getPersistentCacheProvider() {
return this.persistentCacheMap;
}

/**
* Return the minimum staleness of the catalogue, above which {@link ClientImpl} will begin to
* report warning-level messages in its logs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public interface RegistryClient extends AutoCloseable {
*
* @since 1.0.0
*/
@SuppressWarnings("serial")
class AssertionFailedException extends RegistryClientException {
private static final long serialVersionUID = 656646825926200510L;

public AssertionFailedException(String message) {
super(message);
Expand All @@ -44,8 +44,8 @@ public AssertionFailedException(String message) {
*
* @since 1.4.0
*/
@SuppressWarnings("serial")
class InvalidApiEntryElement extends RegistryClientRuntimeException {
private static final long serialVersionUID = 77972919923555248L;

public InvalidApiEntryElement() {
super();
Expand Down Expand Up @@ -103,8 +103,8 @@ protected RegistryClientException(String message, Exception cause) {
*
* @since 1.0.0
*/
@SuppressWarnings("serial")
abstract class RegistryClientRuntimeException extends RuntimeException {
private static final long serialVersionUID = -415231440678898545L;

public RegistryClientRuntimeException() {
super();
Expand All @@ -130,8 +130,8 @@ public RegistryClientRuntimeException(RuntimeException cause) {
*
* @since 1.6.0
*/
@SuppressWarnings("serial")
class StaleApiEntryElement extends InvalidApiEntryElement {
private static final long serialVersionUID = -3103542220915317349L;

public StaleApiEntryElement() {
super();
Expand Down Expand Up @@ -164,8 +164,8 @@ public StaleApiEntryElement(RuntimeException cause) {
*
* @since 1.0.0
*/
@SuppressWarnings("serial")
class UnacceptableStalenessException extends RegistryClientRuntimeException {
private static final long serialVersionUID = 4562127026735066789L;
}

/**
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/eu/erasmuswithoutpaper/registryclient/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Locale;
import java.util.RandomAccess;

import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -94,7 +93,7 @@ static String extractFingerprint(Certificate cert) {
throw new RuntimeException(e);
}
byte[] binDigest = md.digest();
return DatatypeConverter.printHexBinary(binDigest).toLowerCase(Locale.ENGLISH);
return printHexBinary(binDigest).toLowerCase(Locale.ENGLISH);
}

static String extractFingerprint(RSAPublicKey publicKey) {
Expand All @@ -106,7 +105,20 @@ static String extractFingerprint(RSAPublicKey publicKey) {
}
md.update(publicKey.getEncoded());
byte[] binDigest = md.digest();
return DatatypeConverter.printHexBinary(binDigest).toLowerCase(Locale.ENGLISH);
return printHexBinary(binDigest).toLowerCase(Locale.ENGLISH);
}

private static final char[] hexCode = "0123456789ABCDEF".toCharArray();

// javax.xml.bind.DatatypeConverter copy so that code can work with JDK >=11 without any
// additional jar (DatatypeConverter was removed in JDK 11 and Deprecated since JDK 9)
private static String printHexBinary(byte[] data) {
StringBuilder builder = new StringBuilder(data.length * 2);
for (byte b : data) {
builder.append(hexCode[(b >> 4) & 0xF]);
builder.append(hexCode[(b & 0xF)]);
}
return builder.toString();
}

/**
Expand Down

0 comments on commit 054b9d3

Please sign in to comment.