Skip to content

Commit

Permalink
Fix broken directory with space handling
Browse files Browse the repository at this point in the history
Fixes: #8977
  • Loading branch information
geoand committed May 1, 2020
1 parent 06b631e commit 9d865b7
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 12 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ jobs:
virtual-http
rest-client
- category: Misc1
timeout: 40
timeout: 45
test-modules: >
maven
jackson
Expand All @@ -431,6 +431,8 @@ jobs:
jgit
quartz
qute
# This one is converted in the shell script to 'simple with spaces'. It obviously sucks to do it like this, but we don't have a better way of passing strings with spaces
simple-with-spaces
- category: Misc2
timeout: 45
test-modules: >
Expand Down Expand Up @@ -527,8 +529,11 @@ jobs:
env:
TEST_MODULES: ${{matrix.test-modules}}
run: |
for i in $TEST_MODULES
do modules+=("integration-tests/$i"); done
for i in $TEST_MODULES; do
# this sucks, but we don't have a better way of passing a string
finalName=$([ "$i" == "simple-with-spaces" ] && echo "simple with spaces" || echo "$i")
modules+=("integration-tests/$finalName")
done
IFS=,
eval mvn -pl "${modules[*]}" $NATIVE_TEST_MAVEN_OPTS
- name: Prepare failure archive (if maven failed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,21 @@ public static void consumeStream(URL url, Consumer<InputStream> consumer) throws
*/
public static <R> R readStream(URL url, Function<InputStream, R> function) throws IOException {
if (JAR.equals(url.getProtocol())) {
final URI uri;
try {
uri = new URI(url.toString());
} catch (URISyntaxException e) {
throw new IOException(e);
}
final URI uri = toURI(url);
final String file = uri.getSchemeSpecificPart();
final int exclam = file.lastIndexOf('!');
final Path jar = toLocalPath(exclam >= 0 ? new URL(file.substring(0, exclam)) : url);
final int fileExclam = file.lastIndexOf('!');
final URL jarURL;
if (fileExclam > 0) {
// we need to use the original url instead of the scheme specific part because it contains the properly encoded path
String urlFile = url.getFile();
int urlExclam = urlFile.lastIndexOf('!');
jarURL = new URL(urlFile.substring(0, urlExclam));
} else {
jarURL = url;
}
final Path jar = toLocalPath(jarURL);
try (FileSystem jarFs = FileSystems.newFileSystem(jar, (ClassLoader) null)) {
try (InputStream is = Files.newInputStream(jarFs.getPath(file.substring(exclam + 1)))) {
try (InputStream is = Files.newInputStream(jarFs.getPath(file.substring(fileExclam + 1)))) {
return function.apply(is);
}
}
Expand All @@ -200,6 +204,16 @@ public static <R> R readStream(URL url, Function<InputStream, R> function) throw
}
}

private static URI toURI(URL url) throws IOException {
final URI uri;
try {
uri = new URI(url.toString());
} catch (URISyntaxException e) {
throw new IOException(e);
}
return uri;
}

/**
* Translates a URL to local file system path.
* In case the the URL couldn't be translated to a file system path,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<module>reactive-messaging-amqp</module>
<module>rest-client</module>
<module>packaging</module>
<module>simple with space</module>
</modules>

<build>
Expand Down
92 changes: 92 additions & 0 deletions integration-tests/simple with space/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-integration-test-simple-with-space</artifactId>
<name>Quarkus - Integration Tests - Simple with space</name>
<description>
A very basic integration test that contains a space in the directory and also resources files that contain spaces
</description>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<!-- added because /META-INF/resources/licenses/ contains files with spaces in their names -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.spaces;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.primefaces.util.Constants;

@Path("/hello")
public class GreetingResource {

// make sure we reference something from Primefaces so GraalVM doesn't throw out the entire jar
private static final String PRIMEFACES_DOWNLOAD_COOKIE = Constants.DOWNLOAD_COOKIE;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.it.spaces;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class GreetingResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("hello"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.it.spaces;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeGreetingResourceIT extends GreetingResourceTest {

// Execute the same tests but in native mode.
}

0 comments on commit 9d865b7

Please sign in to comment.