Merge pull request #423 from gnodet/i422

Fix the environment update, fixes #422
This commit is contained in:
Guillaume Nodet
2021-06-04 09:57:25 +02:00
committed by GitHub

View File

@@ -700,19 +700,26 @@ public class DaemonMavenCli {
} }
} }
private static float javaSpec = 0.0f;
protected static void chDir(String workingDir) throws Exception { protected static void chDir(String workingDir) throws Exception {
CLibrary.chdir(workingDir); CLibrary.chdir(workingDir);
System.setProperty("user.dir", workingDir); System.setProperty("user.dir", workingDir);
// change current dir for the java.io.File class // change current dir for the java.io.File class
Class<?> fileClass = Class.forName("java.io.File"); Class<?> fileClass = Class.forName("java.io.File");
Field fsField = fileClass.getDeclaredField("fs"); if (javaSpec <= 0.0f) {
fsField.setAccessible(true); javaSpec = Float.parseFloat(System.getProperty("java.specification.version"));
Object fs = fsField.get(null); }
Field userDirField = fs.getClass().getDeclaredField("userDir"); if (javaSpec >= 11.0) {
userDirField.setAccessible(true); Field fsField = fileClass.getDeclaredField("fs");
userDirField.set(fs, workingDir); fsField.setAccessible(true);
Object fs = fsField.get(null);
Field userDirField = fs.getClass().getDeclaredField("userDir");
userDirField.setAccessible(true);
userDirField.set(fs, workingDir);
}
// change current dir for the java.nio.Path class // change current dir for the java.nio.Path class
fs = FileSystems.getDefault(); Object fs = FileSystems.getDefault();
Class<?> fsClass = fs.getClass(); Class<?> fsClass = fs.getClass();
while (fsClass != Object.class) { while (fsClass != Object.class) {
if ("sun.nio.fs.UnixFileSystem".equals(fsClass.getName())) { if ("sun.nio.fs.UnixFileSystem".equals(fsClass.getName())) {