Skip to content

Commit

Permalink
Merge pull request wildfly-extras#735 from spyrkob/issue_726
Browse files Browse the repository at this point in the history
[wildfly-extras#726] Allow multiple manifests in the install command
  • Loading branch information
spyrkob authored Jul 24, 2024
2 parents 2edc26d + 71d8dc3 commit 483e29d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand All @@ -52,9 +53,10 @@ public abstract class AbstractInstallCommand extends AbstractCommand {
@CommandLine.Option(
names = CliConstants.CHANNEL_MANIFEST,
paramLabel = CliConstants.CHANNEL_MANIFEST_REFERENCE,
split = ",",
order = 3
)
Optional<String> manifestCoordinate;
List<String> manifestCoordinates = Collections.emptyList();

@CommandLine.Option(
names = CliConstants.REPOSITORIES,
Expand Down Expand Up @@ -87,7 +89,7 @@ protected ProvisioningDefinition.Builder buildDefinition() throws ArgumentParsin
return ProvisioningDefinition.builder()
.setFpl(featurePackOrDefinition.fpl.orElse(null))
.setProfile(featurePackOrDefinition.profile.orElse(null))
.setManifest(manifestCoordinate.orElse(null))
.setManifests(manifestCoordinates)
.setChannelCoordinates(channelCoordinates)
.setOverrideRepositories(RepositoryDefinition.from(remoteRepositories))
.setDefinitionFile(featurePackOrDefinition.definition.map(Path::toUri).orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,23 @@ public Integer call() throws Exception {
// following is checked by picocli, adding this to avoid IDE warnings
assert featurePackOrDefinition.definition.isPresent() || featurePackOrDefinition.fpl.isPresent() || featurePackOrDefinition.profile.isPresent();

if (featurePackOrDefinition.profile.isEmpty() && channelCoordinates.isEmpty() && manifestCoordinate.isEmpty()) {
if (featurePackOrDefinition.profile.isEmpty() && channelCoordinates.isEmpty() && manifestCoordinates.isEmpty()) {
throw CliMessages.MESSAGES.channelsMandatoryWhenCustomFpl(String.join(",", InstallationProfilesManager.getNames()));
}

if (featurePackOrDefinition.profile.isPresent() && !isStandardFpl(featurePackOrDefinition.profile.get())) {
throw CliMessages.MESSAGES.unknownInstallationProfile(featurePackOrDefinition.profile.get(), String.join(",", InstallationProfilesManager.getNames()));
}

if (!channelCoordinates.isEmpty() && manifestCoordinate.isPresent()) {
if (!channelCoordinates.isEmpty() && !manifestCoordinates.isEmpty()) {
throw CliMessages.MESSAGES.exclusiveOptions(CliConstants.CHANNELS, CliConstants.CHANNEL_MANIFEST);
}

if (manifestCoordinate.isPresent()) {
final ChannelManifestCoordinate manifest = ArtifactUtils.manifestCoordFromString(manifestCoordinate.get());
checkFileExists(manifest.getUrl(), manifestCoordinate.get());
if (!manifestCoordinates.isEmpty()) {
for (String coordinate : manifestCoordinates) {
final ChannelManifestCoordinate manifest = ArtifactUtils.manifestCoordFromString(coordinate);
checkFileExists(manifest.getUrl(), coordinate);
}
}

if (!channelCoordinates.isEmpty()) {
Expand Down
3 changes: 3 additions & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ repositories.2 = These repositories will not be persisted in the server configur
${prospero.dist.name}.install.repositories.0 = ${repositories.0}
${prospero.dist.name}.install.repositories.1 = ${repositories.1}
${prospero.dist.name}.install.repositories.2 = Alternative to --channel.
${prospero.dist.name}.install.manifest.0 = Location of the manifest files containing installations components.
${prospero.dist.name}.install.manifest.1 = Specify the locations as a comma-separated list of file paths, URLs or Maven coordinates (@|bold groupId:artifactId|@).
${prospero.dist.name}.install.manifest.2 = Alternative to --channel. Each manifest will create a separate channel using the same repositories.
channel-name = Name of the new channel. Channel names should be unique for the server installation.
${prospero.dist.name}.channel.remove.channel-name = Name of the channel.
customization-repository = URL to repository containing custom artifacts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,37 @@ public void testListProfiles() throws Exception {
"url: https://repo1.maven.org/maven2/",
"https://repository.jboss.org/nexus/content/groups/public/",
"org.wildfly.core:wildfly-core-galleon-pack:zip");
}

@Test
public void multipleManifestsAreTranslatedToMultipleChannels() throws Exception {
Path channelsFile = temporaryFolder.newFile().toPath();

File installDir = temporaryFolder.newFolder();
String testURL = installDir.toPath().toUri().toString();

MetadataTestUtils.prepareChannel(channelsFile, List.of(new URL("file:some-manifest.yaml")));

int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, installDir.getName(),
CliConstants.REPOSITORIES, "repo1::" + testURL,
CliConstants.CHANNEL_MANIFEST, "g:a:1.0,g:b:2.0",
CliConstants.FPL, "feature:pack");

assertEquals(ReturnCodes.SUCCESS, exitCode);
Mockito.verify(provisionAction).provision(configCaptor.capture(), channelCaptor.capture(), any());
assertThat(channelCaptor.getValue())
// TODO: implement equals toHash in wildfly-channels objects and remove the toString mapping
.map(Channel::toString)
.containsExactly(
new Channel.Builder().
setManifestCoordinate("g","a","1.0")
.addRepository("repo1", testURL)
.build().toString(),
new Channel.Builder().
setManifestCoordinate("g","b","2.0")
.addRepository("repo1", testURL)
.build().toString()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private ProvisioningDefinition(Builder builder) throws NoChannelException {
this.fpl = null;
this.definition = installationProfile.getGalleonConfiguration();
if (this.channelCoordinates.isEmpty()) { // no channels provided by user
if (builder.manifest.isPresent()) { // if manifest given, use it to create a channel
if (!builder.manifests.isEmpty()) { // if manifest given, use it to create a channel
List<Repository> repositories = extractRepositoriesFromChannels(installationProfile.getChannels());
this.channels = List.of(composeChannelFromManifest(builder.manifest.get(), repositories));
this.channels = builder.manifests.stream().map(m->composeChannelFromManifest(m, repositories)).collect(Collectors.toList());
} else if (!installationProfile.getChannels().isEmpty()) { // if no manifest given, use channels from known FP
this.channels = installationProfile.getChannels();
} else {
Expand All @@ -126,13 +126,13 @@ private ProvisioningDefinition(Builder builder) throws NoChannelException {
} else {
this.fpl = builder.fpl.orElse(null);
this.definition = builder.definitionFile.orElse(null);
if (this.channelCoordinates.isEmpty() && builder.manifest.isEmpty()) {
if (this.channelCoordinates.isEmpty() && builder.manifests.isEmpty()) {
throw ProsperoLogger.ROOT_LOGGER.predefinedFplOrChannelRequired(String.join(", ", InstallationProfilesManager.getNames()));
} else if (builder.manifest.isPresent()) { // if manifest given, use it to create a channel
} else if (!builder.manifests.isEmpty()) { // if manifest given, use it to create a channel
if (overrideRepositories.isEmpty()) {
throw ProsperoLogger.ROOT_LOGGER.repositoriesMustBeSetWithManifest();
}
this.channels = List.of(composeChannelFromManifest(builder.manifest.get(), overrideRepositories));
this.channels = builder.manifests.stream().map(m->composeChannelFromManifest(m, overrideRepositories)).collect(Collectors.toList());
}
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ private static List<Repository> extractRepositoriesFromChannels(List<Channel> ch
}

private static Channel composeChannelFromManifest(ChannelManifestCoordinate manifestCoordinate, List<Repository> repositories) {
return new Channel("", "", null, repositories, manifestCoordinate, null, null);
return new Channel(null, null, null, repositories, manifestCoordinate, null, null);
}

public static Builder builder() {
Expand All @@ -277,7 +277,7 @@ public static class Builder {
private Optional<String> fpl = Optional.empty();
private Optional<URI> definitionFile = Optional.empty();
private List<Repository> overrideRepositories = Collections.emptyList();
private Optional<ChannelManifestCoordinate> manifest = Optional.empty();
private List<ChannelManifestCoordinate> manifests = Collections.emptyList();
private List<ChannelCoordinate> channelCoordinates = Collections.emptyList();
private Optional<String> profile = Optional.empty();
private String stabilityLevel;
Expand All @@ -298,9 +298,16 @@ public Builder setOverrideRepositories(List<Repository> repositories) {
return this;
}

public Builder setManifest(String manifest) {
if (manifest != null) {
this.manifest = Optional.of(ArtifactUtils.manifestCoordFromString(manifest));
public Builder setManifest(String manifests) {
if (manifests != null) {
this.manifests = List.of(ArtifactUtils.manifestCoordFromString(manifests));
}
return this;
}

public Builder setManifests(List<String> manifests) {
if (manifests != null) {
this.manifests = manifests.stream().map(ArtifactUtils::manifestCoordFromString).collect(Collectors.toList());
}
return this;
}
Expand Down

0 comments on commit 483e29d

Please sign in to comment.