示例#1
0
        public static string GetJvmLibraryPath()
        {
            var jdkDir = ReadJavaSdkDirectoryFromJdkInfoProps();

            if (jdkDir != null)
            {
                return(jdkDir);
            }
            var jdk = JdkInfo.GetKnownSystemJdkInfos()
                      .FirstOrDefault();

            return(jdk?.JdkJvmPath);
        }
示例#2
0
        public static JdkInfo GetJdkInfo(Action <TraceLevel, string> logger, string javaSdkPath, Version minSupportedVersion, Version maxSupportedVersion)
        {
            JdkInfo info = null;

            try {
                info = new JdkInfo(javaSdkPath);
            } catch {
                info = JdkInfo.GetKnownSystemJdkInfos(logger)
                       .Where(jdk => jdk.Version >= minSupportedVersion && jdk.Version <= maxSupportedVersion)
                       .FirstOrDefault();
            }
            return(info);
        }
        public void GetKnownSystemJdkInfos_PrefersJiJavaHome()
        {
            var previous = Environment.GetEnvironmentVariable("JI_JAVA_HOME", EnvironmentVariableTarget.Process);

            try {
                Environment.SetEnvironmentVariable("JI_JAVA_HOME", FauxJdkDir, EnvironmentVariableTarget.Process);

                var defaultJdkDir = JdkInfo.GetKnownSystemJdkInfos()
                                    .FirstOrDefault();
                Assert.IsNotNull(defaultJdkDir);
                Assert.AreEqual(FauxJdkDir, defaultJdkDir.HomePath);
            }
            finally {
                Environment.SetEnvironmentVariable("JI_JAVA_HOME", previous, EnvironmentVariableTarget.Process);
            }
        }
        string GetJvmPath()
        {
            // NOTE: this doesn't need to use GetRegisteredTaskObjectAssemblyLocal()
            // because JavaSdkPath is the key and the value is a string.
            var key    = new Tuple <string, string> (nameof(ResolveJdkJvmPath), JavaSdkPath);
            var cached = BuildEngine4.GetRegisteredTaskObject(key, RegisteredTaskObjectLifetime.AppDomain) as string;

            if (cached != null)
            {
                Log.LogDebugMessage($"Using cached value for {nameof (JdkJvmPath)}: {cached}");

                return(cached);
            }

            JdkInfo info = null;

            try {
                info = new JdkInfo(JavaSdkPath);
            } catch {
                info = JdkInfo.GetKnownSystemJdkInfos(this.CreateTaskLogger()).FirstOrDefault();
            }

            if (info == null)
            {
                return(null);
            }

            var path = info.JdkJvmPath;

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            BuildEngine4.RegisterTaskObject(key, path, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false);

            return(path);
        }