Skip to content

Commit

Permalink
Merge pull request #554 from jfdenise/WFMP-257
Browse files Browse the repository at this point in the history
Fix for WFMP-257, Glow support ignore channels
  • Loading branch information
jamezp authored Sep 11, 2024
2 parents 621fc1b + a451839 commit 687d0eb
Show file tree
Hide file tree
Showing 8 changed files with 593 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.jboss.galleon.api.MavenStreamResolver;
import org.jboss.galleon.api.Provisioning;
import org.jboss.galleon.universe.maven.MavenArtifact;
Expand Down Expand Up @@ -56,6 +61,8 @@ public class ChannelMavenArtifactRepositoryManager implements MavenRepoManager,
private final Log log;
private final Path localCachePath;
private final RepositorySystem system;
private final DefaultRepositorySystemSession session;
private final List<RemoteRepository> repositories;

public ChannelMavenArtifactRepositoryManager(List<ChannelConfiguration> channels,
RepositorySystem system,
Expand All @@ -66,7 +73,8 @@ public ChannelMavenArtifactRepositoryManager(List<ChannelConfiguration> channels
throw new MojoExecutionException("No channel specified.");
}
this.log = log;
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session = MavenRepositorySystemUtils.newSession();
this.repositories = repositories;
session.setLocalRepositoryManager(contextSession.getLocalRepositoryManager());
session.setOffline(offline);
Map<String, RemoteRepository> mapping = new HashMap<>();
Expand Down Expand Up @@ -201,29 +209,37 @@ public boolean isLatestVersionResolved(MavenArtifact artifact, String lowestQual
@Override
public void resolveLatestVersion(MavenArtifact artifact, String lowestQualifier, Pattern includeVersion,
Pattern excludeVersion) throws MavenUniverseException {
throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe");
resolveLatestVersion(artifact, null, false);
}

@Override
public void resolveLatestVersion(MavenArtifact artifact, String lowestQualifier, boolean locallyAvailable)
throws MavenUniverseException {
throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe");
artifact.setVersion(getLatestVersion(artifact));
resolve(artifact);
}

@Override
public String getLatestVersion(MavenArtifact artifact) throws MavenUniverseException {
throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe");
return getLatestVersion(artifact, null, null, null);
}

@Override
public String getLatestVersion(MavenArtifact artifact, String lowestQualifier) throws MavenUniverseException {
throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe");
return getLatestVersion(artifact, lowestQualifier, null, null);
}

@Override
public String getLatestVersion(MavenArtifact artifact, String lowestQualifier, Pattern includeVersion,
Pattern excludeVersion) throws MavenUniverseException {
throw new MavenUniverseException("Channel resolution can't be applied to Galleon universe");
try {
return channelSession.resolveMavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(),
artifact.getClassifier(), null).getVersion();
} catch (UnresolvedMavenArtifactException e) {
VersionRangeResult res = getVersionRange(new DefaultArtifact(artifact.getGroupId(),
artifact.getArtifactId(), artifact.getExtension(), artifact.getVersionRange()));
return res.getHighestVersion().toString();
}
}

@Override
Expand All @@ -248,4 +264,18 @@ public String getLatestVersion(String groupId, String artifactId, String extensi
baseVersion);
return res.getVersion();
}

