Skip to content

Commit

Permalink
Switch to a single timeout for MavenSettings and MavenRepositoryMirror
Browse files Browse the repository at this point in the history
Based on what's available by default according to the docs, as opposed to our accidental custom format previously.
https://maven.apache.org/guides/mini/guide-http-settings.html#connection-timeouts
  • Loading branch information
timtebeek committed Jul 5, 2024
1 parent ba98138 commit 893b2eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.*;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -245,8 +246,7 @@ private ServerConfiguration interpolate(@Nullable ServerConfiguration configurat
}
return new ServerConfiguration(
ListUtils.map(configuration.httpHeaders, this::interpolate),
configuration.connectTimeout,
configuration.readTimeout
configuration.timeout
);
}

Expand Down Expand Up @@ -422,17 +422,8 @@ public static class ServerConfiguration {
@Nullable
List<HttpHeader> httpHeaders;

/**
* Timeout in milliseconds for establishing a connection.
*/
@Nullable
Long connectTimeout;

/**
* Timeout in milliseconds for reading from the connection.
*/
@Nullable
Long readTimeout;
Long timeout;
}

@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,11 @@ private HttpSender.Request.Builder applyAuthenticationToRequest(MavenRepository
request.withHeader(header.getName(), header.getValue());
}
}
if (configuration.getConnectTimeout() != null) {
request.withConnectTimeout(Duration.ofMillis(configuration.getConnectTimeout()));
if (configuration.getTimeout() != null) {
request.withConnectTimeout(Duration.ofMillis(configuration.getTimeout()));
}
if (configuration.getReadTimeout() != null) {
request.withReadTimeout(Duration.ofMillis(configuration.getReadTimeout()));
if (configuration.getTimeout() != null) {
request.withReadTimeout(Duration.ofMillis(configuration.getTimeout()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public class MavenRepositoryMirror {
Boolean snapshots;

@Nullable
Long connectTimeout;

@Nullable
Long readTimeout;
Long timeout;

private final boolean externalOnly;
private final List<String> mirrorsOf;
Expand Down Expand Up @@ -98,25 +95,20 @@ public MavenRepositoryMirror(@Nullable String id, @Nullable String url, @Nullabl
Optional<MavenSettings.Server> maybeServer = servers.getServers().stream()
.filter(s -> id.equals(s.getId()) && s.getConfiguration() != null)
.findFirst();
if (maybeServer.isPresent()) {
MavenSettings.ServerConfiguration serverConfig = maybeServer.get().getConfiguration();
connectTimeout = serverConfig.getConnectTimeout();
readTimeout = serverConfig.getReadTimeout();
if (maybeServer.isPresent() && maybeServer.get().getConfiguration() != null){
timeout = maybeServer.get().getConfiguration().getTimeout();
} else {
connectTimeout = null;
readTimeout = null;
timeout = null;
}
} else {
connectTimeout = null;
readTimeout = null;
timeout = null;
}
} else {
externalOnly = false;
mirrorsOf = null;
includedRepos = null;
excludedRepos = null;
connectTimeout = null;
readTimeout = null;
timeout = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ void serverCredentials() {

@Test
void serverTimeouts() {
// Deliberately supporting the simpler old configuration of a single timeout
// https://maven.apache.org/guides/mini/guide-http-settings.html#connection-timeouts
var settings = MavenSettings.parse(new Parser.Input(Paths.get("settings.xml"), () -> new ByteArrayInputStream(
//language=xml
"""
Expand All @@ -353,8 +355,7 @@ void serverTimeouts() {
<server>
<id>server001</id>
<configuration>
<connectTimeout>40000</connectTimeout>
<readTimeout>50000</readTimeout>
<timeout>40000</timeout>
</configuration>
</server>
</servers>
Expand All @@ -366,8 +367,7 @@ void serverTimeouts() {
assertThat(settings.getServers().getServers()).hasSize(1);
assertThat(settings.getServers().getServers().get(0))
.matches(repo -> repo.getId().equals("server001"))
.matches(repo -> repo.getConfiguration().getConnectTimeout().equals(40000L))
.matches(repo -> repo.getConfiguration().getReadTimeout().equals(50000L));
.matches(repo -> repo.getConfiguration().getTimeout().equals(40000L));
}

@Nested
Expand Down Expand Up @@ -801,7 +801,7 @@ void canDeserializeSettingsCorrectly() throws IOException {
""").findFirst().get();

MavenSettings.HttpHeader httpHeader = new MavenSettings.HttpHeader("X-JFrog-Art-Api", "myApiToken");
MavenSettings.ServerConfiguration configuration = new MavenSettings.ServerConfiguration(java.util.Collections.singletonList(httpHeader), 10000L, null);
MavenSettings.ServerConfiguration configuration = new MavenSettings.ServerConfiguration(java.util.Collections.singletonList(httpHeader), 10000L);
MavenSettings.Server server = new MavenSettings.Server("maven-snapshots", null, null, configuration);
MavenSettings.Servers servers = new MavenSettings.Servers(java.util.Collections.singletonList(server));
MavenSettings settings = new MavenSettings(null, null, null, null, servers);
Expand Down

0 comments on commit 893b2eb

Please sign in to comment.