Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #287, Ability to list the ChannelManifest and Streams present in a ChannelSession #294

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/main/java/org/wildfly/channel/ChannelSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelManifest> getManifests() {
return channels.stream()
.map(p -> p.getManifest())
.collect(Collectors.toUnmodifiableList());
}

/**
* Resolve a list of Maven artifacts according to the session's channels.
* <p>
Expand Down
41 changes: 41 additions & 0 deletions core/src/test/java/org/wildfly/channel/ChannelSessionTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Channel> 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" +
Expand Down
Loading