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.simpligility.maven.plugins.android.standalonemojos;
19  
20  import static com.simpligility.maven.plugins.android.common.AndroidExtension.APK;
21  
22  import com.simpligility.maven.plugins.android.AbstractAndroidMojo;
23  
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugin.MojoFailureException;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.ResolutionScope;
29  
30  /**
31   * Undeploys and the deploys (= redeploys) the apk(s) of the current project(s) to all
32   * attached devices and emulators. Automatically skips other projects in a multi-module
33   * build that do not use packaging apk without terminating.<br>
34   *
35   * @author clement.escoffier@akquinet.de
36   * @author Manfred Moser - manfred@simpligility.com
37   */
38  @Mojo( name = "redeploy", requiresDependencyResolution = ResolutionScope.RUNTIME )
39  public class RedeployMojo extends AbstractAndroidMojo
40  {
41  
42      public void execute() throws MojoExecutionException, MojoFailureException
43      {
44          if ( project.getPackaging().equals( APK ) )
45          {
46              String packageToUndeploy = renameManifestPackage != null
47                      ? renameManifestPackage
48                      : extractPackageNameFromAndroidManifest( destinationManifestFile );
49              if ( StringUtils.isNotBlank( packageToUndeploy ) ) 
50              {
51                  undeployApk( packageToUndeploy );
52              }
53              deployBuiltApk();
54          } 
55          else 
56          {
57              getLog().info( "Project packaging is not apk, skipping redeployment" );
58          }
59      }
60  
61  }