View Javadoc

1   /*
2    * Copyright (C) 2009 Jayway AB
3    * Copyright (C) 2007-2008 JVending Masa
4    * Copyright (C) 2010 akwuinet A.G.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package com.jayway.maven.plugins.android.standalonemojos;
19  
20  import com.jayway.maven.plugins.android.AbstractAndroidMojo;
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.plugin.MojoFailureException;
23  
24  import java.io.File;
25  
26  /**
27   * Redeploys the built apk file, or another specified apk, to a connected device.
28   * This simply tries to undeploy the APK and re-deploy it.
29   *
30   * @author clement.escoffier@akquinet.de
31   * @goal redeploy
32   * @requiresProject false
33   * @requiresDependencyResolution runtime
34   */
35  public class RedeployMojo extends AbstractAndroidMojo
36  {
37  
38      /**
39       * Optionally used to specify a different apk file to deploy to a connected emulator or usb device, instead of the
40       * built apk from this project.
41       *
42       * @parameter expression="${android.file}"
43       */
44      private File file;
45  
46      public void execute() throws MojoExecutionException, MojoFailureException
47      {
48          if ( file == null )
49          {
50              if ( ! SUPPORTED_PACKAGING_TYPES.contains( project.getPackaging() ) )
51              {
52                  getLog().info( "Skipping redeploy on " + project.getPackaging() );
53                  return;
54              }
55              String packageToUndeploy = extractPackageNameFromAndroidManifest( androidManifestFile );
56              undeployApk( packageToUndeploy );
57              deployBuiltApk();
58          }
59          else
60          {
61              undeployApk( file );
62              deployApk( file );
63          }
64      }
65  
66  }