From 2f411f821a8fa84602f2edc1aef0c9487257b53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Mon, 16 Oct 2023 15:51:25 +0200 Subject: [PATCH] chore: Fix conflicts --- app/build.gradle.kts | 8 +- .../databroker/JavaDataBrokerEngine.java | 7 +- .../kuksa/testapp/KuksaDataBrokerActivity.kt | 2 - .../testapp/databroker/DataBrokerEngine.kt | 2 + .../databroker/KotlinDataBrokerEngine.kt | 2 - .../view/DataBrokerConnectionView.kt | 4 +- .../testapp/databroker/view/DataBrokerView.kt | 214 +----------------- .../viewmodel/ConnectionViewModel.kt | 4 +- .../kuksa/kotest/KotestProjectConfig.kt | 31 --- .../kotlin/org/eclipse/kuksa/kotest/Tag.kt | 32 --- .../kuksa/test/kotest/KotestProjectConfig.kt | 4 - .../java/org/eclipse/kuksa/test/kotest/Tag.kt | 4 - 12 files changed, 13 insertions(+), 301 deletions(-) delete mode 100644 kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt delete mode 100644 kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e32f5d1f..ca15503c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -90,15 +90,9 @@ tasks.withType().configureEach { } } -plugins { - id("com.android.application") - kotlin("plugin.serialization") version "1.9.0" - kotlin("android") -} - dependencies { implementation(project(":kuksa-sdk")) - ksp(project(":vss-processor")) + ksp(project(":vss-processor")) testImplementation(project(":test")) implementation(libs.androidx.appcompat) diff --git a/app/src/main/java/org/eclipse/kuksa/testapp/databroker/JavaDataBrokerEngine.java b/app/src/main/java/org/eclipse/kuksa/testapp/databroker/JavaDataBrokerEngine.java index 3803693e..40088427 100644 --- a/app/src/main/java/org/eclipse/kuksa/testapp/databroker/JavaDataBrokerEngine.java +++ b/app/src/main/java/org/eclipse/kuksa/testapp/databroker/JavaDataBrokerEngine.java @@ -38,7 +38,6 @@ import org.eclipse.kuksa.proto.v1.Types.Datapoint; import org.eclipse.kuksa.testapp.databroker.model.Certificate; import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo; -import org.eclipse.kuksa.testapp.extension.AssetManagerExtensionKt; import org.eclipse.kuksa.vsscore.model.VssSpecification; import org.jetbrains.annotations.NotNull; @@ -103,14 +102,18 @@ private void connectSecure( ) { Certificate certificate = connectInfo.getCertificate(); - ChannelCredentials tlsCredentials = null; + ChannelCredentials tlsCredentials; try { InputStream rootCertFile = context.getContentResolver().openInputStream(certificate.getUri()); + if (rootCertFile == null) return; + tlsCredentials = TlsChannelCredentials.newBuilder() .trustManager(rootCertFile) .build(); } catch (IOException e) { Log.w(TAG, "Could not find file for certificate: " + certificate); + + return; } try { diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt index b0e54829..706aef7c 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt @@ -50,8 +50,6 @@ import org.eclipse.kuksa.testapp.databroker.viewmodel.TopAppBarViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.VSSPropertiesViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.VssSpecificationsViewModel import org.eclipse.kuksa.testapp.extension.TAG -import org.eclipse.kuksa.testapp.extension.valueType -import org.eclipse.kuksa.testapp.model.ConnectionInfo import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme import org.eclipse.kuksa.vsscore.annotation.VssDefinition diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/DataBrokerEngine.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/DataBrokerEngine.kt index 128b9210..8693c273 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/DataBrokerEngine.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/DataBrokerEngine.kt @@ -46,6 +46,8 @@ interface DataBrokerEngine { callback: CoroutineCallback, ) + fun fetch(specification: T, callback: CoroutineCallback) + fun update( property: Property, datapoint: Datapoint, diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/KotlinDataBrokerEngine.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/KotlinDataBrokerEngine.kt index 6922c3c5..7f1f1169 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/KotlinDataBrokerEngine.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/KotlinDataBrokerEngine.kt @@ -40,9 +40,7 @@ import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse import org.eclipse.kuksa.proto.v1.Types.Datapoint import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo -import org.eclipse.kuksa.testapp.extension.open import org.eclipse.kuksa.vsscore.model.VssSpecification -import org.eclipse.kuksa.testapp.model.ConnectionInfo import java.io.IOException @Suppress("complexity:TooManyFunctions") diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerConnectionView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerConnectionView.kt index 3bec4a55..1813bbef 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerConnectionView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerConnectionView.kt @@ -50,10 +50,12 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle +import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.* +import org.eclipse.kuksa.testapp.extension.compose.Headline +import org.eclipse.kuksa.testapp.extension.compose.rememberCountdown import org.eclipse.kuksa.testapp.extension.fetchFileName -import org.eclipse.kuksa.testapp.model.ConnectionInfo import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository @OptIn(ExperimentalComposeUiApi::class) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt index 14e276c1..44c693aa 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt @@ -19,9 +19,7 @@ package org.eclipse.kuksa.testapp.databroker.view -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut +import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -73,12 +71,8 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.launch import org.eclipse.kuksa.proto.v1.Types.Datapoint.ValueCase -import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.* import org.eclipse.kuksa.testapp.databroker.viewmodel.OutputViewModel @@ -90,7 +84,6 @@ import org.eclipse.kuksa.testapp.extension.compose.Headline import org.eclipse.kuksa.testapp.extension.compose.LazyDropdownMenu import org.eclipse.kuksa.testapp.extension.compose.OverflowMenu import org.eclipse.kuksa.testapp.extension.compose.SimpleExposedDropdownMenuBox -import org.eclipse.kuksa.testapp.extension.compose.rememberCountdown import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme @@ -196,211 +189,6 @@ private fun TopBar( ) } -@OptIn(ExperimentalComposeUiApi::class) -@Composable -fun DataBrokerConnection(viewModel: ConnectionViewModel) { - val keyboardController = LocalSoftwareKeyboardController.current - - val connectionInfoState by viewModel.connectionInfoFlow.collectAsStateWithLifecycle(initialValue = ConnectionInfo()) - - var connectionInfo by remember(connectionInfoState) { - mutableStateOf(connectionInfoState) - } - - Headline("Connection") - Column { - AnimatedVisibility(visible = viewModel.isDisconnected) { - Column { - Row( - Modifier - .fillMaxWidth() - .padding(start = DefaultEdgePadding, end = DefaultEdgePadding), - horizontalArrangement = Arrangement.SpaceEvenly, - ) { - TextField( - value = connectionInfo.host, - onValueChange = { - val newConnectionInfo = connectionInfoState.copy(host = it) - connectionInfo = newConnectionInfo - }, - keyboardActions = KeyboardActions( - onDone = { - viewModel.updateConnectionInfo(connectionInfo) - keyboardController?.hide() - }, - ), - modifier = Modifier - .weight(2f), - singleLine = true, - label = { - Text(text = "Host") - }, - ) - Text( - text = ":", - modifier = Modifier - .padding(start = 5.dp, end = 5.dp) - .align(Alignment.CenterVertically), - ) - TextField( - value = connectionInfo.port.toString(), - onValueChange = { value -> - try { - val port = value.toInt() - val newConnectionInfo = connectionInfo.copy(port = port) - connectionInfo = newConnectionInfo - } catch (e: NumberFormatException) { - // ignore gracefully - } - }, - keyboardActions = KeyboardActions( - onDone = { - viewModel.updateConnectionInfo(connectionInfo) - keyboardController?.hide() - }, - ), - modifier = Modifier - .weight(1f), - singleLine = true, - label = { - Text(text = "Port") - }, - keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), - ) - } - Spacer(modifier = Modifier.padding(top = DefaultElementPadding)) - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(start = DefaultEdgePadding, end = DefaultEdgePadding), - ) { - Text(text = "TLS:") - Checkbox(checked = connectionInfo.isTlsEnabled, onCheckedChange = { isChecked -> - val newConnectionInfo = connectionInfo.copy(isTlsEnabled = isChecked) - viewModel.updateConnectionInfo(newConnectionInfo) - }) - TextField( - value = connectionInfo.certificate.overrideAuthority, - onValueChange = { - val certificate = connectionInfo.certificate.copy(overrideAuthority = it) - val newConnectionInfo = connectionInfo.copy(certificate = certificate) - connectionInfo = newConnectionInfo - }, - keyboardActions = KeyboardActions( - onDone = { - viewModel.updateConnectionInfo(connectionInfo) - keyboardController?.hide() - }, - ), - modifier = Modifier.weight(2f), - singleLine = true, - enabled = connectionInfo.isTlsEnabled, - label = { - Text(text = "Authority override") - }, - ) - } - Spacer(modifier = Modifier.padding(top = DefaultElementPadding)) - } - } - Row( - Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly, - ) { - AnimatedContent( - targetState = viewModel.connectionViewState, - label = "ConnectAnimation", - ) { connectionViewState -> - when (connectionViewState) { - ConnectionViewState.DISCONNECTED -> - Button( - onClick = { - viewModel.onConnect(connectionInfo) - - keyboardController?.hide() - }, - modifier = Modifier.width(MinimumButtonWidth), - ) { - Text(text = "Connect", textAlign = TextAlign.Center) - } - - ConnectionViewState.CONNECTING -> - Button( - onClick = { }, - modifier = Modifier.requiredWidth(MinimumButtonWidth), - ) { - val timeout by rememberCountdown(initialMillis = viewModel.connectionTimeoutMillis) - - @Suppress("MagicNumber") // To seconds - val timeoutSeconds = timeout / 1000 - Text(text = "Connecting... ($timeoutSeconds)", textAlign = TextAlign.Center) - } - - ConnectionViewState.CONNECTED -> - Button( - onClick = { viewModel.onDisconnect() }, - modifier = Modifier.requiredWidth(MinimumButtonWidth), - ) { - Text(text = "Disconnect") - } - } - } - } - } -} - -@Composable -fun OverflowMenu(content: @Composable () -> Unit) { - var showMenu by remember { mutableStateOf(false) } - - IconButton(onClick = { - showMenu = !showMenu - }) { - Icon( - imageVector = Icons.Outlined.MoreVert, - contentDescription = "Options", - ) - } - DropdownMenu( - expanded = showMenu, - onDismissRequest = { showMenu = false }, - ) { - content() - } -} - -@Composable -fun Headline(name: String, modifier: Modifier = Modifier, color: Color = Color.Black) { - Text( - text = name, - modifier = modifier - .fillMaxWidth() - .padding(top = 15.dp, bottom = 15.dp), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.titleLarge, - color = color, - ) -} - -@Composable -fun rememberCountdown( - initialMillis: Long, - step: Long = 1000, -): MutableState { - val timeLeft = remember { mutableStateOf(initialMillis) } - - LaunchedEffect(initialMillis, step) { - while (isActive && timeLeft.value > 0) { - val newTimeLeft = (timeLeft.value - step).coerceAtLeast(0) - timeLeft.value = newTimeLeft - - val maximumDelay = step.coerceAtMost(newTimeLeft) - delay(maximumDelay) - } - } - - return timeLeft -} - @Composable fun DataBrokerSpecifications(viewModel: VssSpecificationsViewModel) { Column { diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/ConnectionViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/ConnectionViewModel.kt index 20c5d1fd..3a3168ed 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/ConnectionViewModel.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/ConnectionViewModel.kt @@ -19,16 +19,13 @@ package org.eclipse.kuksa.testapp.databroker.viewmodel -import android.app.Application import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableLongStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.compose.runtime.snapshotFlow import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.launch import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo @@ -76,6 +73,7 @@ class ConnectionViewModel(private val connectionInfoRepository: ConnectionInfoRe override fun create(modelClass: Class): T { return ConnectionViewModel(connectionInfoRepository) as T } + } companion object { private const val TIMEOUT_DEFAULT = 5_000L diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt deleted file mode 100644 index 89e265bf..00000000 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -<<<<<<<< HEAD:kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt -package org.eclipse.kuksa.kotest -======== -package org.eclipse.kuksa.test.kotest ->>>>>>>> Eclipse/main:test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt - -import io.kotest.core.config.AbstractProjectConfig - -// https://kotest.io/docs/framework/project-config.html -object KotestProjectConfig : AbstractProjectConfig() { - override var displayFullTestPath: Boolean? = true -} diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt deleted file mode 100644 index 41a40a59..00000000 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -<<<<<<<< HEAD:kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt -package org.eclipse.kuksa.kotest -======== -package org.eclipse.kuksa.test.kotest ->>>>>>>> Eclipse/main:test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt - -import io.kotest.core.NamedTag - -val Integration = NamedTag("Integration") -val Unit = NamedTag("Unit") - -val Secure = NamedTag("Secure") -val Insecure = NamedTag("Insecure") diff --git a/test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt b/test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt index 89e265bf..3e27f46b 100644 --- a/test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt +++ b/test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt @@ -17,11 +17,7 @@ * */ -<<<<<<<< HEAD:kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/KotestProjectConfig.kt -package org.eclipse.kuksa.kotest -======== package org.eclipse.kuksa.test.kotest ->>>>>>>> Eclipse/main:test/src/main/java/org/eclipse/kuksa/test/kotest/KotestProjectConfig.kt import io.kotest.core.config.AbstractProjectConfig diff --git a/test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt b/test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt index 41a40a59..ca7cc805 100644 --- a/test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt +++ b/test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt @@ -17,11 +17,7 @@ * */ -<<<<<<<< HEAD:kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/kotest/Tag.kt -package org.eclipse.kuksa.kotest -======== package org.eclipse.kuksa.test.kotest ->>>>>>>> Eclipse/main:test/src/main/java/org/eclipse/kuksa/test/kotest/Tag.kt import io.kotest.core.NamedTag