-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JBEAP-26296] Allow specifying --repositories … #569
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChristinaDsl that doesn't work, the local path has to be converted to an URL to be usable:
./prospero install --fpl org.wildfly.core:wildfly-core-galleon-pack:20.0.0.Beta3 \
--manifest examples/wildfly-core-manifest.yaml --repositories test-repo \
--dir installation-dir
Installing feature pack: org.wildfly.core:wildfly-core-galleon-pack:20.0.0.Beta3
Using channels:
# manifest: file:/Users/spyrkob/workspaces/set/prospero/prospero/examples/wildfly-core-manifest.yaml
repositories:
id: temp-repo-0
url: test-repo
ERROR: The following artifacts could not be resolved: org.wildfly.core:wildfly-core-galleon-pack:zip:20.0.0.Beta3 (absent): Could not transfer artifact org.wildfly.core:wildfly-core-galleon-pack:zip:20.0.0.Beta3 from/to temp-repo-0 (test-repo): Cannot access test-repo with type default using the available connector factories: BasicRepositoryConnectorFactory
Also could you add unit tests to RepositoryDefinitionTest
and an integration test to org.wildfly.prospero.it.cli.InstallTest
to verify this change?
e8d4b80
to
c3fb1bb
Compare
c3fb1bb
to
3a9e027
Compare
from(List.of(fileURL)); | ||
from(List.of("file://"+filePath)); | ||
} catch (Exception e) { | ||
fail("Provided URL's absolute or relative path is not correct"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChristinaDsl you don't need to catch the exception. If it fails the test fails. Also you should check that the returned value is correct. The method might run without exception, but the returned value might be wrong
b4b7fb8
to
5e0742c
Compare
if (text.startsWith("file://..")){ | ||
return false; | ||
} else if (text.startsWith("file")){ | ||
if (Pattern.compile("/[A-Z]:").matcher(text).find()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChristinaDsl why do you need this check? Paths.get(url.toURI()
should work on both Windows and Linux paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not work on relative paths. In windows and file URLs Paths.get() throws error and in Linux relative path cannot be converted initially in URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK thank you. Could you add this explanation in a comment in the code please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course
new URL(text); | ||
URL url = new URL(text); | ||
if (text.startsWith("file://..")){ | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a debug message why this is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course
} else { | ||
path = Paths.get(url.getPath()).toAbsolutePath(); | ||
} | ||
return new File(String.valueOf(path)).exists(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Files.exists(path)
or return path.toFile().exists()
final URL temporaryRepo = mockTemporaryRepo(true); | ||
|
||
ExecutionUtils.prosperoExecution(CliConstants.Commands.UPDATE, CliConstants.Commands.PERFORM, | ||
CliConstants.REPOSITORIES, temporaryRepo.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the temporaryRepo
is an URL, for this test to really verify this functionality it would have to be a relative path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. This test is to verify that a local repo can be found and the update command is indeed working when an argument " --repositories" is passed along with the url of local repo. So, why should be a relative path here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already are tests in UpdateWithAdditionalRepositoryTest
that verify this use case. The new use case added in this issue should be that a user can pass a local path (e.g. ../test-repository
or /home/user/test-repository
) as an argument for --repositories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So check both for absolute and relative paths in this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally yes, but relative path would be enough
} | ||
|
||
@Test | ||
public void testCorrectRelativeOrAbsolutePathForFileURL() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about a relative path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relative path is test in the first lines of this method with this url "file:../prospero-common"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a URI with relative path. A relative path would be ../prospero-common
on its own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole method contains URLs and a URI, not just its absolute and relative paths. Should I change the whole method to contain only paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this verifies JBEAP-26295 as well so those are valid tests. Just adding some examples of paths will be enough.
5e0742c
to
b47e196
Compare
|
||
final URL temporaryRepo = mockTemporaryRepo(true); | ||
|
||
Path relativePath = Paths.get(System.getProperty("user.dir")).relativize(Path.of(Path.of(temporaryRepo.toURI()).toUri())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nested Path.of is not needed
Path relativePath = Paths.get(System.getProperty("user.dir")).relativize(Path.of(Path.of(temporaryRepo.toURI()).toUri())); | ||
|
||
ExecutionUtils.prosperoExecution(CliConstants.Commands.UPDATE, CliConstants.Commands.PERFORM, | ||
CliConstants.REPOSITORIES, ".."+File.separator+"integration-tests"+File.separator+relativePath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Path.of(String...) to build the path instead of appending the strings.
Also, relativePath
is already a relative path, so I don't think adding ../integration-tests" to it brings anything to the test. I'd keep it simple and just use the
relativePath` here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding "../integration-tests" is important because if I just use relative path then I have a result "target/folder1/folder2" which is invalid for two reasons:
Firstly, is not a relative path
Secondly, the folder the test exists is "integration-tests". So, if I just put "../"+relative path would go out of integration-tests folder and search the target inside parent folder which is "prospero". I need too search inside "integration-tests" the target folder because there it is created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target/folder1/folder2
is a relative path. An absolute path starts with root directory (e.g. /home/jboss/
on linux or C:\Users\jboss
on Windows). A relative path doesn't have a root folder and is relative to the current folder (e.g. target/foo
is relative because it depends on where the user is)
@@ -418,6 +418,10 @@ default ArgumentParsingException invalidRepositoryDefinition(String repoKey) { | |||
return new ArgumentParsingException(format(bundle.getString("prospero.general.validation.repo_format"), repoKey)); | |||
} | |||
|
|||
default ArgumentParsingException invalidFilePath(String repoKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/repoKey/path
|
||
public class RepositoryDefinition { | ||
|
||
public static List<Repository> from(List<String> repos) throws ArgumentParsingException { | ||
public static List<Repository> from(List<String> repos) throws ArgumentParsingException, MalformedURLException, URISyntaxException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you catch the new exceptions and wrap them in ArgumentParsingException with an explanation message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course
|
||
private static boolean isValidUrl(String text) throws ArgumentParsingException { | ||
if (text.startsWith("file://..")) { | ||
Logger.getLogger("'file://../path/to/repo' is invalid as the format of file URL should be " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean Logger.warn ?
whereas for Linux, Paths.get(url.getPath()).toAbsolutePath() is more suitable. */ | ||
private static Path getPathFromURL(String text) throws MalformedURLException, URISyntaxException, ArgumentParsingException { | ||
URL url = new URL(text); | ||
if (Pattern.compile("/[A-Z]:").matcher(text).find()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not going to correct, e.g. in Linux it's possible to create a folder with name A:
b47e196
to
5cc91b3
Compare
public static List<Repository> from(List<String> repos) throws ArgumentParsingException { | ||
ArrayList<Repository> repositories = new ArrayList<>(repos.size()); | ||
for (int i = 0; i < repos.size(); i++) { | ||
final String text = repos.get(i); | ||
String text = repos.get(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable can be more descriptive than text
. Maybe repoName
?
@@ -56,4 +69,31 @@ private static boolean isValidUrl(String text) { | |||
return false; | |||
} | |||
} | |||
|
|||
public static URI getAbsoluteFileURI(String text) throws ArgumentParsingException, URISyntaxException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
public static URI getAbsoluteFileURI(String text) throws ArgumentParsingException, URISyntaxException { | ||
String path; | ||
path = getPath(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the assignment on a separate line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this
public static URI getAbsoluteFileURI(String text) throws ArgumentParsingException, URISyntaxException { | ||
String path; | ||
path = getPath(text); | ||
File file = new File(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think file
can be a one-liner.
File file = new File(getPath(text));
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If file does not exist, the error message should include the path, so it is used in more than one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean, throw CliMessages.MESSAGES.invalidFilePath(path);
? If so, you are already using path
instead of file
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
file is also used in two lines,
if (file.exists()) {
return file.toURI();
if that is your point..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that you don't need to create a new variable for the single purpose, path
, to be used as a parameter for getPath()
and then used to create a File
object. You can simplify it with File file = new File(getPath(text));
for example.
} | ||
} | ||
|
||
public static String getPath(String text) throws URISyntaxException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text
, same as above.
@@ -241,37 +241,45 @@ public void provisionConfigAndChannelSet() throws IOException { | |||
@Test | |||
public void provisionConfigAndRemoteRepoSet() throws Exception { | |||
Path channelsFile = temporaryFolder.newFile().toPath(); | |||
|
|||
File test = temporaryFolder.newFolder(); | |||
String testURL = test.toURI().toURL().toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why converting to URI, then to URL and then to String?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To create a URL out of a file object. I guess we could skip last call .toURL()
|
||
File test = temporaryFolder.newFolder(); | ||
String testURL = test.toURI().toURL().toString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
@@ -241,37 +241,45 @@ public void provisionConfigAndChannelSet() throws IOException { | |||
@Test | |||
public void provisionConfigAndRemoteRepoSet() throws Exception { | |||
Path channelsFile = temporaryFolder.newFile().toPath(); | |||
|
|||
File test = temporaryFolder.newFolder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable could have a more descriptive name
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void passShadowRepositories() throws Exception { | ||
Path channelsFile = temporaryFolder.newFile().toPath(); | ||
|
||
File test = temporaryFolder.newFolder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable could have a more descriptive name
} | ||
|
||
public static String getPath(String text) throws URISyntaxException { | ||
if (text.startsWith("file")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be file:
to make sure the user is inputting a URI and not a file named file_dir
for example
5cc91b3
to
b636752
Compare
final String text = repos.get(i); | ||
if(text.contains("::")) { | ||
final String[] parts = text.split("::"); | ||
String repoName = repos.get(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick - the repoName
variable name is a bit misleading - the string can either contain repoName::repoLocation or just repoLocation
repositories.add(new Repository(parts[0], parts[1])); | ||
} else { | ||
if (!isValidUrl(text)) { | ||
throw CliMessages.MESSAGES.invalidRepositoryDefinition(text); | ||
if (!repoName.startsWith("http") && !repoName.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check if it starts with either http://
or https://
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it starts with "https", it should be handled differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both http and https should be treated the same - as web URLs. The difference is that http://foo.bar
is an URL http/foo/bar
is a path
URI inputUri = new URI(repoName); | ||
if (inputUri.getScheme().equals("file") && | ||
!inputUri.getSchemeSpecificPart().startsWith("/")) { | ||
inputUri = new URI(("file:/" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC at this point this is a relative URI. In which case Path.of(inputUri.getSchemeSpecificPart()).toAbsolutePath() should be all you need to get the absolute path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this already creates the Path from the URI, why does it need to be converted back to URI and then again to Path?
@@ -100,7 +102,7 @@ protected MavenOptions getMavenOptions() throws ArgumentParsingException { | |||
return mavenOptions.build(); | |||
} | |||
|
|||
protected ProvisioningDefinition.Builder buildDefinition() throws MetadataException, NoChannelException, ArgumentParsingException { | |||
protected ProvisioningDefinition.Builder buildDefinition() throws MetadataException, NoChannelException, ArgumentParsingException, MalformedURLException, URISyntaxException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those exceptions should be wrapped in ArgumentParsingException
b636752
to
4d1db4c
Compare
eb8a7d4
to
4d1db4c
Compare
@ChristinaDsl please remove the |
https://issues.redhat.com/browse/JBEAP-26296