Skip to content

Commit

Permalink
Merge pull request #100 from jfdenise/spaces
Browse files Browse the repository at this point in the history
Fix for Issue #87, Introduce the notion of discovery space for discovered feature-packs
  • Loading branch information
jfdenise authored Nov 26, 2024
2 parents e93e22b + dc7c460 commit aa2975c
Show file tree
Hide file tree
Showing 19 changed files with 490 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public interface Constants {
String SHOW_ADD_ONS_COMMAND = "show-add-ons";
String SHOW_CONFIGURATION_COMMAND = "show-configuration";
String SHOW_SERVER_VERSIONS_COMMAND = "show-server-versions";
String SPACES_OPTION = "--spaces";
String SPACES_OPTION_SHORT = "-sp";
String SPACES_OPTION_LABEL = "<space1,space2, ...>";
String STABILITY_LABEL = "<default|community|preview|experimental>";
String STABILITY_OPTION = "--stability-level";
String STABILITY_OPTION_SHORT = "-sl";
Expand Down
51 changes: 0 additions & 51 deletions cli-support/src/main/java/org/wildfly/glow/cli/support/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,15 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
import org.wildfly.channel.Channel;
import org.wildfly.channel.ChannelMapper;
import org.wildfly.glow.AddOn;
import org.wildfly.glow.Arguments;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.ProvisioningUtils;
import org.wildfly.glow.ScanArguments;
import org.wildfly.glow.maven.MavenResolver;

/**
*
* @author jdenise
*/
public class Utils {

public static void showAddOns(AbstractCommand cmd, String context, Path provisioningXml, boolean isLatest,
String serverVersion, boolean isPreview, Path channelsFile) throws Exception {
CLIConfigurationResolver resolver = new CLIConfigurationResolver();
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
public void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, Set<AddOn>> entry : mapping.getAddOnFamilyMembers().entrySet()) {
builder.append("* @|bold ").append(entry.getKey()).append("|@ add-ons:%n");
for (AddOn member : mapping.getAddOnFamilyMembers().get(entry.getKey())) {
if (!member.getName().endsWith(":default")) {
String deployer = resolver.getPossibleDeployer(member.getLayers());
builder.append(" - ").append(member.getName()).append((deployer == null ? "" : " @|bold (supported by " + deployer + " deployer)|@")).append(member.getDescription() == null ? "" : ": " + member.getDescription()).append("%n");
}
}
}
cmd.print(builder.toString());
cmd.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);

}

};
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(consumer, context, provisioningXml, isLatest, serverVersion,
isPreview, channels, repoManager);
}

