diff --git a/core/src/main/java/org/wildfly/channel/ChannelManifestCoordinate.java b/core/src/main/java/org/wildfly/channel/ChannelManifestCoordinate.java index 9372a96d..59f60f4c 100644 --- a/core/src/main/java/org/wildfly/channel/ChannelManifestCoordinate.java +++ b/core/src/main/java/org/wildfly/channel/ChannelManifestCoordinate.java @@ -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) { diff --git a/core/src/main/java/org/wildfly/channel/ChannelMapper.java b/core/src/main/java/org/wildfly/channel/ChannelMapper.java index 162447c9..7a45521f 100644 --- a/core/src/main/java/org/wildfly/channel/ChannelMapper.java +++ b/core/src/main/java/org/wildfly/channel/ChannelMapper.java @@ -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; diff --git a/core/src/main/java/org/wildfly/channel/MavenCoordinate.java b/core/src/main/java/org/wildfly/channel/MavenCoordinate.java new file mode 100644 index 00000000..185f41aa --- /dev/null +++ b/core/src/main/java/org/wildfly/channel/MavenCoordinate.java @@ -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); + } +} diff --git a/core/src/test/java/org/wildfly/channel/ChannelWithRequirementsTestCase.java b/core/src/test/java/org/wildfly/channel/ChannelWithRequirementsTestCase.java index de50f08e..637dc99d 100644 --- a/core/src/test/java/org/wildfly/channel/ChannelWithRequirementsTestCase.java +++ b/core/src/test/java/org/wildfly/channel/ChannelWithRequirementsTestCase.java @@ -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"); @@ -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"); @@ -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)); } diff --git a/core/src/test/resources/channels/2nd-level-requiring-channel.yaml b/core/src/test/resources/channels/2nd-level-requiring-channel.yaml index 6b88a96a..6d03784a 100644 --- a/core/src/test/resources/channels/2nd-level-requiring-channel.yaml +++ b/core/src/test/resources/channels/2nd-level-requiring-channel.yaml @@ -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 \ No newline at end of file diff --git a/core/src/test/resources/channels/channel-with-unknown-properties.yaml b/core/src/test/resources/channels/channel-with-unknown-properties.yaml index 84af27aa..c953cd76 100644 --- a/core/src/test/resources/channels/channel-with-unknown-properties.yaml +++ b/core/src/test/resources/channels/channel-with-unknown-properties.yaml @@ -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 diff --git a/core/src/test/resources/channels/required-channel-2.yaml b/core/src/test/resources/channels/required-channel-2.yaml index f0d795ca..439fd19d 100644 --- a/core/src/test/resources/channels/required-channel-2.yaml +++ b/core/src/test/resources/channels/required-channel-2.yaml @@ -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 \ No newline at end of file diff --git a/core/src/test/resources/channels/required-channel.yaml b/core/src/test/resources/channels/required-channel.yaml index df256892..32ef78c9 100644 --- a/core/src/test/resources/channels/required-channel.yaml +++ b/core/src/test/resources/channels/required-channel.yaml @@ -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 diff --git a/core/src/test/resources/channels/simple-channel.yaml b/core/src/test/resources/channels/simple-channel.yaml index d0f4baed..2a388a81 100644 --- a/core/src/test/resources/channels/simple-channel.yaml +++ b/core/src/test/resources/channels/simple-channel.yaml @@ -10,4 +10,6 @@ repositories: - id: test url: test-repository manifest: - gav: org.test:test-manifest + maven: + groupId: org.test + artifactId: test-manifest