graalvm / native-build-tools

Native-image plugins for various build tools
https://graalvm.github.io/native-build-tools/
Other
366 stars 57 forks source link

Test agent execution fails in directory with spaces #485

Open Marcono1234 opened 1 year ago

Marcono1234 commented 1 year ago

Describe the bug Trying to run Native Image tests with the agent fails if the project directory path contains spaces.

(Might also apply when running the application with the agent.)

To Reproduce

Steps to reproduce the behavior:

  1. Create a directory with a space in its name, for example path with-spaces
  2. In that directory create a pom.xml file with the following content:

    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <version>1.0-SNAPSHOT</version>
    
      <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>org.junit.jupiter</groupId>
          <artifactId>junit-jupiter</artifactId>
          <version>5.10.0</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.graalvm.buildtools</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <version>0.9.24</version>
            <extensions>true</extensions>
            <executions>
              <execution>
                <id>test-native</id>
                <goals>
                  <goal>test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
  3. Create the test source file src/test/java/MyTest.java with the following content:

    import static org.junit.jupiter.api.Assertions.assertTrue;
    
    import org.junit.jupiter.api.Test;
    
    class MyTest {
        @Test
        void test() {
            assertTrue(true);
        }
    }
  4. Run mvn clean test -Dagent=true :x: Bug: Surefire execution fails with:
    Error: Could not find or load main class with-spaces\target\native\agent-output\test\session-{pid}-{datetime}
    Caused by: java.lang.ClassNotFoundException: with-spaces\target\native\agent-output\test\session-{pid}-{datetime}

Expected behavior Execution does not fail

Logs Surefire log on console:

[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C "C:\Users\...\Downloads\graalvm-jdk-17.0.8+9.1\bin\java -agentlib:native-image-agent=config-output-dir=C:\Users\...\Downloads\test-native\path with-spaces\target\native\agent-output\test\session-{pid}-{datetime} -jar C:\Users\...\AppData\Local\Temp\surefire9367496019182751827\surefirebooter-20230812135354914_3.jar C:\Users\...\AppData\Local\Temp\surefire9367496019182751827 2023-08-12T13-53-54_661-jvmRun1 surefire-20230812135354914_1tmp surefire_0-20230812135354914_2tmp"

Note how there are no quotes around the -agentlib argument.

System Info (please complete the following information):

Additional context The Gradle plugin might be affected as well, but I have not tested it.