Skip to content

Commit 763cdd2

Browse files
Issue KasperskyLab#133 fix detekt
Signed-off-by: Ruslan Mingalievv <[email protected]>
1 parent e5e46a7 commit 763cdd2

File tree

12 files changed

+65
-36
lines changed

12 files changed

+65
-36
lines changed

adb-server/common/src/main/java/com/kaspresky/adbserver/log/LoggerFactory.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ object LoggerFactory {
3535
if (logPolicy == LogPolicy.DEBUG_CUT) FullLoggerOptimiser(fullLogger) else fullLogger
3636
return LoggerImpl(fullLoggerWrapper)
3737
}
38-
3938
}

adb-server/common/src/main/java/com/kaspresky/adbserver/log/fulllogger/LogPolicy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ enum class LogPolicy {
55
DEBUG_FULL,
66
DEBUG_CUT,
77
INFO
8-
}
8+
}

adb-server/common/src/main/java/com/kaspresky/adbserver/log/logger/DesktopLogger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ class DesktopLogger(
66
private val logger: Logger,
77
internal val logPolicy: LogPolicy,
88
internal val desktopName: String
9-
) : Logger by logger
9+
) : Logger by logger

adb-server/connection/src/main/java/com/kaspersky/adbserver/api/ConnectionClientLifecycle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.kaspersky.adbserver.api
33
interface ConnectionClientLifecycle {
44

55
fun onDisconnectedBySocketProblems()
6-
}
6+
}

adb-server/connection/src/main/java/com/kaspersky/adbserver/api/ConnectionServerLifecycle.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ interface ConnectionServerLifecycle {
55
fun onReceivedTask(command: Command)
66
fun onExecutedTask(command: Command, commandResult: CommandResult)
77
fun onDisconnectedBySocketProblems()
8-
9-
}
8+
}

adb-server/connection/src/main/java/com/kaspersky/adbserver/implementation/ConnectionClientImplBySocket.kt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.kaspersky.adbserver.implementation
22

