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.jayway.maven.plugins.android.standalonemojos;
18
19 import com.jayway.maven.plugins.android.AbstractAndroidMojo;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.plugin.MojoFailureException;
22
23 import java.io.File;
24
25 /**
26 * Undeploys the built apk file, or another specified apk, from a connected device.<br/>
27 *
28 * @author hugo.josefson@jayway.com
29 * @goal undeploy
30 * @requiresProject false
31 */
32 public class UndeployMojo extends AbstractAndroidMojo
33 {
34
35 /**
36 * Optionally used to specify a different apk package to undeploy from a connected emulator or usb device, instead
37 * of the built apk from this project.
38 *
39 * @parameter property="package" expression="${android.package}" default-value="null"
40 */
41 private String packageName;
42
43 public void setPackage( String packageName )
44 {
45 this.packageName = packageName;
46 }
47
48 /**
49 * Optionally used to specify a different apk file to undeploy from a connected emulator or usb device, instead of
50 * the built apk from this project.
51 *
52 * @parameter expression="${android.file}"
53 */
54 private File file;
55
56 /**
57 *
58 * @throws MojoExecutionException
59 * @throws MojoFailureException
60 */
61 public void execute() throws MojoExecutionException, MojoFailureException
62 {
63 String packageToUndeploy = packageName;
64 if ( packageToUndeploy != null && ! "".equals( packageToUndeploy ) && ! "null".equals( packageToUndeploy ) )
65 {
66 undeployApk( packageToUndeploy );
67 }
68 else
69 {
70 if ( file != null )
71 {
72 undeployApk( file );
73 }
74 else
75 {
76 if ( ! SUPPORTED_PACKAGING_TYPES.contains( project.getPackaging() ) )
77 {
78 getLog().info( "Skipping undeploy on " + project.getPackaging() );
79 getLog().info( "Execute undeploy within an Maven Android project or specify package with e.g. "
80 + "-Dandroid.package=com.simpligility.android.helloflashlight" );
81 return;
82 }
83
84 packageToUndeploy = renameManifestPackage != null
85 ? renameManifestPackage
86 : extractPackageNameFromAndroidManifest( androidManifestFile );
87
88 undeployApk( packageToUndeploy );
89 }
90 }
91
92 }
93 }