Bug 568079: Reducing transitions from JAVA to native code (part 1)

Advapi32Util.registryGetValues() is more efficient to fetch all the
values since the regiter only needs to be opened once.

XXX: Due to a cycle in the dependencies we need to split this
in two parts, this commit handles the core.native API change
and the next commit handles the use of the new API

Change-Id: Ifd9f1ccc44c652ef3b517278bd342a486155c5fb
Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
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 07649b9..14341ae 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 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.cdt.core.native;singleton:=true
-Bundle-Version: 6.0.100.qualifier
+Bundle-Version: 6.1.0.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 0bee5d6..93d4098 100644
--- a/core/org.eclipse.cdt.core.native/pom.xml
+++ b/core/org.eclipse.cdt.core.native/pom.xml
@@ -23,7 +23,7 @@
     <relativePath>../../pom.xml</relativePath>
   </parent>
 
-  <version>6.0.100-SNAPSHOT</version>
+  <version>6.1.0-SNAPSHOT</version>
   <artifactId>org.eclipse.cdt.core.native</artifactId>
   <packaging>eclipse-plugin</packaging>
 
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 f205451..c35b672 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
@@ -13,6 +13,8 @@
  *******************************************************************************/
 package org.eclipse.cdt.utils;
 
+import java.util.Map;
+
 import org.eclipse.cdt.internal.core.natives.CNativePlugin;
 import org.eclipse.core.runtime.CoreException;
 
@@ -52,6 +54,15 @@
 	public abstract String getLocalMachineValue(String subkey, String name);
 
 	/**
+	 * Given a subkey of HKEY_LOCAL_MACHINE, return the map of valueName => value.
+	 * The return value is an empty map on error or when the subkey does not exist.
+	 * @param subkey subkey of HKEY_LOCAL_MACHINE
+	 * @return valueName => value map of the entries in subkey
+	 * @since 6.1
+	 */
+	public abstract Map<String, Object> getLocalMachineValues(String subkey);
+
+	/**
 	 * Given a subkey of HKEY_LOCAL_MACHINE, and an index (starting from 0)
 	 * to the key's array of values, return the name of the indexed value.
 	 * The return value is null on any error or when the index is invalid.
@@ -69,7 +80,7 @@
 	 * The return value is null on any error or when the index is invalid.
 	 * The key name can be used in the above getLocalMachineValueName()
 	 * to retrieve value names.
-	 * @param subkey   subkey of HKEY_CURRENT_USER
+	 * @param subkey   subkey of HKEY_LOCAL_MACHINE
 	 * @param index    index to the subkey's array of values, starting from 0.
 	 * @return name of registry value or null if not found
 	 */
@@ -86,6 +97,15 @@
 	public abstract String getCurrentUserValue(String subkey, String name);
 
 	/**
+	 * Given a subkey of HKEY_CURRENT_USER, return the map of valueName => value.
+	 * The return value is an empty map on error or when the subkey does not exist.
+	 * @param subkey subkey of HKEY_CURRENT_USER
+	 * @return valueName => value map of the entries in subkey
+	 * @since 6.1
+	 */
+	public abstract Map<String, Object> getCurrentUserValues(String subkey);
+
+	/**
 	 * Given a subkey of HKEY_CURRENT_USER, and an index (starting from 0)
 	 * to the key's array of values, return the name of the indexed value.
 	 * The return value is null on any error or when the index is invalid.
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 17c5c1c..7abccf9 100644
--- a/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %fragmentName.win32
 Bundle-SymbolicName: org.eclipse.cdt.core.win32; singleton:=true
-Bundle-Version: 6.0.0.qualifier
+Bundle-Version: 6.0.100.qualifier
 Bundle-Vendor: %providerName
-Fragment-Host: org.eclipse.cdt.core.native;bundle-version="[6.0.0,7.0.0)"
+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)
diff --git a/core/org.eclipse.cdt.core.win32/pom.xml b/core/org.eclipse.cdt.core.win32/pom.xml
index 3c63574..4de5713 100644
--- a/core/org.eclipse.cdt.core.win32/pom.xml
+++ b/core/org.eclipse.cdt.core.win32/pom.xml
@@ -11,7 +11,7 @@
 		<relativePath>../../pom.xml</relativePath>
 	</parent>
 
-	<version>6.0.0-SNAPSHOT</version>
+	<version>6.0.100-SNAPSHOT</version>
 	<artifactId>org.eclipse.cdt.core.win32</artifactId>
 	<packaging>eclipse-plugin</packaging>
 
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 0327dbf..42b0431 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
@@ -13,6 +13,9 @@
  *******************************************************************************/
 package org.eclipse.cdt.internal.core.win32;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.eclipse.cdt.internal.core.natives.CNativePlugin;
 import org.eclipse.cdt.utils.WindowsRegistry;
 import org.eclipse.core.runtime.Platform;
@@ -42,6 +45,11 @@
 	}
 
 	@Override
+	public Map<String, Object> getLocalMachineValues(String subkey) {
+		return getValues(WinReg.HKEY_LOCAL_MACHINE, subkey);
+	}
+
+	@Override
 	public String getLocalMachineValueName(String subkey, int index) {
 		return getValueName(WinReg.HKEY_LOCAL_MACHINE, subkey, index);
 	}
@@ -57,6 +65,11 @@
 	}
 
 	@Override
+	public Map<String, Object> getCurrentUserValues(String subkey) {
+		return getValues(WinReg.HKEY_CURRENT_USER, subkey);
+	}
+
+	@Override
 	public String getCurrentUserValueName(String subkey, int index) {
 		return getValueName(WinReg.HKEY_CURRENT_USER, subkey, index);
 	}
@@ -118,4 +131,15 @@
 			return null;
 		}
 	}
+
+	private Map<String, Object> getValues(HKEY key, String subkey) {
+		try {
+			return Advapi32Util.registryGetValues(key, subkey);
+		} catch (Win32Exception e) {
+			if (DEBUG) {
+				CNativePlugin.log(String.format("Unable to get values for %s", subkey), e); //$NON-NLS-1$
+			}
+			return Collections.emptyMap();
+		}
+	}
 }