3-
import com.kaspersky.adbserver.api.*
3+
import com.kaspersky.adbserver.api.Command
4+
import com.kaspersky.adbserver.api.CommandResult
5+
import com.kaspersky.adbserver.api.ConnectionClient
6+
import com.kaspersky.adbserver.api.ConnectionClientLifecycle
7+
import com.kaspersky.adbserver.api.ExecutorResultStatus
48
import com.kaspersky.adbserver.implementation.lightsocket.LightSocketWrapperImpl
59
import com.kaspersky.adbserver.implementation.transferring.ExpectedEOFException
610
import com.kaspersky.adbserver.implementation.transferring.ResultMessage
@@ -23,14 +27,18 @@ internal class ConnectionClientImplBySocket(
2327

2428
private var _socket: Socket? = null
2529
private val socket: Socket
26-
get() = _socket ?: throw IllegalStateException("Socket is not initialised. Please call `tryConnect` function at first.")
30+
get() = _socket
31+
?: throw IllegalStateException("Socket is not initialised. Please call `tryConnect` function at first.")
2732

28-
private var _socketMessagesTransferring: SocketMessagesTransferring<ResultMessage<CommandResult>, TaskMessage>? = null
33+
private var _socketMessagesTransferring: SocketMessagesTransferring<ResultMessage<CommandResult>, TaskMessage>? =
34+
null
2935
private val socketMessagesTransferring: SocketMessagesTransferring<ResultMessage<CommandResult>, TaskMessage>
30-
get() = _socketMessagesTransferring ?: throw IllegalStateException("Socket transferring is not initialised. Please call `tryConnect` function at first.")
36+
get() = _socketMessagesTransferring
37+
?: throw IllegalStateException("Socket transferring is not initialised. Please call `tryConnect` function at first.")
3138

3239
private var connectionMaker: ConnectionMaker = ConnectionMaker(logger)
33-
private val commandsInProgress = ConcurrentHashMap<Command, ResultWaiter<ResultMessage<CommandResult>>>()
40+
private val commandsInProgress =
41+
ConcurrentHashMap<Command, ResultWaiter<ResultMessage<CommandResult>>>()
3442

3543
override fun tryConnect() {
3644
logger.d("Start the process")
@@ -66,24 +74,26 @@ internal class ConnectionClientImplBySocket(
6674

6775
private fun handleMessages() {
6876
socketMessagesTransferring.startListening { resultMessage ->
69-
logger.d( "Received resultMessage=$resultMessage")
77+
logger.d("Received resultMessage=$resultMessage")
7078
commandsInProgress[resultMessage.command]?.latchResult(resultMessage)
7179
}
7280
}
7381

7482
private fun tryDisconnectBySocketProblems() {
7583
logger.d("Start the process")
76-
val failureReason = "There was some problem inside a Socket creation process or during a Socket connection. \n" +
77-
"The most possible reason is using of old version of 'desktop.jar'. \n" +
78-
"Please, use the most modern version of 'desktop.jar' located in https://github.com/KasperskyLab/Kaspresso/tree/master/artifacts."
84+
val failureReason =
85+
"There was some problem inside a Socket creation process or during a Socket connection. \n" +
86+
"The most possible reason is using of old version of 'desktop.jar'. \n" +
87+
"Please, use the most modern version of 'desktop.jar' located in https://github.com/KasperskyLab/Kaspresso/tree/master/artifacts."
7988
tryDisconnectCommon(failureReason)
8089
logger.d("The disconnection was completed")
8190
}
8291

8392
override fun tryDisconnect() {
8493
logger.d("Start the process")
85-
val failureReason = "`ConnectionClientImplBySocket.tryDisconnect` function was called earlier. " +
86-
"Please, observe code points and relative logs where this function started."
94+
val failureReason =
95+
"`ConnectionClientImplBySocket.tryDisconnect` function was called earlier. " +
96+
"Please, observe code points and relative logs where this function started."
8797
tryDisconnectCommon(failureReason)
8898
logger.d("The disconnection was completed")
8999
}
@@ -99,8 +109,9 @@ internal class ConnectionClientImplBySocket(
99109
private fun resetCommandsInProgress(failureReason: String) {
100110
for ((adbCommand, resultWaiter) in commandsInProgress) {
101111
val commandResult = CommandResult(ExecutorResultStatus.FAILURE, failureReason)
102-
logger.d("The command=$adbCommand was failed because the socket connection had broken up. \n" +
103-
"Result=$commandResult"
112+
logger.d(
113+
"The command=$adbCommand was failed because the socket connection had broken up. \n" +
114+
"Result=$commandResult"
104115
)
105116
resultWaiter.latchResult(
106117
ResultMessage(

adb-server/connection/src/main/java/com/kaspersky/adbserver/implementation/transferring/ExpectedEOFException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package com.kaspersky.adbserver.implementation.transferring
22

33
import java.io.EOFException
44

5-
class ExpectedEOFException : EOFException()
5+
class ExpectedEOFException : EOFException()

adb-server/connection/src/main/java/com/kaspersky/adbserver/implementation/transferring/SocketMessagesTransferring.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ internal class SocketMessagesTransferring<ReceiveModel, SendModel> private const
9696
return
9797
}
9898
if (exception is EOFException) {
99-
logger.d("EOFException occurred in Socket inputStream. The most possible reason is the opposite socket just broke up the connection. " +
100-
"Additional info: exception=$exception")
99+
logger.d(
100+
"EOFException occurred in Socket inputStream. The most possible reason is the opposite socket just broke up the connection. " +
101+
"Additional info: exception=$exception"
102+
)
101103
} else {
102104
logger.e(exception)
103105
}

adb-server/desktop-device-connection/src/main/java/com/kaspersky/adbserver/DesktopDeviceSocketConnectionFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package com.kaspersky.adbserver
33
object DesktopDeviceSocketConnectionFactory {
44

55
fun getSockets(
6-
desktopDeviceSocketConnectionType: DesktopDeviceSocketConnectionType): DesktopDeviceSocketConnection {
6+
desktopDeviceSocketConnectionType: DesktopDeviceSocketConnectionType
7+
): DesktopDeviceSocketConnection {
78
return when (desktopDeviceSocketConnectionType) {
89
DesktopDeviceSocketConnectionType.FORWARD -> DesktopDeviceSocketConnectionForwardImpl()
910
DesktopDeviceSocketConnectionType.REVERSE -> throw UnsupportedOperationException("Please implement REVERSE DesktopDeviceSocketConnection")

adb-server/desktop/src/main/java/com/kaspersky/adbserver/DeviceMirror.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ internal class DeviceMirror private constructor(
3636
override fun onReceivedTask(command: Command) {
3737
logger.i("The received command to execute: $command")
3838
}
39+
3940
override fun onExecutedTask(command: Command, commandResult: CommandResult) {
4041
logger.i("The executed command: $command. The result: $commandResult")
4142
}
43+
4244
override fun onDisconnectedBySocketProblems() {
43-
logger.i("The socket connection was interrupted. " +
44-
"The possible reason is killed Kaspresso application on the device")
45+
logger.i(
46+
"The socket connection was interrupted. " +
47+
"The possible reason is killed Kaspresso application on the device"
48+
)
4549
}
4650
}
4751
val connectionServer = ConnectionFactory.createServer(
@@ -80,13 +84,17 @@ internal class DeviceMirror private constructor(
8084
while (isRunning.get()) {
8185
if (!connectionServer.isConnected()) {
8286
try {
83-
logger.d("The attempt to connect to Device. " +
84-
"It may take time because the device can be not ready (for example, a kaspresso test was not started).")
87+
logger.d(
88+
"The attempt to connect to Device. " +
89+
"It may take time because the device can be not ready (for example, a kaspresso test was not started)."
90+
)
8591
if (startScanningTrigger.compareAndSet(false, true)) {
86-
logger.i("Desktop tries to connect to the Device.\n " +
87-
"It may take time because the device can be not ready. Possible reasons:\n " +
88-
"1. A kaspresso test has not been started.\n " +
89-
"2. The device port has not been released because Android OS has some time gap to turn the port state.")
92+
logger.i(
93+
"Desktop tries to connect to the Device.\n " +
94+
"It may take time because the device can be not ready. Possible reasons:\n " +
95+
"1. A kaspresso test has not been started.\n " +
96+
"2. The device port has not been released because Android OS has some time gap to turn the port state."
97+
)
9098
}
9199
connectionServer.tryConnect()
92100
if (connectionServer.isConnected()) {

adb-server/device/src/main/java/com/kaspersky/adbserver/Device.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.kaspersky.adbserver
22

3-
import com.kaspersky.adbserver.api.*
3+
import com.kaspersky.adbserver.api.Command
4+
import com.kaspersky.adbserver.api.CommandResult
5+
import com.kaspersky.adbserver.api.ConnectionClient
6+
import com.kaspersky.adbserver.api.ConnectionClientLifecycle
7+
import com.kaspersky.adbserver.api.ConnectionFactory
8+
import com.kaspersky.adbserver.api.ExecutorResultStatus
49
import com.kaspresky.adbserver.log.logger.Logger
510
import java.util.concurrent.TimeUnit
611
import java.util.concurrent.atomic.AtomicBoolean
@@ -22,8 +27,10 @@ internal class Device private constructor(
2227
)
2328
val connectionClientLifecycle = object : ConnectionClientLifecycle {
2429
override fun onDisconnectedBySocketProblems() {
25-
logger.i("The socket connection was interrupted. " +
26-
"The possible reason is the Desktop was killed")
30+
logger.i(
31+
"The socket connection was interrupted. " +
32+
"The possible reason is the Desktop was killed"
33+
)
2734
}
2835
}
2936
val connectionClient = ConnectionFactory.createClient(
@@ -89,7 +96,9 @@ internal class Device private constructor(
8996
}
9097
}
9198

92-
private inner class WatchdogThread : Thread("Connection watchdog thread from Device to Desktop") {
99+
private inner class WatchdogThread : Thread(
100+
"Connection watchdog thread from Device to Desktop"
101+
) {
93102
override fun run() {
94103
logger.i("WatchdogThread is started from Device to Desktop")
95104
while (isRunning.get()) {

static-analysis/config/detekt/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ complexity:
8686
threshold: 6
8787
NestedBlockDepth:
8888
active: true
89-
threshold: 4
89+
threshold: 5
9090
StringLiteralDuplication:
9191
active: false
9292
excludes: ['**/test/**', '**/androidTest/**', '**/*.Test.kt', '**/*.Spec.kt', '**/*.Spek.kt']

0 commit comments

Comments
 (0)