Skip to content

Commit

Permalink
[env-manager] fix central#list-local implementation (version was wron…
Browse files Browse the repository at this point in the history
…gly extracted)
  • Loading branch information
rmannibucau committed Feb 21, 2024
1 parent 1979f01 commit 52d4889
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public CompletionStage<Optional<MatchedVersion>> tryFindByToolVersionAndProvider
.filter(it -> provider == null ||
// enable "--install-provider zulu" for example
Objects.equals(provider, it.name()) ||
it.getClass().getSimpleName().toLowerCase(ROOT).startsWith(provider.toLowerCase(ROOT)))
it.getClass().getSimpleName().toLowerCase(ROOT).startsWith(provider.toLowerCase(ROOT)) ||
(CentralBaseProvider.class == it.getClass() && "central".equals(provider)))
.map(it -> it.listTools().thenCompose(candidates -> {
if (candidates.stream().anyMatch(t -> tool.equals(t.tool()))) {
final var candidateListMap = cache.local.get(it);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public CompletionStage<Map<Candidate, List<Version>>> listLocal() {
.filter(child -> child.getFileName().toString().endsWith("_exploded"))
.map(distro -> {
final var filename = distro.getFileName().toString();
final var version = filename.substring(0, filename.length() - "_exploded".length());
final var version = filename.substring(
gav.artifactId().length() + 1,
filename.length() -
"_exploded".length() -
(gav.classifier() != null && !gav.classifier().isBlank() ? gav.classifier().length() + 1 : 0) -
(gav.type().length() + 1));
return new Version(gav.groupId(), version, gav.artifactId(), version);
})
.toList() // materialize otherwise exploded will be closed and lazy evaluation will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.yupiik.dev.provider.Provider;
import io.yupiik.dev.provider.model.Archive;
import io.yupiik.dev.provider.model.Candidate;
import io.yupiik.dev.provider.model.Version;
import io.yupiik.dev.shared.Archives;
import io.yupiik.dev.shared.http.Cache;
Expand Down Expand Up @@ -72,6 +73,15 @@ void lastVersions(final URI uri, @TempDir final Path work, final YemHttpClient c
actual);
}

@Test
@Mock(uri = "/2/org/foo/bar/1.0.2/bar-1.0.2-simple.tar.gz", payload = "you got a tar.gz", format = "tar.gz")
void listLocal(final URI uri, @TempDir final Path work, final YemHttpClient client) throws IOException, ExecutionException, InterruptedException {
install(uri, work, client);
final var candidates = newProvider(uri, client, work.resolve("m2")).listLocal().toCompletableFuture().get();
assertEquals(1, candidates.size());
assertEquals("1.0.2", candidates.values().iterator().next().get(0).version());
}

@Test
@Mock(uri = "/2/org/foo/bar/1.0.2/bar-1.0.2-simple.tar.gz", payload = "you got a tar.gz")
void download(final URI uri, @TempDir final Path work, final YemHttpClient client) throws IOException, ExecutionException, InterruptedException {
Expand Down

0 comments on commit 52d4889

Please sign in to comment.