/**
 * (C) Copyright 2011-2015 FastConnect SAS
 * (http://www.fastconnect.fr/) and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */
package fr.fastconnect.factory.tibco.bw.maven.deployment;

import java.io.File;
import java.util.ArrayList;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

/**
 * 
 * <p>
 * This goal deploys a TIBCO BusinessWorks application to a TIBCO domain.
 * </p>
 * 
 * @author Mathieu Debove
 * 
 */
@Mojo( name="deploy-bw",
defaultPhase=LifecyclePhase.DEPLOY ) // FIXME: should be deployEAR
//@Execute ( goal="deploy-bw", lifecycle="deploy")
public class DeployEARMojo extends AbstractBWDeployMojo {

	protected final static String DEPLOY_EAR_FAILED = "The deployment of the application failed.";
	protected final static String DEPLOYING_APPLICATION = "Deploying application to ";
	protected final static String DEPLOYING_ON_DOMAIN = " on domain ";

	protected final static String USING_EAR = "Using EAR : ";
	protected final static String USING_XML = "Using XML : ";

	@Parameter
	private boolean redeploy;
	
	/**
	 * If true, the successfully deployed service instances won't be started.
	 * Default is false.
	 */
	@Parameter ( property = "deploy.nostart", defaultValue = "false")
	private boolean noStart;

	/**
	 * If true, the service instances running before deployment won't be stopped.
	 * Default is false.
	 */
	@Parameter ( property = "deploy.nostop", defaultValue = "false")
	private boolean noStop;
	
	/**
	 * If true, deploy service instances one at a time instead of in parallel.
	 * Default is true.
	 */
	@Parameter ( property = "deploy.serialize", defaultValue = "true")
	private boolean serialize;
	
	@Parameter
	private File deployConfigXML;

<<<<<<< HEAD
	private void deployEAR() throws MojoExecutionException, IOException {
		checkAppManage();
		
		File ear = getOutputFile();
		if (ear == null || !ear.exists()) {
			MavenProject project = getProject();
			if (project != null && project.getBasedir() != null && project.getBasedir().exists()) {
				ear = getArtifactFile(getProject().getBasedir(), finalName, classifier);
			}
		}

		getLog().info(DEPLOYING_APPLICATION + "'" + deployedProjectName + "'" +  DEPLOYING_ON_DOMAIN + "'" +  domainName+ "'");
=======
	@Override
	public String getInitMessage() {
		return DEPLOYING_APPLICATION + "'" + deployedProjectName + "'" +  DEPLOYING_ON_DOMAIN + "'" +  domainName+ "'";
	}

	@Override
	public String getFailureMessage() {
		return DEPLOY_EAR_FAILED;
	}

	@Override
	public ArrayList<String> arguments() {
		File ear = getOutputFile();
>>>>>>> Refactoring: all AppManage goals now share the same workflow
		getLog().info(USING_EAR + ear.getAbsolutePath());
		getLog().info(USING_XML + deploymentDescriptorFinal.getAbsolutePath());

		ArrayList<String> arguments = super.commonArguments();
		arguments.add("-deploy");
		arguments.add("-ear");
		arguments.add(ear.getAbsolutePath());
		arguments.add("-deployConfig");
		arguments.add(deploymentDescriptorFinal.getAbsolutePath());
		if (serialize) {
			arguments.add("-serialize");
		}
		if (noStart) {
			arguments.add("-nostart");
		}
		if (noStop) {
			arguments.add("-nostop");
		}
		arguments.add("-force");

		return arguments;
	}

	@Override
	public void postAction() throws MojoExecutionException {
		// nothing to do
	}

}

@@ -2426,531 +2426,8 @@
 L;%0A%0A
-%3C%3C%3C%3C%3C%3C%3C HEAD%0A%09private void deployEAR() throws MojoExecutionException, IOException %7B%0A%09%09checkAppManage();%0A%09%09%0A%09%09File ear = getOutputFile();%0A%09%09if (ear == null %7C%7C !ear.exists()) %7B%0A%09%09%09MavenProject project = getProject();%0A%09%09%09if (project != null && project.getBasedir() != null && project.getBasedir().exists()) %7B%0A%09%09%09%09ear = getArtifactFile(getProject().getBasedir(), finalName, classifier);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09getLog().info(DEPLOYING_APPLICATION + %22'%22 + deployedProjectName + %22'%22 +  DEPLOYING_ON_DOMAIN + %22'%22 +  domainName+ %22'%22);%0A=======%0A
 %09@Ov
@@ -2750,77 +2750,8 @@
 ();%0A
-%3E%3E%3E%3E%3E%3E%3E Refactoring: all AppManage goals now share the same workflow%0A
 %09%09ge

Rebase master into add-appmanage-batch-goals