From 59342ce249e16fb8e720884dad980ce79369c790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0irok=C3=BD?= Date: Tue, 16 May 2023 11:06:05 +0200 Subject: [PATCH] [MNG-7743] Make the build work on JDK 20 (#1065) * [MNG-7743] Make the build work on JDK 20 * the behaviour before the fix was already pretty confusing. JDK 19 and older do not check the presense of '{' in the constructor, so the URL object got created, but when converting to file the result would be e.g. '/../../src/test/remote-repo' which is completely wrong. But it seems the affected tests did not really care, as all of them were passing * Remove forgotten println Co-authored-by: Yeikel * Test with latest JDK * Do not run ITs with jdk 20, but just the "build itself" --------- Co-authored-by: Yeikel Co-authored-by: Guillaume Nodet --- .github/workflows/maven_build_itself.yml | 2 +- .../repository/TestRepositoryConnector.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven_build_itself.yml b/.github/workflows/maven_build_itself.yml index 75758de60e..38a16f0aca 100644 --- a/.github/workflows/maven_build_itself.yml +++ b/.github/workflows/maven_build_itself.yml @@ -31,7 +31,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - java: [8, 17] + java: [8, 17, 20] fail-fast: false runs-on: ${{ matrix.os }} diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java index 9b8214121c..19682633a7 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java @@ -50,13 +50,20 @@ public class TestRepositoryConnector implements RepositoryConnector { public TestRepositoryConnector(RemoteRepository repository) { this.repository = repository; - try { - URL url = new URL(repository.getUrl()); - if ("file".equals(url.getProtocol())) { - basedir = new File(url.getPath()); + String repositoryUrl = repository.getUrl(); + if (repositoryUrl.contains("${")) { + // the repository url contains unresolved properties and getting the basedir is not possible + // in JDK 20+ 'new URL(string)' will fail if the string contains a curly brace + this.basedir = null; + } else { + try { + URL url = new URL(repository.getUrl()); + if ("file".equals(url.getProtocol())) { + basedir = new File(url.getPath()); + } + } catch (MalformedURLException e) { + throw new IllegalStateException(e); } - } catch (MalformedURLException e) { - throw new IllegalStateException(e); } }