Skip to content

Commit

Permalink
Adding RuntimeChannel class to hold resolved channel, manifest and bl…
Browse files Browse the repository at this point in the history
…ocklist
  • Loading branch information
spyrkob committed Oct 3, 2024
1 parent c06cdfe commit 6b441c1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/org/wildfly/channel/ChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ Channel getResolvedChannelDefinition() {
return resolvedChannel;
}

public Blocklist getBlocklist() {
return blocklist.orElse(null);
}

static class ResolveLatestVersionResult {
final String version;
final ChannelImpl channel;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/wildfly/channel/ChannelSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public ChannelSession(List<Channel> channelDefinitions, MavenVersionsResolver.Fa
* Get the definitions of channels used by this session. Returned version contains resolved versions
* of channel metadata (if applicable).
*
* @return List of {@code Channel}s used to resolve artifacts by this session
* @return List of {@code RuntimeChannel}s used to resolve artifacts by this session
*/
public List<Channel> getResolvedChannelDefinitions() {
public List<RuntimeChannel> getRuntimeChannels() {
return this.channels.stream()
.map(ChannelImpl::getResolvedChannelDefinition)
.map(c->new RuntimeChannel(c.getResolvedChannelDefinition(), c.getManifest(), c.getBlocklist()))
.collect(Collectors.toList());
}

Expand Down
58 changes: 58 additions & 0 deletions core/src/main/java/org/wildfly/channel/RuntimeChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.channel;

import java.util.Objects;

public class RuntimeChannel {

private final Channel channel;
private final ChannelManifest channelManifest;
private final Blocklist blocklist;

public RuntimeChannel(Channel channel, ChannelManifest channelManifest, Blocklist blocklist) {
this.channel = channel;
this.channelManifest = channelManifest;
this.blocklist = blocklist;
}

public Channel getChannelDefinition() {
return channel;
}

public ChannelManifest getChannelManifest() {
return channelManifest;
}

public Blocklist getChannelBlocklist() {
return blocklist;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RuntimeChannel that = (RuntimeChannel) o;
return Objects.equals(channel, that.channel) && Objects.equals(channelManifest, that.channelManifest) && Objects.equals(blocklist, that.blocklist);
}

@Override
public int hashCode() {
return Objects.hash(channel, channelManifest, blocklist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public void getVersionOfResolvedManifest() throws Exception {
.setManifestCoordinate("test.channels", "base-manifest")
.build());
try (ChannelSession channelSession = new ChannelSession(channels, factory)) {
assertThat(channelSession.getResolvedChannelDefinitions())
assertThat(channelSession.getRuntimeChannels())
.map(RuntimeChannel::getChannelDefinition)
.map(Channel::getManifestCoordinate)
.map(ChannelManifestCoordinate::getVersion)
.containsOnly("1.0.0");
Expand Down

0 comments on commit 6b441c1

Please sign in to comment.