Skip to content

Embedded.customJavac() only extracts Unix bash scripts (custom-javac.sh / java-forwarder.sh), breaking MavenBuildTool on Windows #1068

Open

Description

@StrayCatDBA

MavenBuildTool instruments Maven builds by extracting a wrapper javac via Embedded.customJavac(...) and passing -Dmaven.compiler.executable=${javac.executable} and -Dmaven.compiler.fork=true to Maven.

On Windows, even after working around #991 (mvnw.cmd / mvn.cmd resolution in MavenBuildTool.kt), Maven compilation immediately fails when maven-compiler-plugin tries to fork the compiler, because Embedded.customJavac() unconditionally extracts POSIX bash scripts (scip-java/custom-javac.sh and scip-java/java-forwarder.sh) to bin/javac and bin/java and calls Files.setPosixFilePermissions(...).

Affected Code (main)

  • scip-java/src/main/kotlin/org/scip_code/scip_java/Embedded.kt (lines 32–56):
    fun customJavac(sourceroot: Path, targetroot: Path, tmp: Path): CustomJavac {
        val bin = tmp.resolve("bin")
        val javac = bin.resolve("javac")
        val java = bin.resolve("java")
        val agentJar = copyJar(tmp, "scip-java/scip-agent.jar")
        val pluginJar = copyJar(tmp, "scip-java/scip-javac.jar")
        copyResource(java, "scip-java/java-forwarder.sh")
        copyResource(javac, "scip-java/custom-javac.sh")
        Files.write(
            bin.resolve(".scip-Env"),
            """
            AGENT_JAR=$agentJar
            PLUGIN_JAR=$pluginJar
            SOURCEROOT=$sourceroot
            TARGETROOT=$targetroot
            JAVA_PATH=$java
            """.trimIndent().toByteArray(StandardCharsets.UTF_8),
        )
        val permissions = PosixFilePermissions.fromString("rwxr-xr-x")
        Files.setPosixFilePermissions(javac, permissions)
        Files.setPosixFilePermissions(java, permissions)
        return CustomJavac(javac, pluginJar)
    }
  • scip-java/src/main/kotlin/org/scip_code/scip_java/buildtools/MavenBuildTool.kt (lines 27–43):
    val javac =
        Embedded.customJavac(
            index.workingDirectory,
            index.finalTargetroot(defaultTargetroot),
            tmp,
        )
    ...
    command += "-Dmaven.compiler.executable=${javac.executable}"
    command += "-Dmaven.compiler.fork=true"

Failure Modes on Windows

  1. Files.setPosixFilePermissions(javac, permissions) in Embedded.customJavac() throws java.lang.UnsupportedOperationException on Windows NTFS filesystems because DefaultFileSystemProvider does not support the posix file attribute view.
  2. -Dmaven.compiler.executable=<tmp>\bin\javac points to an extensionless #!/usr/bin/env bash script (custom-javac.sh). When maven-compiler-plugin forks the compiler on Windows via CreateProcess, it fails with:
    CreateProcess error=193, %1 is not a valid Win32 application
    

Suggested Fix

  1. Guard Files.setPosixFilePermissions(...) behind FileSystems.getDefault().supportedFileAttributeViews().contains("posix") (similar to PR Fix ScipWriter temp file creation on file systems without POSIX permissions #1049).
  2. On Windows (System.getProperty("os.name").lowercase().contains("win")), generate .cmd wrapper scripts (javac.cmd and java.cmd) in Embedded.customJavac(...) that invoke InjectScipOptions and forward to javac.exe / java.exe, and return bin.resolve("javac.cmd") as CustomJavac.executable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions