Skip to content

Commit

Permalink
ensures versions are retrieved properly (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: Violeta Georgieva <[email protected]>
Co-authored-by: Spike Blues <[email protected]>
  • Loading branch information
3 people authored Jan 13, 2023
1 parent 6f8f75a commit c7a2980
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/io/projectreactor/Application.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"));
Expand Down
51 changes: 50 additions & 1 deletion src/main/java/io/projectreactor/ModuleUtils.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -102,6 +103,54 @@ public static void loadModuleVersionsFromArtifactoryVersionsSearch(String json,
versions.forEach(v -> tryAddVersion(module, v));
}

public static void fetchVersionsFromSonatype(Map<String, Module> 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<String> versions = data.findValuesAsText("version");

versions.forEach(v -> tryAddVersion(module, v));
}

/**
* Try to add a version to a module, with some exclusions:
* <ul>
Expand Down

0 comments on commit c7a2980

Please sign in to comment.