diff --git a/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java b/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java index 7e9c8872..388cc4d3 100644 --- a/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java +++ b/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java @@ -73,9 +73,9 @@ public static ManifestVersionRecord getCurrentVersions(ChannelSession session) t record.addManifest(new ManifestVersionRecord.NoManifest(repos, channelDefinition.getNoStreamStrategy().toString())); } else if (manifestCoordinate.getUrl() != null) { String hashCode = HashUtils.hash(read(manifestCoordinate.getUrl())); - record.addManifest(new ManifestVersionRecord.UrlManifest(manifestCoordinate.getUrl().toExternalForm(), hashCode, manifest.getDescription())); + record.addManifest(new ManifestVersionRecord.UrlManifest(manifestCoordinate.getUrl().toExternalForm(), hashCode, getVersionDescription(manifest))); } else if (manifestCoordinate.getMaven() != null) { - final String description = manifest.getDescription(); + final String description = getVersionDescription(manifest); record.addManifest(new ManifestVersionRecord.MavenManifest( manifestCoordinate.getGroupId(), manifestCoordinate.getArtifactId(), @@ -163,18 +163,30 @@ public ManifestVersionRecord getCurrentVersions(List channels) throws I return manifestVersionRecord; } - private String getManifestDescription(ChannelManifestCoordinate manifestCoordinate, MavenVersionsResolver mavenVersionsResolver) { + private static String getManifestDescription(ChannelManifestCoordinate manifestCoordinate, MavenVersionsResolver mavenVersionsResolver) { final List urls = mavenVersionsResolver.resolveChannelMetadata(List.of(manifestCoordinate)); final String description; if (!urls.isEmpty()) { final ChannelManifest manifest = ChannelManifestMapper.from(urls.get(0)); - description = manifest.getName(); + description = getVersionDescription(manifest); } else { description = null; } return description; } + private static String getVersionDescription(ChannelManifest manifest) { + final String description; + if (manifest.getSchemaVersion().equals(ChannelManifestMapper.SCHEMA_VERSION_1_0_0)) { + // before manifest v1.1.0, we had a convention of using "name" as version description + // after "logicalVersion" was introduced, this was abandoned + description = manifest.getName(); + } else { + description = manifest.getLogicalVersion(); + } + return description; + } + private static String read(URL url) throws IOException { try(InputStream inputStream = url.openStream(); OutputStream outputStream = new ByteArrayOutputStream()) { diff --git a/src/test/java/org/wildfly/prospero/metadata/ManifestVersionResolverTest.java b/src/test/java/org/wildfly/prospero/metadata/ManifestVersionResolverTest.java index ff394e4b..73390d66 100644 --- a/src/test/java/org/wildfly/prospero/metadata/ManifestVersionResolverTest.java +++ b/src/test/java/org/wildfly/prospero/metadata/ManifestVersionResolverTest.java @@ -69,7 +69,7 @@ public void getVersionOfLatestMavenManifest() throws Exception { final File manifestFile = temp.newFile(); final URL url = manifestFile.toURI().toURL(); - Files.writeString(manifestFile.toPath(), ChannelManifestMapper.toYaml(new ChannelManifest("test", null, null, Collections.emptyList()))); + Files.writeString(manifestFile.toPath(), ChannelManifestMapper.toYaml(new ChannelManifest("1.0.0", "test", null, null, null, null, Collections.emptyList()))); when(mavenResolver.getAllVersions("org.test", "test", "yaml", "manifest")) .thenReturn(Set.of("1.0.0", "1.0.1")); @@ -90,6 +90,33 @@ public void getVersionOfLatestMavenManifest() throws Exception { assertThat(currentVersions.getUrlManifests()).isEmpty(); } + @Test + public void getVersionOfLatestMavenManifestWithLogicalVersion() throws Exception { + final ManifestVersionResolver resolver = new ManifestVersionResolver(factory); + + final File manifestFile = temp.newFile(); + final URL url = manifestFile.toURI().toURL(); + Files.writeString(manifestFile.toPath(), ChannelManifestMapper.toYaml(new ChannelManifest("1.1.0", "test", null, "logical-version", null, null, Collections.emptyList()))); + + when(mavenResolver.getAllVersions("org.test", "test", "yaml", "manifest")) + .thenReturn(Set.of("1.0.0", "1.0.1")); + when(mavenResolver.resolveChannelMetadata(any())) + .thenReturn(List.of(url)); + + final Channel channel = new Channel("test", "", null, Collections.emptyList(), + new ChannelManifestCoordinate("org.test", "test"), null, null); + final ManifestVersionRecord currentVersions = resolver.getCurrentVersions(List.of(channel)); + + assertThat(currentVersions.getMavenManifests()) + .map(ManifestVersionRecord.MavenManifest::getVersion) + .containsExactly("1.0.1"); + assertThat(currentVersions.getMavenManifests()) + .map(ManifestVersionRecord.MavenManifest::getDescription) + .containsExactly("logical-version"); + assertThat(currentVersions.getOpenManifests()).isEmpty(); + assertThat(currentVersions.getUrlManifests()).isEmpty(); + } + @Test public void getHardcodedVersionOfManifestIfPresent() throws Exception { final ManifestVersionResolver resolver = new ManifestVersionResolver(factory); @@ -198,8 +225,12 @@ public void channelSessionToVersionRecord() throws Exception { .addRepository("test-repo", "http://test.te") .build(); - final ChannelManifest manifest1 = new ChannelManifest.Builder().setDescription("Manifest 1").build(); - final ChannelManifest manifest2 = new ChannelManifest.Builder().setDescription("Manifest 2").build(); + final ChannelManifest manifest1 = new ChannelManifest.Builder() + .setSchemaVersion(ChannelManifestMapper.SCHEMA_VERSION_1_0_0) + .setName("Manifest 1").build(); + final ChannelManifest manifest2 = new ChannelManifest.Builder() + .setSchemaVersion(ChannelManifestMapper.SCHEMA_VERSION_1_0_0) + .setName("Manifest 2").build(); final List channels = List.of( new RuntimeChannel(channel1, manifest1, null),