private VersionRangeResult getVersionRange(Artifact artifact) throws MavenUniverseException {
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(repositories);
VersionRangeResult rangeResult;
try {
rangeResult = system.resolveVersionRange(session, rangeRequest);
} catch (VersionRangeResolutionException ex) {
throw new MavenUniverseException(ex.getLocalizedMessage(), ex);
}
return rangeResult;
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

<!-- galleon properties -->
<version.org.jboss.galleon>6.0.3.Final</version.org.jboss.galleon>
<version.org.wildfly.glow>1.0.6.Final</version.org.wildfly.glow>
<version.org.wildfly.glow>1.1.0.Final</version.org.wildfly.glow>
<plugin.fork.embedded>true</plugin.fork.embedded>
<!-- used by tests -->
<version.org.jboss.logging.slf4j-jboss-logging>1.2.1.Final</version.org.jboss.logging.slf4j-jboss-logging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
@RunWith(JUnit4.class)
public abstract class AbstractProvisionConfiguredMojoTestCase extends AbstractMojoTestCase {
private static final String TEST_REPLACE_WF_VERSION = "WF_VERSION";
private static final String TEST_REPLACE_BASE_DIR_ABSOLUTE_URL = "WF_BASE_DIR_ABSOLUTE_URL";
static final String WILDFLY_VERSION = "wildfly.test.version";
private final String artifactId;

Expand Down Expand Up @@ -153,6 +154,9 @@ private void patchPomFile(final Path pom) throws IOException {
if (s.contains(TEST_REPLACE_WF_VERSION)) {
s = s.replace(TEST_REPLACE_WF_VERSION, System.getProperty(WILDFLY_VERSION));
}
if (s.contains(TEST_REPLACE_BASE_DIR_ABSOLUTE_URL)) {
s = s.replace(TEST_REPLACE_BASE_DIR_ABSOLUTE_URL, pom.getParent().toUri().toString());
}
content.append(s).append(System.lineSeparator());
}
Files.write(pom, content.toString().getBytes());
Expand Down
6 changes: 5 additions & 1 deletion tests/standalone-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@
<artifactId>parsson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.wildfly.channel</groupId>
<artifactId>channel-core</artifactId>
<scope>test</scope>
</dependency>
<!-- to fix slf4j warning when provisioning -->
<dependency>
<groupId>org.jboss.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ public void testPackage() throws Exception {
"org.wildfly.maven.plugin-package-goal-from-script");
}

@Test
public void testPackageWithChannel() throws Exception {

final Mojo packageMojo = lookupConfiguredMojo(AbstractWildFlyMojoTest.getPomFile("package-channel-pom.xml").toFile(),
"package");

packageMojo.execute();
Path jbossHome = AbstractWildFlyMojoTest.getBaseDir().resolve("target").resolve("packaged-channel-server");
Assert.assertTrue(Files.exists(jbossHome.resolve("standalone").resolve("configuration").resolve("foo.txt")));
String[] layers = { "jaxrs-server" };
String[] excluded = { "deployment-scanner" };
checkStandaloneWildFlyHome(jbossHome, 1, layers, excluded, true, "org.wildfly.maven.plugin-package-goal",
"org.wildfly.maven.plugin-package-goal-from-script");
}

@Test
public void testPackageWithChannelGlow() throws Exception {

final Mojo packageMojo = lookupConfiguredMojo(
AbstractWildFlyMojoTest.getPomFile("package-channel-glow-pom.xml").toFile(),
"package");

packageMojo.execute();
Path jbossHome = AbstractWildFlyMojoTest.getBaseDir().resolve("target").resolve("packaged-channel-glow-server");
Assert.assertTrue(Files.exists(jbossHome.resolve("standalone").resolve("configuration").resolve("foo.txt")));
String[] layers = { "ee-core-profile-server" };
checkStandaloneWildFlyHome(jbossHome, 1, layers, null, true, "org.wildfly.maven.plugin-package-goal",
"org.wildfly.maven.plugin-package-goal-from-script");
}

@Test
public void testDefaultConfigPackage() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testing</groupId>
<artifactId>testing</artifactId>
<version>0.1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<channels>
<channel>
<manifest>
<!-- Use local file until keycloak version 25.x is used by Glow, will be WF 34.0.0.Final -->
<url>WF_BASE_DIR_ABSOLUTE_URL/wildfly-32.0.0.Final-manifest.yaml</url>
</manifest>
</channel>
</channels>
<discover-provisioning-info />
<packaging-scripts>
<packaging-script>
<scripts>
<script>test-package.cli</script>
</scripts>
<commands>
<command>/system-property=org.wildfly.maven.plugin-package-goal:add(value=true)</command>
</commands>
</packaging-script>
</packaging-scripts>
<filename>test.war</filename>
<extra-server-content-dirs>
<dir>extra-content</dir>
</extra-server-content-dirs>
<record-provisioning-state>true</record-provisioning-state>
<provisioning-dir>packaged-channel-glow-server</provisioning-dir>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testing</groupId>
<artifactId>testing</artifactId>
<version>0.1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<channels>
<channel>
<manifest>
<groupId>org.wildfly.channels</groupId>
<artifactId>wildfly</artifactId>
</manifest>
</channel>
</channels>
<feature-packs>
<feature-pack>
<location>org.wildfly:wildfly-galleon-pack</location>
</feature-pack>
</feature-packs>
<layers>
<layer>jaxrs-server</layer>
</layers>
<excluded-layers>
<layer>deployment-scanner</layer>
</excluded-layers>
<packaging-scripts>
<packaging-script>
<scripts>
<script>test-package.cli</script>
</scripts>
<commands>
<command>/system-property=org.wildfly.maven.plugin-package-goal:add(value=true)</command>
</commands>
</packaging-script>
</packaging-scripts>
<filename>test.war</filename>
<extra-server-content-dirs>
<dir>extra-content</dir>
</extra-server-content-dirs>
<record-provisioning-state>true</record-provisioning-state>
<provisioning-dir>packaged-channel-server</provisioning-dir>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 687d0eb

Please sign in to comment.