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 com.simpligility.maven.plugins.android.AbstractAndroidMojo;
21  import com.simpligility.maven.plugins.android.config.ConfigHandler;
22  import com.simpligility.maven.plugins.android.config.ConfigPojo;
23  import com.simpligility.maven.plugins.android.config.PullParameter;
24  import com.simpligility.maven.plugins.android.configuration.DeployApk;
25  import com.simpligility.maven.plugins.android.configuration.ValidationResponse;
26  
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugins.annotations.Mojo;
30  import org.apache.maven.plugins.annotations.Parameter;
31  
32  import java.io.File;
33  
34  /**
35   * Reploys a specified Android application apk to attached devices and emulators. 
36   * By default it will deploy to all, but a asubset or single one can be configured 
37   * with the device and devices parameters. This simply tries to undeploy the APK 
38   * first and then deploy it again. This goal can be used in non-android projects and 
39   * as standalone execution on the command line.<br>
40   *
41   * @author Manfred Moser - manfred@simpligility.com
42   */
43  @Mojo( name = "redeploy-apk", requiresProject = false )
44  public class RedeployApkMojo extends AbstractAndroidMojo
45  {
46      /**
47       * Configuration for apk file redeployment within a pom file. See {@link #deployapkFilename}. 
48       * 
49       * <pre>
50       * &lt;deployapk&gt;
51       *    &lt;filename&gt;yourapk.apke&lt;/filename&gt;
52       * &lt;/deployapk&gt;
53       * </pre>
54       */
55      @Parameter
56      @ConfigPojo
57      protected DeployApk deployapk;
58  
59      @Parameter( property = "android.deployapk.filename" )
60      private File deployapkFilename;
61  
62      @PullParameter
63      private File parsedFilename;
64  
65      public void execute() throws MojoExecutionException, MojoFailureException
66      {
67          ConfigHandler configHandler = new ConfigHandler( this, this.session, this.execution );
68          configHandler.parseConfiguration();
69          
70          ValidationResponse response = DeployApk.validFileParameter( parsedFilename );
71          if ( response.isValid() ) 
72          {   
73              getLog().debug( "Undeploying with file " + parsedFilename );
74              undeployApk( parsedFilename );
75              getLog().debug( "Deploying with apkFile " + parsedFilename );
76              deployApk( parsedFilename );
77          } 
78          else 
79          {
80              throw new MojoFailureException( response.getMessage() );
81          }
82      }
83  }