Skip to content

Commit

Permalink
Merge pull request #109 from jfdenise/maven-metadata
Browse files Browse the repository at this point in the history
Fix for Issue #108, Glow Metadata should be retrieved from Maven
  • Loading branch information
jfdenise authored Jan 15, 2025
2 parents 3d97b61 + 834759d commit dcf644b
Show file tree
Hide file tree
Showing 22 changed files with 576 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.FeaturePackLocation.FPID;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.util.IoUtils;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.glow.AddOn;
import org.wildfly.glow.Arguments;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.MetadataProvider;
import org.wildfly.glow.ProvisioningUtils;
import org.wildfly.glow.ScanArguments;
import org.wildfly.glow.Space;
import org.wildfly.glow.WildFlyMavenMetadataProvider;
import org.wildfly.glow.cli.support.CLIConfigurationResolver;
import org.wildfly.glow.maven.MavenResolver;
import picocli.CommandLine;
Expand Down Expand Up @@ -73,38 +75,55 @@ public class ShowAddOnsCommand extends AbstractCommand {
@Override
public Integer call() throws Exception {
print("Wildfly Glow is retrieving add-ons...");
String context = Arguments.BARE_METAL_EXECUTION_CONTEXT;
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
ScanArguments.Builder builder = Arguments.scanBuilder();
MavenRepoManager repoManager;
List<Channel> channels = Collections.emptyList();
if (channelsFile.isPresent()) {
String content = Files.readString(channelsFile.get());
channels = ChannelMapper.fromString(content);
builder.setChannels(channels);
repoManager = MavenResolver.newMavenResolver(channels);
} else {
repoManager = MavenResolver.newMavenResolver();
}
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata");
try {
MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(repoManager, tmpMetadataDirectory);
String context = Arguments.BARE_METAL_EXECUTION_CONTEXT;
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
}
}
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
}
showAddOns(Space.DEFAULT, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
wildflyPreview.orElse(false), channelsFile.orElse(null));
String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : FeaturePacks.getLatestVersion();
for(String spaceName : spaces) {
Set<String> versions = FeaturePacks.getAllVersions(spaceName);
if (versions.contains(vers)) {
Space space = FeaturePacks.getSpace(spaceName);
showAddOns(space, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
wildflyPreview.orElse(false), channelsFile.orElse(null));
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
}
print("@|bold Add-ons can be set using the|@ @|fg(yellow) %s=<list of add-ons>|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.ADD_ONS_OPTION, Constants.SCAN_COMMAND);
showAddOns(Space.DEFAULT, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
wildflyPreview.orElse(false), channels, repoManager, metadataProvider);
String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : metadataProvider.getLatestVersion();
for (String spaceName : spaces) {
Set<String> versions = metadataProvider.getAllVersions(spaceName);
if (versions.contains(vers)) {
Space space = metadataProvider.getSpace(spaceName);
showAddOns(space, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
wildflyPreview.orElse(false), channels, repoManager, metadataProvider);
}
}
print("@|bold Add-ons can be set using the|@ @|fg(yellow) %s=<list of add-ons>|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.ADD_ONS_OPTION, Constants.SCAN_COMMAND);

return 0;
return 0;
} finally {
IoUtils.recursiveDelete(tmpMetadataDirectory);
}
}

public void showAddOns(Space space, String context, Path provisioningXml, boolean isLatest,
String serverVersion, boolean isPreview, Path channelsFile) throws Exception {
String serverVersion, boolean isPreview, List<Channel> channels, MavenRepoManager repoManager, MetadataProvider metadataProvider) throws Exception {
CLIConfigurationResolver resolver = new CLIConfigurationResolver();
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
Expand Down Expand Up @@ -161,18 +180,7 @@ public void consume(Space space, GalleonProvisioningConfig provisioning, Map<Str
}

};
ScanArguments.Builder builder = Arguments.scanBuilder();
MavenRepoManager repoManager;
List<Channel> channels = Collections.emptyList();
if (channelsFile != null) {
String content = Files.readString(channelsFile);
channels = ChannelMapper.fromString(content);
builder.setChannels(channels);
repoManager = MavenResolver.newMavenResolver(channels);
} else {
repoManager = MavenResolver.newMavenResolver();
}
ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml, isLatest, serverVersion,
isPreview, channels, repoManager);
isPreview, channels, repoManager, metadataProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
import org.jboss.galleon.universe.FeaturePackLocation.FPID;
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.jboss.galleon.util.IoUtils;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.glow.maven.MavenResolver;
import org.wildfly.glow.Arguments;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.MetadataProvider;
import org.wildfly.glow.ScanArguments;
import org.wildfly.glow.Space;
import org.wildfly.glow.WildFlyMavenMetadataProvider;
import org.wildfly.glow.deployment.openshift.api.Deployer;

