package org.jerrymouse.gaes.mavenPlugin.base;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Path;

public class AppCfgTask extends BaseTask {

	Log log = LogFactory.getLog(getClass());

	@Override
	public void execute(String libPath, String args) {
		Java java = new Java();
		Project project = new Project();
		DefaultLogger consoleLogger = new DefaultLogger();
		consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
		consoleLogger.setErrorPrintStream(System.err);
		consoleLogger.setOutputPrintStream(System.out);
		project.addBuildListener(consoleLogger);

		java.setProject(project);
		java.setTaskName("appcfg");
		Path path = new Path(project, libPath);
		java.setClasspath(path);
		java.setClassname("com.google.appengine.tools.admin.AppCfg");
		java.setFork(true);
		java.setFailonerror(true);
		java.createArg().setLine(args);
		log.info("args:" + args);
		java.execute();
	}
}
