Skip to content

Commit 21f97ef

Browse files
authored
fix: build failing on Windows (#4484) (#4504)
Change path handling to correctly handle Windows pathnames. Change line ending handling from using `System.lineSeparator` to using the regex \R to treat all unicode line ending character sequences as the line endings. Change unit tests that compared certificates read from file, to ignore the line ending characters, so differences in line ending did not break the test. Refs: #4484
1 parent 9a8329e commit 21f97ef

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

core/common/connector-core/src/test/java/org/eclipse/edc/connector/core/LocalPublicKeyDefaultExtensionTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.jupiter.api.Test;
2727
import org.junit.jupiter.api.extension.ExtendWith;
2828

29+
import java.nio.file.Paths;
2930
import java.security.PublicKey;
3031
import java.util.Map;
3132

@@ -73,7 +74,7 @@ void localPublicKeyService_withPathConfig(LocalPublicKeyDefaultExtension extensi
7374
var value = TestUtils.getResourceFileContentAsString("rsa_2048.pem");
7475
var keys = Map.of(
7576
"key1.id", "key1",
76-
"key1.path", path.getPath());
77+
"key1.path", Paths.get(path).toString());
7778

7879
when(keyParserRegistry.parsePublic(value)).thenReturn(Result.success(mock(PublicKey.class)));
7980
when(context.getConfig(EDC_PUBLIC_KEYS_PREFIX)).thenReturn(ConfigFactory.fromMap(keys));

core/common/junit/src/main/java/org/eclipse/edc/junit/extensions/ClasspathReader.java

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class ClasspathReader {
4040
*/
4141
public static URL[] classpathFor(String... modules) {
4242
try {
43+
if (modules.length == 0) {
44+
return new URL[0];
45+
}
4346
// Run a Gradle custom task to determine the runtime classpath of the module to run
4447
var printClasspath = Arrays.stream(modules).map(it -> it + ":printClasspath");
4548
var commandStream = Stream.of(GRADLE_WRAPPER.getCanonicalPath(), "-q");

core/common/lib/keys-lib/src/main/java/org/eclipse/edc/keys/VaultCertificateResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public VaultCertificateResolver(@NotNull Vault vault) {
4747
}
4848

4949
try {
50-
var encoded = certificateRepresentation.replace(HEADER, "").replaceAll(System.lineSeparator(), "").replace(FOOTER, "");
50+
var encoded = certificateRepresentation.replace(HEADER, "").replaceAll("\\R", "").replace(FOOTER, "");
5151
CertificateFactory fact = CertificateFactory.getInstance("X.509");
5252
return (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(Base64.getDecoder().decode(encoded.getBytes())));
5353
} catch (GeneralSecurityException | IllegalArgumentException e) {

core/common/lib/keys-lib/src/test/java/org/eclipse/edc/keys/VaultCertificateResolverTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void resolveCertificate() throws RuntimeException, IOException {
5858
var pemReceived = convertCertificateToPem(certificate);
5959

6060
verify(vault, times(1)).resolveSecret(KEY);
61-
assertThat(pemReceived).isEqualTo(pemExpected);
61+
assertThat(pemReceived.split("\\R")).isEqualTo(pemExpected.split("\\R"));
6262
}
6363

6464
@Test

extensions/common/iam/oauth2/oauth2-core/src/test/java/org/eclipse/edc/iam/oauth2/jwt/X509CertificateDecoratorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class X509CertificateDecoratorTest {
3636
private static X509Certificate createCertificate() throws CertificateException, IOException {
3737
var classloader = Thread.currentThread().getContextClassLoader();
3838
var pem = new String(Objects.requireNonNull(classloader.getResourceAsStream(TEST_CERT_FILE)).readAllBytes());
39-
var encoded = pem.replace(HEADER, "").replaceAll(System.lineSeparator(), "").replace(FOOTER, "");
39+
var encoded = pem.replace(HEADER, "").replaceAll("\\R", "").replace(FOOTER, "");
4040
CertificateFactory fact = CertificateFactory.getInstance("X.509");
4141
return (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(Base64.getDecoder().decode(encoded.getBytes())));
4242
}

0 commit comments

Comments
 (0)