From c61e61ee0776b326c0b3503667d8b9b3e94fd2ea Mon Sep 17 00:00:00 2001 From: Florian Wendland Date: Mon, 18 Mar 2024 15:12:20 +0100 Subject: [PATCH] Fix deprecated logging functions (#824) --- .../cpg/coko/evaluators/OrderEvaluator.kt | 2 +- .../aisec/codyze/core/VersionProvider.kt | 2 +- .../aisec/codyze/core/VersionProviderTest.kt | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 codyze-core/src/test/kotlin/de/fraunhofer/aisec/codyze/core/VersionProviderTest.kt diff --git a/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/evaluators/OrderEvaluator.kt b/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/evaluators/OrderEvaluator.kt index 1461ed47f..45de71d39 100644 --- a/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/evaluators/OrderEvaluator.kt +++ b/codyze-backends/cpg/src/main/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/coko/evaluators/OrderEvaluator.kt @@ -116,7 +116,7 @@ class OrderEvaluator(val baseNodes: Collection, val order: Order) : Evalua val usedBases = syntaxTree.filterIsInstanceToList().map { it.baseName }.toSet() if (usedBases.size > 1) { - logger.warn("Order statement contains more than one base. Not supported.") + logger.warn { "Order statement contains more than one base. Not supported." } return emptySet() } diff --git a/codyze-core/src/main/kotlin/de/fraunhofer/aisec/codyze/core/VersionProvider.kt b/codyze-core/src/main/kotlin/de/fraunhofer/aisec/codyze/core/VersionProvider.kt index 95d1879c7..09af745a3 100644 --- a/codyze-core/src/main/kotlin/de/fraunhofer/aisec/codyze/core/VersionProvider.kt +++ b/codyze-core/src/main/kotlin/de/fraunhofer/aisec/codyze/core/VersionProvider.kt @@ -37,7 +37,7 @@ object VersionProvider { if ( !props.containsKey("project.name") || props.getProperty("project.name").lowercase() != "codyze" ) { - logger.warn("Could not find correct version properties file") + logger.warn { "Could not find correct version properties file" } props.clear() } } diff --git a/codyze-core/src/test/kotlin/de/fraunhofer/aisec/codyze/core/VersionProviderTest.kt b/codyze-core/src/test/kotlin/de/fraunhofer/aisec/codyze/core/VersionProviderTest.kt new file mode 100644 index 000000000..5af5d0bf0 --- /dev/null +++ b/codyze-core/src/test/kotlin/de/fraunhofer/aisec/codyze/core/VersionProviderTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. + * + * 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. + */ +package de.fraunhofer.aisec.codyze.core + +import org.junit.jupiter.api.Test +import java.io.FileOutputStream +import java.util.Properties +import kotlin.test.assertEquals + +class VersionProviderTest { + + @Test + fun `test initialisation from properties file with incorrect project name`() { + val properties = Properties() + + /* get the property file and load it; we want to fail if we can't find the property file to begin with */ + val propFile = VersionProvider::class.java.classLoader.getResource("codyze.properties")!! + propFile.openStream().use { + properties.load(it) + } + + // change property s.t. internal check fails + val oldValue = properties.setProperty("project.name", "test") as String + FileOutputStream(propFile.file).use { + properties.store(it, null) + } + + // instantiate `VersionProvider` with altered properties -> properties in VersionProvider should now be empty + val vp = VersionProvider + + // check empty properties through reflection + val vpProps = vp.javaClass.getDeclaredField("props") + .also { it.trySetAccessible() } + .let { it.get(vp) as Properties } + assertEquals(vpProps.size, 0) + + // restore original properties file + properties.setProperty("project.name", oldValue) + FileOutputStream(propFile.file).use { + properties.store(it, null) + } + } +}