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

[#323] Use version in the Stream comparator #324

Merged
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
14 changes: 12 additions & 2 deletions core/src/main/java/org/wildfly/channel/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,25 @@ public String toString() {
}

/*
* Sort streams by groupId and then artifactId
* Sort streams by groupId, artifactId and finally version or versionPattern.
*/
@Override
public int compareTo(Stream other) {
int groupIdComp = this.groupId.compareTo(other.groupId);
if (groupIdComp != 0) {
return groupIdComp;
}
return this.artifactId.compareTo(other.artifactId);
final int artifactIdComp = this.artifactId.compareTo(other.artifactId);
if (artifactIdComp != 0) {
return artifactIdComp;
}
if (this.version != null && other.getVersion() != null) {
return version.compareTo(other.getVersion());
}
if (this.versionPattern != null && other.getVersionPattern() != null) {
return versionPattern.pattern().compareTo(other.getVersionPattern().pattern());
}
return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.regex.Pattern;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.wildfly.channel.ChannelManifestMapper.CURRENT_SCHEMA_VERSION;

Expand Down Expand Up @@ -115,4 +117,16 @@ public void manifestWithRequires() {
assertEquals("org.foo.channels", requirement.getGroupId());
assertEquals("my-required-channel", requirement.getArtifactId());
}

@Test
public void manifestStreamsContainsChecksStreamVersion() {
final ChannelManifest manifest = new ChannelManifest.Builder()
.addStreams(new Stream("a", "b", "1"))
.build();

assertTrue(manifest.getStreams().contains(new Stream("a", "b", "1")));
assertFalse(manifest.getStreams().contains(new Stream("a", "b", "2")));
assertFalse(manifest.getStreams().contains(new Stream("b", "b", "1")));
assertFalse(manifest.getStreams().contains(new Stream("b", "b", Pattern.compile(".*"))));
}
}
Loading