<commit_before>'use strict';

let path = require('path');
let fs = require('fs-extra');
var rimraf = require('rimraf');

import JbosseapAutoInstallGenerator from './jbosseap-autoinstall';
import InstallableItem from './installable-item';
import Installer from './helpers/installer';
import Logger from '../services/logger';
import JdkInstall from './jdk-install';

class JbosseapInstall extends InstallableItem {
  constructor(installerDataSvc, targetFolderName, downloadUrl, fileName, sha256sum) {
    super(JbosseapInstall.KEY, downloadUrl, fileName, targetFolderName, installerDataSvc, true);
    this.sha256 = sha256sum;
    this.installConfigFile = path.join(this.installerDataSvc.tempDir(), 'jbosseap-autoinstall.xml');
    this.configFile = path.join(this.installerDataSvc.tempDir(), 'jbosseap-autoinstall.xml.variables');
    this.addOption('install', this.version, '', true);
  }

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

  installAfterRequirements(progress, success, failure) {
    progress.setStatus('Installing');
    let version = /(\d+\.\d+\.\d+).*/.exec(this.version)[1];
    this.installGenerator = new JbosseapAutoInstallGenerator(this.installerDataSvc.jbosseapDir(), this.installerDataSvc.jdkDir(), version);
    let installer = new Installer(this.keyName, progress, success, failure);

    if(fs.existsSync(this.installerDataSvc.jbosseapDir())) {
      rimraf.sync(this.installerDataSvc.jbosseapDir());
    }

    Logger.info(this.keyName + ' - Generate jbosseap auto install file content');
    let data = this.installGenerator.fileContent();
    Logger.info(JbosseapInstall.KEY + ' - Generate jbosseap auto install file content SUCCESS');
    return Promise.resolve().then(()=> {
      return installer.writeFile(this.installConfigFile, data);
    }).then((result) => {
      return this.postJDKInstall(installer, result);
    }).then(() => {
      let devstudio = this.installerDataSvc.getInstallable('devstudio');
      if(devstudio.installed) {
        this.configureRuntimeDetection();
      } else {
        let that = this;
        this.ipcRenderer.on('installComplete', function(event, arg) {
          if(arg == 'devstudio') {
            that.configureRuntimeDetection();
          }
        });
      }
      installer.succeed(true);
    }).catch((error) => {
      installer.fail(error);
    });
  }

  configureRuntimeDetection() {
    let runtimeproperties = path.join(this.installerDataSvc.devstudioDir(), 'studio', 'runtime_locations.properties');
    let escapedLocation = this.installerDataSvc.jbosseapDir().replace(/\\/g, '\\\\').replace(/\:/g, '\\:');
    if(fs.existsSync(runtimeproperties)) {
      fs.appendFile(runtimeproperties, `\njbosseap=${escapedLocation},true`).catch((error)=>{
        Logger.error(this.keyName + ' - error occured during runtime detection configuration in DevStudio');
        Logger.error(this.keyName + ` -  ${error}`);
      });
    }
  }

  postJDKInstall(installer, result) {
    return new Promise((resolve, reject) => {
      let jdkInstall = this.installerDataSvc.getInstallable(JdkInstall.KEY);

      if (jdkInstall.isInstalled()) {<commit_msg>JBDS-4430 EAP is not added to runtime locations<commit_after>'use strict';

let path = require('path');
let fs = require('fs-extra');
var rimraf = require('rimraf');

import JbosseapAutoInstallGenerator from './jbosseap-autoinstall';
import InstallableItem from './installable-item';
import Installer from './helpers/installer';
import Logger from '../services/logger';
import Platform from '../services/platform'
import JdkInstall from './jdk-install';

class JbosseapInstall extends InstallableItem {
  constructor(installerDataSvc, targetFolderName, downloadUrl, fileName, sha256sum) {
    super(JbosseapInstall.KEY, downloadUrl, fileName, targetFolderName, installerDataSvc, true);
    this.sha256 = sha256sum;
    this.installConfigFile = path.join(this.installerDataSvc.tempDir(), 'jbosseap-autoinstall.xml');
    this.configFile = path.join(this.installerDataSvc.tempDir(), 'jbosseap-autoinstall.xml.variables');
    this.addOption('install', this.version, '', true);
  }

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

  installAfterRequirements(progress, success, failure) {
    progress.setStatus('Installing');
    let version = /(\d+\.\d+\.\d+).*/.exec(this.version)[1];
    this.installGenerator = new JbosseapAutoInstallGenerator(this.installerDataSvc.jbosseapDir(), this.installerDataSvc.jdkDir(), version);
    let installer = new Installer(this.keyName, progress, success, failure);

    if(fs.existsSync(this.installerDataSvc.jbosseapDir())) {
      rimraf.sync(this.installerDataSvc.jbosseapDir());
    }

    Logger.info(this.keyName + ' - Generate jbosseap auto install file content');
    let data = this.installGenerator.fileContent();
    Logger.info(JbosseapInstall.KEY + ' - Generate jbosseap auto install file content SUCCESS');
    return Promise.resolve().then(()=> {
      return installer.writeFile(this.installConfigFile, data);
    }).then((result) => {
      return this.postJDKInstall(installer, result);
    }).then(() => {
      let devstudio = this.installerDataSvc.getInstallable('devstudio');
      if(devstudio.installed) {
        this.configureRuntimeDetection();
      } else {
        let that = this;
        this.ipcRenderer.on('installComplete', function(event, arg) {
          if(arg == 'devstudio') {
            that.configureRuntimeDetection();
          }
        });
      }
      installer.succeed(true);
    }).catch((error) => {
      installer.fail(error);
    });
  }

  configureRuntimeDetection() {
    let runtimeproperties =  Platform.OS === 'win32' ? path.join(this.installerDataSvc.devstudioDir(), 'studio', 'runtime_locations.properties') : path.join(this.installerDataSvc.devstudioDir(), 'studio/devstudio.app/Contents/Eclipse', 'runtime_locations.properties');
    let escapedLocation = this.installerDataSvc.jbosseapDir().replace(/\\/g, '\\\\').replace(/\:/g, '\\:');
    if(fs.existsSync(runtimeproperties)) {
      fs.appendFile(runtimeproperties, `\njbosseap=${escapedLocation},true`).catch((error)=>{
        Logger.error(this.keyName + ' - error occured during runtime detection configuration in DevStudio');
        Logger.error(this.keyName + ` -  ${error}`);
      });
    }
  }

  postJDKInstall(installer, result) {
    return new Promise((resolve, reject) => {
      let jdkInstall = this.installerDataSvc.getInstallable(JdkInstall.KEY);

      if (jdkInstall.isInstalled()) {
{'fraction_non_alphanumeric': 0.14714946070878274, 'fraction_numerical': 0.004006163328197226, 'mean_word_length': 3.98923904688701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3710860', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1957, 'n_words': 344}