Skip to content

Commit a089439

Browse files
1) Added APK Inspector.
2) Updated to java-client 4.1.1. 3) Added methods related to contexts. 4) Follows the Google Java Style as a coding standards.
1 parent 6ab42b1 commit a089439

File tree

21 files changed

+1673
-1536
lines changed

21 files changed

+1673
-1536
lines changed

pom.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.mobilebox.appium.repl</groupId>
55
<artifactId>appium-repl</artifactId>
6-
<version>0.0.1</version>
6+
<version>0.1.0</version>
77
<name>Appium REPL</name>
88
<description>Simple Java REPL (Read-eval-print Loop) for controlling mobile apps through Appium</description>
99

@@ -16,13 +16,17 @@
1616
<id>jitpack.io</id>
1717
<url>https://jitpack.io</url>
1818
</repository>
19+
<repository>
20+
<id>oss.sonatype.org</id>
21+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
22+
</repository>
1923
</repositories>
2024

2125
<dependencies>
2226
<dependency>
2327
<groupId>io.appium</groupId>
2428
<artifactId>java-client</artifactId>
25-
<version>4.0.0</version>
29+
<version>4.1.1</version>
2630
</dependency>
2731

2832
<dependency>
@@ -64,6 +68,18 @@
6468
<version>1.0.8</version>
6569
</dependency>
6670

71+
<dependency>
72+
<groupId>net.dongliu</groupId>
73+
<artifactId>apk-parser</artifactId>
74+
<version>2.1.0</version>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>com.jcabi</groupId>
79+
<artifactId>jcabi-xml</artifactId>
80+
<version>1.0-SNAPSHOT</version>
81+
</dependency>
82+
6783
</dependencies>
6884

6985
<build>

src/main/java/com/mobilebox/repl/Appium.java

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,63 @@
1212
import com.mobilebox.repl.commands.IOSCommands;
1313

