Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFMP-225] Add a property for the channels configuration parameter. #417

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface PropertyNames {

String BATCH = "wildfly.batch";

String CHANNELS = "wildfly.channels";

String CHECK_PACKAGING = "wildfly.checkPackaging";

String COMMANDS = "wildfly.commands";
Expand Down
35 changes: 33 additions & 2 deletions plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,39 @@ public class DevMojo extends AbstractServerStartMojo {

/**
* A list of channels used for resolving artifacts while provisioning.
* <p>
* Defining a channel:
*
* <pre>
* &lt;channels&gt;
* &lt;channel&gt;
* &lt;manifest&gt;
* &lt;groupId&gt;org.wildfly.channels&lt;/groupId&gt;
* &lt;artifactId&gt;wildfly-30.0&lt;/artifactId&gt;
* &lt;/manifest&gt;
* &lt;/channel&gt;
* &lt;channel&gt;
* &lt;manifest&gt;
* &lt;url&gt;https://example.example.org/channel/30&lt;/url&gt;
* &lt;/manifest&gt;
* &lt;/channel&gt;
* &lt;/channels&gt;
* </pre>
* </p>
* <p>
* The {@code wildfly.channels} property can be used pass a comma delimited string for the channels. The channel
* can be a URL or a Maven GAV. If a Maven GAV is used, the groupId and artifactId are required.
* <br>
* Examples:
*
* <pre>
* -Dwildfly.channels=&quot;https://channels.example.org/30&quot;
* -Dwildfly.channels=&quot;https://channels.example.org/30,org.example.channel:updates-30&quot;
* -Dwildfly.channels=&quot;https://channels.example.org/30,org.example.channel:updates-30:1.0.2&quot;
* </pre>
* </p>
*/
@Parameter(alias = "channels")
@Parameter(property = PropertyNames.CHANNELS)
private List<ChannelConfiguration> channels;

/**
Expand Down Expand Up @@ -479,7 +510,7 @@ public String goal() {

@Override
protected MavenRepoManager createMavenRepoManager() throws MojoExecutionException {
if (channels == null) {
if (channels == null || channels.isEmpty()) {
return offlineProvisioning ? new MavenArtifactRepositoryManager(repoSystem, session)
: new MavenArtifactRepositoryManager(repoSystem, session, repositories);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,41 @@ abstract class AbstractProvisionServerMojo extends AbstractMojo {
@Parameter(alias = "layers-configuration-file-name", property = PropertyNames.WILDFLY_LAYERS_CONFIGURATION_FILE_NAME, defaultValue = STANDALONE_XML)
String layersConfigurationFileName;

@Parameter(alias = "channels", required = false)
/**
* A list of channels used for resolving artifacts while provisioning.
* <p>
* Defining a channel:
*
* <pre>
* <channels>
* <channel>
* <manifest>
* <groupId>org.wildfly.channels</groupId>
* <artifactId>wildfly-30.0</artifactId>
* </manifest>
* </channel>
* <channel>
* <manifest>
* <url>https://example.example.org/channel/30</url>
* </manifest>
* </channel>
* </channels>
* </pre>
* </p>
* <p>
* The {@code wildfly.channels} property can be used pass a comma delimited string for the channels. The channel
* can be a URL or a Maven GAV. If a Maven GAV is used, the groupId and artifactId are required.
* <br>
* Examples:
*
* <pre>
* -Dwildfly.channels=&quot;https://channels.example.org/30&quot;
* -Dwildfly.channels=&quot;https://channels.example.org/30,org.example.channel:updates-30&quot;
* -Dwildfly.channels=&quot;https://channels.example.org/30,org.example.channel:updates-30:1.0.2&quot;
* </pre>
* </p>
*/
@Parameter(alias = "channels", property = PropertyNames.CHANNELS)
List<ChannelConfiguration> channels;

/**
Expand Down Expand Up @@ -217,7 +251,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}
enrichRepositories();
if (channels == null) {
if (channels == null || channels.isEmpty()) {
artifactResolver = offlineProvisioning ? new MavenArtifactRepositoryManager(repoSystem, repoSession)
: new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/
package org.wildfly.plugin.provision;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.maven.plugin.MojoExecutionException;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -32,6 +35,7 @@
* @author jdenise
*/
public class ChannelConfiguration {
private static final Pattern FILE_MATCHER = Pattern.compile("^(file|http|https)://.*");

private ChannelManifestCoordinate manifest;

Expand All @@ -42,6 +46,28 @@ public ChannelManifestCoordinate getManifest() {
return manifest;
}

public void set(final String channel) {
// Is this a URL?
if (FILE_MATCHER.matcher(channel).matches()) {
try {
this.manifest = new ChannelManifestCoordinate(new URL(channel));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to parse URL for " + channel, e);
}
} else {
// Treat as a Maven GAV
final String[] coords = channel.split(":");
if (coords.length > 2) {
this.manifest = new ChannelManifestCoordinate(coords[0], coords[1], coords[2]);
} else if (coords.length == 2) {
this.manifest = new ChannelManifestCoordinate(coords[0], coords[1]);
} else {
throw new IllegalArgumentException(
"A channel must be a Maven GAV in the format groupId:artifactId:version. The groupId and artifactId are both required.");
}
}
}

void setManifest(ChannelManifestCoordinate manifest) {
this.manifest = manifest;
}
Expand Down