Skip to content

Commit

Permalink
Merge pull request #358 from jfdenise/main
Browse files Browse the repository at this point in the history
Upgrade Galleon to 5.1.0.Final and wildfly-core to 20.0.0.Final
  • Loading branch information
jfdenise authored Apr 6, 2023
2 parents ebdd2c2 + c2cfbef commit 0d9e58d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,6 @@ public abstract class AbstractBuildBootableJarMojo extends AbstractMojo {
@Parameter(alias = "channels", required = false)
List<ChannelConfiguration> channels;

/**
* When channels are configured, the maven artifact versions are retrieved
* from the configured channels. If the artifact version can't be resolved
* from the channel, the provisioning fails. By setting this parameter to
* true, the original version of the artifact (e.g.: feature-pack versions
* configured in the plugin or artifact versions known by the feature-pack)
* is used.
*/
@Parameter(alias = "original-artifact-version-resolution", required = false, property = "wildfly.bootable.jar.original-artifact-version-resolution", defaultValue = "false")
boolean originalVersionResolution;

MavenProjectArtifactVersions artifactVersions;

@Inject
Expand Down Expand Up @@ -438,7 +427,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
artifactResolver = new ChannelMavenArtifactRepositoryManager(channels,
repoSystem, repoSession, repositories,
getLog(), offline, originalVersionResolution);
getLog(), offline);
} catch (MalformedURLException | UnresolvedMavenArtifactException ex) {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
*/
package org.wildfly.plugins.bootablejar.maven.goals;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.regex.Pattern;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -33,9 +37,12 @@
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.layout.FeaturePackDescriber;
import org.jboss.galleon.universe.maven.MavenArtifact;
import org.jboss.galleon.universe.maven.MavenUniverseException;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.util.ZipUtils;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.ChannelSession;
Expand All @@ -49,23 +56,22 @@
import org.wildfly.prospero.metadata.ProsperoMetadataUtils;

public class ChannelMavenArtifactRepositoryManager implements MavenRepoManager, ChannelResolvable {
private static final String REQUIRE_CHANNEL_FOR_ALL_ARTIFACT = "org.wildfly.plugins.galleon.all.artifact.requires.channel.resolution";

private final ChannelSession channelSession;
private final List<Channel> channels = new ArrayList<>();
private final boolean originalVersionResolution;
private final Log log;
private final Path localCachePath;
private final RepositorySystem system;

public ChannelMavenArtifactRepositoryManager(List<ChannelConfiguration> channels,
RepositorySystem system,
RepositorySystemSession contextSession,
List<RemoteRepository> repositories, Log log, boolean offline, boolean originalVersionResolution) throws MalformedURLException, UnresolvedMavenArtifactException, MojoExecutionException {
List<RemoteRepository> repositories, Log log, boolean offline) throws MalformedURLException, UnresolvedMavenArtifactException, MojoExecutionException {
if (channels.isEmpty()) {
throw new MojoExecutionException("No channel specified.");
}
this.log = log;
this.originalVersionResolution = originalVersionResolution;
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(contextSession.getLocalRepositoryManager());
session.setOffline(offline);
Expand Down Expand Up @@ -94,19 +100,30 @@ public void resolve(MavenArtifact artifact) throws MavenUniverseException {
try {
resolveFromChannels(artifact);
} catch (UnresolvedMavenArtifactException ex) {
if (originalVersionResolution) {
log.warn("Resolution of artifact " + artifact.getGroupId() + ":" +
artifact.getArtifactId() + " failed. Using original version.");
boolean requireChannel = Boolean.parseBoolean(artifact.getMetadata().get(REQUIRE_CHANNEL_FOR_ALL_ARTIFACT));
if (!requireChannel) {
// Could be a feature-pack that could require to be resolved from a channel.
try {
requireChannel = fpRequireChannel(artifact);
} catch (Exception exception) {
log.error("Error attempting to read artifact as a feature-pack", exception);
ex.addSuppressed(exception);
throw new MavenUniverseException(ex.getLocalizedMessage(), ex);
}
}
if (!requireChannel) {
log.warn("Resolution of artifact " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + " failed using configured channels. Using original version.");
// unable to resolve the artifact through the channel.
// if the version is defined, let's resolve it directly
if (artifact.getVersion() == null) {
log.error("No version provided.");
throw new MavenUniverseException(ex.getLocalizedMessage(), ex);
}
try {
log.warn("Using version " + artifact.getVersion() +
" to resolve artifact " + artifact.getGroupId() + ":" +
artifact.getArtifactId());
log.warn("Using version " + artifact.getVersion()
+ " to resolve artifact " + artifact.getGroupId() + ":"
+ artifact.getArtifactId());
org.wildfly.channel.MavenArtifact mavenArtifact = channelSession.resolveDirectMavenArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(), artifact.getClassifier(), artifact.getVersion());
artifact.setPath(mavenArtifact.getFile().toPath());
} catch (UnresolvedMavenArtifactException e) {
Expand All @@ -119,6 +136,40 @@ public void resolve(MavenArtifact artifact) throws MavenUniverseException {
}
}

private boolean fpRequireChannel(MavenArtifact artifact) throws Exception {
boolean requireChannel = false;
if (artifact.getVersion() != null && artifact.getExtension() != null && artifact.getExtension().equalsIgnoreCase("zip")) {
org.wildfly.channel.MavenArtifact mavenArtifact = channelSession.
resolveDirectMavenArtifact(artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getExtension(),
artifact.getClassifier(),
artifact.getVersion());
try {
FeaturePackDescriber.readSpec(mavenArtifact.getFile().toPath());
} catch(ProvisioningException ex) {
// Not a feature-pack
return requireChannel;
}
try (FileSystem fs = ZipUtils.newFileSystem(mavenArtifact.getFile().toPath())) {
Path resPath = fs.getPath("resources");
final Path wfRes = resPath.resolve("wildfly");
final Path channelPropsPath = wfRes.resolve("wildfly-channel.properties");
if (Files.exists(channelPropsPath)) {
Properties props = new Properties();
try(BufferedReader reader = Files.newBufferedReader(channelPropsPath)) {
props.load(reader);
}
String resolution = props.getProperty("resolution");
if (resolution != null) {
requireChannel = "REQUIRED".equals(resolution) || "REQUIRED_FP_ONLY".equals(resolution);
}
}
}
}
return requireChannel;
}

private void resolveFromChannels(MavenArtifact artifact) throws UnresolvedMavenArtifactException {
org.wildfly.channel.MavenArtifact result = channelSession.resolveMavenArtifact(artifact.getGroupId(),
artifact.getArtifactId(), artifact.getExtension(), artifact.getClassifier(), artifact.getVersion());
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
<version.org.apache.maven.plugin-tools>3.6.4</version.org.apache.maven.plugin-tools>
<version.org.apache.maven.plugin-plugin>3.6.4</version.org.apache.maven.plugin-plugin>
<version.org.asciidoctor>2.0.0</version.org.asciidoctor>
<version.org.jboss.galleon>5.0.9.Final</version.org.jboss.galleon>
<version.org.wildfly.core.wildfly-core>20.0.0.Beta8</version.org.wildfly.core.wildfly-core>
<version.org.jboss.galleon>5.1.0.Final</version.org.jboss.galleon>
<version.org.wildfly.core.wildfly-core>20.0.0.Final</version.org.wildfly.core.wildfly-core>
<version.org.wildfly.common>1.5.4.Final</version.org.wildfly.common>
<version.org.wildfly.plugins.wildfly-maven-plugin>4.1.0.Beta4</version.org.wildfly.plugins.wildfly-maven-plugin>
<version.org.wildfly.channel>1.0.0.Beta6</version.org.wildfly.channel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private void setupTestChannel(BuildBootableJarMojo mojo) throws IOException {
ChannelConfiguration config = new ChannelConfiguration();
config.setManifest(coordinate);
mojo.channels.add(config);
mojo.originalVersionResolution=true;
}

@Test
Expand Down

0 comments on commit 0d9e58d

Please sign in to comment.