package com.byclosure.maven.plugins.phonegap;

import org.apache.commons.exec.CommandLine;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * @goal create
 * @requiresProject true
 */
public class CreateMojo extends AbstractPhoneGapMojo {

	/**
	 * @parameter default-value="com.easyeasyapps.framework" expression="${phonegap.package}"
	 */
	protected String package_;

	/**
	 * @parameter default-value="Hello World" expression="${phonegap.name}"
	 */
	protected String name;


	@Override
	protected void executeComand() throws IOException {
		final String phonegapBinPath;

		if (phonegapBin != null) {
			phonegapBinPath = new File(phonegapBin, "phonegap").getPath();
		} else {
			phonegapBinPath = "phonegap";
		}

		final CommandLine cmd = getCrossPlatformCommandLine();
		cmd.addArgument(phonegapBinPath + " create " + projectPath + " \"" + package_ + "\" \"" + name + "\"", false);

		final Map<String, String> env = getEnv();

		System.out.println("Executing: " + cmd.toString());
		executeCommandLine(cmd, env, workingDir);
	}
}
@@ -742,16 +742,170 @@
 %22;%0A%09%09%7D%0A%0A
+%09%09final String fixedName = name.replaceAll(%22-%22, %22%22).replaceAll(%22 %22, %22%22);%0A%09%09final String fixedPackage = package_.replaceAll(%22-%22, %22%22).replaceAll(%22 %22, %22%22);%0A%0A
 %09%09final 
@@ -1024,24 +1024,28 @@
 %22 %5C%22%22 + 
-p
+fixedP
 ackage
-_
  + %22%5C%22 %5C
@@ -1049,17 +1049,22 @@
 %22 %5C%22%22 + 
-n
+fixedN
 ame + %22%5C

replace "-" and " " by "" in package and app name on phonegap:create