Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 67e19b3

Browse files
committed
Version 2.84 add read and parsing ADB version
1 parent e5657a5 commit 67e19b3

File tree

7 files changed

+102
-22
lines changed

7 files changed

+102
-22
lines changed

pom.xml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010

1111
<groupId>com.bitbar</groupId>
1212
<artifactId>remote-device-client</artifactId>
13-
<version>0.3.4</version>
13+
<version>2.84</version>
1414
<packaging>jar</packaging>
1515

1616
<properties>
1717
<java.version>1.8</java.version>
18-
<testdroid-api.version>2.78</testdroid-api.version>
19-
<jackson.version>2.9.9</jackson.version>
18+
<testdroid-api.version>2.84</testdroid-api.version>
2019
<cli.version>1.3.1</cli.version>
2120
<jsch.version>0.1.54</jsch.version>
22-
<springboot.version>2.0.4.RELEASE</springboot.version>
23-
<slf4j.version>1.7.13</slf4j.version>
21+
<springboot.version>2.2.0.RELEASE</springboot.version>
2422
</properties>
2523

2624
<dependencies>
@@ -46,25 +44,26 @@
4644
</exclusions>
4745
</dependency>
4846
<dependency>
49-
<groupId>com.fasterxml.jackson.core</groupId>
50-
<artifactId>jackson-databind</artifactId>
51-
<version>${jackson.version}.2</version>
52-
</dependency>
53-
<dependency>
54-
<groupId>com.fasterxml.jackson.core</groupId>
55-
<artifactId>jackson-core</artifactId>
56-
<version>${jackson.version}</version>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-test</artifactId>
49+
<version>${springboot.version}</version>
50+
<scope>test</scope>
51+
<exclusions>
52+
<exclusion>
53+
<groupId>org.junit.vintage</groupId>
54+
<artifactId>junit-vintage-engine</artifactId>
55+
</exclusion>
56+
<exclusion>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-logging</artifactId>
59+
</exclusion>
60+
</exclusions>
5761
</dependency>
5862
<dependency>
5963
<groupId>commons-cli</groupId>
6064
<artifactId>commons-cli</artifactId>
6165
<version>${cli.version}</version>
6266
</dependency>
63-
<dependency>
64-
<groupId>org.slf4j</groupId>
65-
<artifactId>slf4j-log4j12</artifactId>
66-
<version>${slf4j.version}</version>
67-
</dependency>
6867
</dependencies>
6968

7069
<build>

src/main/java/com/bitbar/remotedevice/RemoteDeviceClientMain.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bitbar.remotedevice;
22

3+
import com.bitbar.remotedevice.android.ADBVersionParser;
34
import com.bitbar.remotedevice.android.PortForwardingParameters;
45
import com.bitbar.remotedevice.android.RemoteAndroidDeviceSession;
56
import com.bitbar.remotedevice.api.APIClientManager;
@@ -15,12 +16,15 @@
1516
import org.apache.commons.cli.CommandLine;
1617
import org.apache.commons.cli.HelpFormatter;
1718
import org.apache.commons.cli.ParseException;
19+
import org.apache.commons.io.IOUtils;
1820
import org.slf4j.Logger;
1921
import org.slf4j.LoggerFactory;
2022

