diff --git a/plugin/pom.xml b/plugin/pom.xml
index 23326a1..1fd0667 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -136,6 +136,12 @@
+
+ io.smallrye
+ jandex
+ ${version.jandex}
+
+
org.apache.maven.shared
@@ -164,9 +170,9 @@
test
- io.smallrye
- jandex
- ${version.jandex}
+ org.mockito
+ mockito-core
+ test
diff --git a/plugin/src/main/java/org/wildfly/channelplugin/AbstractChannelMojo.java b/plugin/src/main/java/org/wildfly/channelplugin/AbstractChannelMojo.java
index c3a2035..b4adfcf 100644
--- a/plugin/src/main/java/org/wildfly/channelplugin/AbstractChannelMojo.java
+++ b/plugin/src/main/java/org/wildfly/channelplugin/AbstractChannelMojo.java
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
@@ -104,7 +105,8 @@ protected void initChannelSession() throws MojoExecutionException {
channelFilePath = Path.of(mavenSession.getExecutionRootDirectory()).resolve(channelFilePath);
}
getLog().info("Reading channel file " + channelFilePath);
- channels.add(ChannelMapper.from(channelFilePath.toUri().toURL()));
+ String yaml = Files.readString(channelFilePath);
+ channels.addAll(ChannelMapper.fromString(yaml));
}
}
if (StringUtils.isNotBlank(channelGAV)) {
@@ -140,6 +142,8 @@ protected void initChannelSession() throws MojoExecutionException {
}
} catch (MalformedURLException e) {
throw new MojoExecutionException("Can't parse the channel or manifest file path", e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Can't read channel metadata file", e);
}
if (!remoteRepositories.isEmpty()) {
diff --git a/plugin/src/test/java/org/wildfly/channelplugin/AbstractChannelMojoTestCase.java b/plugin/src/test/java/org/wildfly/channelplugin/AbstractChannelMojoTestCase.java
new file mode 100644
index 0000000..b63c2c2
--- /dev/null
+++ b/plugin/src/test/java/org/wildfly/channelplugin/AbstractChannelMojoTestCase.java
@@ -0,0 +1,76 @@
+package org.wildfly.channelplugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.assertj.core.api.Assertions;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mockito;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+
+public class AbstractChannelMojoTestCase {
+
+ @TempDir
+ File tempDir;
+
+ private final RepositorySystem repositorySystem = Mockito.mock(RepositorySystem.class);
+
+ private AbstractChannelMojo mojo;
+
+ @BeforeEach
+ public void before() throws Exception {
+ // Prepare test resources as local files
+ Path channelFile = prepareResource("multiple-channels.yaml");
+ Path manifestFile = prepareResource("manifest.yaml");
+
+ // Mock RepositorySystem, the resolveArtifact() method must return a valid manifest file because this is needed
+ // for ChannelSession init.
+ ArtifactResult artifactResult = new ArtifactResult(new ArtifactRequest());
+ artifactResult.setArtifact(new DefaultArtifact(null, null, null, null, null, Collections.emptyMap(),
+ manifestFile.toFile()));
+ Mockito.when(repositorySystem.resolveArtifact(Mockito.any(), Mockito.any()))
+ .thenReturn(artifactResult);
+
+ // Initialize a concrete instance of the AbstractChannelMojo class
+ mojo = new AbstractChannelMojo() {
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ }
+ };
+ mojo.channelFile = channelFile.toString();
+ mojo.remoteRepositories = Collections.emptyList();
+ mojo.repositorySystem = repositorySystem;
+ }
+
+ @Test
+ public void testMultipleChannelsInFile() throws Exception {
+ mojo.initChannelSession();
+
+ Assertions.assertThat(mojo.channels.size()).isEqualTo(2);
+ Assertions.assertThat(mojo.channels).extracting("manifestCoordinate.artifactId").containsAll(
+ List.of("eap-8.0", "eap-xp-5.0"));
+ }
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ private Path prepareResource(String resourceName) throws IOException {
+ tempDir.mkdir();
+ Path targetFile = tempDir.toPath().resolve(resourceName);
+ InputStream resource = getClass().getResourceAsStream(resourceName);
+ Assertions.assertThat(resource).isNotNull().withFailMessage("Resource not found: " + resourceName);
+ Files.copy(resource, targetFile);
+ return targetFile;
+ }
+}
diff --git a/plugin/src/test/resources/org/wildfly/channelplugin/manifest.yaml b/plugin/src/test/resources/org/wildfly/channelplugin/manifest.yaml
new file mode 100644
index 0000000..499b5dc
--- /dev/null
+++ b/plugin/src/test/resources/org/wildfly/channelplugin/manifest.yaml
@@ -0,0 +1,2 @@
+---
+schemaVersion: 1.0.0
\ No newline at end of file
diff --git a/plugin/src/test/resources/org/wildfly/channelplugin/multiple-channels.yaml b/plugin/src/test/resources/org/wildfly/channelplugin/multiple-channels.yaml
new file mode 100644
index 0000000..7fb105e
--- /dev/null
+++ b/plugin/src/test/resources/org/wildfly/channelplugin/multiple-channels.yaml
@@ -0,0 +1,24 @@
+---
+schemaVersion: "2.0.0"
+name: "eap-xp-5.0-channel"
+repositories:
+ - id: "Brew"
+ url: "https://download.eng.bos.redhat.com/brewroot/repos/jb-eap-8.0-maven-build/latest/maven/"
+manifest:
+ maven:
+ groupId: "org.jboss.eap.channels"
+ artifactId: "eap-xp-5.0"
+ version: "1.0.0"
+noStreamStrategy: "none"
+---
+schemaVersion: "2.0.0"
+name: "eap-8.0-channel"
+repositories:
+ - id: "Brew"
+ url: "https://download.eng.bos.redhat.com/brewroot/repos/jb-eap-8.0-maven-build/latest/maven/"
+manifest:
+ maven:
+ groupId: "org.jboss.eap.channels"
+ artifactId: "eap-8.0"
+ version: "1.0.0"
+noStreamStrategy: "none"
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 769c540..ae98f5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -219,6 +219,13 @@
test
+
+ org.mockito
+ mockito-core
+ 5.11.0
+ test
+
+
com.soebes.itf.jupiter.extension