<commit_before>'use strict';

import path from 'path';
import Logger from '../services/logger';
import InstallableItem from './installable-item';
import Platform from '../services/platform';
import Installer from './helpers/installer';
import globby from 'globby';
import fs from 'fs-extra';
import pify from 'pify';

class CDKInstall extends InstallableItem {
  constructor(installerDataSvc, targetFolderName, minishiftUrl, fileName, minishiftSha256) {
    super(CDKInstall.KEY, minishiftUrl, fileName, targetFolderName, installerDataSvc, true);

    this.sha256 = minishiftSha256;
    this.addOption('install', this.version, '', true);
    this.selected = false;
  }

  static get KEY() {
    return 'cdk';
  }

  get minishiftExeLocation() {
    return path.join(this.installerDataSvc.ocDir(), Platform.OS === 'win32' ? 'minishift.exe' : 'minishift');
  }

  installAfterRequirements(progress, success, failure) {
    progress.setStatus('Installing');
    let minishiftExe = this.minishiftExeLocation;
    let installer = new Installer(CDKInstall.KEY, progress, success, failure);
    let ocExe;
    let ocExePattern = Platform.OS === 'win32' ? '/**/oc.exe' : '/**/oc';
    let home;
    let driverName = 'virtualbox';
    return Promise.resolve().then(()=> {
      if(this.downloadedFile.endsWith('.exe') || path.parse(this.downloadedFile).ext == '') {
        return installer.copyFile(this.downloadedFile, minishiftExe);
      }
      return Promise.reject('Cannot process downloaded cdk distribution');
    }).then(()=> {
      return Platform.makeFileExecutable(minishiftExe);
    }).then(()=> {
      let hv = this.installerDataSvc.getInstallable('hyperv');
      if (hv && hv.hasOption('detected')) {
        driverName = 'hyperv';
        return installer.exec(
          'net localgroup "Hyper-V Administrators" %USERDOMAIN%\\%USERNAME% /add'
        ).catch(()=>Promise.resolve());
      }
      return Promise.resolve();
    }).then(()=> {
      return installer.exec(
        `${minishiftExe} stop`
      ).catch(()=>Promise.resolve());
    }).then(()=> {
      return installer.exec(`${minishiftExe} setup-cdk --force --default-vm-driver=${driverName}`, this.createEnvironment());
    }).then(()=> {
      return Platform.getUserHomePath();
    }).then((result)=> {
      home = Platform.ENV.MINISHIFT_HOME ? Platform.ENV.MINISHIFT_HOME : path.join(result, '.minishift');
      return globby(ocExePattern, {root: path.join(home, 'cache', 'oc')});
    }).then((files)=> {
      ocExe = files[0].replace(/\//g, path.sep);
      return Promise.resolve();
    }).then(()=> {
      return Platform.makeFileExecutable(ocExe);
    }).then(()=> {
      return Platform.addToUserPath([ocExe, minishiftExe]);
    }).then(()=> {
      return pify(fs.appendFile)(
        path.join(home, 'cdk'),
        `rhel.subscription.username=${this.installerDataSvc.username}`);
    }).then(()=> {
      installer.succeed(true);
    }).catch((error)=> {
      installer.fail(error);
    });
  }

  createEnvironment() {
    let vboxInstall = this.installerDataSvc.getInstallable('virtualbox');
    let cygwinInstall = this.installerDataSvc.getInstallable('cygwin');
    let env = Object.assign({}, Platform.ENV);
    let newPath = [];
    let oldPath = Platform.ENV[Platform.PATH];

    newPath.push(vboxInstall.getLocation());

    if(cygwinInstall) {
      newPath.push(cygwinInstall.getLocation());
    }

    if(oldPath.trim()) {
      newPath.push(oldPath);
    }

    env[Platform.PATH] = newPath.join(path.delimiter);
    Logger.info(CDKInstall.KEY + ' - Set PATH environment variable to \'' + env[Platform.PATH] + '\'');
    return env;
  }

}

export default CDKInstall;
<commit_msg>JBDS-4453 Skip adding vbox to path when using hyper-v<commit_after>'use strict';

import path from 'path';
import Logger from '../services/logger';
import InstallableItem from './installable-item';
import Platform from '../services/platform';
import Installer from './helpers/installer';
import globby from 'globby';
import fs from 'fs-extra';
import pify from 'pify';

class CDKInstall extends InstallableItem {
  constructor(installerDataSvc, targetFolderName, minishiftUrl, fileName, minishiftSha256) {
    super(CDKInstall.KEY, minishiftUrl, fileName, targetFolderName, installerDataSvc, true);

    this.sha256 = minishiftSha256;
    this.addOption('install', this.version, '', true);
    this.selected = false;
  }

