Skip to content
This repository

Devices #117

Merged
merged 2 commits into from almost 2 years ago

2 participants

Manfred Moser Manfred Moser
Manfred Moser
Collaborator
mosabua commented May 21, 2012

an new simple mojo to display the list of attached devices using the same naming convention as used in the rest of the plugin to make it easier to know which device is which.

Manfred Moser mosabua merged commit 7883d7a into from May 21, 2012
Manfred Moser mosabua closed this May 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
14  src/main/java/com/jayway/maven/plugins/android/common/DeviceHelper.java
@@ -54,4 +54,18 @@ public static String getModel(IDevice device) {
54 54
             return StringUtils.deleteWhitespace(device.getProperty(MODEL_PROPERTY));
55 55
     }
56 56
 
  57
+    /**
  58
+     * @return the descriptive name with online/offline/unknown status string appended.
  59
+     */
  60
+    public static String getDescriptiveNameWithStatus(IDevice device) {
  61
+        String status;
  62
+        if (device.isOnline()) {
  63
+            status = "Online";
  64
+        } else if (device.isOffline()) {
  65
+            status = "Offline";
  66
+        } else {
  67
+            status = "Unknown";
  68
+        }
  69
+        return getDescriptiveName(device) + " " + status;
  70
+    }
57 71
 }
38  src/main/java/com/jayway/maven/plugins/android/standalonemojos/DevicesMojo.java
... ...
@@ -0,0 +1,38 @@
  1
+package com.jayway.maven.plugins.android.standalonemojos;
  2
+
  3
+import com.android.ddmlib.IDevice;
  4
+import com.jayway.maven.plugins.android.AbstractAndroidMojo;
  5
+import com.jayway.maven.plugins.android.DeviceCallback;
  6
+import com.jayway.maven.plugins.android.common.DeviceHelper;
  7
+import org.apache.maven.plugin.MojoExecutionException;
  8
+import org.apache.maven.plugin.MojoFailureException;
  9
+
  10
+/**
  11
+ * DevicesMojo lists all attached devices and emulators found with the android debug bridge. It uses the same
  12
+ * naming convention for the emulator as used in other places in the Android Maven Plugin and adds the status
  13
+ * of the device in the list.
  14
+ *
  15
+ * TODO The goal is very simple and could be enhanced for better display, a verbose option to display and to take the
  16
+ * android.device paramter into account.
  17
+ *
  18
+ * @author Manfred Moser <manfred@simpligility.com>
  19
+ * @goal devices
  20
+ * @requiresProject false
  21
+ */
  22
+public class DevicesMojo extends AbstractAndroidMojo {
  23
+    /**
  24
+     * Display a list of attached devices.
  25
+     *
  26
+     * @throws org.apache.maven.plugin.MojoExecutionException
  27
+     * @throws org.apache.maven.plugin.MojoFailureException
  28
+     */
  29
+    public void execute() throws MojoExecutionException, MojoFailureException {
  30
+        doWithDevices(
  31
+            new DeviceCallback() {
  32
+                public void doWithDevice(final IDevice device) throws MojoExecutionException {
  33
+                    getLog().info(DeviceHelper.getDescriptiveNameWithStatus(device));
  34
+                }
  35
+            }
  36
+        );
  37
+    }
  38
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.