[platform] reuses platform detection code from JNA (IDEA-166870)

This commit is contained in:
Roman Shevchenko
2017-01-23 15:59:27 +03:00
parent 002e6fa32f
commit 0eeb0d0c52
2 changed files with 24 additions and 31 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import com.intellij.util.TimeoutUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.BaseDataReader;
import com.intellij.util.io.BaseOutputReader;
import com.sun.jna.Platform;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -58,6 +59,7 @@ public class NativeFileWatcherImpl extends PluggableFileWatcher {
private static final String PROPERTY_WATCHER_DISABLED = "idea.filewatcher.disabled";
private static final String PROPERTY_WATCHER_EXECUTABLE_PATH = "idea.filewatcher.executable.path";
private static final File PLATFORM_NOT_SUPPORTED = new File("_platform_not_supported");
private static final String ROOTS_COMMAND = "ROOTS";
private static final String EXIT_COMMAND = "EXIT";
private static final int MAX_PROCESS_LAUNCH_ATTEMPT_COUNT = 10;
@@ -87,6 +89,9 @@ public class NativeFileWatcherImpl extends PluggableFileWatcher {
else if (myExecutable == null) {
notifyOnFailure(ApplicationBundle.message("watcher.exe.not.found"), null);
}
else if (myExecutable == PLATFORM_NOT_SUPPORTED) {
LOG.info("Native file watcher is not supported on this platform");
}
else if (!myExecutable.canExecute()) {
String message = ApplicationBundle.message("watcher.exe.not.exe", myExecutable);
notifyOnFailure(message, (notification, event) -> ShowFilePathAction.openFile(myExecutable));
@@ -142,7 +147,8 @@ public class NativeFileWatcherImpl extends PluggableFileWatcher {
String[] names = null;
String prefix = null;
if (SystemInfo.isWindows) {
names = SystemInfo.is64Bit ? new String[]{"fsnotifier64.exe", "fsnotifier.exe"} : new String[]{"fsnotifier.exe"};
if ("win32-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier.exe"};
if ("win32-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64.exe", "fsnotifier.exe"};
prefix = "win";
}
else if (SystemInfo.isMac) {
@@ -150,12 +156,12 @@ public class NativeFileWatcherImpl extends PluggableFileWatcher {
prefix = "mac";
}
else if (SystemInfo.isLinux) {
String arch = "arm".equals(SystemInfo.OS_ARCH) ? "-arm" : "ppc".equals(SystemInfo.OS_ARCH) ? "-ppc" : "";
String bits = SystemInfo.is64Bit ? "64" : "";
names = new String[]{"fsnotifier" + arch + bits};
if ("linux-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier"};
else if ("linux-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64"};
else if ("linux-arm".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier-arm"};
prefix = "linux";
}
if (names == null) return null;
if (names == null) return PLATFORM_NOT_SUPPORTED;
String[] dirs = {PathManager.getBinPath(),
PathManager.getHomePath() + "/ultimate/community/bin/" + prefix,
@@ -25,6 +25,7 @@ import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -425,31 +426,17 @@ public class FileSystemUtil {
private final boolean myCoarseTs = SystemProperties.getBooleanProperty(COARSE_TIMESTAMP_KEY, false);
private JnaUnixMediatorImpl() throws Exception {
if (SystemInfo.isLinux) {
if ("arm".equals(SystemInfo.OS_ARCH)) {
if (SystemInfo.is32Bit) {
myOffsets = LNX_ARM32;
}
else {
throw new IllegalStateException("AArch64 architecture is not supported");
}
}
else if ("ppc".equals(SystemInfo.OS_ARCH)) {
myOffsets = SystemInfo.is32Bit ? LNX_PPC32 : LNX_PPC64;
}
else {
myOffsets = SystemInfo.is32Bit ? LINUX_32 : LINUX_64;
}
}
else if (SystemInfo.isMac | SystemInfo.isFreeBSD) {
myOffsets = SystemInfo.is32Bit ? BSD_32 : BSD_64;
}
else if (SystemInfo.isSolaris) {
myOffsets = SystemInfo.is32Bit ? SUN_OS_32 : SUN_OS_64;
}
else {
throw new IllegalStateException("Unsupported OS/arch: " + SystemInfo.OS_NAME + "/" + SystemInfo.OS_ARCH);
}
if ("linux-x86".equals(Platform.RESOURCE_PREFIX)) myOffsets = LINUX_32;
else if ("linux-x86-64".equals(Platform.RESOURCE_PREFIX)) myOffsets = LINUX_64;
else if ("linux-arm".equals(Platform.RESOURCE_PREFIX)) myOffsets = LNX_ARM32;
else if ("linux-ppc".equals(Platform.RESOURCE_PREFIX)) myOffsets = LNX_PPC32;
else if ("linux-ppc64le".equals(Platform.RESOURCE_PREFIX)) myOffsets = LNX_PPC64;
else if ("freebsd-x86".equals(Platform.RESOURCE_PREFIX)) myOffsets = BSD_32;
else if ("darwin".equals(Platform.RESOURCE_PREFIX) ||
"freebsd-x86-64".equals(Platform.RESOURCE_PREFIX)) myOffsets = BSD_64;
else if ("sunos-x86".equals(Platform.RESOURCE_PREFIX)) myOffsets = SUN_OS_32;
else if ("sunos-x86-64".equals(Platform.RESOURCE_PREFIX)) myOffsets = SUN_OS_64;
else throw new IllegalStateException("Unsupported OS/arch: " + SystemInfo.OS_NAME + "/" + SystemInfo.OS_ARCH);
Native.register(LibC.class, "c");
Native.register(SystemInfo.isLinux ? LinuxLibC.class : UnixLibC.class, "c");