Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Jan 12, 2023
1 parent c1d4ebb commit 7ac35f9
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,25 @@ public ChannelManifestCoordinate(URL url) {
}

@JsonCreator
public static ChannelManifestCoordinate create(@JsonProperty(value = "url") String url, @JsonProperty(value = "gav") String gav) throws MalformedURLException {
public static ChannelManifestCoordinate create(@JsonProperty(value = "url") String url, @JsonProperty(value = "maven") MavenCoordinate gav) throws MalformedURLException {
if (gav != null) {
final String[] parsedGav = gav.split(":");
if (parsedGav.length < 2 || parsedGav.length > 3) {
throw new IllegalArgumentException("Illegal GAV expression: " + gav);
}
if (parsedGav.length == 3) {
return new ChannelManifestCoordinate(parsedGav[0], parsedGav[1], parsedGav[2]);
if (gav.getVersion() == null || gav.getVersion().isEmpty()) {
return new ChannelManifestCoordinate(gav.getGroupId(), gav.getArtifactId());
} else {
return new ChannelManifestCoordinate(parsedGav[0], parsedGav[1]);
return new ChannelManifestCoordinate(gav.getGroupId(), gav.getArtifactId(), gav.getVersion());
}
} else {
return new ChannelManifestCoordinate(new URL(url));
}
}

@JsonProperty(value = "gav")
@JsonProperty(value = "maven")
@JsonInclude(NON_NULL)
public String getGav() {
public MavenCoordinate getMaven() {
if (isEmpty(getGroupId()) || isEmpty(getArtifactId())) {
return null;
}
if (isEmpty(getVersion())) {
return getGroupId() + ":" + getArtifactId();
} else {
return getGroupId() + ":" + getArtifactId() + ":" + getVersion();
}
return new MavenCoordinate(getGroupId(), getArtifactId(), getVersion());
}

private boolean isEmpty(String text) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/wildfly/channel/ChannelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down
60 changes: 60 additions & 0 deletions core/src/main/java/org/wildfly/channel/MavenCoordinate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.wildfly.channel;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

public class MavenCoordinate {

private String groupId;
private String artifactId;
private String version;

@JsonCreator
public MavenCoordinate(@JsonProperty(value = "groupId") String groupId,
@JsonProperty(value = "artifactId") String artifactId,
@JsonProperty(value = "version") String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}

public String getGroupId() {
return groupId;
}

public String getArtifactId() {
return artifactId;
}

@JsonInclude(NON_NULL)
public String getVersion() {
return version;
}

@Override
public String toString() {
return "MavenCoordinate{" +
"groupId='" + groupId + '\'' +
", artifactId='" + artifactId + '\'' +
", version='" + version + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MavenCoordinate that = (MavenCoordinate) o;
return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId) && Objects.equals(version, that.version);
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ public void testRequiringChannelOverridesStreamFromRequiredChannel() throws Unre
" artifactId: required-channel\n" +
" version: 2.0.0.Final\n" +
"manifest:\n" +
" gav: org.channels:base-manifest:1.0.0\n" +
" maven:\n" +
" groupId: org.channels\n" +
" artifactId: base-manifest\n" +
" version: 1.0.0\n" +
"repositories:\n" +
"- id: test\n" +
" url: test-repository");
Expand Down Expand Up @@ -372,7 +375,10 @@ public void testChannelRequirementNesting() throws UnresolvedMavenArtifactExcept
" artifactId: 2nd-level-requiring-channel\n" +
" version: 2.0.0.Final\n" +
"manifest:\n" +
" gav: org.channels:base-manifest:1.0.0\n" +
" maven:\n" +
" groupId: org.channels\n" +
" artifactId: base-manifest\n" +
" version: 1.0.0\n" +
"repositories:\n" +
" - id: test\n" +
" url: test");
Expand Down Expand Up @@ -546,7 +552,9 @@ private void mockManifest(MavenVersionsResolver resolver, String manifest, Strin
mockManifest(resolver, manifestFile.toUri().toURL(), gav);
}

private void mockManifest(MavenVersionsResolver resolver, URL manifestUrl, String gav) throws IOException {
private void mockManifest(MavenVersionsResolver resolver, URL manifestUrl, String gavString) throws IOException {
final String[] splitGav = gavString.split(":");
final MavenCoordinate gav = new MavenCoordinate(splitGav[0], splitGav[1], splitGav.length == 3 ? splitGav[2] : null);
when(resolver.resolveChannelMetadata(eq(List.of(ChannelManifestCoordinate.create(null, gav)))))
.thenReturn(List.of(manifestUrl));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ requires:
artifactId: required-channel
version: 2.0.0.Final
manifest:
gav: test.channels:required-2nd-level-manifest:1.0.0
maven:
groupId: test.channels
artifactId: required-2nd-level-manifest
version: 1.0.0
repositories:
- id: test
url: test-repository
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ vendor:
support: community
foo: not an known property
manifest:
gav: test.channels:channel
maven:
groupId: test.channels
artifactId: channel
bar: not a known property
repositories:
- id: test
Expand Down
5 changes: 4 additions & 1 deletion core/src/test/resources/channels/required-channel-2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
schemaVersion: "2.0.0"
name: My Required Channel
manifest:
gav: test.channels:required-manifest-2:1.0.0
maven:
groupId: "test.channels"
artifactId: "required-manifest-2"
version: "1.0.0"
repositories:
- id: test
url: test-repository
5 changes: 4 additions & 1 deletion core/src/test/resources/channels/required-channel.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
schemaVersion: "2.0.0"
name: My Required Channel
manifest:
gav: "test.channels:required-manifest:1.0.0"
maven:
groupId: "test.channels"
artifactId: "required-manifest"
version: "1.0.0"
repositories:
- id: test
url: test-repository
4 changes: 3 additions & 1 deletion core/src/test/resources/channels/simple-channel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ repositories:
- id: test
url: test-repository
manifest:
gav: org.test:test-manifest
maven:
groupId: org.test
artifactId: test-manifest

0 comments on commit 7ac35f9

Please sign in to comment.