<commit_before>/**
 * BMotion Studio for ProB Standalone Module
 *
 */
define(['socketio', 'angularAMD', 'bms.func', 'angular', 'prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common', 'prob.modal', 'angular-route'], function (io, angularAMD, bms) {

    var module = angular.module('prob.standalone', ['prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common', 'prob.modal', 'ngRoute'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider
                .when('/loading', {
                    template: '<div ng-controller="bmsLoadingModalCtrl"></div>',
                    controller: 'loadingController'
                })
                .when('/', {
                    templateUrl: 'bmsUi.html',
                    controller: 'readyController'
                });
        }])
        .run(['editableOptions', 'bmsMainService', function (editableOptions, bmsMainService) {
            bmsMainService.mode = 'ModeStandalone';
            editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
        }])
        .controller('loadingController', ['$scope', 'bmsModalService', '$location', 'bmsSocketService', '$q', 'bmsConfigService', function ($scope, bmsModalService, $location, bmsSocketService, $q, bmsConfigService) {

            //Window.showDevTools('', false);

            var checkIfConnectionExists = function () {

                var defer = $q.defer();

                bmsSocketService.socket().then(function (socket) {
                    var n = 0;
                    var connectedInterval = setInterval(function () {
                        if (socket.connected) {
                            clearInterval(connectedInterval);
                            defer.resolve(true);
                        }
                        if (n === 5) {
                            clearInterval(connectedInterval);
                            defer.resolve(false);
                        }
                        n++;
                    }, 1000);
                });

                return defer.promise;

            };

            var startServer = function (connected) {
                var defer = $q.defer();
                if (!connected) {
                    var spawn = require('child_process').spawn;
                    var server = spawn('java', ['-Xmx1024m', '-cp', './libs/libs/*:./libs/bmotion-prob-standalone.jar', "-Dprob.home=./cli/", 'Start', '-standalone', '-local']);
                    server.stdout.on('data', function (data) {
                        try {
                            var json = JSON.parse(data.toString('utf8'));
                            if (json) defer.resolve(json);
                        } catch (e) {
                            console.log(data.toString('utf8'));
                        }
                    });
                    server.on('close', function (code) {
                        console.log('BMotion Studio for ProB Server process exited with code ' + code);
                    });
                } else {
                    defer.resolve();
                }
                return defer.promise;
            };

            var updateConfig = function (obj) {
                var defer = $q.defer();
                bmsConfigService.getConfig().then(function (config) {
                    if (obj) {
                        config.socket.host = obj.host;<commit_msg>try catch spawn<commit_after>/**
 * BMotion Studio for ProB Standalone Module
 *
 */
define(['socketio', 'angularAMD', 'bms.func', 'angular', 'prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common', 'prob.modal', 'angular-route'], function (io, angularAMD, bms) {

    var module = angular.module('prob.standalone', ['prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common', 'prob.modal', 'ngRoute'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider
                .when('/loading', {
                    template: '<div ng-controller="bmsLoadingModalCtrl"></div>',
                    controller: 'loadingController'
                })
                .when('/', {
                    templateUrl: 'bmsUi.html',
                    controller: 'readyController'
                });
        }])
        .run(['editableOptions', 'bmsMainService', function (editableOptions, bmsMainService) {
            bmsMainService.mode = 'ModeStandalone';
            editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
        }])
        .controller('loadingController', ['$scope', 'bmsModalService', '$location', 'bmsSocketService', '$q', 'bmsConfigService', function ($scope, bmsModalService, $location, bmsSocketService, $q, bmsConfigService) {

            //Window.showDevTools('', false);

            var checkIfConnectionExists = function () {

                var defer = $q.defer();

                bmsSocketService.socket().then(function (socket) {
                    var n = 0;
                    var connectedInterval = setInterval(function () {
                        if (socket.connected) {
                            clearInterval(connectedInterval);
                            defer.resolve(true);
                        }
                        if (n === 5) {
                            clearInterval(connectedInterval);
                            defer.resolve(false);
                        }
                        n++;
                    }, 1000);
                });

                return defer.promise;

            };

            var startServer = function (connected) {
                var defer = $q.defer();
                if (!connected) {

                    try {
                        var spawn = require('child_process').spawn;
                        var server = spawn('java', ['-Xmx1024m', '-cp', './libs/libs/*:./libs/bmotion-prob-standalone.jar', "-Dprob.home=./cli/", 'Start', '-standalone', '-local']);
                        server.stdout.on('data', function (data) {
                            try {
                                var json = JSON.parse(data.toString('utf8'));
                                if (json) defer.resolve(json);
                            } catch (e) {
                                console.log(data.toString('utf8'));
                            }
                        });
                        server.on('close', function (code) {
                            console.log('BMotion Studio for ProB Server process exited with code ' + code);
                        });
                    } catch (err) {
                        console.log("Error while trying to start child process: " + JSON.stringify(err));
                    }

                } else {
                    defer.resolve();
                }
                return defer.promise;
            };

            var updateConfig = function (obj) {
                var defer = $q.defer();
                bmsConfigService.getConfig().then(function (config) {
                    if (obj) {
                        config.socket.host = obj.host;
{'fraction_non_alphanumeric': 0.13360380526021265, 'fraction_numerical': 0.004196978175713486, 'mean_word_length': 1.33322454308094, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '781108', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1662, 'n_words': 354}