Skip to content

Commit 9432423

Browse files
committed
Merge branch 'feature/migrate_from_spring_to_dagger2' into develop
2 parents 9cce19d + 5a61f74 commit 9432423

38 files changed

+643
-338
lines changed

pom.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<version>0.0.10s-SNAPSHOT</version>
77
<name>Android Screencast</name>
88
<properties>
9-
<spring.version>4.3.6.RELEASE</spring.version>
9+
<dagger2.version>2.9</dagger2.version>
1010
<ddmlib.version>25.2.0</ddmlib.version>
11-
<slf4j.version>1.7.22</slf4j.version>
11+
<slf4j.version>1.7.24</slf4j.version>
1212
<logback-classic.version>1.2.1</logback-classic.version>
1313
<guava.version>21.0</guava.version>
1414
<main.class>com.github.xsavikx.androidscreencast.Main</main.class>
@@ -41,15 +41,16 @@
4141
<version>${slf4j.version}</version>
4242
</dependency>
4343
<dependency>
44-
<groupId>org.springframework</groupId>
45-
<artifactId>spring-context</artifactId>
46-
<version>${spring.version}</version>
47-
<exclusions>
48-
<exclusion>
49-
<groupId>commons-logging</groupId>
50-
<artifactId>commons-logging</artifactId>
51-
</exclusion>
52-
</exclusions>
44+
<groupId>com.google.dagger</groupId>
45+
<artifactId>dagger</artifactId>
46+
<version>${dagger2.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.google.dagger</groupId>
50+
<artifactId>dagger-compiler</artifactId>
51+
<version>${dagger2.version}</version>
52+
<optional>true</optional>
53+
<scope>provided</scope>
5354
</dependency>
5455
<dependency>
5556
<groupId>com.google.guava</groupId>
@@ -82,7 +83,7 @@
8283
<plugin>
8384
<groupId>org.apache.maven.plugins</groupId>
8485
<artifactId>maven-shade-plugin</artifactId>
85-
<version>2.4.3</version>
86+
<version>3.0.0</version>
8687
<executions>
8788
<execution>
8889
<phase>package</phase>

src/main/java/com/github/xsavikx/androidscreencast/Main.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.github.xsavikx.androidscreencast;
22

3-
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
43
import com.github.xsavikx.androidscreencast.app.Application;
5-
import com.github.xsavikx.androidscreencast.spring.config.ApplicationContextProvider;
4+
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
87

@@ -13,9 +12,8 @@ public class Main {
1312

1413
public static void main(String args[]) {
1514
LOGGER.debug("main(String[] args={}) - start", Arrays.toString(args));
16-
Application application;
1715
try {
18-
application = ApplicationContextProvider.getBean(AndroidScreencastApplication.class);
16+
Application application = MainComponentProvider.mainComponent().application();
1917
application.init();
2018
application.start();
2119
} finally {

src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,62 @@
99
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
12-
import org.springframework.beans.factory.annotation.Autowired;
13-
import org.springframework.stereotype.Component;
1412

13+
import javax.inject.Inject;
14+
import javax.inject.Singleton;
1515
import java.io.ByteArrayOutputStream;
1616
import java.io.File;
1717
import java.lang.reflect.Method;
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
@Component
21+
@Singleton
2222
public class AndroidDeviceImpl implements AndroidDevice {
2323
private static final Logger LOGGER = LoggerFactory.getLogger(AndroidDeviceImpl.class);
2424
private final IDevice device;
2525

26-
@Autowired
27-
public AndroidDeviceImpl(IDevice device) {
26+
@Inject
27+
public AndroidDeviceImpl(final IDevice device) {
2828
this.device = device;
2929
}
3030

3131
@Override
32-
public String executeCommand(String cmd) {
32+
public String executeCommand(final String cmd) {
3333
if (LOGGER.isDebugEnabled()) {
3434
LOGGER.debug("executeCommand(String) - start");
3535
}
36-
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
36+
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
3737
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
38-
String returnString = new String(bos.toByteArray(), "UTF-8");
38+
final String returnString = new String(bos.toByteArray(), "UTF-8");
3939
if (LOGGER.isDebugEnabled()) {
4040
LOGGER.debug("executeCommand(String) - end");
4141
}
4242
return returnString;
43-
} catch (Exception ex) {
43+
} catch (final Exception ex) {
4444
LOGGER.error("executeCommand(String)", ex);
4545
throw new ExecuteCommandException(cmd);
4646
}
4747
}
4848

4949
@Override
50-
public List<FileInfo> list(String path) {
50+
public List<FileInfo> list(final String path) {
5151
if (LOGGER.isDebugEnabled()) {
5252
LOGGER.debug("list(String) - start");
5353
}
5454

5555
try {
56-
String s = executeCommand("ls -l " + path);
57-
String[] entries = s.split("\r\n");
58-
List<FileInfo> fileInfos = new ArrayList<>();
59-
for (String entry : entries) {
56+
final String s = executeCommand("ls -l " + path);
57+
final String[] entries = s.split("\r\n");
58+
final List<FileInfo> fileInfos = new ArrayList<>();
59+
for (final String entry : entries) {
6060
String[] data = entry.split(" ");
6161
if (data.length < 4)
6262
continue;
6363
String attributes = data[0];
6464
boolean directory = attributes.charAt(0) == 'd';
6565
String name = data[data.length - 1];
6666

67-
FileInfo fi = new FileInfo();
67+
final FileInfo fi = new FileInfo();
6868
fi.attribs = attributes;
6969
fi.directory = directory;
7070
fi.name = name;
@@ -78,14 +78,14 @@ public List<FileInfo> list(String path) {
7878
LOGGER.debug("list(String) - end");
7979
}
8080
return fileInfos;
81-
} catch (Exception ex) {
81+
} catch (final Exception ex) {
8282
LOGGER.error("list(String)", ex);
8383
throw new AndroidScreenCastRuntimeException(ex);
8484
}
8585
}
8686

8787
@Override
88-
public void openUrl(String url) {
88+
public void openUrl(final String url) {
8989
if (LOGGER.isDebugEnabled()) {
9090
LOGGER.debug("openUrl(String) - start");
9191
}
@@ -98,7 +98,7 @@ public void openUrl(String url) {
9898
}
9999

100100
@Override
101-
public void pullFile(String removeFrom, File localTo) {
101+
public void pullFile(final String removeFrom, final File localTo) {
102102
if (LOGGER.isDebugEnabled()) {
103103
LOGGER.debug("pullFile(String, File) - start");
104104
}
@@ -107,12 +107,12 @@ public void pullFile(String removeFrom, File localTo) {
107107
try {
108108
if (device.getSyncService() == null)
109109
throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
110-
Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class,
110+
final Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class,
111111
ISyncProgressMonitor.class);
112112
m.setAccessible(true);
113113
device.getSyncService();
114114
m.invoke(device.getSyncService(), removeFrom, localTo.getAbsolutePath(), SyncService.getNullProgressMonitor());
115-
} catch (Exception ex) {
115+
} catch (final Exception ex) {
116116
LOGGER.error("pullFile(String, File)", ex);
117117

118118
throw new AndroidScreenCastRuntimeException(ex);
@@ -124,7 +124,7 @@ public void pullFile(String removeFrom, File localTo) {
124124
}
125125

126126
@Override
127-
public void pushFile(File localFrom, String remoteTo) {
127+
public void pushFile(final File localFrom, final String remoteTo) {
128128
if (LOGGER.isDebugEnabled()) {
129129
LOGGER.debug("pushFile(File, String) - start");
130130
}
@@ -135,7 +135,7 @@ public void pushFile(File localFrom, String remoteTo) {
135135

136136
device.getSyncService().pushFile(localFrom.getAbsolutePath(), remoteTo, SyncService.getNullProgressMonitor());
137137

138-
} catch (Exception ex) {
138+
} catch (final Exception ex) {
139139
LOGGER.error("pushFile(File, String)", ex);
140140

141141
throw new AndroidScreenCastRuntimeException(ex);

src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,52 @@
33
import com.android.ddmlib.AndroidDebugBridge;
44
import com.android.ddmlib.IDevice;
55
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
6-
import org.springframework.beans.factory.annotation.Value;
7-
import org.springframework.stereotype.Service;
8-
import org.springframework.util.StringUtils;
6+
import com.github.xsavikx.androidscreencast.util.StringUtils;
97

10-
import javax.annotation.PreDestroy;
8+
import javax.inject.Inject;
9+
import javax.inject.Named;
10+
import javax.inject.Singleton;
1111
import java.io.IOException;
1212

13-
@Service
13+
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY;
14+
15+
@Singleton
1416
public class AndroidDebugBridgeWrapper {
15-
@Value("${adb.path:}")
16-
private String adbPath;
17+
private final String adbPath;
1718
private AndroidDebugBridge adb;
1819

20+
@Inject
21+
public AndroidDebugBridgeWrapper(@Named(ADB_PATH_KEY) String adbPath) {
22+
this.adbPath = adbPath;
23+
}
24+
1925
public IDevice[] getDevices() {
20-
init();
21-
return adb.getDevices();
26+
return getAdb().getDevices();
2227
}
2328

2429
public boolean hasInitialDeviceList() {
25-
init();
26-
return adb.hasInitialDeviceList();
30+
return getAdb().hasInitialDeviceList();
2731
}
2832

29-
30-
@PreDestroy
31-
void cleanUp() {
33+
public void stop() {
3234
AndroidDebugBridge.disconnectBridge();
3335
AndroidDebugBridge.terminate();
3436
}
3537

38+
private AndroidDebugBridge getAdb() {
39+
if (adb == null) {
40+
init();
41+
}
42+
return adb;
43+
}
44+
3645
private void init() {
3746
if (adb != null) {
3847
return;
3948
}
4049
try {
4150
AndroidDebugBridge.initIfNeeded(false);
42-
if (!StringUtils.isEmpty(adbPath)) {
51+
if (StringUtils.isNotEmpty(adbPath)) {
4352
adb = AndroidDebugBridge.createBridge(adbPath, false);
4453
} else {
4554
adb = AndroidDebugBridge.createBridge();

src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@
99
import com.github.xsavikx.androidscreencast.api.injector.MultiLineReceiverPrinter;
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
12-
import org.springframework.beans.factory.annotation.Autowired;
13-
import org.springframework.beans.factory.annotation.Value;
14-
import org.springframework.stereotype.Service;
1512

13+
import javax.inject.Inject;
14+
import javax.inject.Named;
15+
import javax.inject.Singleton;
1616
import java.io.IOException;
1717
import java.util.concurrent.TimeUnit;
1818

19-
@Service
19+
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
20+
21+
@Singleton
2022
public class ShellCommandExecutor implements CommandExecutor {
2123
private static final Logger LOGGER = LoggerFactory.getLogger(ShellCommandExecutor.class);
2224
private final IDevice device;
2325
private final MultiLineReceiverPrinter multiLineReceiverPrinter;
24-
@Value("${adb.command.timeout:5}")
25-
private long adbCommandTimeout;
26+
private final long adbCommandTimeout;
2627

27-
@Autowired
28-
public ShellCommandExecutor(IDevice device, MultiLineReceiverPrinter multiLineReceiverPrinter) {
28+
@Inject
29+
public ShellCommandExecutor(final IDevice device,
30+
final MultiLineReceiverPrinter multiLineReceiverPrinter,
31+
@Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) {
2932
this.device = device;
3033
this.multiLineReceiverPrinter = multiLineReceiverPrinter;
34+
this.adbCommandTimeout = adbCommandTimeout;
3135
}
3236

3337
@Override

src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/AdbInputCommandFactory.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,45 @@
66
import com.github.xsavikx.androidscreencast.api.injector.InputKeyEvent;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9-
import org.springframework.stereotype.Service;
109

11-
@Service
12-
public final class AdbInputCommandFactory {
10+
import javax.inject.Inject;
11+
import javax.inject.Singleton;
12+
13+
@Singleton
14+
public class AdbInputCommandFactory implements InputCommandFactory {
1315
private static final Logger LOGGER = LoggerFactory.getLogger(AdbInputCommandFactory.class);
1416

15-
public static KeyCommand getKeyCommand(int keyCode) {
16-
KeyCommand returnKeyCommand = new KeyCommand(keyCode);
17-
LOGGER.debug(String.valueOf(returnKeyCommand));
18-
return returnKeyCommand;
19-
}
17+
@Inject
18+
public AdbInputCommandFactory() {
2019

21-
public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent) {
22-
KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent);
23-
LOGGER.debug(String.valueOf(returnKeyCommand));
24-
return returnKeyCommand;
2520
}
2621

27-
28-
public static KeyCommand getKeyCommand(int keyCode, boolean longpress) {
29-
KeyCommand returnKeyCommand = new KeyCommand(keyCode, longpress);
22+
@Override
23+
public KeyCommand getKeyCommand(final int keyCode) {
24+
final KeyCommand returnKeyCommand = new KeyCommand(keyCode);
3025
LOGGER.debug(String.valueOf(returnKeyCommand));
3126
return returnKeyCommand;
3227
}
3328

34-
public static KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
35-
KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress);
29+
@Override
30+
public KeyCommand getKeyCommand(final InputKeyEvent inputKeyEvent, final boolean longpress) {
31+
final KeyCommand returnKeyCommand = new KeyCommand(inputKeyEvent, longpress);
3632
LOGGER.debug(String.valueOf(returnKeyCommand));
3733
return returnKeyCommand;
3834
}
3935

40-
public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration) {
41-
SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2, duration);
42-
LOGGER.debug(String.valueOf(returnSwipeCommand));
43-
return returnSwipeCommand;
44-
}
45-
46-
public static SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2) {
47-
SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2);
36+
@Override
37+
public SwipeCommand getSwipeCommand(final int x1, final int y1, final int x2, final int y2, final long duration) {
38+
final SwipeCommand returnSwipeCommand = new SwipeCommand(x1, y1, x2, y2, duration);
4839
LOGGER.debug(String.valueOf(returnSwipeCommand));
4940
return returnSwipeCommand;
5041
}
5142

52-
public static TapCommand getTapCommand(int x, int y) {
53-
TapCommand returnTapCommand = new TapCommand(x, y);
43+
@Override
44+
public TapCommand getTapCommand(final int x, final int y) {
45+
final TapCommand returnTapCommand = new TapCommand(x, y);
5446
LOGGER.debug(String.valueOf(returnTapCommand));
5547
return returnTapCommand;
5648
}
49+
5750
}

0 commit comments

Comments
 (0)