1414
/**
15-
* This class acts as entry point to JavaREPL also provides commands that
16-
* basically are wrappers over some Appium methods such as find an element, get
17-
* source, etc.
15+
* This class acts as entry point to JavaREPL also provides commands that basically are wrappers
16+
* over some Appium methods such as find an element, get source, etc.
1817
*
1918
* @see <a href="https://github.com/albertlatacz/java-repl">JavaREPL</a>
2019
*
2120
*/
2221
public class Appium {
2322

24-
public static AndroidCommands android;
25-
public static IOSCommands ios;
26-
27-
static{
28-
android = new AndroidCommands();
29-
ios = new IOSCommands();
30-
}
31-
32-
public static void main(String... args) throws Exception {
33-
welcome();
34-
Main.main(args);
35-
}
23+
public static AndroidCommands android;
24+
public static IOSCommands ios;
3625

37-
private static void welcome(){
38-
console("----------------------------");
39-
console(" :::- Appium Java REPL -::: " + SEPARATOR);
40-
console("Type import static com.mobilebox.repl.Appium.*;" + SEPARATOR);
41-
console("Type help() for more options.");
42-
console("-----------------------------" + SEPARATOR);
43-
}
44-
45-
@CommandRef(desc = "Prints this help.")
46-
public static void help() {
47-
printCommands(Appium.class);
48-
}
49-
50-
@CommandRef(desc = "Quit Appium REPL")
51-
public static void exit() {
52-
System.exit(0);
53-
}
54-
55-
@CommandRef(desc = "Prints all commands available for Android and iOS.")
56-
public static void commands_appium() {
57-
printCommands(AppiumCommands.class);
58-
}
26+
static {
27+
android = new AndroidCommands();
28+
ios = new IOSCommands();
29+
}
5930

60-
@CommandRef(desc = "Prints all commands available especifc for Android.")
61-
public static void commands_android() {
62-
printCommands(AndroidCommands.class);
63-
}
31+
public static void main(String... args) throws Exception {
32+
welcome();
33+
Main.main(args);
34+
}
6435

65-
@CommandRef(desc = "Prints all commands available for iOS.")
66-
public static void commands_ios() {
67-
printCommands(IOSCommands.class);
68-
}
69-
70-
@CommandRef(desc = "Prints all commands available for Android Device.")
71-
public static void commands_android_device() {
72-
printCommands(AndroidDeviceCommands.class);
73-
}
74-
75-
}
36+
private static void welcome() {
37+
console("----------------------------");
38+
console(" :::- Appium Java REPL -::: " + SEPARATOR);
39+
console("Type import static com.mobilebox.repl.Appium.*;" + SEPARATOR);
40+
console("Type help() for more options.");
41+
console("-----------------------------" + SEPARATOR);
42+
}
43+
44+
@CommandRef(desc = "Prints this help.")
45+
public static void help() {
46+
printCommands(Appium.class);
47+
}
48+
49+
@CommandRef(desc = "Quit Appium REPL")
50+
public static void exit() {
51+
System.exit(0);
52+
}
53+
54+
@CommandRef(desc = "Prints all commands available for Android and iOS.")
55+
public static void commands_appium() {
56+
printCommands(AppiumCommands.class);
57+
}
58+
59+
@CommandRef(desc = "Prints all commands available especifc for Android.")
60+
public static void commands_android() {
61+
printCommands(AndroidCommands.class);
62+
}
63+
64+
@CommandRef(desc = "Prints all commands available for iOS.")
65+
public static void commands_ios() {
66+
printCommands(IOSCommands.class);
67+
}
68+
69+
@CommandRef(desc = "Prints all commands available for Android Device.")
70+
public static void commands_android_device() {
71+
printCommands(AndroidDeviceCommands.class);
72+
}
73+
74+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.mobilebox.repl.app;
2+
3+
import static com.google.common.base.Strings.nullToEmpty;
4+
5+
import java.io.File;
6+
import java.util.Locale;
7+
8+
import com.mobilebox.repl.exceptions.CommandsException;
9+
10+
import net.dongliu.apk.parser.ApkParser;
11+
import net.dongliu.apk.parser.bean.ApkMeta;
12+
13+
/**
14+
* A Simple APK inspector.
15+
*/
16+
@SuppressWarnings("resource")
17+
public class APKInspector {
18+
19+
/**
20+
* Retrieve basic apk metas, such as title, icon, package name, version, etc.
21+
*
22+
* @param appPath The app path.
23+
* @return An {@link ApkData} instance.
24+
* @throws CommandsException
25+
*/
26+
public ApkData inspect(final String appPath) throws CommandsException {
27+
File apkFile = new File(appPath);
28+
ApkData app = new ApkData();
29+
30+
if (apkFile.exists()) {
31+
try {
32+
ApkParser parser = new ApkParser(appPath);
33+
parser.setPreferredLocale(Locale.getDefault());
34+
ApkMeta data = parser.getApkMeta();
35+
36+
app.setPackageName(nullToEmpty(data.getPackageName()))
37+
.setLabel(nullToEmpty(data.getLabel()))
38+
.setVersionName(nullToEmpty(data.getVersionName()))
39+
.setMaxSdkVersion(nullToEmpty(data.getMaxSdkVersion()))
40+
.setMinSdkVersion(nullToEmpty(data.getMinSdkVersion()))
41+
.setTargetSdkVersion(nullToEmpty(data.getTargetSdkVersion()))
42+
.setUsesFeature(data.getUsesFeatures())
43+
.setUserPermissions(data.getUsesPermissions());
44+
45+
} catch (Exception e) {
46+
throw new CommandsException("Error: " + e.getMessage());
47+
}
48+
}
49+
50+
return app;
51+
}
52+
53+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package com.mobilebox.repl.app;
2+
3+
import static com.mobilebox.repl.misc.Utils.console;
4+
5+
import java.util.List;
6+
7+
import com.google.gson.Gson;
8+
9+
import net.dongliu.apk.parser.bean.UseFeature;
10+
11+
public class ApkData {
12+
13+
private String packageName;
14+
15+
private String label;
16+
17+
private String icon;
18+
19+
private String versionName;
20+
21+
private String minSdkVersion;
22+
23+
private String targetSdkVersion;
24+
25+
private String maxSdkVersion;
26+
27+
private List<UseFeature> usesFeature;
28+
29+
private List<String> userPermissions;
30+
31+
private List<String> activities;
32+
33+
34+
public String getPackageName() {
35+
return packageName;
36+
}
37+
38+
39+
public ApkData setPackageName(String packageName) {
40+
this.packageName = packageName;
41+
return this;
42+
}
43+
44+
45+
public String getLabel() {
46+
return label;
47+
}
48+
49+
public ApkData setLabel(String label) {
50+
this.label = label;
51+
return this;
52+
}
53+
54+
public String getIcon() {
55+
return icon;
56+
}
57+
58+
59+
public ApkData setIcon(String icon) {
60+
this.icon = icon;
61+
return this;
62+
}
63+
64+
65+
public String getVersionName() {
66+
return versionName;
67+
}
68+
69+
70+
public ApkData setVersionName(String versionName) {
71+
this.versionName = versionName;
72+
return this;
73+
}
74+
75+
public String getMinSdkVersion() {
76+
return minSdkVersion;
77+
}
78+
79+
80+
public ApkData setMinSdkVersion(String minSdkVersion) {
81+
this.minSdkVersion = minSdkVersion;
82+
return this;
83+
}
84+
85+
86+
public String getTargetSdkVersion() {
87+
return targetSdkVersion;
88+
}
89+
90+
91+
public ApkData setTargetSdkVersion(String targetSdkVersion) {
92+
this.targetSdkVersion = targetSdkVersion;
93+
return this;
94+
}
95+
96+
97+
public String getMaxSdkVersion() {
98+
return maxSdkVersion;
99+
}
100+
101+
102+
public ApkData setMaxSdkVersion(String maxSdkVersion) {
103+
this.maxSdkVersion = maxSdkVersion;
104+
return this;
105+
}
106+
107+
108+
public String toJson() {
109+
return new Gson().toJson(this);
110+
}
111+
112+
public List<UseFeature> getUsesFeature() {
113+
return usesFeature;
114+
}
115+
116+
117+
public ApkData setUsesFeature(List<UseFeature> usesFeature) {
118+
this.usesFeature = usesFeature;
119+
return this;
120+
}
121+
122+
public List<String> getUserPermissions() {
123+
return userPermissions;
124+
}
125+
126+
public ApkData setUserPermissions(List<String> userPermissions) {
127+
this.userPermissions = userPermissions;
128+
return this;
129+
}
130+
131+
public List<String> getActivities() {
132+
return activities;
133+
}
134+
135+
public ApkData setActivities(List<String> activities) {
136+
this.activities = activities;
137+
return this;
138+
}
139+
140+
public void toConsole() {
141+
console("---> Package name: " + packageName);
142+
console("---> Label: " + label);
143+
console("---> Version name: " + versionName);
144+
console("---> Min SDK version: " + minSdkVersion);
145+
console("---> Target SDK version: " + targetSdkVersion);
146+
console("---> Max SDK version: " + maxSdkVersion);
147+
console("---> Uses Feature: " + usesFeature);
148+
console("---> Uses Permissions: " + userPermissions);
149+
}
150+
151+
}

0 commit comments

Comments
 (0)