<commit_before>﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Worker.Common
{
    public class JavaManager : SoftwareManager
    {
        public const string JAVA_HOME = "JAVA_HOME";
        public const string JAVA_REGISTRY_PATH = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
        public const string INSTALL_LOG_FILE = "jdk.txt";

        public JavaManager(WebArtifact artifact, string archiveRoot, string  logRoot )
            :base(artifact,archiveRoot,logRoot)
        {
           
        }

        public override Task EnsureConfigured()
        {
            return Task.Factory.StartNew(() =>
            {
                //if no binary then java is definitely not installed
                DownloadIfNotExists();

                //If java registry keys are not set run the installer
                InstallIfNeeded();

                //Java home is not confugerd so lets do that
                SetJavaHomeIfNeeded();

            });
        


         
            
        }

        protected virtual bool JavaHomeConfigured()
        {
            var javaHome = Environment.GetEnvironmentVariable(JAVA_HOME, EnvironmentVariableTarget.Machine);
            var configured = !string.IsNullOrWhiteSpace(javaHome);
            return configured;
        }

        protected virtual string JavaVersion()
        {
            var value = (string)Registry.GetValue(JAVA_REGISTRY_PATH,"CurrentVersion",string.Empty);
            return value;
        }

        protected virtual void InstallIfNeeded()
        {
            if (string.IsNullOrWhiteSpace(JavaVersion()))
            {
                var installLog = Path.Combine(_logRoot, INSTALL_LOG_FILE);
                var pi = new ProcessStartInfo(_binaryArchive)
                {
                    Arguments = " /s /L " + installLog,
                    UseShellExecute = true,
                    RedirectStandardError = true,
                    Verb = "runas"
                };

                Trace.TraceInformation("Java not installed. Starting installer");
                var installer = Process.Start(pi);
                var error = installer.StandardError.ReadToEnd();
                installer.WaitForExit();
<commit_msg>Disable UseShellExecute<commit_after>﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Worker.Common
{
    public class JavaManager : SoftwareManager
    {
        public const string JAVA_HOME = "JAVA_HOME";
        public const string JAVA_REGISTRY_PATH = "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment";
        public const string INSTALL_LOG_FILE = "jdk.txt";

        public JavaManager(WebArtifact artifact, string archiveRoot, string  logRoot )
            :base(artifact,archiveRoot,logRoot)
        {
           
        }

        public override Task EnsureConfigured()
        {
            return Task.Factory.StartNew(() =>
            {
                //if no binary then java is definitely not installed
                DownloadIfNotExists();

                //If java registry keys are not set run the installer
                InstallIfNeeded();

                //Java home is not confugerd so lets do that
                SetJavaHomeIfNeeded();

            });
        


         
            
        }

        protected virtual bool JavaHomeConfigured()
        {
            var javaHome = Environment.GetEnvironmentVariable(JAVA_HOME, EnvironmentVariableTarget.Machine);
            var configured = !string.IsNullOrWhiteSpace(javaHome);
            return configured;
        }

        protected virtual string JavaVersion()
        {
            var value = (string)Registry.GetValue(JAVA_REGISTRY_PATH,"CurrentVersion",string.Empty);
            return value;
        }

        protected virtual void InstallIfNeeded()
        {
            if (string.IsNullOrWhiteSpace(JavaVersion()))
            {
                var installLog = Path.Combine(_logRoot, INSTALL_LOG_FILE);
                var pi = new ProcessStartInfo(_binaryArchive)
                {
                    Arguments = " /s /L " + installLog,
                    RedirectStandardError = true,
                    Verb = "runas"
                };

                Trace.TraceInformation("Java not installed. Starting installer");
                var installer = Process.Start(pi);
                var error = installer.StandardError.ReadToEnd();
                installer.WaitForExit();

{'fraction_non_alphanumeric': 0.07542478242851222, 'fraction_numerical': 0.0008288437629506838, 'mean_word_length': 1.837742504409171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2856922', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1147, 'n_words': 291}