Skip to content

Commit

Permalink
[JBEAP-26296] [installation-manager] Allow specifying --repositories …
Browse files Browse the repository at this point in the history
…without IDs and using local paths
  • Loading branch information
ChristinaDsl committed Mar 11, 2024
1 parent 4585a0f commit c3fb1bb
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package org.wildfly.prospero.it.cli;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
Expand All @@ -31,15 +32,18 @@
import org.wildfly.prospero.it.ExecutionUtils;
import org.wildfly.prospero.test.MetadataTestUtils;

public class InstallTest {
import static org.wildfly.prospero.test.MetadataTestUtils.upgradeStreamInManifest;

public class InstallTest extends CliTestBase {

@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

private File targetDir;

@Before
public void setUp() throws IOException {
public void setUp() throws Exception {
super.setUp();
targetDir = tempDir.newFolder();
}

Expand All @@ -55,4 +59,26 @@ public void testInstallWithProvisionConfig() throws Exception {
.execute()
.assertReturnCode(ReturnCodes.SUCCESS);
}

@Test
public void testInstallWithLocalRepositories() throws Exception {
final Path manifestPath = tempDir.newFile().toPath();
final Path provisionConfig = tempDir.newFile().toPath();
MetadataTestUtils.copyManifest("manifests/wfcore-base.yaml", manifestPath);
MetadataTestUtils.prepareChannel(provisionConfig, List.of(manifestPath.toUri().toURL()));

install(provisionConfig, targetDir.toPath());

upgradeStreamInManifest(manifestPath, resolvedUpgradeArtifact);

final URL temporaryRepo = mockTemporaryRepo(true);

ExecutionUtils.prosperoExecution(CliConstants.Commands.UPDATE, CliConstants.Commands.PERFORM,
CliConstants.REPOSITORIES, temporaryRepo.toString(),
CliConstants.Y,
CliConstants.NO_LOCAL_MAVEN_CACHE,
CliConstants.DIR, targetDir.getAbsolutePath())
.execute()
.assertReturnCode(ReturnCodes.SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import org.wildfly.channel.Repository;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -50,7 +52,12 @@ public static List<Repository> from(List<String> repos) throws ArgumentParsingEx

private static boolean isValidUrl(String text) {
try {
new URL(text);
URL url = new URL(text);
if (text.startsWith("file")){
String path = Paths.get(url.getPath()).normalize().toString();
File f = new File(path);
return f.exists();
}
return true;
} catch (MalformedURLException e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ prospero.general.error.resolve.offline=offline
prospero.general.error.resolve.streams.header=Required artifact streams are not available in any of the configured channels.
prospero.general.validation.conflicting_options=Only one of %s and %s can be set.
prospero.general.validation.local_repo.not_directory=Repository path `%s` is a file not a directory.
prospero.general.validation.repo_format=Repository definition [%s] is invalid. The definition format should be [id::url]
prospero.general.validation.repo_format=Repository definition [%s] is invalid. The definition format should be [id::url] or [url].
prospero.general.error.missing_file=Required file at `%s` cannot be opened.
prospero.general.error.galleon.parse=Failed to parse provisioning configuration: %s
prospero.general.error.feature_pack.not_found=The feature pack `%s` is not available in the subscribed channels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
package org.wildfly.prospero.cli;

import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.wildfly.channel.Repository;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -32,6 +37,16 @@

public class RepositoryDefinitionTest {

@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

private File targetDir;

@Before
public void setUp() throws IOException {
targetDir = tempDir.newFolder();
}

@Test
public void generatesRepositoryIdsIfNotProvided() throws Exception {
assertThat(from(List.of("http://test.te")))
Expand Down Expand Up @@ -75,5 +90,21 @@ public void throwsErrorIfFormatIsIncorrect() throws Exception {
assertThrows(ArgumentParsingException.class, ()->from(List.of("foo::bar::http://test1.te")));

assertThrows(ArgumentParsingException.class, ()->from(List.of("imnoturl")));

}

@Test
public void throwsErrorIfLocalFileDoesNotExistOrFormatIsIncorrect() throws Exception {
assertThrows(ArgumentParsingException.class, ()->from(List.of("::"+targetDir.toURI().toURL())));

assertThrows(ArgumentParsingException.class, ()->from(List.of("repo-1::")));

assertThrows(ArgumentParsingException.class, ()->from(List.of("repo-1:::"+targetDir.toURI().toURL())));

assertThrows(ArgumentParsingException.class, ()->from(List.of("foo::bar::"+targetDir.toURI().toURL())));

assertThrows(ArgumentParsingException.class, ()->from(List.of("/path/to/repo")));

assertThrows(ArgumentParsingException.class, ()->from(List.of(targetDir.getAbsolutePath())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,36 +242,40 @@ public void provisionConfigAndChannelSet() throws IOException {
public void provisionConfigAndRemoteRepoSet() throws Exception {
Path channelsFile = temporaryFolder.newFile().toPath();
MetadataTestUtils.prepareChannel(channelsFile, List.of(new URL("file:some-manifest.yaml")));
URL test = temporaryFolder.newFolder().toURI().toURL();

int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, "test",
int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, test.toString(),
CliConstants.CHANNELS, channelsFile.toString(),
CliConstants.REPOSITORIES, "file:/test",
CliConstants.REPOSITORIES, test.toString(),
CliConstants.FPL, "g:a");

assertEquals(ReturnCodes.SUCCESS, exitCode);
Mockito.verify(provisionAction).provision(configCaptor.capture(), channelCaptor.capture(), any());
assertThat(channelCaptor.getValue().get(0).getRepositories()
.stream().map(Repository::getUrl).collect(Collectors.toList()))
.containsOnly("file:/test");
.containsOnly(String.valueOf(test));
}

@SuppressWarnings("unchecked")
@Test
public void passShadowRepositories() throws Exception {

Path channelsFile = temporaryFolder.newFile().toPath();
URL test = temporaryFolder.newFolder().toURI().toURL();

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

int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, "test",
int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, test.toString(),
CliConstants.CHANNELS, channelsFile.toString(),
CliConstants.SHADE_REPOSITORIES, "file:/test",
CliConstants.SHADE_REPOSITORIES, test.toString(),
CliConstants.FPL, "g:a");

assertEquals(ReturnCodes.SUCCESS, exitCode);
final ArgumentCaptor<List<Repository>> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
Mockito.verify(provisionAction).provision(configCaptor.capture(), channelCaptor.capture(), listArgumentCaptor.capture());
assertThat(listArgumentCaptor.getValue())
.map(Repository::getUrl)
.contains("file:/test");
.contains(String.valueOf(test));
}

@Test
Expand Down

0 comments on commit c3fb1bb

Please sign in to comment.