/**
 * Copyright 2012 Google Inc. All Rights Reserved.
 */
package com.google.appengine.appcfg;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Create or update an app version.
 *
 * @author Matt Stephenson <mattstep@google.com>
 * @goal update
 * @execute phase="package"
 */
public class Update extends AbstractAppCfgMojo {

  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("");
    getLog().info("Google App Engine Java SDK - Updating Application");
    getLog().info("");

    getLog().info("Retrieving Google App Engine Java SDK from Maven");

    resolveAndSetSdkRoot();

    String appDir = project.getBuild().getDirectory() + "/" + project.getBuild().getFinalName();

    getLog().info("Updating Google App Engine Application");

    executeAppCfgCommand("update", appDir);
  }
}

@@ -197,16 +197,262 @@
 ception;
+%0Aimport com.google.appengine.gcloudapp.GCloudAppDeploy;%0Aimport com.google.apphosting.utils.config.AppEngineWebXml;%0Aimport com.google.apphosting.utils.config.AppEngineWebXmlReader;%0Aimport java.io.File;%0Aimport org.apache.maven.project.MavenProject;
 %0A%0A/**%0A *
@@ -953,207 +953,1057 @@
     
-String appDir = project.getBuild().getDirectory() + %22/%22 + project.getBuild().getFinalName
+getLog().info(%22Updating Google App Engine Application%22);%0A    String appDir = getAppDir();%0A    Boolean useCloud = false;%0A    File f = new File(appDir, %22WEB-INF/appengine-web.xml%22);%0A    if (f.exists()) %7B%0A      AppEngineWebXmlReader aewebReader = new AppEngineWebXmlReader(appDir);%0A      AppEngineWebXml appEngineWebXml = aewebReader.readAppEngineWebXml
 ();%0A
-%0A
+  
     
-getLog().info(%22Updating Google App Engine Applicat
+useCloud = %22java11%22.equals(appEngineWebXml.getRuntime());%0A    %7D%0A%0A    if (useCloud) %7B%0A      CloudDeploy deploy = new CloudDeploy(mavenProject, getProjectId(), this.vers
 ion
-%22
 );%0A
-%0A    executeAppCfgCommand(%22update%22, appDir);
+      deploy.execute();%0A    %7D else %7B%0A      executeAppCfgCommand(%22update%22, getAppDir());%0A    %7D%0A  %7D%0A%0A  private class CloudDeploy extends GCloudAppDeploy %7B%0A%0A    CloudDeploy(MavenProject project, String app, String version) %7B%0A      this.maven_project = project;%0A      this.staging_directory = project.getBuild().getDirectory() + %22/appengine-staging%22;%0A      this.docker_host = %22localhost%22;%0A      this.gcloud_project = app;%0A      this.version = version;%0A    %7D%0A%0A    @Override%0A    public void resolveAndSetSdkRoot() %7B%0A%0A    %7D
 %0A  %7D

stop using appcfg path for new apps..