Code coverage report for lib/services/android-project-properties-manager.js

Statements: 98.68% (75 / 76)      Branches: 75% (9 / 12)      Functions: 100% (21 / 21)      Lines: 98.65% (73 / 74)      Ignored: none     

All files » lib/services/ » android-project-properties-manager.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109    1 1 1 5 5 5 5 5 5 5   1 10 10 10 10 10 10 35 25     10     1 3 3 3 6 3 3       1 2 2 2 4 2 2             1 5 5 5     1 24   1 10   1 25             1 3 3 3 3 3 6   3 3 3     1 2 2 2 2 2 2 2 4 2 2 2   2 2   2   2 2     1   1  
///<reference path="../.d.ts"/>
"use strict";
var path = require("path");
var AndroidProjectPropertiesManager = (function () {
    function AndroidProjectPropertiesManager($propertiesParser, $fs, $logger, directoryPath) {
        this.$propertiesParser = $propertiesParser;
        this.$fs = $fs;
        this.$logger = $logger;
        this._editor = null;
        this.filePath = null;
        this.dirty = false;
        this.filePath = path.join(directoryPath, "project.properties");
    }
    AndroidProjectPropertiesManager.prototype.getProjectReferences = function () {
        var _this = this;
        return (function () {
            Eif (!_this.projectReferences || _this.dirty) {
                var allProjectProperties = _this.getAllProjectProperties().wait();
                var allProjectPropertiesKeys = _.keys(allProjectProperties);
                _this.projectReferences = _(allProjectPropertiesKeys)
                    .filter(function (key) { return _.startsWith(key, "android.library.reference."); })
                    .map(function (key) { return _this.createLibraryReference(key, allProjectProperties[key]); })
                    .value();
            }
            return _this.projectReferences;
        }).future()();
    };
    AndroidProjectPropertiesManager.prototype.addProjectReference = function (referencePath) {
        var _this = this;
        return (function () {
            var references = _this.getProjectReferences().wait();
            var libRefExists = _.any(references, function (r) { return path.normalize(r.path) === path.normalize(referencePath); });
            Eif (!libRefExists) {
                _this.addToPropertyList("android.library.reference", referencePath).wait();
            }
        }).future()();
    };
    AndroidProjectPropertiesManager.prototype.removeProjectReference = function (referencePath) {
        var _this = this;
        return (function () {
            var references = _this.getProjectReferences().wait();
            var libRefExists = _.any(references, function (r) { return path.normalize(r.path) === path.normalize(referencePath); });
            Eif (libRefExists) {
                _this.removeFromPropertyList("android.library.reference", referencePath).wait();
            }
            else {
                _this.$logger.error("Could not find " + referencePath + ".");
            }
        }).future()();
    };
    AndroidProjectPropertiesManager.prototype.createEditor = function () {
        var _this = this;
        return (function () {
            return _this._editor || _this.$propertiesParser.createEditor(_this.filePath).wait();
        }).future()();
    };
    AndroidProjectPropertiesManager.prototype.buildKeyName = function (key, index) {
        return key + "." + index;
    };
    AndroidProjectPropertiesManager.prototype.getAllProjectProperties = function () {
        return this.$propertiesParser.read(this.filePath);
    };
    AndroidProjectPropertiesManager.prototype.createLibraryReference = function (referenceName, referencePath) {
        return {
            idx: parseInt(referenceName.split("android.library.reference.")[1]),
            key: referenceName,
            path: referencePath,
            adjustedPath: path.join(path.dirname(this.filePath), referencePath)
        };
    };
    AndroidProjectPropertiesManager.prototype.addToPropertyList = function (key, value) {
        var _this = this;
        return (function () {
            var editor = _this.createEditor().wait();
            var i = 1;
            while (editor.get(_this.buildKeyName(key, i))) {
                i++;
            }
            editor.set(_this.buildKeyName(key, i), value);
            _this.$propertiesParser.saveEditor().wait();
            _this.dirty = true;
        }).future()();
    };
    AndroidProjectPropertiesManager.prototype.removeFromPropertyList = function (key, value) {
        var _this = this;
        return (function () {
            var editor = _this.createEditor().wait();
            var valueLowerCase = value.toLowerCase();
            var i = 1;
            var currentValue;
            while (currentValue = editor.get(_this.buildKeyName(key, i))) {
                if (currentValue.toLowerCase() === valueLowerCase) {
                    while (currentValue = editor.get(_this.buildKeyName(key, i + 1))) {
                        editor.set(_this.buildKeyName(key, i), currentValue);
                        i++;
                    }
                    editor.set(_this.buildKeyName(key, i));
                    break;
                }
                i++;
            }
            _this.$propertiesParser.saveEditor().wait();
            _this.dirty = true;
        }).future()();
    };
    return AndroidProjectPropertiesManager;
})();
exports.AndroidProjectPropertiesManager = AndroidProjectPropertiesManager;