diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/InstallTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/InstallTest.java index 85565043e..f79b8f460 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/InstallTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/InstallTest.java @@ -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; @@ -31,7 +32,9 @@ 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(); @@ -39,7 +42,8 @@ public class InstallTest { private File targetDir; @Before - public void setUp() throws IOException { + public void setUp() throws Exception { + super.setUp(); targetDir = tempDir.newFolder(); } @@ -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); + } } diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/RepositoryDefinition.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/RepositoryDefinition.java index 06b77d3ef..482470a1f 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/RepositoryDefinition.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/RepositoryDefinition.java @@ -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; @@ -50,7 +52,12 @@ public static List from(List 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; diff --git a/prospero-cli/src/main/resources/UsageMessages.properties b/prospero-cli/src/main/resources/UsageMessages.properties index ecbe542b6..b4f968475 100644 --- a/prospero-cli/src/main/resources/UsageMessages.properties +++ b/prospero-cli/src/main/resources/UsageMessages.properties @@ -339,7 +339,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. diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/RepositoryDefinitionTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/RepositoryDefinitionTest.java index 5988bc076..de85ca47a 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/RepositoryDefinitionTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/RepositoryDefinitionTest.java @@ -18,9 +18,13 @@ 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.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -32,6 +36,20 @@ public class RepositoryDefinitionTest { + @Rule + public TemporaryFolder tempDir = new TemporaryFolder(); + + public String fileURL; + + public String filePath; + + @Before + public void setUp() throws Exception { + File target = tempDir.newFolder(); + filePath = target.getAbsolutePath(); + fileURL = target.toURI().toURL().toString(); + } + @Test public void generatesRepositoryIdsIfNotProvided() throws Exception { assertThat(from(List.of("http://test.te"))) @@ -75,5 +93,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 throwsErrorIfFormatIsIncorrectForFileURLOrPathDoesNotExist() throws Exception { + assertThrows(ArgumentParsingException.class, ()->from(List.of("::"+fileURL))); + + assertThrows(ArgumentParsingException.class, ()->from(List.of("repo-1::"))); + + assertThrows(ArgumentParsingException.class, ()->from(List.of("repo-1:::"+fileURL))); + + assertThrows(ArgumentParsingException.class, ()->from(List.of("foo::bar::"+fileURL))); + + assertThrows(ArgumentParsingException.class, ()->from(List.of("file:/path/to/repo"))); + + assertThrows(ArgumentParsingException.class, ()->from(List.of(filePath))); } } \ No newline at end of file diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java index ac31700ca..e7ddfa9b8 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java @@ -241,29 +241,33 @@ public void provisionConfigAndChannelSet() throws IOException { @Test public void provisionConfigAndRemoteRepoSet() throws Exception { Path channelsFile = temporaryFolder.newFile().toPath(); + String test = temporaryFolder.newFolder().toURI().toURL().toString(); + 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, CliConstants.CHANNELS, channelsFile.toString(), - CliConstants.REPOSITORIES, "file:/test", + CliConstants.REPOSITORIES, test, 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(test); } @SuppressWarnings("unchecked") @Test public void passShadowRepositories() throws Exception { Path channelsFile = temporaryFolder.newFile().toPath(); + String test = temporaryFolder.newFolder().toURI().toURL().toString(); + 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, CliConstants.CHANNELS, channelsFile.toString(), - CliConstants.SHADE_REPOSITORIES, "file:/test", + CliConstants.SHADE_REPOSITORIES, test, CliConstants.FPL, "g:a"); assertEquals(ReturnCodes.SUCCESS, exitCode); @@ -271,7 +275,7 @@ public void passShadowRepositories() throws Exception { Mockito.verify(provisionAction).provision(configCaptor.capture(), channelCaptor.capture(), listArgumentCaptor.capture()); assertThat(listArgumentCaptor.getValue()) .map(Repository::getUrl) - .contains("file:/test"); + .contains(test); } @Test