Skip to content

Commit

Permalink
[wildfly-extras#570] Add support for feature pack stability level.
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Mar 7, 2024
1 parent 9579ed7 commit a525151
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,4 +631,9 @@ default String metadataExistsAlready(Path path, String distName) {
default String serverVersionsHeader() {
return bundle.getString("prospero.channels.versions.header");
}

default IllegalArgumentException unknownStabilityLevel(String stabilityLevel, List<String> supportedStabilityLevels) {
return new IllegalArgumentException(format(bundle.getString("prospero.install.unknown_stability_level"),
stabilityLevel, String.join(",", supportedStabilityLevels)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,14 @@ protected MavenOptions getMavenOptions() throws ArgumentParsingException {
return mavenOptions.build();
}

protected ProvisioningDefinition buildDefinition() throws MetadataException, NoChannelException, ArgumentParsingException {
final ProvisioningDefinition provisioningDefinition = ProvisioningDefinition.builder()
protected ProvisioningDefinition.Builder buildDefinition() throws MetadataException, NoChannelException, ArgumentParsingException {
return ProvisioningDefinition.builder()
.setFpl(featurePackOrDefinition.fpl.orElse(null))
.setProfile(featurePackOrDefinition.profile.orElse(null))
.setManifest(manifestCoordinate.orElse(null))
.setChannelCoordinates(channelCoordinates)
.setOverrideRepositories(RepositoryDefinition.from(remoteRepositories))
.setDefinitionFile(featurePackOrDefinition.definition.map(Path::toUri).orElse(null))
.build();
return provisioningDefinition;
.setDefinitionFile(featurePackOrDefinition.definition.map(Path::toUri).orElse(null));
}

protected static VersionResolverFactory createVersionResolverFactory(MavenSessionManager mavenSessionManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private Commands() {
public static final String CHANNELS = "--channels";
public static final String REPOSITORIES = "--repositories";
public static final String SHADE_REPOSITORIES = "--shade-repositories";
public static final String STABILITY_LEVEL = "--stability-level";
public static final String DEFINITION = "--definition";
public static final String DIR = "--dir";
public static final String FPL = "--fpl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import org.jboss.galleon.Constants;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;

import org.wildfly.channel.Channel;
Expand Down Expand Up @@ -73,6 +77,23 @@ public class InstallCommand extends AbstractInstallCommand {
)
List<String> shadowRepositories = new ArrayList<>();

private static final List<String> STABILITY_LEVELS = List.of(Constants.STABILITY_EXPERIMENTAL,
Constants.STABILITY_PREVIEW,
Constants.STABILITY_DEFAULT,
Constants.STABILITY_COMMUNITY);

private static class StabilityCandidates implements Iterable<String> {
@Override
public Iterator<String> iterator() {
return STABILITY_LEVELS.stream().map(String::toLowerCase).iterator();
}
}
@CommandLine.Option(
names = CliConstants.STABILITY_LEVEL,
completionCandidates = StabilityCandidates.class
)
String stabilityLevel;


static class FeaturePackOrDefinition {
@CommandLine.Option(
Expand Down Expand Up @@ -136,14 +157,20 @@ public Integer call() throws Exception {
}
}

if (stabilityLevel != null && !STABILITY_LEVELS.contains(stabilityLevel.toLowerCase(Locale.ROOT))) {
throw CliMessages.MESSAGES.unknownStabilityLevel(stabilityLevel, STABILITY_LEVELS);
}

if (featurePackOrDefinition.definition.isPresent()) {
final Path definition = featurePackOrDefinition.definition.get().toAbsolutePath();
checkFileExists(definition.toUri().toURL(), definition.toString());
}

verifyTargetDirectoryIsEmpty(directory);

final ProvisioningDefinition provisioningDefinition = buildDefinition();
final ProvisioningDefinition provisioningDefinition = buildDefinition()
.setStabilityLevel(stabilityLevel==null?null:stabilityLevel.toLowerCase(Locale.ROOT))
.build();
final MavenOptions mavenOptions = getMavenOptions();
final GalleonProvisioningConfig provisioningConfig = provisioningDefinition.toProvisioningConfig();
final List<Channel> channels = resolveChannels(provisioningDefinition, mavenOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Integer call() throws Exception {

final Path tempDirectory = Files.createTempDirectory("tmp-installer");
try {
final ProvisioningDefinition provisioningDefinition = buildDefinition();
final ProvisioningDefinition provisioningDefinition = buildDefinition().build();
final MavenOptions mavenOptions = getMavenOptions();
final GalleonProvisioningConfig provisioningConfig = provisioningDefinition.toProvisioningConfig();
final List<Channel> channels = resolveChannels(provisioningDefinition, mavenOptions);
Expand Down
2 changes: 2 additions & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ yes = Performs the operation without asking for a confirmation.
path = Path of the file to export to or import from.
candidate-dir = Path of the server candidate created using the @|bold --update prepare|@ command.
rm = Remove the candidate server after applying it.
stability-level = The minimal stability level of provisioned server. Valid options are ${COMPLETION-CANDIDATES}.

${prospero.dist.name}.update.prepare.candidate-dir = Target directory where the candidate server will be provisioned. The existing server is not updated.
${prospero.dist.name}.update.subscribe.product = Specify the product name. This must be a known feature pack supported by ${prospero.dist.name}.
Expand Down Expand Up @@ -239,6 +240,7 @@ prospero.install.validation.unknown_fpl.details=Either a --channels or a combina
needed when using a custom feature pack.
prospero.install.validation.unknown_profile=Unknown profile [%s]
prospero.install.validation.unknown_profile.details=Did you mean one of [%s]?
prospero.install.unknown_stability_level=Unknown stability level [%s]. Valid levels are: [%s].

prospero.updates.no_updates=No updates found.
prospero.updates.header=Updates found:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.jboss.galleon.Constants;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -51,10 +52,12 @@
import org.wildfly.prospero.cli.ReturnCodes;
import org.wildfly.prospero.test.MetadataTestUtils;

import static org.assertj.core.api.Assertions.assertThat;
import org.jboss.galleon.api.GalleonBuilder;
import org.jboss.galleon.api.Provisioning;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -271,6 +274,22 @@ public void passShadowRepositories() throws Exception {
.contains("file:/test");
}

@Test
public void stabilityLevelIsPassedOn() throws Exception {
final File channelsFile = temporaryFolder.newFile();
Channel channel = createChannel("test", "test", "http://test.org", "org.test");
MetadataTestUtils.writeChannels(channelsFile.toPath(), List.of(channel));

int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, "test",
CliConstants.FPL, "org.wildfly:wildfly-ee-galleon-pack",
CliConstants.CHANNELS, channelsFile.getAbsolutePath(),
CliConstants.STABILITY_LEVEL, "default");
assertEquals(ReturnCodes.SUCCESS, exitCode);
Mockito.verify(provisionAction).provision(configCaptor.capture(), any(), any());
assertThat(configCaptor.getValue().getOptions())
.contains(entry(Constants.STABILITY_LEVEL, "default"));
}

@Override
protected MavenOptions getCapturedMavenOptions() throws Exception {
Mockito.verify(actionFactory).install(any(), mavenOptions.capture(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.apache.commons.io.IOUtils;
import org.eclipse.aether.repository.RemoteRepository;
import org.jboss.galleon.Constants;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.api.config.GalleonFeaturePackConfig;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
Expand Down Expand Up @@ -87,10 +88,14 @@ public class ProvisioningDefinition {
*/
private final URI definition;

private final String stabilityLevel;

private ProvisioningDefinition(Builder builder) throws NoChannelException {
this.overrideRepositories.addAll(builder.overrideRepositories);
this.channelCoordinates.addAll(builder.channelCoordinates);

this.stabilityLevel = builder.stabilityLevel;

if (builder.profile.isPresent()) {

if (!KnownFeaturePacks.isWellKnownName(builder.profile.get())) { // if known FP name
Expand Down Expand Up @@ -146,10 +151,23 @@ public GalleonProvisioningConfig toProvisioningConfig() throws MetadataException
FeaturePackLocation loc = FeaturePackLocationParser.resolveFpl(getFpl());

final GalleonFeaturePackConfig.Builder configBuilder = GalleonFeaturePackConfig.builder(loc);
return GalleonProvisioningConfig.builder().addFeaturePackDep(configBuilder.build()).build();
final GalleonProvisioningConfig.Builder builder = GalleonProvisioningConfig.builder()
.addFeaturePackDep(configBuilder.build());
if (stabilityLevel != null) {
builder.addOption(Constants.STABILITY_LEVEL, stabilityLevel);
}
return builder.build();

} else if (definition != null) {
try {
return GalleonUtils.loadProvisioningConfig(definition);
final GalleonProvisioningConfig config = GalleonUtils.loadProvisioningConfig(definition);
if (stabilityLevel == null) {
return config;
} else {
return GalleonProvisioningConfig.builder(config)
.addOption(Constants.STABILITY_LEVEL, stabilityLevel)
.build();
}
} catch (XMLStreamException e) {
throw ProsperoLogger.ROOT_LOGGER.unableToParseConfigurationUri(definition, e);
}
Expand Down Expand Up @@ -242,6 +260,7 @@ public static class Builder {
private Optional<ChannelManifestCoordinate> manifest = Optional.empty();
private List<ChannelCoordinate> channelCoordinates = Collections.emptyList();
private Optional<String> profile = Optional.empty();
private String stabilityLevel;

public ProvisioningDefinition build() throws MetadataException, NoChannelException {
return new ProvisioningDefinition(this);
Expand Down Expand Up @@ -286,5 +305,10 @@ public Builder setProfile(String profile) {
this.profile = Optional.ofNullable(profile);
return this;
}

public Builder setStabilityLevel(String stabilityLevel) {
this.stabilityLevel = stabilityLevel;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.xml.stream.XMLStreamException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -252,6 +253,32 @@ public void unknownProfileNameThrowsException() throws Exception {
});
}

@Test
public void setStabilityLevelWithFpl() throws Exception {
final ProvisioningDefinition.Builder builder = new ProvisioningDefinition.Builder()
.setFpl("custom:fpl")
.setManifest("tmp/foo.bar")
.setStabilityLevel("default")
.setOverrideRepositories(Arrays.asList(
new Repository("temp-repo-0", "http://test.repo1"),
new Repository("temp-repo-1", "http://test.repo2")));

final ProvisioningDefinition def = builder.build();
assertThat(def.toProvisioningConfig().getOptions())
.contains(entry("stability-level", "default"));
}

@Test
public void setStabilityLevelWithProfile() throws Exception {
final ProvisioningDefinition.Builder builder = new ProvisioningDefinition.Builder()
.setProfile(EAP_FPL)
.setStabilityLevel("default");

final ProvisioningDefinition def = builder.build();
assertThat(def.toProvisioningConfig().getOptions())
.contains(entry("stability-level", "default"));
}

private void verifyFeaturePackLocation(ProvisioningDefinition definition) throws ProvisioningException, XMLStreamException {
assertNull(definition.getFpl());
GalleonProvisioningConfig galleonConfig = GalleonUtils.loadProvisioningConfig(definition.getDefinition());
Expand Down

0 comments on commit a525151

Please sign in to comment.