From 0a71cd3dceac41832a033ec1e196dc10b1c73101 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 7 Nov 2023 22:48:02 +0100 Subject: [PATCH 1/5] [MRESOLVER-426] Make some HTTP configuration shared Also, make possible some newer java.net.http.HttpClient options to be applied. --- https://issues.apache.org/jira/browse/MRESOLVER-426 --- .../aether/ConfigurationProperties.java | 38 +++++++++ .../transport/http/HttpTransporter.java | 35 ++++---- .../transport/http/HttpTransporterTest.java | 6 +- .../transport/jdk/JdkHttpTransporter.java | 2 + .../jdk/JdkHttpTransporterCustomizer.java | 35 ++++++++ .../maven-resolver-transport-jdk-19/pom.xml | 85 +++++++++++++++++++ .../jdk/JdkHttpTransporterCustomizer.java | 65 ++++++++++++++ .../maven-resolver-transport-jdk/pom.xml | 19 +++++ maven-resolver-transport-jdk-parent/pom.xml | 1 + 9 files changed, 266 insertions(+), 20 deletions(-) create mode 100644 maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java create mode 100644 maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/pom.xml create mode 100644 maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java b/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java index 279e707cd..959d28766 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java @@ -274,6 +274,44 @@ public final class ConfigurationProperties { */ public static final int DEFAULT_HTTP_MAX_CONNECTIONS_PER_ROUTE = 50; + /** + * The local address (interface) to use with HTTP transport. Not all transport supports this option. + * + * @since 2.0.0 + */ + public static final String HTTP_LOCAL_ADDRESS = PREFIX_CONNECTOR + "http.localAddress"; + + /** + * Boolean flag should the HTTP transport support WebDAV remote. Not all transport support this option. + * + * @see #DEFAULT_HTTP_SUPPORT_WEBDAV + * @since 2.0.0 (moved out from maven-resolver-transport-http). + */ + public static final String HTTP_SUPPORT_WEBDAV = PREFIX_CONNECTOR + "http.supportWebDav"; + + /** + * Default value to use if {@link #HTTP_SUPPORT_WEBDAV} is not set: {@code false}. + * + * @since 2.0.0 + */ + public static final boolean DEFAULT_HTTP_SUPPORT_WEBDAV = false; + + /** + * Boolean flag should the HTTP transport use preemptive-auth for PUT requests. Not all transport support this + * option. + * + * @see #DEFAULT_HTTP_PREEMPTIVE_PUT_AUTH + * @since 2.0.0 (moved out from maven-resolver-transport-http). + */ + public static final String HTTP_PREEMPTIVE_PUT_AUTH = PREFIX_CONNECTOR + "http.preemptivePutAuth"; + + /** + * Default value if {@link #HTTP_PREEMPTIVE_PUT_AUTH} is not set: {@code true}. + * + * @since 2.0.0 + */ + public static final boolean DEFAULT_HTTP_PREEMPTIVE_PUT_AUTH = true; + /** * The mode that sets HTTPS transport "security mode": to ignore any SSL errors (certificate validity checks, * hostname verification). The default value is {@link #HTTPS_SECURITY_MODE_DEFAULT}. diff --git a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java index 870204747..9bd588986 100644 --- a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java +++ b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java @@ -106,12 +106,6 @@ */ final class HttpTransporter extends AbstractTransporter { - static final String BIND_ADDRESS = "aether.connector.bind.address"; - - static final String SUPPORT_WEBDAV = "aether.connector.http.supportWebDav"; - - static final String PREEMPTIVE_PUT_AUTH = "aether.connector.http.preemptivePutAuth"; - static final String USE_SYSTEM_PROPERTIES = "aether.connector.http.useSystemProperties"; static final String HTTP_RETRY_HANDLER_NAME = "aether.connector.http.retryHandler.name"; @@ -211,11 +205,16 @@ final class HttpTransporter extends AbstractTransporter { ConfigurationProperties.DEFAULT_HTTP_PREEMPTIVE_AUTH, ConfigurationProperties.HTTP_PREEMPTIVE_AUTH + "." + repository.getId(), ConfigurationProperties.HTTP_PREEMPTIVE_AUTH); - this.preemptivePutAuth = // defaults to true: Wagon does same - ConfigUtils.getBoolean( - session, true, PREEMPTIVE_PUT_AUTH + "." + repository.getId(), PREEMPTIVE_PUT_AUTH); - this.supportWebDav = // defaults to false: who needs it will enable it - ConfigUtils.getBoolean(session, false, SUPPORT_WEBDAV + "." + repository.getId(), SUPPORT_WEBDAV); + this.preemptivePutAuth = ConfigUtils.getBoolean( + session, + ConfigurationProperties.DEFAULT_HTTP_PREEMPTIVE_PUT_AUTH, + ConfigurationProperties.HTTP_PREEMPTIVE_PUT_AUTH + "." + repository.getId(), + ConfigurationProperties.HTTP_PREEMPTIVE_PUT_AUTH); + this.supportWebDav = ConfigUtils.getBoolean( + session, + ConfigurationProperties.DEFAULT_HTTP_SUPPORT_WEBDAV, + ConfigurationProperties.HTTP_SUPPORT_WEBDAV + "." + repository.getId(), + ConfigurationProperties.HTTP_SUPPORT_WEBDAV); String credentialEncoding = ConfigUtils.getString( session, ConfigurationProperties.DEFAULT_HTTP_CREDENTIAL_ENCODING, @@ -277,7 +276,7 @@ final class HttpTransporter extends AbstractTransporter { RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(connectTimeout) .setConnectionRequestTimeout(connectTimeout) - .setLocalAddress(getBindAddress(session, repository)) + .setLocalAddress(getHttpLocalAddress(session, repository)) .setSocketTimeout(requestTimeout) .build(); @@ -338,9 +337,12 @@ final class HttpTransporter extends AbstractTransporter { /** * Returns non-null {@link InetAddress} if set in configuration, {@code null} otherwise. */ - private InetAddress getBindAddress(RepositorySystemSession session, RemoteRepository repository) { - String bindAddress = - ConfigUtils.getString(session, null, BIND_ADDRESS + "." + repository.getId(), BIND_ADDRESS); + private InetAddress getHttpLocalAddress(RepositorySystemSession session, RemoteRepository repository) { + String bindAddress = ConfigUtils.getString( + session, + null, + ConfigurationProperties.HTTP_LOCAL_ADDRESS + "." + repository.getId(), + ConfigurationProperties.HTTP_LOCAL_ADDRESS); if (bindAddress == null) { return null; } @@ -591,7 +593,7 @@ private T commonHeaders(T request) { } @SuppressWarnings("checkstyle:magicnumber") - private T resume(T request, GetTask task) { + private void resume(T request, GetTask task) { long resumeOffset = task.getResumeOffset(); if (resumeOffset > 0L && task.getDataFile() != null) { request.setHeader(HttpHeaders.RANGE, "bytes=" + resumeOffset + '-'); @@ -600,7 +602,6 @@ private T resume(T request, GetTask task) { DateUtils.formatDate(new Date(task.getDataFile().lastModified() - 60L * 1000L))); request.setHeader(HttpHeaders.ACCEPT_ENCODING, "identity"); } - return request; } @SuppressWarnings("checkstyle:magicnumber") diff --git a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java index 1226e7cc5..1764a6a5d 100644 --- a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java +++ b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java @@ -687,7 +687,7 @@ void testPut_Authenticated_ExpectContinue() throws Exception { @Test void testPut_Authenticated_ExpectContinueBroken() throws Exception { // this makes OPTIONS recover, and have only 1 PUT (startedCount=1 as OPTIONS is not counted) - session.setConfigProperty(HttpTransporter.SUPPORT_WEBDAV, true); + session.setConfigProperty(ConfigurationProperties.HTTP_SUPPORT_WEBDAV, true); httpServer.setAuthentication("testuser", "testpass"); httpServer.setExpectSupport(HttpServer.ExpectContinue.BROKEN); auth = new AuthenticationBuilder() @@ -828,7 +828,7 @@ void testPut_SSL() throws Exception { @Test void testPut_WebDav() throws Exception { httpServer.setWebDav(true); - session.setConfigProperty(HttpTransporter.SUPPORT_WEBDAV, true); + session.setConfigProperty(ConfigurationProperties.HTTP_SUPPORT_WEBDAV, true); newTransporter(httpServer.getHttpUrl()); RecordingTransportListener listener = new RecordingTransportListener(); @@ -943,7 +943,7 @@ void testPut_PreemptiveIsDefault() throws Exception { @Test void testPut_AuthCache() throws Exception { - session.setConfigProperty(HttpTransporter.PREEMPTIVE_PUT_AUTH, false); + session.setConfigProperty(ConfigurationProperties.HTTP_PREEMPTIVE_PUT_AUTH, false); httpServer.setAuthentication("testuser", "testpass"); auth = new AuthenticationBuilder() .addUsername("testuser") diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java index 2200aa870..71b355f83 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java @@ -389,6 +389,8 @@ private static HttpClient getOrCreateClient(RepositorySystemSession session, Rem .connectTimeout(Duration.ofMillis(connectTimeout)) .sslContext(sslContext); + JdkHttpTransporterCustomizer.customize(session, repository, builder); + if (repository.getProxy() != null) { ProxySelector proxy = ProxySelector.of(new InetSocketAddress( repository.getProxy().getHost(), diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java new file mode 100644 index 000000000..790d5a31a --- /dev/null +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.eclipse.aether.transport.jdk; + +import java.net.http.HttpClient; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; + +/** + * JDK Transport customizer. + * + * @since TBD + */ +final class JdkHttpTransporterCustomizer { + private JdkHttpTransporterCustomizer() {} + + static void customize(RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) {} +} diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/pom.xml new file mode 100644 index 000000000..4bbfc270a --- /dev/null +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + + org.apache.maven.resolver + maven-resolver-transport-jdk-parent + 2.0.0-SNAPSHOT + + + maven-resolver-transport-jdk-19 + jar + + Maven Artifact Resolver Transport JDK (19) + Maven Artifact Transport JDK Java 11+. + + + org.apache.maven.resolver.transport.jdk + ${Automatic-Module-Name} + + 19 + + + + + org.apache.maven.resolver + maven-resolver-api + + + org.apache.maven.resolver + maven-resolver-spi + + + org.apache.maven.resolver + maven-resolver-util + + + javax.inject + javax.inject + provided + true + + + + + + + org.eclipse.sisu + sisu-maven-plugin + + + biz.aQute.bnd + bnd-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java new file mode 100644 index 000000000..7186b1163 --- /dev/null +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.eclipse.aether.transport.jdk; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.net.http.HttpClient; + +import org.eclipse.aether.ConfigurationProperties; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.ConfigUtils; + +/** + * JDK Transport customizer. + * + * @since TBD + */ +final class JdkHttpTransporterCustomizer { + private JdkHttpTransporterCustomizer() {} + + static void customize(RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) { + InetAddress localAddress = getHttpLocalAddress(session, repository); + if (localAddress != null) { + builder.localAddress(localAddress); + } + } + + /** + * Returns non-null {@link InetAddress} if set in configuration, {@code null} otherwise. + */ + private static InetAddress getHttpLocalAddress(RepositorySystemSession session, RemoteRepository repository) { + String bindAddress = ConfigUtils.getString( + session, + null, + ConfigurationProperties.HTTP_LOCAL_ADDRESS + "." + repository.getId(), + ConfigurationProperties.HTTP_LOCAL_ADDRESS); + if (bindAddress == null) { + return null; + } + try { + return InetAddress.getByName(bindAddress); + } catch (UnknownHostException uhe) { + throw new IllegalArgumentException( + "Given bind address (" + bindAddress + ") cannot be resolved for remote repository " + repository, + uhe); + } + } +} diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml index f6b32f9a7..923c704a0 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml @@ -108,6 +108,25 @@ + + java19 + + unpack + + generate-resources + + + + org.apache.maven.resolver + maven-resolver-transport-jdk-19 + ${project.version} + jar + ${project.build.directory}/generated-resources/META-INF/versions/19 + **/*.class + + + + diff --git a/maven-resolver-transport-jdk-parent/pom.xml b/maven-resolver-transport-jdk-parent/pom.xml index d25f5805d..3ca7ce053 100644 --- a/maven-resolver-transport-jdk-parent/pom.xml +++ b/maven-resolver-transport-jdk-parent/pom.xml @@ -35,6 +35,7 @@ maven-resolver-transport-jdk-8 maven-resolver-transport-jdk-11 + maven-resolver-transport-jdk-19 maven-resolver-transport-jdk From ebdfa98b3bc8e9cc9f604e066a2cb79710a49ea0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 7 Nov 2023 23:27:05 +0100 Subject: [PATCH 2/5] Make jdk19 module optional That does not really make any sense, but for now let it be like it. --- .../maven-resolver-transport-jdk/pom.xml | 74 +++++++++++++++++++ maven-resolver-transport-jdk-parent/pom.xml | 13 +++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml index 923c704a0..73211eb03 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml @@ -38,6 +38,19 @@ + + org.apache.maven.resolver + maven-resolver-transport-jdk-8 + ${project.version} + true + + + org.apache.maven.resolver + maven-resolver-transport-jdk-11 + ${project.version} + true + + org.apache.maven.resolver maven-resolver-api @@ -66,6 +79,21 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-bytecode-version + + enforce + + + true + + + + org.apache.maven.plugins maven-dependency-plugin @@ -144,4 +172,50 @@ + + + jdk19 + + [19,) + + + + org.apache.maven.resolver + maven-resolver-transport-jdk-19 + ${project.version} + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + java19 + + unpack + + generate-resources + + + + org.apache.maven.resolver + maven-resolver-transport-jdk-19 + ${project.version} + jar + ${project.build.directory}/generated-resources/META-INF/versions/19 + **/*.class + + + + + + + + + + + diff --git a/maven-resolver-transport-jdk-parent/pom.xml b/maven-resolver-transport-jdk-parent/pom.xml index 3ca7ce053..38bc165eb 100644 --- a/maven-resolver-transport-jdk-parent/pom.xml +++ b/maven-resolver-transport-jdk-parent/pom.xml @@ -35,8 +35,19 @@ maven-resolver-transport-jdk-8 maven-resolver-transport-jdk-11 - maven-resolver-transport-jdk-19 maven-resolver-transport-jdk + + + jdk19 + + [19,) + + + maven-resolver-transport-jdk-19 + + + + From eebfe00542901ea3d5556bc1b416483901e5651d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 7 Nov 2023 23:32:10 +0100 Subject: [PATCH 3/5] Remove dupe --- .../maven-resolver-transport-jdk/pom.xml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml index 73211eb03..9fcf1035a 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml @@ -136,25 +136,6 @@ - - java19 - - unpack - - generate-resources - - - - org.apache.maven.resolver - maven-resolver-transport-jdk-19 - ${project.version} - jar - ${project.build.directory}/generated-resources/META-INF/versions/19 - **/*.class - - - - From 875053f917edcca8652d3c2193008b711d04fb65 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 8 Nov 2023 20:21:25 +0100 Subject: [PATCH 4/5] Prepare for onSessionClose --- .../transport/jdk/JdkHttpTransporter.java | 6 +- .../jdk/JdkHttpTransporterCustomizer.java | 5 +- .../jdk/JdkHttpTransporterCustomizer.java | 5 +- .../maven-resolver-transport-jdk-21/pom.xml | 85 ++++++++++++++++ .../jdk/JdkHttpTransporterCustomizer.java | 70 +++++++++++++ .../maven-resolver-transport-jdk/pom.xml | 98 ++++++++++--------- maven-resolver-transport-jdk-parent/pom.xml | 14 +-- 7 files changed, 221 insertions(+), 62 deletions(-) create mode 100644 maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/pom.xml create mode 100644 maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java index 71b355f83..ece185172 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporter.java @@ -389,7 +389,7 @@ private static HttpClient getOrCreateClient(RepositorySystemSession session, Rem .connectTimeout(Duration.ofMillis(connectTimeout)) .sslContext(sslContext); - JdkHttpTransporterCustomizer.customize(session, repository, builder); + JdkHttpTransporterCustomizer.customizeBuilder(session, repository, builder); if (repository.getProxy() != null) { ProxySelector proxy = ProxySelector.of(new InetSocketAddress( @@ -419,7 +419,9 @@ protected PasswordAuthentication getPasswordAuthentication() { }); } - return builder.build(); + HttpClient result = builder.build(); + JdkHttpTransporterCustomizer.customizeHttpClient(session, repository, result); + return result; } catch (NoSuchAlgorithmException e) { throw new WrapperEx(e); } diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java index 790d5a31a..7695d0e72 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-11/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java @@ -31,5 +31,8 @@ final class JdkHttpTransporterCustomizer { private JdkHttpTransporterCustomizer() {} - static void customize(RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) {} + static void customizeBuilder( + RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) {} + + static void customizeHttpClient(RepositorySystemSession session, RemoteRepository repository, HttpClient client) {} } diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java index 7186b1163..63929635c 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-19/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java @@ -35,13 +35,16 @@ final class JdkHttpTransporterCustomizer { private JdkHttpTransporterCustomizer() {} - static void customize(RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) { + static void customizeBuilder( + RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) { InetAddress localAddress = getHttpLocalAddress(session, repository); if (localAddress != null) { builder.localAddress(localAddress); } } + static void customizeHttpClient(RepositorySystemSession session, RemoteRepository repository, HttpClient client) {} + /** * Returns non-null {@link InetAddress} if set in configuration, {@code null} otherwise. */ diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/pom.xml new file mode 100644 index 000000000..743101231 --- /dev/null +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + + org.apache.maven.resolver + maven-resolver-transport-jdk-parent + 2.0.0-SNAPSHOT + + + maven-resolver-transport-jdk-21 + jar + + Maven Artifact Resolver Transport JDK (21) + Maven Artifact Transport JDK Java 11+. + + + org.apache.maven.resolver.transport.jdk + ${Automatic-Module-Name} + + 19 + + + + + org.apache.maven.resolver + maven-resolver-api + + + org.apache.maven.resolver + maven-resolver-spi + + + org.apache.maven.resolver + maven-resolver-util + + + javax.inject + javax.inject + provided + true + + + + + + + org.eclipse.sisu + sisu-maven-plugin + + + biz.aQute.bnd + bnd-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java new file mode 100644 index 000000000..51b8b9f3d --- /dev/null +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk-21/src/main/java/org/eclipse/aether/transport/jdk/JdkHttpTransporterCustomizer.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.eclipse.aether.transport.jdk; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.net.http.HttpClient; + +import org.eclipse.aether.ConfigurationProperties; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.ConfigUtils; + +/** + * JDK Transport customizer. + * + * @since TBD + */ +final class JdkHttpTransporterCustomizer { + private JdkHttpTransporterCustomizer() {} + + static void customizeBuilder( + RepositorySystemSession session, RemoteRepository repository, HttpClient.Builder builder) { + InetAddress localAddress = getHttpLocalAddress(session, repository); + if (localAddress != null) { + builder.localAddress(localAddress); + } + } + + static void customizeHttpClient(RepositorySystemSession session, RemoteRepository repository, HttpClient client) { + // TODO: register client.close(); once onSessionClose feature present + } + + /** + * Returns non-null {@link InetAddress} if set in configuration, {@code null} otherwise. + */ + private static InetAddress getHttpLocalAddress(RepositorySystemSession session, RemoteRepository repository) { + String bindAddress = ConfigUtils.getString( + session, + null, + ConfigurationProperties.HTTP_LOCAL_ADDRESS + "." + repository.getId(), + ConfigurationProperties.HTTP_LOCAL_ADDRESS); + if (bindAddress == null) { + return null; + } + try { + return InetAddress.getByName(bindAddress); + } catch (UnknownHostException uhe) { + throw new IllegalArgumentException( + "Given bind address (" + bindAddress + ") cannot be resolved for remote repository " + repository, + uhe); + } + } +} diff --git a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml index 9fcf1035a..b90c1cb93 100644 --- a/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml +++ b/maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk/pom.xml @@ -38,6 +38,7 @@ + org.apache.maven.resolver maven-resolver-transport-jdk-8 @@ -50,7 +51,20 @@ ${project.version} true + + org.apache.maven.resolver + maven-resolver-transport-jdk-19 + ${project.version} + true + + + org.apache.maven.resolver + maven-resolver-transport-jdk-21 + ${project.version} + true + + org.apache.maven.resolver maven-resolver-api @@ -136,6 +150,44 @@ + + java19 + + unpack + + generate-resources + + + + org.apache.maven.resolver + maven-resolver-transport-jdk-19 + ${project.version} + jar + ${project.build.directory}/generated-resources/META-INF/versions/19 + **/*.class + + + + + + java21 + + unpack + + generate-resources + + + + org.apache.maven.resolver + maven-resolver-transport-jdk-21 + ${project.version} + jar + ${project.build.directory}/generated-resources/META-INF/versions/21 + **/*.class + + + + @@ -153,50 +205,4 @@ - - - jdk19 - - [19,) - - - - org.apache.maven.resolver - maven-resolver-transport-jdk-19 - ${project.version} - true - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - java19 - - unpack - - generate-resources - - - - org.apache.maven.resolver - maven-resolver-transport-jdk-19 - ${project.version} - jar - ${project.build.directory}/generated-resources/META-INF/versions/19 - **/*.class - - - - - - - - - - - diff --git a/maven-resolver-transport-jdk-parent/pom.xml b/maven-resolver-transport-jdk-parent/pom.xml index 38bc165eb..78a507866 100644 --- a/maven-resolver-transport-jdk-parent/pom.xml +++ b/maven-resolver-transport-jdk-parent/pom.xml @@ -35,19 +35,9 @@ maven-resolver-transport-jdk-8 maven-resolver-transport-jdk-11 + maven-resolver-transport-jdk-19 + maven-resolver-transport-jdk-21 maven-resolver-transport-jdk - - - jdk19 - - [19,) - - - maven-resolver-transport-jdk-19 - - - - From fa5089f2a7e357a1a98a26abb2d714ba659587f8 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 8 Nov 2023 20:26:15 +0100 Subject: [PATCH 5/5] Document configuration key change And by the way, old key was wrong... --- src/site/markdown/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index d8bffd8e0..acd48b5f2 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -34,11 +34,11 @@ Option | Type | Description | Default Value | Supports Repo ID Suffix `aether.connector.basic.parallelPut` | boolean | Enables or disables parallel PUT processing (parallel deploys) on basic connector globally or per remote repository. When disabled, connector behaves exactly as in Maven 3.8.x did: GETs are parallel while PUTs are sequential. | `true` | yes `aether.connector.classpath.loader` | ClassLoader | `ClassLoader` from which resources should be retrieved which start with the `classpath:` protocol. | `Thread.currentThread().getContextClassLoader()` | no `aether.connector.connectTimeout` | long | Connect timeout in milliseconds. | `10000` | yes -`aether.connector.http.bind.address` | String | Set the outgoing interface (globally or per remote repository). Valid values are local accessible IP addresses or host names. The default will use the system's default route. Invalid addresses will result in HttpTransport creation failure. | - | yes `aether.connector.http.cacheState` | boolean | Flag indicating whether a memory-based cache is used for user tokens, connection managers, expect continue requests and authentication schemes. | `true` | no `aether.connector.http.connectionMaxTtl` | int | Total time to live in seconds for an HTTP connection, after that time, the connection will be dropped (no matter for how long it was idle). | `300` | yes `aether.connector.http.credentialEncoding` | String | The encoding/charset to use when exchanging credentials with HTTP servers. | `"ISO-8859-1"` | yes `aether.connector.http.headers` | `Map` | The request headers to use for HTTP-based repository connectors. The headers are specified using a map of strings mapping a header name to its value. The repository-specific headers map is supposed to be complete, i.e. is not merged with the general headers map. | - | yes +`aether.connector.http.localAddress` | String | Set the outgoing interface (globally or per remote repository). Valid values are local accessible IP addresses or host names. The default will use the system's default route. Invalid addresses will result in HttpTransport creation failure. | - | yes `aether.connector.http.maxConnectionsPerRoute` | int | The maximum concurrent connections per route HTTP client is allowed to use. | `50` | yes `aether.connector.http.preemptiveAuth` | boolean | Should HTTP client use preemptive-authentication for all HTTP verbs (works only w/ BASIC). By default is disabled, as it is considered less secure. | `false` | yes `aether.connector.http.preemptivePutAuth` | boolean | Should HTTP client use preemptive-authentication for HTTP PUTs only (works only w/ BASIC). By default is enabled (same as Wagon). | `true` | yes