final boolean run()

in src/main/java/org/apache/maven/plugin/compiler/ForkedTool.java [137:176]


    final boolean run(
            Writer out,
            ForkedToolSources fileManager,
            Iterable<String> options,
            Iterable<? extends JavaFileObject> compilationUnits)
            throws IOException {
        ProcessBuilder builder = builder();
        List<String> command = builder.command();
        for (String option : options) {
            command.add(option);
        }
        fileManager.addAllLocations(command);
        for (JavaFileObject source : compilationUnits) {
            Path path = fileManager.asPath(source);
            if (basedir != null) {
                try {
                    path = basedir.relativize(path);
                } catch (IllegalArgumentException e) {
                    // Ignore, keep the absolute path.
                }
            }
            command.add(path.toString());
        }
        File output = File.createTempFile("javac", null);
        try {
            var dest = ProcessBuilder.Redirect.appendTo(output);
            builder.redirectError(dest);
            builder.redirectOutput(dest);
            return start(builder, out) == 0;
        } finally {
            /*
             * Need to use the native encoding because it is the encoding used by the native process.
             * This is not necessarily the default encoding of the JVM, which is "file.encoding".
             * This property is available since Java 17.
             */
            String cs = System.getProperty("native.encoding");
            out.append(Files.readString(output.toPath(), Charset.forName(cs)));
            output.delete();
        }
    }