Skip to content

Commit

Permalink
Fix for WFMP-178, Upgrade to wildfly-channel 1.0.0.Beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Jan 25, 2023
1 parent d8ef131 commit 041e1f0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.jboss.galleon.util.IoUtils;
import org.jboss.galleon.xml.ProvisioningXmlWriter;
import org.wildfly.channel.UnresolvedMavenArtifactException;
import org.wildfly.channel.maven.ChannelCoordinate;
import org.wildfly.plugin.common.PropertyNames;
import org.wildfly.plugin.common.Utils;
import org.wildfly.plugin.core.GalleonUtils;
Expand Down Expand Up @@ -178,7 +177,7 @@ abstract class AbstractProvisionServerMojo extends AbstractMojo {
String layersConfigurationFileName;

@Parameter(alias = "channels", required = false)
List<ChannelCoordinate> channels;
List<ChannelConfiguration> channels;

private Path wildflyDir;

Expand All @@ -203,8 +202,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
: new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
} else {
try {
artifactResolver = offlineProvisioning ? new ChannelMavenArtifactRepositoryManager(channels, repoSystem, repoSession)
: new ChannelMavenArtifactRepositoryManager(channels, repoSystem, repoSession, repositories);
artifactResolver = new ChannelMavenArtifactRepositoryManager(channels, repoSystem, repoSession, repositories, getLog(), offlineProvisioning);
} catch (MalformedURLException | UnresolvedMavenArtifactException ex) {
throw new MojoExecutionException(ex.getLocalizedMessage(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.plugin.provision;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.eclipse.aether.repository.RemoteRepository;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelManifestCoordinate;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.channel.InvalidChannelMetadataException;
import org.wildfly.channel.Repository;

/**
* A channel configuration. One of url or manifest coordinates.
*
* @author jdenise
*/
public class ChannelConfiguration {

private URL url;
private ChannelManifestCoordinate manifestCoordinate;

/**
* @return the url
*/
public URL getUrl() {
return url;
}

/**
* @return the manifestCoordinate
*/
public ChannelManifestCoordinate getManifestCoordinate() {
return manifestCoordinate;
}

private void validate() throws MojoExecutionException {
if (getUrl() != null) {
if (getManifestCoordinate() != null) {
throw new MojoExecutionException("Invalid Channel. A manifest-coordinate is specified although an URL is provided.");
}
} else {
if (getManifestCoordinate() == null) {
throw new MojoExecutionException("Invalid Channel. No manifest-coordinate or URL specified.");
} else {
ChannelManifestCoordinate coordinates = getManifestCoordinate();
if (coordinates.getUrl() == null) {
if (coordinates.getGroupId() == null) {
throw new MojoExecutionException("Invalid Channel. Manifest groupId is null.");
}
if (coordinates.getArtifactId() == null) {
throw new MojoExecutionException("Invalid Channel. Manifest artifactId is null.");
}
} else {
if (coordinates.getGroupId() != null) {
throw new MojoExecutionException("Invalid Channel. Manifest groupId is set although an URL is provided.");
}
if (coordinates.getArtifactId() != null) {
throw new MojoExecutionException("Invalid Channel. Manifest artifactId is set although an URL is provided.");
}
}
}
}
}

public Channel toChannel(Set<String> remoteRepositories, List<RemoteRepository> repositories, Log log) throws MojoExecutionException {
validate();
Channel channel;
if (getUrl() == null) {
List<Repository> repos = new ArrayList<>();
for (RemoteRepository r : repositories) {
repos.add(new Repository(r.getId(), r.getUrl()));
}
channel = new Channel(null, null, null, repos, getManifestCoordinate(), null, null);
} else {
try {
channel = ChannelMapper.from(getUrl());
for (Repository r : channel.getRepositories()) {
if (!remoteRepositories.contains(r.getId())) {
log.warn("Repository id " + r.getId() + " defined in channel " + getUrl()
+ " is not found in the configured Maven "
+ "repositories. Will create a new repository.");
}
}
} catch (InvalidChannelMetadataException ex) {
throw new MojoExecutionException("Invalid Channel: "
+ (ex.getValidationMessages() == null ? "" : ex.getValidationMessages()), ex);
}
}
return channel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Pattern;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;

import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
Expand All @@ -33,30 +39,44 @@
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelManifest;
import org.wildfly.channel.ChannelSession;
import org.wildfly.channel.Repository;
import org.wildfly.channel.UnresolvedMavenArtifactException;
import org.wildfly.channel.maven.ChannelCoordinate;
import org.wildfly.channel.maven.VersionResolverFactory;
import static org.wildfly.channel.maven.VersionResolverFactory.DEFAULT_REPOSITORY_MAPPER;
import org.wildfly.channel.spi.ChannelResolvable;
import org.wildfly.prospero.metadata.ProsperoMetadataUtils;

public class ChannelMavenArtifactRepositoryManager implements MavenRepoManager, ChannelResolvable {

private final ChannelSession channelSession;
private final List<Channel> channels;
public ChannelMavenArtifactRepositoryManager(List<ChannelCoordinate> channelCoords,
RepositorySystem system, RepositorySystemSession contextSession) throws MalformedURLException, UnresolvedMavenArtifactException {
this(channelCoords, system, contextSession, null);
}

public ChannelMavenArtifactRepositoryManager(List<ChannelCoordinate> channelCoords,
RepositorySystem system,
RepositorySystemSession contextSession,
List<RemoteRepository> repositories) throws MalformedURLException, UnresolvedMavenArtifactException {
private final List<Channel> channels = new ArrayList<>();

public ChannelMavenArtifactRepositoryManager(List<ChannelConfiguration> channels,
RepositorySystem system,
RepositorySystemSession contextSession,
List<RemoteRepository> repositories, Log log, boolean offline) throws MalformedURLException, UnresolvedMavenArtifactException, MojoExecutionException {
if (channels.isEmpty()) {
throw new MojoExecutionException("No channel specified.");
}
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(contextSession.getLocalRepositoryManager());
VersionResolverFactory factory = new VersionResolverFactory(system, session);
channels = factory.resolveChannels(channelCoords, repositories);
channelSession = new ChannelSession(channels, factory);
session.setOffline(offline);
Map<String, RemoteRepository> mapping = new HashMap<>();
for (RemoteRepository r : repositories) {
mapping.put(r.getId(), r);
}
for (ChannelConfiguration channelConfiguration : channels) {
this.channels.add(channelConfiguration.toChannel(mapping.keySet(), repositories, log));
}
Function<Repository, RemoteRepository> mapper = r -> {
RemoteRepository rep = mapping.get(r.getId());
if (rep == null) {
rep = DEFAULT_REPOSITORY_MAPPER.apply(r);
}
return rep;
};
VersionResolverFactory factory = new VersionResolverFactory(system, session, mapper);
channelSession = new ChannelSession(this.channels, factory);
}

@Override
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
<!-- This version property is also retrieved by plugin at runtime to resolve CLI artifact -->
<version.org.wildfly.core>19.0.1.Final</version.org.wildfly.core>
<version.org.wildfly>26.1.2.Final</version.org.wildfly>
<version.org.wildfly.channel>1.0.0.Beta4-SNAPSHOT</version.org.wildfly.channel>
<version.org.wildfly.prospero>1.0.0.Beta5-SNAPSHOT</version.org.wildfly.prospero>
<version.org.wildfly.channel>1.0.0.Beta4</version.org.wildfly.channel>
<version.org.wildfly.prospero>1.0.0.Beta5</version.org.wildfly.prospero>
<!-- maven dependencies -->
<version.javax.inject.javax.inject>1</version.javax.inject.javax.inject>
<version.org.apache.maven.maven-core>3.3.9</version.org.apache.maven.maven-core>
Expand Down Expand Up @@ -358,6 +358,12 @@
<groupId>org.wildfly.prospero</groupId>
<artifactId>prospero-metadata</artifactId>
<version>${version.org.wildfly.prospero}</version>
<exclusions>
<exclusion>
<groupId>org.wildfly.channel</groupId>
<artifactId>channel-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
Expand Down

0 comments on commit 041e1f0

Please sign in to comment.