Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.5.1</version>
<version>5.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/io/github/mfoo/libyear/LibYearMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
import javax.inject.Inject;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.core5.http.HttpResponseInterceptor;
Expand Down Expand Up @@ -360,14 +360,18 @@ public LibYearMojo(RepositorySystem repositorySystem, ArtifactFactory artifactFa

private CloseableHttpClient setupHTTPClient() {
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(MAVEN_API_HTTP_TIMEOUT_SECONDS))
.setConnectionRequestTimeout(Timeout.ofSeconds(MAVEN_API_HTTP_TIMEOUT_SECONDS))
.setResponseTimeout(Timeout.ofSeconds(MAVEN_API_HTTP_TIMEOUT_SECONDS))
.build();

ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(MAVEN_API_HTTP_TIMEOUT_SECONDS))
.build();

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(20);
connectionManager.setDefaultMaxPerRoute(20);
connectionManager.setDefaultConnectionConfig(connectionConfig);

return HttpClientBuilder.create()
.setConnectionManager(connectionManager)
Expand Down Expand Up @@ -825,33 +829,33 @@ private Optional<LocalDate> getReleaseDate(String groupId, String artifactId, St
}

/** Make the API call to fetch the release date */
private Optional<String> fetchReleaseDate(String groupId, String artifactId, String version) {
if (version.equals("${project.version}")) {
version = project.getVersion();
}
private Optional<String> fetchReleaseDate(String groupId, String artifactId, final String version) {
final String versionToFetch = version.equals("${project.version}") ? project.getVersion() : version;

URI artifactUri = URI.create(String.format(
"%s/solrsearch/select?q=g:%s+AND+a:%s+AND+v:%s&wt=json", searchUri, groupId, artifactId, version));
"%s/solrsearch/select?q=g:%s+AND+a:%s+AND+v:%s&wt=json",
searchUri, groupId, artifactId, versionToFetch));

getLog().debug("Fetching " + artifactUri);

final HttpGet httpGet = new HttpGet(artifactUri);

try {
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
return httpClient.execute(httpGet, response -> {
if (response.getCode() != 200) {
getLog().error(String.format(
"Failed to fetch release date for %s:%s %s (%s)",
groupId, artifactId, version, response.getReasonPhrase()));
groupId, artifactId, versionToFetch, response.getReasonPhrase()));
return Optional.empty();
}

String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
return Optional.of(responseBody);
}
});
} catch (Exception e) {
getLog().error(String.format(
"Failed to fetch release date for %s:%s %s (%s)", groupId, artifactId, version, e.getMessage()));
"Failed to fetch release date for %s:%s %s (%s)",
groupId, artifactId, versionToFetch, e.getMessage()));
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
Expand Down Expand Up @@ -49,7 +49,8 @@ public static long parseHttpDate(String httpDate) {
public static long getLastModifiedTimestamp(String groupId, String artifactId, String version) throws IOException {
final String path = groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-"
+ version + ".pom";
final HttpURLConnection connection = (HttpURLConnection) new URL(MAVEN_CENTRAL + path).openConnection();
final HttpURLConnection connection =
(HttpURLConnection) URI.create(MAVEN_CENTRAL + path).toURL().openConnection();

connection.setRequestMethod("HEAD");
connection.connect();
Expand Down
Loading