diff --git a/core/src/main/java/org/wildfly/channel/ChannelSession.java b/core/src/main/java/org/wildfly/channel/ChannelSession.java index 1eea2a21..31b27764 100644 --- a/core/src/main/java/org/wildfly/channel/ChannelSession.java +++ b/core/src/main/java/org/wildfly/channel/ChannelSession.java @@ -124,6 +124,16 @@ public MavenArtifact resolveMavenArtifact(String groupId, String artifactId, Str return new MavenArtifact(groupId, artifactId, extension, classifier, latestVersion, artifact.file, artifact.channel.getChannelDefinition().getName()); } + /** + * Return the list of manifests configured in this channel session. + * @return The list of manifests. + */ + public List getManifests() { + return channels.stream() + .map(p -> p.getManifest()) + .collect(Collectors.toUnmodifiableList()); + } + /** * Resolve a list of Maven artifacts according to the session's channels. *

diff --git a/core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java b/core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java index 7a77e60c..0bcc08f6 100644 --- a/core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java +++ b/core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java @@ -43,6 +43,7 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -571,6 +572,46 @@ public void testChannelWithStrictStrategy() throws Exception { } } + @Test + public void testGetManifests() throws Exception { + String name1 = "manifest1"; + String name2 = "manifest2"; + Stream[] streams1 = {new Stream("org.foo", "foo", "25.0.0.Final"), new Stream("org.foo", "bar", "23.0.0.Final")}; + Stream[] streams2 = {new Stream("org.bar", "foo", "20.0.0.Final"), new Stream("org.bar", "bar", "21.0.0.Final")}; + String manifest1 = buildManifest(name1, streams1); + String manifest2 = buildManifest(name2, streams2); + + MavenVersionsResolver.Factory factory = mock(MavenVersionsResolver.Factory.class); + MavenVersionsResolver resolver = mock(MavenVersionsResolver.class); + when(factory.create(any())).thenReturn(resolver); + + final List channels = mockChannel(resolver, tempDir, manifest1, manifest2); + + try (ChannelSession session = new ChannelSession(channels, factory)) { + assertEquals(2,session.getManifests().size()); + checkManifest(session.getManifests().get(0), name1, streams1); + checkManifest(session.getManifests().get(1), name2, streams2); + } + } + + private String buildManifest(String name, Stream... streams) { + StringBuilder manifest = new StringBuilder("schemaVersion: " + CURRENT_SCHEMA_VERSION + "\n" + + "name: " + name + "\n" + + "streams:\n"); + for(Stream stream : streams) { + manifest.append( + " - groupId: "+ stream.getGroupId() + "\n" + + " artifactId: "+ stream.getArtifactId() + "\n" + + " version: \"" + stream.getVersion() + "\"\n"); + } + return manifest.toString(); + } + + private void checkManifest(ChannelManifest manifest, String name, Stream... streams) { + assertEquals(name, manifest.getName()); + assertTrue(Set.of(streams).containsAll(manifest.getStreams())); + } + @Test public void testChannelWithDefaultStrategy() throws Exception { String manifest = "schemaVersion: " + CURRENT_SCHEMA_VERSION + "\n" +