-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[GR-50220] Allow resources inclusion from jar files in paths containing spaces #7815
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
[GR-50220] Allow resources inclusion from jar files in paths containing spaces #7815
Conversation
c39af7b to
7a31d81
Compare
jerboaa
left a comment
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 we should change this to ((JarURLConnection) url.openConnection()).getJarFileURL().toURI().getPath(); instead. See below.
| private JarFile urlToJarFile(URL url) { | ||
| try { | ||
| return ((JarURLConnection) url.openConnection()).getJarFileURL().getFile(); | ||
| return ((JarURLConnection) url.openConnection()).getJarFile(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| private boolean resourceIsDirectory(URL url, boolean fromJar, String resourcePath) throws IOException, URISyntaxException { | ||
| if (fromJar) { | ||
| try (JarFile jf = new JarFile(urlToJarPath(url))) { | ||
| try (JarFile jf = urlToJarFile(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.
This seems to be the gist of it. Let url be new URL("jar:file:///home/sgehwolf/Documents/mandrel/bugs/quarkus/itest-with-space/test%20with%20space/byteman.jar!/META-INF/MANIFEST.MF")
Then we have this for the old code:
jshell> var x = ((JarURLConnection) url.openConnection()).getJarFileURL().getFile();
x ==> "/home/sgehwolf/Documents/mandrel/bugs/quarkus/it ... 0with%20space/byteman.jar"
jshell> JarFile f = new JarFile(x);
| Exception java.nio.file.NoSuchFileException: /home/sgehwolf/Documents/mandrel/bugs/quarkus/itest-with-space/test%20with%20space/byteman.jar
| at UnixException.translateToIOException (UnixException.java:92)
| at UnixException.rethrowAsIOException (UnixException.java:106)
| at UnixException.rethrowAsIOException (UnixException.java:111)
| at UnixFileAttributeViews$Basic.readAttributes (UnixFileAttributeViews.java:55)
| at UnixFileSystemProvider.readAttributes (UnixFileSystemProvider.java:148)
| at LinuxFileSystemProvider.readAttributes (LinuxFileSystemProvider.java:99)
| at Files.readAttributes (Files.java:1851)
| at ZipFile$Source.get (ZipFile.java:1394)
| at ZipFile$CleanableResource.<init> (ZipFile.java:716)
| at ZipFile.<init> (ZipFile.java:250)
| at ZipFile.<init> (ZipFile.java:179)
| at JarFile.<init> (JarFile.java:346)
| at JarFile.<init> (JarFile.java:317)
| at JarFile.<init> (JarFile.java:256)
| at (#29:1)
jshell> System.out.println(x);
/home/sgehwolf/Documents/mandrel/bugs/quarkus/itest-with-space/test%20with%20space/byteman.jar
And the new code:
jshell> URL url = new URL("jar:file:///home/sgehwolf/Documents/mandrel/bugs/quarkus/itest-with-space/test%20with%20space/byteman.jar!/META-INF/MANIFEST.MF")
url ==> jar:file:///home/sgehwolf/Documents/mandrel/bugs/ ... .jar!/META-INF/MANIFEST.MF
jshell> var x = ((JarURLConnection) url.openConnection()).getJarFile();
x ==> sun.net.www.protocol.jar.URLJarFile@4aa8f0b4
I.e. JarFile created from a String, expects URL decoded paths. OK. But looking at the implementation of getJarFile() I see that it creates a copy of the file, which is probably not what we want.
So I suggest to use:
private String urlToJarFile(URL url) {
try {
return ((JarURLConnection) url.openConnection()).getJarFileURL().toURI().getPath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
... which should properly decode %20 to :
jshell> URL url = new URL("jar:file:///home/sgehwolf/Documents/mandrel/bugs/quarkus/itest-with-space/test%20with%20space/byteman.jar!/META-INF/MANIFEST.MF")
url ==> jar:file:///home/sgehwolf/Documents/mandrel/bugs/ ... .jar!/META-INF/MANIFEST.MF
jshell> var x = ((JarURLConnection) url.openConnection()).getJarFileURL().toURI().getPath();
x ==> "/home/sgehwolf/Documents/mandrel/bugs/quarkus/it ... st with space/byteman.jar"
jshell> JarFile f = new JarFile(x);
f ==> java.util.jar.JarFile@2a3046da
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 see that it creates a copy of the file, which is probably not what we want.
Good catch @jerboaa
So I suggest to use...
Done. Thanks!
7a31d81 to
3eedd42
Compare
jerboaa
left a comment
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.
Would be nice to actually catch this in a test, but this seems fine to me and should be a safe change. Thanks!
One option would be to build graal in a folder containing a space, but unfortunately that's not supported (there are some ninja related failures if you try to do it). Another option would be to add a space in the jar file itself, the name is derived from graal/substratevm/mx.substratevm/suite.py Line 1978 in 35d412e
diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py
index 7c9555bccb5..713abcb06f4 100644
--- a/substratevm/mx.substratevm/suite.py
+++ b/substratevm/mx.substratevm/suite.py
@@ -1975,7 +1975,7 @@ suite = {
"testDistribution" : True,
},
- "SVM_TESTS" : {
+ "SVM TESTS" : {
"subDir": "src",
"relpath" : True,
"dependencies" : [However, it will apply to all tests, i.e. we won't have a separate jar with spaces in the filename only for this test case. Which means that without this PR it results in: I will try to create a new jar file (mx distribution) and add it as a dependency to |
Done in 8e03be8 |
436f857 to
8e03be8
Compare
jerboaa
left a comment
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.
LGTM. @fniephaus Could you help us get this pushed/reviewed? Thanks!
| "testDistribution" : True, | ||
| }, | ||
|
|
||
| "SVM_TESTS WITH SPACE" : { |
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.
Might warrant a comment that there is intentionally a space in the name. Hard to spot ;-)
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.
Yes indeed. @zakkak please add a comment in suite.py why we need exactly that.
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.
Done.
Next week is fine. We just don't want such issues hanging in the air without knowing if you guys are aware (as it's causing test failures for us). Thanks for the reply! |
|
Looks good to me! @olpaw can you also take a look on it before it gets merged? |
|
Thanks for the review! |
| return ((JarURLConnection) url.openConnection()).getJarFileURL().getFile(); | ||
| } catch (IOException e) { | ||
| return ((JarURLConnection) url.openConnection()).getJarFileURL().toURI().getPath(); | ||
| } catch (IOException | URISyntaxException e) { |
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 the small cleanups as well 😁
8e03be8 to
2d4c719
Compare
|
Am I correct in thinking that this is in the merge queue? |
|
Running in internal CI. Should be in merge queue soon. |
|
Thanks! |
|
@olpaw Any update on the merge queue status of this? Did it fail? |
|
@jerboaa it is still in the merge queue. There is a lot going on currently, but I'm having an eye on it and make sure that it will go in. |
|
@zapster Thank you! Appreciate that. |
Since #7670 it is no longer possible to build projects that include resources from paths with spaces.
How to reproduce:
masterfrom sourceexport GRAALVM_HOME=/path/to/graal/master/buildgit clone https://github.com/quarkusio/quarkuscd quarkus./mvnw -Dquickly./mvnw -Dnative -pl integration-tests/simple\ with\ space -Dnative.surefire.skip -Dformat.skip -Dno-descriptor-tests clean verify -Dquarkus.native.container-build=falseThis PR resolves this issue and adds a set of tests for resource names with spaces (which don't catch the issue at hand, but are still good to test against).
Closes quarkusio/quarkus#36998