'use strict';

const tools = require('../../tools');
const mavenUtils = require('../../maven-utils');
const notificationUtils = require('../../notification/notification-utils');


module.exports.build = (pkg, isMaster) => {
  tools.logTitle('Building maven backend package...');

  return Promise.resolve()
    .then(() => {
      tools.logInfo('Executing maven build...');

      if (pkg.build && pkg.build.mavenTestCommand) {
        return mavenUtils.execute(pkg.paths.root, pkg.build.mavenTestCommand);
      } else {
        return mavenUtils.execute(pkg.paths.root, 'clean test package');
      }
    })

    .then(() => {
      return notificationUtils.package.sendPackageMessage({
        package: pkg
      })
    })
    .catch((e) => {
      throw e;
    });
}