public static void setSystemProperties(Set<String> systemProperties) throws Exception {
if (!systemProperties.isEmpty()) {
for (String p : systemProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.Constants;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import org.wildfly.glow.Arguments;
import static org.wildfly.glow.Arguments.CLOUD_EXECUTION_CONTEXT;
import org.wildfly.glow.GlowMessageWriter;
Expand Down Expand Up @@ -48,6 +50,9 @@ public class GoOfflineCommand extends AbstractCommand {
@CommandLine.Option(names = Constants.INPUT_FEATURE_PACKS_FILE_OPTION, paramLabel = "<provisioning file path>")
Optional<Path> provisioningXml;

@CommandLine.Option(names = {Constants.SPACES_OPTION_SHORT, Constants.SPACES_OPTION}, split = ",", paramLabel = Constants.SPACES_OPTION_LABEL)
Set<String> spaces = new LinkedHashSet<>();

@Override
public Integer call() throws Exception {
print("Wildfly Glow is assembling offline content...");
Expand All @@ -65,6 +70,9 @@ public Integer call() throws Exception {
if (provisioningXml.isPresent()) {
builder.setProvisoningXML(provisioningXml.get());
}
if (!spaces.isEmpty()) {
builder.setSpaces(spaces);
}
GlowSession.goOffline(MavenResolver.newMavenResolver(), builder.build(), GlowMessageWriter.DEFAULT);
print("Offline zip file %s generated", OFFLINE_ZIP);
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public OutputFormat convert(String value) throws Exception {
@CommandLine.Option(names = Constants.DRY_RUN_OPTION)
Optional<Boolean> dryRun;

@CommandLine.Option(names = {Constants.SPACES_OPTION_SHORT, Constants.SPACES_OPTION}, split = ",", paramLabel = Constants.SPACES_OPTION_LABEL)
Set<String> spaces = new LinkedHashSet<>();

@Override
public Integer call() throws Exception {
Utils.setSystemProperties(systemProperties);
Expand All @@ -188,6 +191,9 @@ public Integer call() throws Exception {
if (!layersForJndi.isEmpty()) {
builder.setJndiLayers(layersForJndi);
}
if (!spaces.isEmpty()) {
builder.setSpaces(spaces);
}
if (suggest.orElse(false)) {
builder.setSuggest(true);
}
Expand Down
113 changes: 111 additions & 2 deletions cli/src/main/java/org/wildfly/glow/cli/commands/ShowAddOnsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@
*/
package org.wildfly.glow.cli.commands;

import java.nio.file.Files;
import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.Utils;
import org.wildfly.glow.cli.support.Constants;
import java.nio.file.Path;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.jboss.galleon.universe.FeaturePackLocation.FPID;
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
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.ProvisioningUtils;
import org.wildfly.glow.ScanArguments;
import org.wildfly.glow.Space;
import org.wildfly.glow.cli.support.CLIConfigurationResolver;
import org.wildfly.glow.maven.MavenResolver;
import picocli.CommandLine;

@CommandLine.Command(
Expand All @@ -45,6 +65,11 @@ public class ShowAddOnsCommand extends AbstractCommand {
@CommandLine.Option(names = {Constants.CHANNELS_OPTION_SHORT, Constants.CHANNELS_OPTION}, paramLabel = Constants.CHANNELS_OPTION_LABEL)
Optional<Path> channelsFile;

@CommandLine.Option(names = {Constants.SPACES_OPTION_SHORT, Constants.SPACES_OPTION}, split = ",", paramLabel = Constants.SPACES_OPTION_LABEL)
Set<String> spaces = new LinkedHashSet<>();

private Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> defaultSpaceFpDependencies;

@Override
public Integer call() throws Exception {
print("Wildfly Glow is retrieving add-ons...");
Expand All @@ -62,8 +87,92 @@ public Integer call() throws Exception {
throw new Exception(Constants.SERVER_VERSION_OPTION + "can't be set when " + Constants.CHANNELS_OPTION + " is set.");
}
}
Utils.showAddOns(this, context, provisioningXml.orElse(null), wildflyServerVersion.isEmpty(), wildflyServerVersion.orElse(null),
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));
}
}
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;
}

public void showAddOns(Space space, String context, Path provisioningXml, boolean isLatest,
String serverVersion, boolean isPreview, Path channelsFile) throws Exception {
CLIConfigurationResolver resolver = new CLIConfigurationResolver();
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;
}
StringBuilder builder = new StringBuilder();
builder.append("\nAdd-ons found in the @|bold ").append(space.getName()).append("|@ space:\n");
if (provisioning == null) {
builder.append("- No Add-ons.");
} else {
boolean foundAddOns = false;
for (Map.Entry<String, Set<AddOn>> entry : mapping.getAddOnFamilyMembers().entrySet()) {
StringBuilder addOnFamilyBuilder = new StringBuilder();
for (AddOn member : mapping.getAddOnFamilyMembers().get(entry.getKey())) {
boolean ignore = false;
if (!Space.DEFAULT.equals(space)) {
// Only keep addOns that are not defined in feature-packs from the default space.
for(Layer l : member.getLayers()) {
for(FPID fpid : l.getFeaturePacks()) {
for (FPID dfpid : defaultSpaceFpDependencies.keySet()) {
if (dfpid.getProducer().equals(fpid.getProducer())) {
ignore = true;
break;
}
}
if (ignore) {
break;
}
}
if(ignore) {
break;
}
}
}
if (!member.getName().endsWith(":default") && !ignore) {
foundAddOns = true;
String deployer = resolver.getPossibleDeployer(member.getLayers());
addOnFamilyBuilder.append(" - ").append(member.getName()).append((deployer == null ? "" : " @|bold (supported by " + deployer + " deployer)|@")).append(member.getDescription() == null ? "" : ": " + member.getDescription()).append("%n");
}
}
if (addOnFamilyBuilder.length() != 0) {
builder.append("* @|bold ").append(entry.getKey()).append("|@ add-ons:%n");
builder.append(addOnFamilyBuilder.toString());
}
}
if (!foundAddOns) {
builder.append("- No Add-ons.");
}
}
print(builder.toString());
}

};
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);
}
}
Loading

0 comments on commit aa2975c

Please sign in to comment.