View Javadoc
1   /*
2    * Copyright (C) 2009 Jayway AB
3    * Copyright (C) 2007-2008 JVending Masa
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package com.simpligility.maven.plugins.android.standalonemojos;
18  
19  import com.simpligility.maven.plugins.android.AbstractAndroidMojo;
20  import com.simpligility.maven.plugins.android.config.ConfigHandler;
21  import com.simpligility.maven.plugins.android.config.ConfigPojo;
22  import com.simpligility.maven.plugins.android.config.PullParameter;
23  import com.simpligility.maven.plugins.android.configuration.DeployApk;
24  import com.simpligility.maven.plugins.android.configuration.ValidationResponse;
25  
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.apache.maven.plugins.annotations.Parameter;
30  
31  import java.io.File;
32  
33  /**
34   * Deploys a specified Android application apk to attached devices and emulators. 
35   * By default it will deploy to all, but a subset or single one can be configured 
36   * with the device and devices parameters.This goal can be used in non-android 
37   * projects and as standalone execution on the command line. <br>
38   *
39   * @author Manfred Moser - manfred@simpligility.com
40   */
41  @Mojo( name = "deploy-apk", requiresProject = false )
42  public class DeployApkMojo extends AbstractAndroidMojo
43  {
44      /**
45       * Configuration for apk file deployment within a pom file. See {@link #deployapkFilename}. 
46       * 
47       * <pre>
48       * &lt;deployapk&gt;
49       *    &lt;filename&gt;yourapk.apke&lt;/filename&gt;
50       * &lt;/deployapk&gt;
51       * </pre>
52       */
53      @Parameter
54      @ConfigPojo
55      protected DeployApk deployapk;
56  
57      @Parameter( property = "android.deployapk.filename" )
58      private File deployapkFilename;
59  
60      @PullParameter
61      private File parsedFilename;
62  
63      /**
64       * Deploy the app to the attached devices and emulators.
65       *
66       * @throws MojoExecutionException
67       * @throws MojoFailureException
68       */
69      public void execute() throws MojoExecutionException, MojoFailureException
70      {
71          ConfigHandler configHandler = new ConfigHandler( this, this.session, this.execution );
72          configHandler.parseConfiguration();
73          
74          ValidationResponse response = DeployApk.validFileParameter( parsedFilename );
75          if ( response.isValid() ) 
76          {   
77              getLog().info( "Deploying apk file at " + parsedFilename );
78              deployApk( parsedFilename );
79          } 
80          else 
81          {
82              throw new MojoFailureException( response.getMessage() );
83          }
84      }
85  }