From 9c370cfcf02e965950c311adf374d1940d86b16a Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Wed, 22 Jul 2020 02:46:47 -0400 Subject: [PATCH] Bug 521515: Update to JNA 5.6.0 Change-Id: Id56f6366e0bbaa33b1d0967cd64487fc173b3833 --- .../META-INF/MANIFEST.MF | 2 +- core/org.eclipse.cdt.core.native/pom.xml | 2 +- .../eclipse/cdt/utils/WindowsRegistry.java | 16 +++-- .../META-INF/MANIFEST.MF | 6 +- core/org.eclipse.cdt.core.win32/pom.xml | 2 +- .../cdt/internal/core/win32/ProcessList.java | 67 +------------------ .../core/win32/WindowsRegistryImpl.java | 3 +- releng/org.eclipse.cdt.repo/category.xml | 2 + releng/org.eclipse.cdt.target/cdt.target | 4 +- 9 files changed, 26 insertions(+), 78 deletions(-) diff --git a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF index 14341ae6e72..99abb67a88d 100644 --- a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core.native;singleton:=true -Bundle-Version: 6.1.0.qualifier +Bundle-Version: 6.1.100.qualifier Bundle-Activator: org.eclipse.cdt.internal.core.natives.CNativePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core.native/pom.xml b/core/org.eclipse.cdt.core.native/pom.xml index c8bfafd4360..f0a212fe5ec 100644 --- a/core/org.eclipse.cdt.core.native/pom.xml +++ b/core/org.eclipse.cdt.core.native/pom.xml @@ -23,7 +23,7 @@ ../../pom.xml - 6.1.0-SNAPSHOT + 6.1.100-SNAPSHOT org.eclipse.cdt.core.native eclipse-plugin diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java index c35b672efb1..9dca255178a 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java @@ -17,6 +17,7 @@ import java.util.Map; import org.eclipse.cdt.internal.core.natives.CNativePlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; /** * @author DSchaefer @@ -33,14 +34,19 @@ public abstract class WindowsRegistry { } public static WindowsRegistry getRegistry() { - if (registry == null) { - try { - registry = CNativePlugin.getDefault().getWindowsRegistry(); - } catch (CoreException e) { + if (Platform.getOS().equals(Platform.OS_WIN32)) { + if (registry == null) { + try { + registry = CNativePlugin.getDefault().getWindowsRegistry(); + } catch (CoreException e) { + CNativePlugin.log("Failed to load WindowsRegistry", e); //$NON-NLS-1$ + } } + return registry; + } else { + return null; } - return registry; } /** diff --git a/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF index 7abccf9023e..d8f6b48dc7c 100644 --- a/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF @@ -2,12 +2,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %fragmentName.win32 Bundle-SymbolicName: org.eclipse.cdt.core.win32; singleton:=true -Bundle-Version: 6.0.100.qualifier +Bundle-Version: 6.0.200.qualifier Bundle-Vendor: %providerName Fragment-Host: org.eclipse.cdt.core.native;bundle-version="[6.1.0,7.0.0)" Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-11 Eclipse-PlatformFilter: (osgi.os=win32) Automatic-Module-Name: org.eclipse.cdt.core.win32 -Require-Bundle: com.sun.jna;bundle-version="4.5.1", - com.sun.jna.platform;bundle-version="4.5.1" +Require-Bundle: com.sun.jna;bundle-version="[5.6.0,6.0.0)", + com.sun.jna.platform;bundle-version="[5.6.0,6.0.0)" diff --git a/core/org.eclipse.cdt.core.win32/pom.xml b/core/org.eclipse.cdt.core.win32/pom.xml index a9a10c53224..01acea75d05 100644 --- a/core/org.eclipse.cdt.core.win32/pom.xml +++ b/core/org.eclipse.cdt.core.win32/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 6.0.100-SNAPSHOT + 6.0.200-SNAPSHOT org.eclipse.cdt.core.win32 eclipse-plugin diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java index ba3af06c6c2..4810f09c248 100644 --- a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java +++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/ProcessList.java @@ -15,79 +15,16 @@ package org.eclipse.cdt.internal.core.win32; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.eclipse.cdt.core.IProcessInfo; import org.eclipse.cdt.core.IProcessList; -import com.sun.jna.Native; -import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.Kernel32Util; +import com.sun.jna.platform.win32.PsapiUtil; import com.sun.jna.platform.win32.Win32Exception; -import com.sun.jna.platform.win32.WinDef.DWORD; -import com.sun.jna.platform.win32.WinNT; -import com.sun.jna.platform.win32.WinNT.HANDLE; -import com.sun.jna.ptr.IntByReference; -import com.sun.jna.win32.W32APIOptions; public class ProcessList implements IProcessList { - // TODO: Remove this inner class when JNA 5.6 is available - private static abstract class PsapiUtil { - public interface Psapi extends com.sun.jna.platform.win32.Psapi { - Psapi INSTANCE = Native.loadLibrary("psapi", Psapi.class, W32APIOptions.DEFAULT_OPTIONS); //$NON-NLS-1$ - - boolean EnumProcesses(int[] lpidProcess, int cb, IntByReference lpcbNeeded); - } - - public static int[] enumProcesses() { - int size = 0; - int[] lpidProcess = null; - IntByReference lpcbNeeded = new IntByReference(); - do { - size += 1024; - lpidProcess = new int[size]; - if (!Psapi.INSTANCE.EnumProcesses(lpidProcess, size * DWORD.SIZE, lpcbNeeded)) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } - } while (size == lpcbNeeded.getValue() / DWORD.SIZE); - - return Arrays.copyOf(lpidProcess, lpcbNeeded.getValue() / DWORD.SIZE); - } - } - - // TODO: Remove this inner class when JNA 5.6 is available - private static abstract class Kernel32Util extends com.sun.jna.platform.win32.Kernel32Util { - public static final String QueryFullProcessImageName(int pid, int dwFlags) { - HANDLE hProcess = null; - Win32Exception we = null; - - try { - hProcess = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_QUERY_INFORMATION | WinNT.PROCESS_VM_READ, false, - pid); - if (hProcess == null) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } - return QueryFullProcessImageName(hProcess, dwFlags); - } catch (Win32Exception e) { - we = e; - throw we; // re-throw to invoke finally block - } finally { - try { - closeHandle(hProcess); - } catch (Win32Exception e) { - if (we == null) { - we = e; - } else { - we.addSuppressed(e); - } - } - if (we != null) { - throw we; - } - } - } - } - private IProcessInfo[] NOPROCESS = new IProcessInfo[0]; @Override diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java index 42b0431c76a..c54dd22ccd0 100644 --- a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java +++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.utils.WindowsRegistry; import org.eclipse.core.runtime.Platform; import com.sun.jna.Native; +import com.sun.jna.Pointer; import com.sun.jna.platform.win32.Advapi32; import com.sun.jna.platform.win32.Advapi32Util; import com.sun.jna.platform.win32.Advapi32Util.EnumKey; @@ -114,7 +115,7 @@ public class WindowsRegistryImpl extends WindowsRegistry { char[] lpValueName = new char[Advapi32.MAX_KEY_LENGTH]; IntByReference lpcchValueName = new IntByReference(Advapi32.MAX_KEY_LENGTH); int rc = Advapi32.INSTANCE.RegEnumValue(phkKey.getValue(), index, lpValueName, lpcchValueName, null, - null, null, null); + null, (Pointer) null, null); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); diff --git a/releng/org.eclipse.cdt.repo/category.xml b/releng/org.eclipse.cdt.repo/category.xml index e08b7891d8b..f8b6d69b8c4 100644 --- a/releng/org.eclipse.cdt.repo/category.xml +++ b/releng/org.eclipse.cdt.repo/category.xml @@ -216,6 +216,8 @@ + + diff --git a/releng/org.eclipse.cdt.target/cdt.target b/releng/org.eclipse.cdt.target/cdt.target index 9821492d2d8..bf6c0550055 100644 --- a/releng/org.eclipse.cdt.target/cdt.target +++ b/releng/org.eclipse.cdt.target/cdt.target @@ -1,6 +1,6 @@ - + @@ -74,6 +74,8 @@ + +