  static get KEY() {
    return 'cdk';
  }

  get minishiftExeLocation() {
    return path.join(this.installerDataSvc.ocDir(), Platform.OS === 'win32' ? 'minishift.exe' : 'minishift');
  }

  installAfterRequirements(progress, success, failure) {
    progress.setStatus('Installing');
    let minishiftExe = this.minishiftExeLocation;
    let installer = new Installer(CDKInstall.KEY, progress, success, failure);
    let ocExe;
    let ocExePattern = Platform.OS === 'win32' ? '/**/oc.exe' : '/**/oc';
    let home;
    let driverName = 'virtualbox';
    return Promise.resolve().then(()=> {
      if(this.downloadedFile.endsWith('.exe') || path.parse(this.downloadedFile).ext == '') {
        return installer.copyFile(this.downloadedFile, minishiftExe);
      }
      return Promise.reject('Cannot process downloaded cdk distribution');
    }).then(()=> {
      return Platform.makeFileExecutable(minishiftExe);
    }).then(()=> {
      let hv = this.installerDataSvc.getInstallable('hyperv');
      if (hv && hv.hasOption('detected')) {
        driverName = 'hyperv';
        return installer.exec(
          'net localgroup "Hyper-V Administrators" %USERDOMAIN%\\%USERNAME% /add'
        ).catch(()=>Promise.resolve());
      }
      return Promise.resolve();
    }).then(()=> {
      return installer.exec(
        `${minishiftExe} stop`
      ).catch(()=>Promise.resolve());
    }).then(()=> {
      return installer.exec(`${minishiftExe} setup-cdk --force --default-vm-driver=${driverName}`, this.createEnvironment());
    }).then(()=> {
      return Platform.getUserHomePath();
    }).then((result)=> {
      home = Platform.ENV.MINISHIFT_HOME ? Platform.ENV.MINISHIFT_HOME : path.join(result, '.minishift');
      return globby(ocExePattern, {root: path.join(home, 'cache', 'oc')});
    }).then((files)=> {
      ocExe = files[0].replace(/\//g, path.sep);
      return Promise.resolve();
    }).then(()=> {
      return Platform.makeFileExecutable(ocExe);
    }).then(()=> {
      return Platform.addToUserPath([ocExe, minishiftExe]);
    }).then(()=> {
      return pify(fs.appendFile)(
        path.join(home, 'cdk'),
        `rhel.subscription.username=${this.installerDataSvc.username}`);
    }).then(()=> {
      installer.succeed(true);
    }).catch((error)=> {
      installer.fail(error);
    });
  }

  createEnvironment() {
    let vboxInstall = this.installerDataSvc.getInstallable('virtualbox');
    let cygwinInstall = this.installerDataSvc.getInstallable('cygwin');
    let env = Object.assign({}, Platform.ENV);
    let newPath = [];
    let oldPath = Platform.ENV[Platform.PATH];

    if(vboxInstall) {
      newPath.push(vboxInstall.getLocation());
    }

    if(cygwinInstall) {
      newPath.push(cygwinInstall.getLocation());
    }

    if(oldPath.trim()) {
      newPath.push(oldPath);
    }

    env[Platform.PATH] = newPath.join(path.delimiter);
    Logger.info(CDKInstall.KEY + ' - Set PATH environment variable to \'' + env[Platform.PATH] + '\'');
    return env;
  }

}

export default CDKInstall;

{'fraction_non_alphanumeric': 0.16608438591776403, 'fraction_numerical': 0.00429991937651169, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263394', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2343, 'n_words': 445}