package com.brewinapps.ios;

import java.util.HashMap;
import java.util.Map;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;


/**
 * 
 * @author Brewin' Apps AS
 * @goal build
 * @phase compile
 */
public class IOSBuildMojo extends AbstractMojo {
	
	/**
	 * iOS Source Directory
	 * @parameter
	 * 		expression="${ios.sourceDir}"
	 * 		default-value="."
	 */
	private String sourceDir;
	
	/**
	 * iOS app name
	 * @parameter
	 * 		expression="${ios.appName}"
	 * @required
	 */
	private String appName;
	
	/**
	 * iOS scheme
	 * @parameter
	 * 		expression="${ios.scheme}"
	 */
	private String scheme;		
	
	/**
	 * iOS SDK
	 * @parameter
	 * 		expression="${ios.sdk}"
	 * 		default-value="iphoneos"
	 */
	private String sdk;
	
	/**
	 * iOS code sign identity
	 * @parameter
	 * 		expression="${ios.codeSignIdentity}"
	 * @required
	 */
	private String codeSignIdentity;
	
	/**
	 * iOS configuration
	 * @parameter
	 * 		expression="${ios.configuration}"
	 * 		default-value="Release"
	 */
	private String configuration;
	
	/**
	 * build id
	 * @parameter
	 * 		expression="${ios.buildId}"
	 */
	private String buildId;	
		
	/**
	* The maven project.
	* 
	* @parameter expression="${project}"
	* @required
	* @readonly
	*/
	protected MavenProject project;
	
	/**
	 * 
	 */
	public void execute() throws MojoExecutionException, MojoFailureException {
		try {
			final String targetDir = project.getBuild().getDirectory();
			
			Map<String, String> properties = new HashMap<String, String>();
			properties.put("appName", appName);
			properties.put("codeSignIdentity", codeSignIdentity);
			properties.put("sdk", sdk);
			properties.put("baseDir", project.getBasedir().toString());
			properties.put("sourceDir", sourceDir);
			properties.put("targetDir", targetDir);
			properties.put("configuration", configuration);
			properties.put("buildId", buildId);
			properties.put("version", project.getVersion());
			properties.put("scheme", scheme);
			
			ProjectBuilder.build(properties);
		} catch (IOSException e) {
			throw new MojoExecutionException(e.getMessage());
		}
	}

}

@@ -1165,16 +1165,118 @@
 uration;
+%0A%0A%09/**%0A%09 * iOS version %0A%09 * @parameter%0A%09 * %09%09expression=%22$%7Bios.version%7D%22%0A%09 */%0A%09private String version;
 %0A%09%0A%09/**%0A
@@ -1336,16 +1336,58 @@
 uildId%7D%22
+ %0A%09 * %09%09default-value=%22$%7Bproject.version%7D%22
 %0A%09 */%0A%09p
@@ -2180,28 +2180,15 @@
 n%22, 
-project.getV
+v
 ersion
-()
 );%0A%09

Allow an iOS version to be specified as per the README