1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
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.commons.lang3.StringUtils;
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  
36  
37  
38  
39  
40  
41  
42  
43  @Mojo( name = "undeploy-apk", requiresProject = false )
44  public class UndeployApkMojo extends AbstractAndroidMojo
45  {
46      
47  
48  
49  
50  
51  
52  
53  
54  
55  
56      @ConfigPojo
57      @Parameter
58      protected DeployApk deployapk;
59  
60      @Parameter( property = "android.deployapk.filename" )
61      private File deployapkFilename;
62  
63      @PullParameter
64      private File parsedFilename;
65  
66      @Parameter( property = "android.deployapk.packagename" )
67      private String deployapkPackagename;
68  
69      @PullParameter
70      private String parsedPackagename;
71  
72      
73  
74  
75  
76      public void execute() throws MojoExecutionException, MojoFailureException
77      {
78          ConfigHandler configHandler = new ConfigHandler( this, this.session, this.execution );
79          configHandler.parseConfiguration();
80  
81          if ( parsedFilename == null && parsedPackagename == null )
82          {
83              throw new MojoFailureException( "\n\n One of the parameters android.deployapk.packagename "
84                      + "or android.deployapk.filename is required. \n" );
85          }
86          
87          if ( StringUtils.isNotBlank( parsedPackagename ) )
88          {
89              getLog().debug( "Undeploying with packagename " + parsedPackagename );
90              undeployApk( parsedPackagename );
91          }
92  
93          ValidationResponse response = DeployApk.validFileParameter( parsedFilename );
94          if ( response.isValid() ) 
95          {
96              getLog().debug( "Undeploying with file " + parsedFilename );
97              undeployApk( parsedFilename );
98          } 
99          else 
100         {
101             getLog().info( "Ignoring invalid file parameter." );
102             getLog().debug( response.getMessage() );
103             
104         }
105     }
106 }