From c7a298022c62fe88fb69d73caa5033f9ec1413be Mon Sep 17 00:00:00 2001 From: Oleh Dokuka <5380167+OlegDokuka@users.noreply.github.com> Date: Fri, 13 Jan 2023 09:47:44 +0200 Subject: [PATCH] ensures versions are retrieved properly (#110) Co-authored-by: Violeta Georgieva Co-authored-by: Spike Blues <4684223+SpikeBlues@users.noreply.github.com> --- .../java/io/projectreactor/Application.java | 6 ++- .../java/io/projectreactor/ModuleUtils.java | 51 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/projectreactor/Application.java b/src/main/java/io/projectreactor/Application.java index add9932d..0e159c80 100644 --- a/src/main/java/io/projectreactor/Application.java +++ b/src/main/java/io/projectreactor/Application.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2022 VMware Inc. or its affiliates, All Rights Reserved. + * Copyright (c) 2015-2023 VMware Inc. or its affiliates, All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,6 +94,10 @@ public final class Application { ModuleUtils.fetchVersionsFromArtifactory(modules, "core", "test", "adapter", "extra", "netty", "nettyArchive", "kafka", "rabbitmq", "BlockHound", "kotlin", "pool"); + //then get the versions from Sonatype + ModuleUtils.fetchVersionsFromSonatype(modules, "core", "test", "adapter", + "extra", "netty", "nettyArchive", "kafka", "rabbitmq", "BlockHound", + "kotlin", "pool"); LOGGER.info("Boms and modules loaded in " + (System.currentTimeMillis() - start) + "ms"); docsModel.put("oldBoms", modules.get("olderBoms")); diff --git a/src/main/java/io/projectreactor/ModuleUtils.java b/src/main/java/io/projectreactor/ModuleUtils.java index 17c00c79..4a335d70 100644 --- a/src/main/java/io/projectreactor/ModuleUtils.java +++ b/src/main/java/io/projectreactor/ModuleUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021 VMware Inc. or its affiliates, All Rights Reserved. + * Copyright (c) 2019-2023 VMware Inc. or its affiliates, All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import io.netty.handler.codec.http.HttpHeaders; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -102,6 +103,54 @@ public static void loadModuleVersionsFromArtifactoryVersionsSearch(String json, versions.forEach(v -> tryAddVersion(module, v)); } + public static void fetchVersionsFromSonatype(Map modules, String... moduleNames) { + final HttpClient client = HttpClient.create() + .baseUrl("https://s01.oss.sonatype.org/service/local/lucene") + .headers(h -> h.set("accept", "application/json")); + + Flux.fromArray(moduleNames) + .filter(modules::containsKey) + .map(modules::get) + .flatMap(module -> { + final String params = "/search?g=" + module.getGroupId() + "&a=" + module.getArtifactId(); + LOGGER.info("Loading version information for {} via GET {}", module.getName(), params); + + return client.get() + .uri(params) + .response((r, content) -> { + if (r.status().code() < 400) { + return content.aggregate() + .asString() + .doOnNext(json -> loadModuleVersionsFromSonatypeVersionsSearch(json, module)); + } + else { + return content.aggregate() + .asString() + .doOnNext(errorBody -> LOGGER.warn("Couldn't scrape versions for {}: {} - {}", + module.getName(), r.status(), errorBody)); + } + }) + .then(Mono.fromCallable(module::sortAndDeduplicateVersions)); + }) + .blockLast(); + } + + public static void loadModuleVersionsFromSonatypeVersionsSearch(String json, Module module) { + ObjectMapper mapper = new ObjectMapper(); + final JsonNode node; + try { + node = mapper.readTree(json); + } + catch (JsonProcessingException e) { + throw Exceptions.propagate(e); + } + + JsonNode data = node.findValue("data"); + List versions = data.findValuesAsText("version"); + + versions.forEach(v -> tryAddVersion(module, v)); + } + /** * Try to add a version to a module, with some exclusions: *