Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E21FE19D1E for ; Fri, 25 Mar 2016 08:23:30 +0000 (UTC) Received: (qmail 10345 invoked by uid 500); 25 Mar 2016 08:23:30 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 10265 invoked by uid 500); 25 Mar 2016 08:23:30 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 10126 invoked by uid 99); 25 Mar 2016 08:23:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Mar 2016 08:23:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5D21CE38E3; Fri, 25 Mar 2016 08:23:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ntikhonov@apache.org To: commits@ignite.apache.org Date: Fri, 25 Mar 2016 08:23:32 -0000 Message-Id: <7dbbc2608f3e4701a45bd874b3632eec@git.apache.org> In-Reply-To: <382c44106cc349e28c42c9af1fe716aa@git.apache.org> References: <382c44106cc349e28c42c9af1fe716aa@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/11] 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-11048 Commit: afe453ff6d219134685f5e5b8224156e8d6673b9 Parents: 7b63eee Author: Pavel Tupitsyn Authored: Thu Mar 24 16:57:55 2016 +0300 Committer: vozerov-gridgain 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 @@ + 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; + + /// + /// Tests the JAVA_HOME detection. + /// + public class JavaHomeTest + { + /** Environment variable: JAVA_HOME. */ + private const string EnvJavaHome = "JAVA_HOME"; + + /** Backed up value. */ + private string _javaHomeBackup; + + /// + /// Fixture set up. + /// + [TestFixtureSetUp] + public void FixtureSetUp() + { + _javaHomeBackup = Environment.GetEnvironmentVariable(EnvJavaHome); + + Environment.SetEnvironmentVariable(EnvJavaHome, null); + } + + /// + /// Fixture tear down. + /// + [TestFixtureTearDown] + public void FixtureTearDown() + { + Environment.SetEnvironmentVariable(EnvJavaHome, _javaHomeBackup); + } + + /// + /// Tests the detection. + /// + [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; /// @@ -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(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(verKey.Name, dllPath); + } + } + } + } } ///