You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/03/28 08:34:00 UTC
[04/16] ignite git commit: IGNITE-2866 .NET: Added automatic
JAVA_HOME detection. This closes #577.
IGNITE-2866 .NET: Added automatic JAVA_HOME detection. This closes #577.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/afe453ff
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/afe453ff
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/afe453ff
Branch: refs/heads/ignite-gg-10994
Commit: afe453ff6d219134685f5e5b8224156e8d6673b9
Parents: 7b63eee
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Thu Mar 24 16:57:55 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Mar 24 16:57:55 2016 +0300
----------------------------------------------------------------------
.../Apache.Ignite.Core.Tests.csproj | 1 +
.../Apache.Ignite.Core.Tests/JavaHomeTest.cs | 69 ++++++++++++++++++++
.../Apache.Ignite.Core/Impl/IgniteUtils.cs | 34 ++++++++++
3 files changed, 104 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/afe453ff/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 0dcd1f0..fedbd63 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -130,6 +130,7 @@
<Compile Include="IgniteConfigurationSerializerTest.cs" />
<Compile Include="IgniteConfigurationTest.cs" />
<Compile Include="IgniteTestBase.cs" />
+ <Compile Include="JavaHomeTest.cs" />
<Compile Include="LifecycleTest.cs" />
<Compile Include="LoadDllTest.cs" />
<Compile Include="IgniteManagerTest.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/afe453ff/modules/platforms/dotnet/Apache.Ignite.Core.Tests/JavaHomeTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/JavaHomeTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/JavaHomeTest.cs
new file mode 100644
index 0000000..b229557
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/JavaHomeTest.cs
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Tests
+{
+ using System;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests the JAVA_HOME detection.
+ /// </summary>
+ public class JavaHomeTest
+ {
+ /** Environment variable: JAVA_HOME. */
+ private const string EnvJavaHome = "JAVA_HOME";
+
+ /** Backed up value. */
+ private string _javaHomeBackup;
+
+ /// <summary>
+ /// Fixture set up.
+ /// </summary>
+ [TestFixtureSetUp]
+ public void FixtureSetUp()
+ {
+ _javaHomeBackup = Environment.GetEnvironmentVariable(EnvJavaHome);
+
+ Environment.SetEnvironmentVariable(EnvJavaHome, null);
+ }
+
+ /// <summary>
+ /// Fixture tear down.
+ /// </summary>
+ [TestFixtureTearDown]
+ public void FixtureTearDown()
+ {
+ Environment.SetEnvironmentVariable(EnvJavaHome, _javaHomeBackup);
+ }
+
+ /// <summary>
+ /// Tests the detection.
+ /// </summary>
+ [Test]
+ public void TestDetection([Values(null, "c:\\invalid111")] string javaHome)
+ {
+ Environment.SetEnvironmentVariable(EnvJavaHome, javaHome);
+
+ using (var ignite = Ignition.Start(TestUtils.GetTestConfiguration()))
+ {
+ Assert.IsNotNull(ignite);
+ Console.WriteLine("Detected JVM dll path: " + ignite.GetConfiguration().JvmDllPath);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/afe453ff/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
index 3206fc8..7f6fab8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -33,6 +33,7 @@ namespace Apache.Ignite.Core.Impl
using Apache.Ignite.Core.Impl.Cluster;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Unmanaged;
+ using Microsoft.Win32;
using BinaryReader = Apache.Ignite.Core.Impl.Binary.BinaryReader;
/// <summary>
@@ -46,6 +47,13 @@ namespace Apache.Ignite.Core.Impl
/** Lookup paths. */
private static readonly string[] JvmDllLookupPaths = {@"jre\bin\server", @"jre\bin\default"};
+ /** Registry lookup paths. */
+ private static readonly string[] JreRegistryKeys =
+ {
+ @"Software\JavaSoft\Java Runtime Environment",
+ @"Software\Wow6432Node\JavaSoft\Java Runtime Environment"
+ };
+
/** File: jvm.dll. */
internal const string FileJvmDll = "jvm.dll";
@@ -256,6 +264,32 @@ namespace Apache.Ignite.Core.Impl
foreach (var path in JvmDllLookupPaths)
yield return
new KeyValuePair<string, string>(EnvJavaHome, Path.Combine(javaHomeDir, path, FileJvmDll));
+
+ // Get paths from the Windows Registry
+ foreach (var regPath in JreRegistryKeys)
+ {
+ using (var jSubKey = Registry.LocalMachine.OpenSubKey(regPath))
+ {
+ if (jSubKey == null)
+ continue;
+
+ var curVer = jSubKey.GetValue("CurrentVersion") as string;
+
+ // Current version comes first
+ var versions = new[] {curVer}.Concat(jSubKey.GetSubKeyNames().Where(x => x != curVer));
+
+ foreach (var ver in versions)
+ {
+ using (var verKey = jSubKey.OpenSubKey(ver))
+ {
+ var dllPath = verKey == null ? null : verKey.GetValue("RuntimeLib") as string;
+
+ if (dllPath != null)
+ yield return new KeyValuePair<string, string>(verKey.Name, dllPath);
+ }
+ }
+ }
+ }
}
/// <summary>