<commit_before>/* jshint node:true */
/*
 * grunt-teamcity
 *
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

// Nodejs libs.
var util = require('util');

module.exports = function(grunt) {

  grunt.registerMultiTask('teamcity', 'Send log warnings in TeamCity service message format.', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      suppressGruntLog: false,
      status: {
        // TC WARNING does not trigger a task fail
        warning: 'ERROR',
        failure: 'FAILURE',
        error: 'ERROR'
      }
    });

    var log = grunt.log;
    var _log = {
      warn: log.warn,
      error: log.error,
      errorlns: log.errorlns,
      fail: log.fail
    };


    log.warn = function() {
      if (!options.suppressGruntLog) {
        _log.warn.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.warning);
    };

    log.error = function() {
      if (!options.suppressGruntLog) {
        _log.error.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.error);
    };

    log.errorlns = function() {
      if (!options.suppressGruntLog) {
        _log.errorlns.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.error);
    };

    log.fail = function() {
      if (!options.suppressGruntLog) {
        _log.fail.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.failure);
    };


    function writeMsg (msg, status) {
      if (msg) {
        process.stdout.write(tcFormat(msg, status));
      } else {
        process.stdout.write(tcFormat(status, status));
      }
    }

    function tcFormat(text, status, errorDetails) {
      if (text.indexOf('##teamcity[') !== -1) {
        return text;
      }

      return  ("##teamcity[message text='" + text +
        "' errorDetails='" + (errorDetails || '') +
        "' status='" + status + "']\n").grey;
    }

    // verbatum from grunt.log
    function format(args) {
      // Args is a argument array so copy it in order to avoid wonky behavior.
      args = [].slice.call(args, 0);
      if (args.length > 0) {
        args[0] = String(args[0]);
      }
      return util.format.apply(util, args);
    }
  });

};<commit_msg>write synchronous to stdout<commit_after>/* jshint node:true */
/*
 * grunt-teamcity
 *
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

// Nodejs libs.
var util = require('util');
var fs = require('fs');

module.exports = function(grunt) {

  grunt.registerMultiTask('teamcity', 'Send log warnings in TeamCity service message format.', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      suppressGruntLog: false,
      status: {
        // TC WARNING does not trigger a task fail
        warning: 'ERROR',
        failure: 'FAILURE',
        error: 'ERROR'
      }
    });

    var log = grunt.log;
    var _log = {
      warn: log.warn,
      error: log.error,
      errorlns: log.errorlns,
      fail: log.fail
    };


    log.warn = function() {
      if (!options.suppressGruntLog) {
        _log.warn.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.warning);
    };

    log.error = function() {
      if (!options.suppressGruntLog) {
        _log.error.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.error);
    };

    log.errorlns = function() {
      if (!options.suppressGruntLog) {
        _log.errorlns.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.error);
    };

    log.fail = function() {
      if (!options.suppressGruntLog) {
        _log.fail.apply(log, arguments);
      }
      writeMsg(format(arguments), options.status.failure);
    };


    function writeMsg (msg, status) {
      if (msg) {
        writeSync(tcFormat(msg, status));
      } else {
        writeSync(tcFormat(status, status));
      }
    }

    function tcFormat(text, status, errorDetails) {
      if (text.indexOf('##teamcity[') !== -1) {
        return text;
      }

      return  ("##teamcity[message text='" + text +
        "' errorDetails='" + (errorDetails || '') +
        "' status='" + status + "']\n").grey;
    }

    function writeSync(text){
        fs.writeSync(process.stdout.fd,text);
    }

    // verbatum from grunt.log
    function format(args) {
      // Args is a argument array so copy it in order to avoid wonky behavior.
      args = [].slice.call(args, 0);
      if (args.length > 0) {
        args[0] = String(args[0]);
      }
      return util.format.apply(util, args);
    }
  });

};
{'fraction_non_alphanumeric': 0.14616193480546794, 'fraction_numerical': 0.0037854889589905363, 'mean_word_length': 2.2845303867403315, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1257341', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1484, 'n_words': 337}