/*
	Licensed Material - Property of IBM

	(C) Copyright 2016 IBM Corp.

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/


'use strict';

var Q = require('q');
var exec = require('mdo-exec');
var messages = require('../externalizedStrings');

module.exports.printInfo = function() {
  // if more infomation, add method and add to Q.all([])
  return Q.all([getMavenVersion()]).then(
    function (values) {
      printSystemInfo(values[0]);
    }
  );
};

function printSystemInfo(mavenVersionInfo) {
  console.log();
  console.log(messages.maven_info);

  if (mavenVersionInfo !== messages.maven_not_installed) {
    console.log('  ' + mavenVersionInfo);
  } else
    console.log('  ' + messages.maven_not_installed);
}

function getMavenVersion() {
  var deferred = Q.defer();

  exec.run('mvn', ['-v']).done(
    function (version) {
      deferred.resolve(version.stdOut.replace(/\n/g, '\n  '));
    },
    function () {
      deferred.resolve(messages.maven_not_installed);
    }
  );

  return deferred.promise;
}
