/*
 * Copyright 2008 Kindleit Technologies. All rights reserved. This file, all
 * proprietary knowledge and algorithms it details are the sole property of
 * Kindleit Technologies unless otherwise specified. The software this file
 * belong with is the confidential and proprietary information of Kindleit
 * Technologies. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with Kindleit.
 */
package org.jerrymouse.gaes.mavenPlugin.mojos;

import org.jerrymouse.gaes.mavenPlugin.base.MojoBase;
import org.jerrymouse.gaes.mavenPlugin.base.RunTask;

/**
 * @author jpeynado@kindleit.net
 * @author rhansen@kindleit.net Goal for run a WAR project on the GAE dev
 *         server.
 * @goal run
 * @requiresDependencyResolution runtime
 * @execute phase="test-compile"
 */
public class RunMojo extends MojoBase {

	/**
	 * Port to run in.
	 * 
	 * @parameter expression="${gae.port}" default-value="8080"
	 */
	private String port;

	/**
	 * Address to bind to.
	 * 
	 * @parameter expression="${gae.address}" default-value="0.0.0.0"
	 */
	private String address;

	/**
	 * Do not check for new SDK versions.
	 * 
	 * @parameter expression="${gae.disableUpdateCheck}" default-value="false"
	 */
	protected boolean disableUpdateCheck;

	void run(String args) {
		runTask(new RunTask(), args);
	}

	@Override
	protected void gaeExecute() {
		getLog().info("run gae");
		if (disableUpdateCheck) {
			run("com.google.appengine.tools.development.DevAppServerMain --address="
					+ address
					+ " --port="
					+ port
					+ " --disable_update_check"
					+ " " + appDir);

		} else {
			run("com.google.appengine.tools.development.DevAppServerMain --address="
					+ address + " --port=" + port + " " + appDir);
		}
	}

	@Override
	protected void normalExecute() {
		runMvnCommond("jetty:run-war");
	}

	@Override
	protected void hadoopExecute() {
		runMvnCommond("jetty:run-war");
	}

}