23+
import java.io.IOException;
2124
import java.net.InetAddress;
2225
import java.net.InetSocketAddress;
2326
import java.net.ServerSocket;
27+
import java.nio.charset.StandardCharsets;
2428
import java.util.HashMap;
2529
import java.util.Map;
2630
import java.util.Scanner;
@@ -47,6 +51,23 @@ public class RemoteDeviceClientMain {
4751

4852
private static Object keyboardLock = new Object();
4953

54+
private static String ADB_VERSION;
55+
56+
static {
57+
try {
58+
ProcessBuilder ps = new ProcessBuilder("adb", "version");
59+
Process process = ps.start();
60+
String output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8.name());
61+
ADB_VERSION = new ADBVersionParser().parse(output);
62+
process.waitFor();
63+
} catch (IOException | InterruptedException exc) {
64+
LOGGER.error("Error", exc);
65+
System.exit(1);
66+
} finally {
67+
LOGGER.info(String.format("ADB version detected: %s", ADB_VERSION));
68+
}
69+
}
70+
5071
private RemoteDeviceClientMain(CommandLine commandLine) throws RequiredParameterIsEmptyException, APIException {
5172
String cloudUrl = commandLine.getOptionValue(CommandLineParameter.CLOUD_URI.getArgument());
5273
String apiKey = commandLine.getOptionValue(CommandLineParameter.API_KEY.getArgument());
@@ -174,8 +195,7 @@ private void connect(CommandLine commandLine)
174195
private void checkPortFree(int port) throws PortNotFreeException {
175196
try (ServerSocket serverSocket = new ServerSocket()) {
176197
serverSocket.setReuseAddress(false);
177-
serverSocket.bind(new InetSocketAddress(InetAddress.getByName("localhost"),
178-
port));
198+
serverSocket.bind(new InetSocketAddress(InetAddress.getByName("localhost"), port));
179199
} catch (Exception e) {
180200
throw new PortNotFreeException();
181201
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.bitbar.remotedevice.android;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
6+
public class ADBVersionParser {
7+
8+
private static final Pattern ADB_VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+\\.\\d+)");
9+
10+
private static final String UNKNOWN_VERSION = "UNKNOWN";
11+
12+
public String parse(String input) {
13+
Matcher matcher = ADB_VERSION_PATTERN.matcher(input);
14+
return matcher.find() ? matcher.group(1) : UNKNOWN_VERSION;
15+
}
16+
}

src/main/java/com/bitbar/remotedevice/api/APIClientManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import com.testdroid.api.filter.NumberFilterEntry;
1212
import com.testdroid.api.filter.StringFilterEntry;
1313
import com.testdroid.api.model.*;
14+
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
1415
import org.apache.commons.lang3.StringUtils;
1516

1617
import java.util.*;
1718

1819
import static com.bitbar.remotedevice.StaticParameters.DEVICE_SESSIONS_URI;
1920
import static com.bitbar.remotedevice.StaticParameters.RELEASE_DS_URI;
21+
import static com.testdroid.api.dto.MappingKey.LABEL_IDS_ARR;
2022

2123
public class APIClientManager {
2224

@@ -61,8 +63,9 @@ public List<APIDevice> getSupportedDevices() throws APIException {
6163
Context<APIDevice> ctx = new Context<>(APIDevice.class);
6264
ctx.getFilters().add(new ListStringFilterEntry(MappingKey.OS_TYPE, Operand.IN,
6365
Arrays.asList(APIDevice.OsType.ANDROID.getDisplayName(), APIDevice.OsType.IOS.getDisplayName())));
64-
getRemoteSessionsLabelId().ifPresent(val ->
65-
ctx.setExtraParams(Collections.singletonMap(MappingKey.LABEL_IDS_ARR, val)));
66+
getRemoteSessionsLabelId().ifPresent(val -> ctx.setExtraParams(
67+
new HashSetValuedHashMap<>(Collections.singletonMap(LABEL_IDS_ARR, val))
68+
));
6669
ctx.setLimit(0);
6770
List<APISort.SortItem> sortItems = new ArrayList<>();
6871
sortItems.add(new APISort.SortItem(MappingKey.DISPLAY_NAME, APISort.Type.ASC));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.bitbar.remotedevice.android;
2+
3+
import org.apache.commons.io.IOUtils;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.MethodSource;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Arrays;
10+
import java.util.Collection;
11+
12+
import static java.nio.charset.StandardCharsets.UTF_8;
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
class ADBVersionParserTest {
16+
17+
private static Collection<Object[]> data() {
18+
Object[][] data = new Object[][]{
19+
{"1.0.32"},
20+
{"1.0.41"}
21+
};
22+
return Arrays.asList(data);
23+
}
24+
25+
@ParameterizedTest
26+
@MethodSource("data")
27+
void parse(String version) throws IOException{
28+
ADBVersionParser classUnderTest = new ADBVersionParser();
29+
assertThat(classUnderTest.parse(getStringFromFile(version))).isEqualTo(version);
30+
}
31+
32+
private static String getStringFromFile(String version) throws IOException {
33+
try (InputStream inputStream = ADBVersionParserTest.class.getResourceAsStream("/adb-version-output/" + version)) {
34+
return IOUtils.toString(inputStream, UTF_8);
35+
}
36+
}
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Android Debug Bridge version 1.0.32
2+
Revision eac51f2bb6a8-android
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Android Debug Bridge version 1.0.41
2+
Version 28.0.3-5475833
3+
Installed as /usr/local/bin/adb

0 commit comments

Comments
 (0)