import picocli.CommandLine;
Expand Down Expand Up @@ -79,47 +81,6 @@ public class ShowConfigurationCommand extends AbstractCommand {
public Integer call() throws Exception {
print("Wildfly Glow is retrieving known provisioning configuration...");
StringBuilder ocBuilder = new StringBuilder();
ocBuilder.append("\nDeployers enabled when provisioning to OpenShift:\n");
for (Deployer d : ServiceLoader.load(Deployer.class)) {
ocBuilder.append("* @|bold " + d.getName() + "|@. Enabled when the layer(s) " + d.getSupportedLayers() + " is/are discovered.\n");
}
print(ocBuilder.toString());
StringBuilder spacesBuilder = new StringBuilder();
spacesBuilder.append("\nSpaces from which more feature-packs can be used when scanning deployments (use the " + Constants.SPACES_OPTION + " option to enable the space(s):\n");
for(Space space : FeaturePacks.getAllSpaces()) {
spacesBuilder.append("* @|bold " + space.getName() + "|@. " + space.getDescription() + "\n");
}
print(spacesBuilder.toString());

String context = Arguments.BARE_METAL_EXECUTION_CONTEXT;
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
}
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
String finalContext = context;
boolean isLatest = wildflyServerVersion.isEmpty();
String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : FeaturePacks.getLatestVersion();
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
public void consume(Space space, GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception {
if (Space.DEFAULT.equals(space)) {
defaultSpaceFpDependencies = fpDependencies;
}
String configStr = dumpConfiguration(space, fpDependencies, finalContext, vers, all,
mapping, provisioning, isLatest, wildflyPreview.orElse(false), provisioningXml.orElse(null));
print(configStr);
}
};
ScanArguments.Builder builder = Arguments.scanBuilder();
MavenRepoManager repoManager;
List<Channel> channels = Collections.emptyList();
Expand All @@ -131,13 +92,60 @@ public void consume(Space space, GalleonProvisioningConfig provisioning, Map<Str
} else {
repoManager = MavenResolver.newMavenResolver();
}
ProvisioningUtils.traverseProvisioning(Space.DEFAULT, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager);
for(String spaceName : spaces) {
Set<String> versions = FeaturePacks.getAllVersions(spaceName);
if (versions.contains(vers)) {
Space space = FeaturePacks.getSpace(spaceName);
ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager);
Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata");
try {
MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(repoManager, tmpMetadataDirectory);
ocBuilder.append("\nDeployers enabled when provisioning to OpenShift:\n");
for (Deployer d : ServiceLoader.load(Deployer.class)) {
ocBuilder.append("* @|bold " + d.getName() + "|@. Enabled when the layer(s) " + d.getSupportedLayers() + " is/are discovered.\n");
}
print(ocBuilder.toString());
StringBuilder spacesBuilder = new StringBuilder();
spacesBuilder.append("\nSpaces from which more feature-packs can be used when scanning deployments (use the " + Constants.SPACES_OPTION + " option to enable the space(s):\n");
for (Space space : metadataProvider.getAllSpaces()) {
spacesBuilder.append("* @|bold " + space.getName() + "|@. " + space.getDescription() + "\n");
}
print(spacesBuilder.toString());

String context = Arguments.BARE_METAL_EXECUTION_CONTEXT;
if (cloud.orElse(false)) {
context = Arguments.CLOUD_EXECUTION_CONTEXT;
}
if (wildflyPreview.orElse(false)) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.WILDFLY_PREVIEW_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
if (wildflyServerVersion.isPresent()) {
if (channelsFile.isPresent()) {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
String finalContext = context;
boolean isLatest = wildflyServerVersion.isEmpty();
String vers = wildflyServerVersion.isPresent() ? wildflyServerVersion.get() : metadataProvider.getLatestVersion();
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
public void consume(Space space, GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception {
if (Space.DEFAULT.equals(space)) {
defaultSpaceFpDependencies = fpDependencies;
}
String configStr = dumpConfiguration(space, fpDependencies, finalContext, vers, all,
mapping, provisioning, isLatest, wildflyPreview.orElse(false), provisioningXml.orElse(null));
print(configStr);
}
};
ProvisioningUtils.traverseProvisioning(Space.DEFAULT, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager, metadataProvider);
for (String spaceName : spaces) {
Set<String> versions = metadataProvider.getAllVersions(spaceName);
if (versions.contains(vers)) {
Space space = metadataProvider.getSpace(spaceName);
ProvisioningUtils.traverseProvisioning(space, consumer, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), vers, wildflyPreview.orElse(false), channels, repoManager, metadataProvider);
}
}
} finally {
IoUtils.recursiveDelete(tmpMetadataDirectory);
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
*/
package org.wildfly.glow.cli.commands;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jboss.galleon.util.IoUtils;
import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.Constants;
import org.wildfly.glow.FeaturePacks;
import org.wildfly.glow.MetadataProvider;
import org.wildfly.glow.Space;
import org.wildfly.glow.WildFlyMavenMetadataProvider;
import org.wildfly.glow.maven.MavenResolver;
import picocli.CommandLine;

@CommandLine.Command(
Expand All @@ -36,12 +41,18 @@ public class ShowServerVersionsCommand extends AbstractCommand {
@Override
public Integer call() throws Exception {
print("WildFly server versions in the " + Space.DEFAULT.getName() + " space:");
print(FeaturePacks.getAllVersions());
for(String space : spaces) {
print("WildFly server versions in the " + space + " space:");
print(FeaturePacks.getAllVersions(space));
Path tmpMetadataDirectory = Files.createTempDirectory("glow-metadata");
try {
MetadataProvider metadataProvider = new WildFlyMavenMetadataProvider(MavenResolver.newMavenResolver(), tmpMetadataDirectory);
print(metadataProvider.getAllVersions());
for (String space : spaces) {
print("WildFly server versions in the " + space + " space:");
print(metadataProvider.getAllVersions(space));
}
print("@|bold WildFly server version can be set using the|@ @|fg(yellow) %s=<server version>|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.SERVER_VERSION_OPTION, Constants.SCAN_COMMAND);
return 0;
} finally {
IoUtils.recursiveDelete(tmpMetadataDirectory);
}
print("@|bold WildFly server version can be set using the|@ @|fg(yellow) %s=<server version>|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.SERVER_VERSION_OPTION, Constants.SCAN_COMMAND);
return 0;
}
}
13 changes: 12 additions & 1 deletion core/src/main/java/org/wildfly/glow/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Arguments implements GoOfflineArguments, ScanArguments {
private final boolean isCli;
private final List<Channel> channels;
private final Set<String> spaces;
private final MetadataProvider metadataProvider;

protected Arguments(
String executionContext,
Expand All @@ -59,7 +60,8 @@ protected Arguments(
String defaultConfigStability,
boolean isCli,
List<Channel> channels,
Set<String> spaces) {
Set<String> spaces,
MetadataProvider metadataProvider) {
this.executionProfiles = executionProfiles;
this.userEnabledAddOns = userEnabledAddOns;
this.binaries = binaries;
Expand Down Expand Up @@ -87,6 +89,7 @@ protected Arguments(
this.isCli = isCli;
this.channels = channels;
this.spaces = spaces == null ? Collections.emptySet() : spaces;
this.metadataProvider = metadataProvider;
}

/**
Expand Down Expand Up @@ -231,6 +234,14 @@ public Set<String> getSpaces() {
return spaces;
}

/**
* @return the metadata provider
*/
@Override
public MetadataProvider getMetadataProvider() {
return metadataProvider;
}

static GoOfflineArguments.Builder goOfflineBuilder() {
return new GoOfflineArguments.Builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class BaseArgumentsBuilder {
protected boolean isCli;
protected List<Channel> channels;
protected Set<String> spaces;
protected MetadataProvider metadataProvider;

protected BaseArgumentsBuilder() {

Expand Down Expand Up @@ -75,6 +76,7 @@ public Arguments build() {
defaultConfigStability,
isCli,
channels,
spaces);
spaces,
metadataProvider);
}
}
Loading

0 comments on commit dcf644b

Please sign in to comment.