Skip to content

Commit

Permalink
[#411] Create candidate properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob authored and Wildfly.org CI committed Dec 7, 2023
1 parent e57d4f4 commit d4f19a7
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.wildfly.channel.ChannelMapper;
import org.wildfly.channel.Repository;
import org.wildfly.channel.Stream;
import org.wildfly.prospero.actions.ApplyCandidateAction;
import org.wildfly.prospero.api.exceptions.MetadataException;
import org.wildfly.prospero.metadata.ManifestVersionRecord;
import org.wildfly.prospero.actions.UpdateAction;
Expand All @@ -44,6 +45,8 @@
import org.wildfly.prospero.metadata.ProsperoMetadataUtils;
import org.wildfly.prospero.model.ManifestYamlSupport;
import org.wildfly.prospero.test.MetadataTestUtils;
import org.wildfly.prospero.updates.CandidateProperties;
import org.wildfly.prospero.updates.CandidatePropertiesParser;
import org.wildfly.prospero.wfchannel.MavenSessionManager;

import java.io.File;
Expand Down Expand Up @@ -176,6 +179,12 @@ public void prepareUpdateCreatesMarkerFile() throws Exception {
assertThat(record.get().getMavenManifests())
.map(ManifestVersionRecord.MavenManifest::getVersion)
.containsExactly("1.0.1");

final Path channelNamesFile = preparedUpdatePath.resolve(ProsperoMetadataUtils.METADATA_DIR).resolve(ApplyCandidateAction.CANDIDATE_CHANNEL_NAME_LIST);
assertTrue(Files.exists(channelNamesFile));

final CandidateProperties candidateProperties = CandidatePropertiesParser.read(channelNamesFile);
assertEquals("test", candidateProperties.getUpdateChannel("org.wildfly.core:wildfly-cli"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

package org.wildfly.prospero.cli.commands;

import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.jboss.galleon.ProvisioningException;
import org.jboss.galleon.config.ProvisioningConfig;
Expand Down Expand Up @@ -54,16 +65,6 @@
import picocli.CommandLine;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

@CommandLine.Command(
name = CliConstants.Commands.UPDATE,
Expand Down Expand Up @@ -188,7 +189,7 @@ public Integer call() throws Exception {

try (UpdateAction updateAction = actionFactory.update(installationDir,
mavenOptions, console, repositories)) {
if (buildUpdate(updateAction, candidateDirectory, yes, console, () -> console.confirmBuildUpdates(), installationDir)) {
if (buildUpdate(updateAction, candidateDirectory, yes, console, ()->console.confirmBuildUpdates())) {
console.println("");
console.buildUpdatesComplete();
console.println(CliMessages.MESSAGES.updateCandidateGenerated(candidateDirectory));
Expand Down Expand Up @@ -254,7 +255,7 @@ public Integer call() throws Exception {
applyCandidateAction.applyUpdate(ApplyCandidateAction.Type.UPDATE);
console.updatesComplete();

if (remove) {
if(remove) {
applyCandidateAction.removeCandidate(candidateDir.toFile());
}
final float totalTime = (System.currentTimeMillis() - startTime) / 1000f;
Expand All @@ -271,7 +272,6 @@ public static class ListCommand extends AbstractMavenCommand {
public ListCommand(CliConsole console, ActionFactory actionFactory) {
super(console, actionFactory);
}

@Override
public Integer call() throws Exception {
final long startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -313,7 +313,7 @@ public SubscribeCommand(CliConsole console, ActionFactory actionFactory) {
public Integer call() throws Exception {
final Path installDir = directory.orElse(currentDir()).toAbsolutePath();
if (Files.exists(ProsperoMetadataUtils.manifestPath(installDir))
|| Files.exists(ProsperoMetadataUtils.configurationPath(installDir))) {
|| Files.exists(ProsperoMetadataUtils.configurationPath(installDir))) {
console.println(CliMessages.MESSAGES.metadataExistsAlready(installDir, DistributionInfo.DIST_NAME));
return ReturnCodes.INVALID_ARGUMENTS;
}
Expand All @@ -340,8 +340,8 @@ public Integer call() throws Exception {
private void generateMeta(Path installDir, SubscribeNewServerAction.GenerateResult generateResult) throws IOException, ProvisioningException {
// compare hashes
FsEntryFactory fsEntryFactory = FsEntryFactory.getInstance()
.filterGalleonPaths()
.filter(ProsperoMetadataUtils.METADATA_DIR);
.filterGalleonPaths()
.filter(ProsperoMetadataUtils.METADATA_DIR);
final FsEntry originalState = fsEntryFactory.forPath(generateResult.getProvisionDir());
final FsEntry currentState = fsEntryFactory.forPath(installDir);
final FsDiff diff = FsDiff.diff(originalState, currentState);
Expand Down Expand Up @@ -379,7 +379,7 @@ private void generateMeta(Path installDir, SubscribeNewServerAction.GenerateResu
channels = channels.stream().map(c -> {
try {
return new Channel(c.getName(), c.getDescription(), c.getVendor(), c.getRepositories(),
new ChannelManifestCoordinate(manifestPathCopy.toUri().toURL()), c.getBlocklistCoordinate(), c.getNoStreamStrategy());
new ChannelManifestCoordinate(manifestPathCopy.toUri().toURL()), c.getBlocklistCoordinate(), c.getNoStreamStrategy());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -409,11 +409,11 @@ private FeaturePackLocation getFpl(KnownFeaturePack knownFeaturePack, String ver
public UpdateCommand(CliConsole console, ActionFactory actionFactory) {
super(console, actionFactory, CliConstants.Commands.UPDATE,
List.of(
new UpdateCommand.PrepareCommand(console, actionFactory),
new UpdateCommand.ApplyCommand(console, actionFactory),
new UpdateCommand.PerformCommand(console, actionFactory),
new UpdateCommand.ListCommand(console, actionFactory),
new SubscribeCommand(console, actionFactory))
new UpdateCommand.PrepareCommand(console, actionFactory),
new UpdateCommand.ApplyCommand(console, actionFactory),
new UpdateCommand.PerformCommand(console, actionFactory),
new UpdateCommand.ListCommand(console, actionFactory),
new SubscribeCommand(console, actionFactory))
);
}

Expand All @@ -434,23 +434,6 @@ private static boolean buildUpdate(UpdateAction updateAction, Path updateDirecto
return true;
}

private static boolean buildUpdate(UpdateAction updateAction, Path updateDirectory, boolean yes, CliConsole console, Supplier<Boolean> confirmation, Path installationDir) throws OperationException, ProvisioningException {
final UpdateSet updateSet = updateAction.findUpdates();

console.updatesFound(updateSet.getArtifactUpdates());
if (updateSet.isEmpty()) {
return false;
}

if (!yes && !confirmation.get()) {
return false;
}

updateAction.buildUpdate(updateDirectory.toAbsolutePath());

return true;
}

public static void verifyInstallationContainsOnlyProspero(Path dir) throws ArgumentParsingException {
verifyDirectoryContainsInstallation(dir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,47 @@ public class CliConsoleTest extends AbstractConsoleTest {
private CliConsole cliConsole;

private ByteArrayOutputStream outputStream;
private PrintStream originalOut;

@Before
public void setUp() {
cliConsole = new CliConsole();
outputStream = new ByteArrayOutputStream();
originalOut = System.out;
System.setOut(new PrintStream(outputStream));
}

@Test
public void testUpdatesFoundWithUpdates_ArtifactChange_update() {
List<ArtifactChange> artifactChanges = new ArrayList<>();
ArtifactChange artifactChange = ArtifactChange.updated(new DefaultArtifact("test.group", "test-artifact2", "jar", "2.0.0"), new DefaultArtifact("test.group", "test-artifact2", "jar", "2.1.0"), "channel-1");
final List<ArtifactChange> artifactChanges = new ArrayList<>();
final ArtifactChange artifactChange = ArtifactChange.updated(new DefaultArtifact("test.group", "test-artifact2", "jar", "2.0.0"), new DefaultArtifact("test.group", "test-artifact2", "jar", "2.1.0"), "channel-1");

artifactChanges.add(artifactChange);
cliConsole.updatesFound(artifactChanges);
String capturedOutput = outputStream.toString();
final String capturedOutput = outputStream.toString();

assertThat(capturedOutput.contains(String.format(
" %s%-50s %-20s ==> %-20s ==> %-20s%n",
"",
artifactChange.getArtifactName(),
artifactChange.getOldVersion().orElse("[]"),
artifactChange.getNewVersion().orElse("[]"),
artifactChange.getChannelName()
)));
assertThat(capturedOutput)
.contains("test.group:test-artifact2")
.contains("[channel-1]");
}
@Test
public void testUpdatesFoundWithUpdates_ArtifactChange_add() {
List<ArtifactChange> artifactChanges = new ArrayList<>();
ArtifactChange artifactChange = ArtifactChange.added(new DefaultArtifact("test.group", "test-artifact2", "jar", "2.0.0"), "channel-1");
final List<ArtifactChange> artifactChanges = new ArrayList<>();
final ArtifactChange artifactChange = ArtifactChange.added(new DefaultArtifact("test.group", "test-artifact2", "jar", "2.0.0"), "channel-1");

artifactChanges.add(artifactChange);
cliConsole.updatesFound(artifactChanges);
String capturedOutput = outputStream.toString();
final String capturedOutput = outputStream.toString();

assertThat(capturedOutput.contains(String.format(
" %s%-50s %-20s ==> %-20s ==> %-20s%n",
"",
artifactChange.getArtifactName(),
artifactChange.getOldVersion().orElse("[]"),
artifactChange.getNewVersion().orElse("[]"),
artifactChange.getChannelName()
)));
assertThat(capturedOutput)
.contains("test.group:test-artifact2")
.contains("[channel-1]");
}

@After
public void destory() throws IOException {
outputStream.close();
cliConsole = null;
System.setOut(originalOut);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.wildfly.prospero.api.exceptions.NoChannelException;
import org.wildfly.prospero.api.exceptions.ProvisioningRuntimeException;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
Expand Down Expand Up @@ -353,13 +352,14 @@ public interface ProsperoLogger extends BasicLogger {
IllegalArgumentException dirMustBeWritable(Path directory);

@Message(id = 261, value = "Channel map data has been written to %s.")
String channelMap(String name);
@LogMessage(level = Logger.Level.DEBUG)
void channelNamesWrittenToFile(String fileName);

@Message(id = 262, value = "An error occurred while writing channel data to the file %s.")
@Message(id = 262, value = "Unable to create a candidate properties file %s.")
@LogMessage(level = Logger.Level.ERROR)
void unableToWriteChannelDataToFile(String name, @Cause IOException e);
void unableToWriteChannelNamesToFile(String fileName, @Cause Exception e);

@Message(id = 263, value = "Unable to read the channel names from file %s.")
@Message(id = 263, value = "Unable to read the candidate properties file %s.")
@LogMessage(level = Logger.Level.ERROR)
void unableToReadChannel(String name, @Cause IOException e);
void unableToReadChannelNames(String fileName, @Cause Exception e);
}
Loading

0 comments on commit d4f19a7

Please sign in to comment.