You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/08/26 15:30:30 UTC
(maven) branch feature/maven-4.0.x-try-with-resources created (now 104c0c834b)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch feature/maven-4.0.x-try-with-resources
in repository https://gitbox.apache.org/repos/asf/maven.git
at 104c0c834b Use try-with-resources for AuthenticationContext
This branch includes the following new commits:
new 104c0c834b Use try-with-resources for AuthenticationContext
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven) 01/01: Use try-with-resources for AuthenticationContext
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch feature/maven-4.0.x-try-with-resources
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 104c0c834b95031a02f54d2f56b3f9b348ab36fc
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Wed Aug 26 17:08:22 2026 +0200
Use try-with-resources for AuthenticationContext
Closes #669
---
.../repository/legacy/LegacyRepositorySystem.java | 27 +++++++++++-----------
.../apache/maven/bridge/MavenRepositorySystem.java | 27 +++++++++++-----------
.../LegacyRepositorySystemSessionExtender.java | 26 ++++++++++-----------
3 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java b/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java
index f748a477d2..281f4069e6 100644
--- a/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java
+++ b/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java
@@ -526,13 +526,14 @@ private Authentication getAuthentication(RepositorySystemSession session, Artifa
repo = new RemoteRepository.Builder(repo)
.setAuthentication(auth)
.build();
- AuthenticationContext authCtx = AuthenticationContext.forRepository(session, repo);
- Authentication result = new Authentication(
- authCtx.get(AuthenticationContext.USERNAME), authCtx.get(AuthenticationContext.PASSWORD));
- result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
- result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
- authCtx.close();
- return result;
+ try (AuthenticationContext authCtx = AuthenticationContext.forRepository(session, repo)) {
+ Authentication result = new Authentication(
+ authCtx.get(AuthenticationContext.USERNAME),
+ authCtx.get(AuthenticationContext.PASSWORD));
+ result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
+ result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
+ return result;
+ }
}
}
}
@@ -623,12 +624,12 @@ private Proxy getProxy(RepositorySystemSession session, ArtifactRepository repos
repo = new RemoteRepository.Builder(repo)
.setProxy(proxy)
.build();
- AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo);
- p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
- p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
- p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
- p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
- authCtx.close();
+ try (AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo)) {
+ p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
+ p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
+ p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
+ p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
+ }
}
return p;
}
diff --git a/impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
index 1617b19c37..e7f4451c47 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java
@@ -230,13 +230,14 @@ private Authentication getAuthentication(RepositorySystemSession session, Artifa
repo = new RemoteRepository.Builder(repo)
.setAuthentication(auth)
.build();
- AuthenticationContext authCtx = AuthenticationContext.forRepository(session, repo);
- Authentication result = new Authentication(
- authCtx.get(AuthenticationContext.USERNAME), authCtx.get(AuthenticationContext.PASSWORD));
- result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
- result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
- authCtx.close();
- return result;
+ try (AuthenticationContext authCtx = AuthenticationContext.forRepository(session, repo)) {
+ Authentication result = new Authentication(
+ authCtx.get(AuthenticationContext.USERNAME),
+ authCtx.get(AuthenticationContext.PASSWORD));
+ result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
+ result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
+ return result;
+ }
}
}
}
@@ -266,12 +267,12 @@ private Proxy getProxy(RepositorySystemSession session, ArtifactRepository repos
repo = new RemoteRepository.Builder(repo)
.setProxy(proxy)
.build();
- AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo);
- p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
- p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
- p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
- p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
- authCtx.close();
+ try (AuthenticationContext authCtx = AuthenticationContext.forProxy(session, repo)) {
+ p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
+ p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
+ p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
+ p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
+ }
}
return p;
}
diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/aether/LegacyRepositorySystemSessionExtender.java b/impl/maven-core/src/main/java/org/apache/maven/internal/aether/LegacyRepositorySystemSessionExtender.java
index ee7129246d..ea580f2101 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/internal/aether/LegacyRepositorySystemSessionExtender.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/internal/aether/LegacyRepositorySystemSessionExtender.java
@@ -110,12 +110,12 @@ private org.apache.maven.repository.Proxy getProxy(ProxySelector selector, Artif
p.setPort(proxy.getPort());
if (proxy.getAuthentication() != null) {
repo = new RemoteRepository.Builder(repo).setProxy(proxy).build();
- AuthenticationContext authCtx = AuthenticationContext.forProxy(null, repo);
- p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
- p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
- p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
- p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
- authCtx.close();
+ try (AuthenticationContext authCtx = AuthenticationContext.forProxy(null, repo)) {
+ p.setUserName(authCtx.get(AuthenticationContext.USERNAME));
+ p.setPassword(authCtx.get(AuthenticationContext.PASSWORD));
+ p.setNtlmDomain(authCtx.get(AuthenticationContext.NTLM_DOMAIN));
+ p.setNtlmHost(authCtx.get(AuthenticationContext.NTLM_WORKSTATION));
+ }
}
return p;
}
@@ -139,13 +139,13 @@ private Authentication getAuthentication(AuthenticationSelector selector, Artifa
repo = new RemoteRepository.Builder(repo)
.setAuthentication(auth)
.build();
- AuthenticationContext authCtx = AuthenticationContext.forRepository(null, repo);
- Authentication result = new Authentication(
- authCtx.get(AuthenticationContext.USERNAME), authCtx.get(AuthenticationContext.PASSWORD));
- result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
- result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
- authCtx.close();
- return result;
+ try (AuthenticationContext authCtx = AuthenticationContext.forRepository(null, repo)) {
+ Authentication result = new Authentication(
+ authCtx.get(AuthenticationContext.USERNAME), authCtx.get(AuthenticationContext.PASSWORD));
+ result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
+ result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
+ return result;
+ }
}
}
return null;