Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "add adbserver plugin and setup publication" #612

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ check_android_30_task:
kvm: true
cpu: 8
memory: 24G
# xfce4 somehow helps to pass "Geolocation" test
install_de_script: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install xfce4 -y
apt-get purge -y pm-utils xscreensaver*
apt-get install xvfb -y
start_de_background_script: |
Xvfb :99 -screen 0 1000x1000x16 &
sleep 5
startxfce4
start_adb_server_background_script:
java -jar artifacts/adbserver-desktop.jar || true
accept_licenses_script:
echo yes | sdkmanager --licenses
install_emulator_script:
Expand All @@ -42,7 +33,7 @@ check_android_30_task:
-no-snapshot
-no-window
assemble_instrumented_tests_script:
cd samples && ./gradlew assembleDebugAndroidTest
./gradlew -PCI=true assembleDebugAndroidTest
wait_for_avd_script:
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 3; done; input keyevent 82'
configure_avd_script: |
Expand All @@ -54,9 +45,7 @@ check_android_30_task:
start_logcat_background_script:
adb logcat > log.log
run_tests_script:
cd samples && ./gradlew connectedDebugAndroidTest
# After we do "adb root" connection is closed for a moment. So first attempt to pull screenshots usually fails
# That's why we make 5 attempts to pull folders
./gradlew -PCI=true connectedDebugAndroidTest
always:
stop_logcat_script: |
if [[ $(adb devices | awk 'NR>1 {print $1}') =~ "emulator.*" ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kaspersky.adbserver.common.log

import com.kaspersky.adbserver.common.log.filterlog.FullLoggerOptimiser
import com.kaspersky.adbserver.common.log.fulllogger.FullLogger
import com.kaspersky.adbserver.common.log.fulllogger.FullLoggerSystemImpl
import com.kaspersky.adbserver.common.log.logger.DesktopLogger
import com.kaspersky.adbserver.common.log.logger.LogLevel
Expand All @@ -13,12 +12,8 @@ import com.kaspersky.adbserver.common.log.logger.LoggerImpl
*/
object LoggerFactory {

fun getDesktopLogger(
logLevel: LogLevel,
desktopName: String,
fullLogger: FullLogger = FullLoggerSystemImpl(logLevel, desktopName, null)
): DesktopLogger {
val logger = getCommonLogger(logLevel, desktopName, fullLogger = fullLogger)
fun getDesktopLogger(logLevel: LogLevel, desktopName: String): DesktopLogger {
val logger = getCommonLogger(logLevel, desktopName)
return DesktopLogger(logger, logLevel, desktopName)
}

Expand All @@ -31,12 +26,8 @@ object LoggerFactory {
fun getDeviceLogger(logLevel: LogLevel): Logger =
getCommonLogger(logLevel)

private fun getCommonLogger(
logLevel: LogLevel,
desktopName: String? = null,
deviceName: String? = null,
fullLogger: FullLogger = FullLoggerSystemImpl(logLevel, desktopName, deviceName)
): Logger {
private fun getCommonLogger(logLevel: LogLevel, desktopName: String? = null, deviceName: String? = null): Logger {
val fullLogger = FullLoggerSystemImpl(logLevel, desktopName, deviceName)
val fullLoggerWrapper =
if (logLevel == LogLevel.DEBUG) FullLoggerOptimiser(originalFullLogger = fullLogger, generateLogs = true) else fullLogger
return LoggerImpl(fullLoggerWrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.kaspersky.adbserver.common.log.fulllogger

import com.kaspersky.adbserver.common.log.logger.LogLevel

interface FullLogger {
internal interface FullLogger {

fun log(
logLevel: LogLevel? = null,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ package com.kaspersky.adbserver.desktop

import com.kaspersky.adbserver.common.api.CommandResult
import com.kaspersky.adbserver.common.api.ExecutorResultStatus
import java.io.File
import java.nio.file.Path
import java.util.concurrent.TimeUnit

/**
* @param workingDir - working directory used to execute any cmd command if null when use default process working directory
*/
class CmdCommandPerformer(
private val desktopName: String,
private val workingDir: Path? = null
internal class CmdCommandPerformer(
private val desktopName: String
) {

companion object {
Expand All @@ -23,8 +17,7 @@ class CmdCommandPerformer(
*/
fun perform(command: String): CommandResult {
val serviceInfo = "The command was executed on desktop=$desktopName"
val workingDir = workingDir?.toFile() ?: File(".")
val process = Runtime.getRuntime().exec(command, emptyArray(), workingDir)
val process = Runtime.getRuntime().exec(command)
try {
if (process.waitFor(EXECUTION_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
val exitCode = process.exitValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.lang.UnsupportedOperationException

internal class CommandExecutorImpl(
private val cmdCommandPerformer: CmdCommandPerformer,
private val adbCommandPerformer: AdbCommandPerformer,
private val deviceName: String,
private val adbServerPort: String?,
private val logger: Logger,
Expand All @@ -21,9 +20,9 @@ internal class CommandExecutorImpl(
return when (command) {
is CmdCommand -> cmdCommandPerformer.perform(command.body)
is AdbCommand -> {
val adbCommand = "${ adbServerPort?.let { "-P $adbServerPort " } ?: "" }-s $deviceName ${command.body}"
logger.d("The created adbCommand=adb $adbCommand")
adbCommandPerformer.perform(adbCommand)
val adbCommand = "$adbPath ${ adbServerPort?.let { "-P $adbServerPort " } ?: "" }-s $deviceName ${command.body}"
logger.d("The created adbCommand=$adbCommand")
cmdCommandPerformer.perform(adbCommand)
}
else -> throw UnsupportedOperationException("The command=$command is unsupported command")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package com.kaspersky.adbserver.desktop
import com.kaspersky.adbserver.common.api.ExecutorResultStatus
import com.kaspersky.adbserver.common.log.LoggerFactory
import com.kaspersky.adbserver.common.log.logger.DesktopLogger
import java.util.concurrent.atomic.AtomicBoolean
import java.util.regex.Pattern
import kotlin.concurrent.thread

class Desktop(
internal class Desktop(
private val cmdCommandPerformer: CmdCommandPerformer,
private val adbCommandPerformer: AdbCommandPerformer,
private val presetEmulators: List<String>,
private val adbServerPort: String?,
private val logger: DesktopLogger,
Expand All @@ -18,52 +15,20 @@ class Desktop(

companion object {
private const val PAUSE_MS = 500L
private val DEVICE_PATTERN = Pattern.compile("^([a-zA-Z0-9\\-:.]+)(\\s+)(device)")
}

private val devices: MutableCollection<DeviceMirror> = mutableListOf()
private var isRunning = AtomicBoolean(false)

/**
* Start Desktop server.
* Blocking current thread while server working
* @throws IllegalStateException - if server already running
*/
fun startDevicesObservingSync() {
if (!isRunning.compareAndSet(false, true)) error("Desktop already running")
startDevicesObservingInternal()
}

/**
* Start Desktop server asynchronously
* @throws IllegalStateException - if server already running
*/
fun startDevicesObservingAsync() {
if (!isRunning.compareAndSet(false, true)) error("Desktop already running")
thread {
startDevicesObservingInternal()
}
}

/**
* Stop Desktop server
* @throws IllegalStateException - if server already stopped
*/
fun stopDevicesObserving() {
if (!isRunning.compareAndSet(true, false)) error("Desktop already stopped")
}

private fun startDevicesObservingInternal() {
fun startDevicesObserving() {
logger.d("start")
while (isRunning.get()) {
while (true) {
val namesOfAttachedDevicesByAdb = getAttachedDevicesByAdb()
namesOfAttachedDevicesByAdb.forEach { deviceName ->
if (devices.find { client -> client.deviceName == deviceName } == null) {
logger.i("New device has been found: $deviceName. Initialize connection to the device...")
val deviceMirror =
DeviceMirror.create(
cmdCommandPerformer,
adbCommandPerformer,
deviceName,
adbServerPort,
LoggerFactory.getDesktopLoggerReflectingDevice(logger, deviceName),
Expand All @@ -84,22 +49,18 @@ class Desktop(
}
Thread.sleep(PAUSE_MS)
}

devices.forEach { client ->
client.stopConnectionToDevice()
}
devices.clear()
}

private fun getAttachedDevicesByAdb(): List<String> {
val commandResult = adbCommandPerformer.perform("devices")
val pattern = Pattern.compile("^([a-zA-Z0-9\\-:.]+)(\\s+)(device)")
val commandResult = cmdCommandPerformer.perform("$adbPath devices")
if (commandResult.status != ExecutorResultStatus.SUCCESS) {
return emptyList()
}
val adbDevicesCommandResult: String = commandResult.description
return adbDevicesCommandResult.lines()
.asSequence()
.map { DEVICE_PATTERN.matcher(it) }
.map { pattern.matcher(it) }
.filter { matcher -> matcher.find() }
.map { matcher -> matcher.group(1) }
.filter { foundEmulator -> presetEmulators.isEmpty() || presetEmulators.contains(foundEmulator) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class DeviceMirror private constructor(

fun create(
cmdCommandPerformer: CmdCommandPerformer,
adbCommandPerformer: AdbCommandPerformer,
deviceName: String,
adbServerPort: String?,
logger: Logger,
Expand All @@ -32,7 +31,6 @@ internal class DeviceMirror private constructor(
DesktopDeviceSocketConnectionFactory.getSockets(DesktopDeviceSocketConnectionType.FORWARD)
val commandExecutor = CommandExecutorImpl(
cmdCommandPerformer,
adbCommandPerformer,
deviceName,
adbServerPort,
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import kotlinx.cli.ArgType
import kotlinx.cli.default
import kotlinx.cli.delimiter
import java.lang.management.ManagementFactory
import java.nio.file.Path

private const val DESKTOP = "Desktop-"
private const val ERROR_EXIT_CODE = -1

// It is assumed that adb is preinstall and available by "adb" keyword
private const val DEFAULT_ADB_PATH = "adb"

Expand Down Expand Up @@ -54,16 +51,14 @@ internal fun main(args: Array<String>) {
desktopLogger.i("Desktop started with arguments: emulators=$emulators, adbServerPort=$port, adbPath=$adbPath")

val cmdCommandPerformer = CmdCommandPerformer(desktopName)
val adbCommandPerformer = AdbCommandPerformer(Path.of(adbPath), cmdCommandPerformer)
val desktop = Desktop(
cmdCommandPerformer = cmdCommandPerformer,
adbCommandPerformer = adbCommandPerformer,
presetEmulators = emulators,
adbServerPort = port,
logger = desktopLogger,
adbPath = adbPath
)
desktop.startDevicesObservingSync()
desktop.startDevicesObserving()
}

private fun getDesktopName(): String {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
enableFeaturePreview("VERSION_CATALOGS")

rootProject.name = "build-logic"

include("android")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 0 additions & 38 deletions kaspresso-plugin/build.gradle.kts

This file was deleted.

This file was deleted.

Loading
Loading