From 5672d7c02651d790d3b6c1f34c43dcd7dac6203e Mon Sep 17 00:00:00 2001 From: Robert Haimerl Date: Wed, 3 Apr 2024 11:23:04 +0200 Subject: [PATCH 1/4] Fix creation of Path objects with absolute Windows paths --- .../coko/dsl/CokoCpgIntegrationTest.kt | 19 ++++++++++++++----- .../coko/dsl/cli/CokoOptionGroupTest.kt | 5 +++-- .../coko/dsl/cli/ValidationTest.kt | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt index 10a603410..870080835 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt @@ -34,12 +34,21 @@ import kotlin.test.* @TestInstance(TestInstance.Lifecycle.PER_CLASS) class CokoCpgIntegrationTest { + /** private val sourceFiles = listOfNotNull( CokoCpgIntegrationTest::class.java.classLoader .getResource("IntegrationTests/CokoCpg/Main.java"), CokoCpgIntegrationTest::class.java.classLoader .getResource("IntegrationTests/CokoCpg/SimpleOrder.java") ).map { Path(it.path) }.also { assertEquals(2, it.size) } + */ + + private val sourceFiles = listOfNotNull( + CokoCpgIntegrationTest::class.java.classLoader + .getResource("IntegrationTests/CokoCpg/Main.java"), + CokoCpgIntegrationTest::class.java.classLoader + .getResource("IntegrationTests/CokoCpg/SimpleOrder.java") + ).map { it.toURI().toPath() }.also { assertEquals(2, it.size) } val cpgConfiguration = CPGConfiguration( @@ -72,7 +81,7 @@ class CokoCpgIntegrationTest { .getResource("IntegrationTests/CokoCpg/orderFull.codyze.kts"), CokoCpgIntegrationTest::class.java.classLoader .getResource("IntegrationTests/CokoCpg/followedByFull.codyze.kts") - ).map { Path(it.path) }.also { assertEquals(2, it.size) } + ).map { it.toURI().toPath() }.also { assertEquals(2, it.size) } val cokoConfiguration = CokoConfiguration( @@ -102,7 +111,7 @@ class CokoCpgIntegrationTest { .getResource("IntegrationTests/CokoCpg/followedByTwoFiles/followedByImplementations.codyze.kts"), CokoCpgIntegrationTest::class.java.classLoader .getResource("IntegrationTests/CokoCpg/followedByTwoFiles/followedByModels.codyze.kts") - ).map { Path(it.path) }.also { assertEquals(2, it.size) } + ).map { it.toURI().toPath() }.also { assertEquals(2, it.size) } val cokoConfiguration = CokoConfiguration( @@ -218,7 +227,7 @@ class CokoCpgIntegrationTest { fun `test coko with cpg backend without good findings`() { val specFiles = listOfNotNull( CokoCpgIntegrationTest::class.java.classLoader.getResource("IntegrationTests/CokoCpg/orderFull.codyze.kts"), - ).map { Path(it.path) }.also { assertEquals(1, it.size) } + ).map { it.toURI().toPath() }.also { assertEquals(1, it.size) } val cokoConfiguration = CokoConfiguration( @@ -249,7 +258,7 @@ class CokoCpgIntegrationTest { ) val permutations = fileMap.permutate() for (p in permutations) { - val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip() + val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip() stream.add( Arguments.of( specFiles, @@ -275,7 +284,7 @@ class CokoCpgIntegrationTest { ) val permutations = fileMap.permutate() for (p in permutations) { - val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip() + val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip() stream.add( Arguments.of( specFiles, diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt index 2c16724e1..65a83d63e 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt @@ -26,6 +26,7 @@ import java.nio.file.Path import kotlin.io.path.Path import kotlin.io.path.div import kotlin.io.path.isRegularFile +import kotlin.io.path.toPath import kotlin.streams.asSequence import kotlin.test.* @@ -103,7 +104,7 @@ class CokoOptionGroupTest : KoinTest { val topTestDirResource = CokoOptionGroupTest::class.java.classLoader.getResource("cli-test-directory") assertNotNull(topTestDirResource) - topTestDir = Path(topTestDirResource.path) + topTestDir = topTestDirResource.toURI().toPath() val testDir3SpecResource = CokoOptionGroupTest::class @@ -111,7 +112,7 @@ class CokoOptionGroupTest : KoinTest { .classLoader .getResource("cli-test-directory/dir3-spec") assertNotNull(testDir3SpecResource) - testDir3Spec = Path(testDir3SpecResource.path) + testDir3Spec = testDir3SpecResource.toURI().toPath() allFiles = Files.walk(topTestDir).asSequence().filter { it.isRegularFile() }.toList() } diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/ValidationTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/ValidationTest.kt index ba2b58949..6eba531de 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/ValidationTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/ValidationTest.kt @@ -20,6 +20,7 @@ import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import java.nio.file.Path import kotlin.io.path.Path +import kotlin.io.path.toPath import kotlin.test.assertContains import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -58,7 +59,7 @@ class ValidationTest { .classLoader .getResource("cli-test-directory/dir3-spec") assertNotNull(testDir3SpecResource) - testDir3Spec = Path(testDir3SpecResource.path) + testDir3Spec = testDir3SpecResource.toURI().toPath() } } } From 1291307064ce945bcd36749ed6108a9267bf0844 Mon Sep 17 00:00:00 2001 From: Robert Haimerl Date: Wed, 3 Apr 2024 11:23:48 +0200 Subject: [PATCH 2/4] remove unused import --- .../specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt index 65a83d63e..769533cce 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/cli/CokoOptionGroupTest.kt @@ -23,7 +23,6 @@ import org.koin.test.KoinTest import org.koin.test.junit5.KoinTestExtension import java.nio.file.Files import java.nio.file.Path -import kotlin.io.path.Path import kotlin.io.path.div import kotlin.io.path.isRegularFile import kotlin.io.path.toPath From 0d5846b5cc4b2c7a9ae1761bc8009aa3c29963d3 Mon Sep 17 00:00:00 2001 From: Robert Haimerl Date: Wed, 3 Apr 2024 11:54:09 +0200 Subject: [PATCH 3/4] remove commented out code --- .../coko/dsl/CokoCpgIntegrationTest.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt index 870080835..2762a80a1 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt @@ -34,15 +34,6 @@ import kotlin.test.* @TestInstance(TestInstance.Lifecycle.PER_CLASS) class CokoCpgIntegrationTest { - /** - private val sourceFiles = listOfNotNull( - CokoCpgIntegrationTest::class.java.classLoader - .getResource("IntegrationTests/CokoCpg/Main.java"), - CokoCpgIntegrationTest::class.java.classLoader - .getResource("IntegrationTests/CokoCpg/SimpleOrder.java") - ).map { Path(it.path) }.also { assertEquals(2, it.size) } - */ - private val sourceFiles = listOfNotNull( CokoCpgIntegrationTest::class.java.classLoader .getResource("IntegrationTests/CokoCpg/Main.java"), From 01221682e0c0744050607f8087833c29eca94f24 Mon Sep 17 00:00:00 2001 From: "Wendland, Florian" Date: Wed, 3 Apr 2024 15:57:22 +0200 Subject: [PATCH 4/4] Fix a few more occurrences of resource URL to Path conversions --- .../aisec/codyze/backends/cpg/CpgOptionGroupTest.kt | 13 +++++-------- .../codyze/backends/cpg/FollowsEvaluationTest.kt | 2 +- .../codyze/backends/cpg/ImplementationDslTest.kt | 4 ++-- .../codyze/backends/cpg/NeverEvaluationTest.kt | 4 ++-- .../aisec/codyze/backends/cpg/OnlyEvaluationTest.kt | 2 +- .../de/fraunhofer/aisec/codyze/cli/CodyzeCliTest.kt | 8 ++++---- .../coko/dsl/CokoCpgIntegrationTest.kt | 2 +- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CpgOptionGroupTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CpgOptionGroupTest.kt index 7ebfdfbea..b893e2ab9 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CpgOptionGroupTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/CpgOptionGroupTest.kt @@ -30,10 +30,7 @@ import org.junit.jupiter.params.provider.MethodSource import java.nio.file.Files import java.nio.file.Path import java.util.stream.Stream -import kotlin.io.path.Path -import kotlin.io.path.absolute -import kotlin.io.path.div -import kotlin.io.path.isRegularFile +import kotlin.io.path.* import kotlin.streams.asSequence import kotlin.test.* @@ -223,19 +220,19 @@ class CpgOptionGroupTest { val topTestDirResource = CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory") assertNotNull(topTestDirResource) - topTestDir = Path(topTestDirResource.path) + topTestDir = topTestDirResource.toURI().toPath() assertNotNull(topTestDir) // TODO: why is this necessary val testDir1Resource = CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory/dir1") assertNotNull(testDir1Resource) - testDir1 = Path(testDir1Resource.path) + testDir1 = testDir1Resource.toURI().toPath() assertNotNull(testDir1) val testDir2Resource = CpgOptionGroupTest::class.java.classLoader.getResource("cli-test-directory/dir2") assertNotNull(testDir2Resource) - testDir2 = Path(testDir2Resource.path) + testDir2 = testDir2Resource.toURI().toPath() assertNotNull(testDir2) val testFile1Resource = @@ -244,7 +241,7 @@ class CpgOptionGroupTest { .classLoader .getResource("cli-test-directory/file1.java") assertNotNull(testFile1Resource) - testFile1 = Path(testFile1Resource.path) + testFile1 = testFile1Resource.toURI().toPath() assertNotNull(testFile1) allFiles = Files.walk(topTestDir).asSequence().filter { it.isRegularFile() }.toList() diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/FollowsEvaluationTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/FollowsEvaluationTest.kt index e7067bcd3..231f0b736 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/FollowsEvaluationTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/FollowsEvaluationTest.kt @@ -117,7 +117,7 @@ class FollowsEvaluationTest { val testFileResource = classLoader.getResource("FollowsEvaluationTest/SimpleFollows.java") assertNotNull(testFileResource) - testFile = Path(testFileResource.path) + testFile = testFileResource.toURI().toPath() val fooInstance = FooModel() val barInstance = BarModel() diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/ImplementationDslTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/ImplementationDslTest.kt index 2085ec80d..0dece26f6 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/ImplementationDslTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/ImplementationDslTest.kt @@ -23,7 +23,7 @@ import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.op import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.signature import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test -import kotlin.io.path.Path +import kotlin.io.path.toPath import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -94,7 +94,7 @@ class ImplementationDslTest { val testFileResource = classLoader.getResource("ImplementationDslTest/SimpleJavaFile.java") assertNotNull(testFileResource) - val testFile = Path(testFileResource.path) + val testFile = testFileResource.toURI().toPath() backend = CokoCpgBackend(config = createCpgConfiguration(testFile)) } } diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/NeverEvaluationTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/NeverEvaluationTest.kt index 3b7e2bcad..615c531df 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/NeverEvaluationTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/NeverEvaluationTest.kt @@ -107,11 +107,11 @@ class NeverEvaluationTest { val violationFileResource = classLoader.getResource("NeverEvaluationTest/NeverViolation.java") assertNotNull(violationFileResource) - violationFile = Path(violationFileResource.path) + violationFile = violationFileResource.toURI().toPath() val passFileResource = classLoader.getResource("NeverEvaluationTest/NeverPass.java") assertNotNull(passFileResource) - passFile = Path(passFileResource.path) + passFile = passFileResource.toURI().toPath() } } } diff --git a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/OnlyEvaluationTest.kt b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/OnlyEvaluationTest.kt index 887942276..5b99e2a31 100644 --- a/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/OnlyEvaluationTest.kt +++ b/codyze-backends/cpg/src/test/kotlin/de/fraunhofer/aisec/codyze/backends/cpg/OnlyEvaluationTest.kt @@ -73,7 +73,7 @@ class OnlyEvaluationTest { val testFileResource = classLoader.getResource("OnlyEvaluationTest/SimpleOnly.java") assertNotNull(testFileResource) - testFile = Path(testFileResource.path) + testFile = testFileResource.toURI().toPath() } } } diff --git a/codyze-cli/src/test/kotlin/de/fraunhofer/aisec/codyze/cli/CodyzeCliTest.kt b/codyze-cli/src/test/kotlin/de/fraunhofer/aisec/codyze/cli/CodyzeCliTest.kt index bafee3277..b4f8b913a 100644 --- a/codyze-cli/src/test/kotlin/de/fraunhofer/aisec/codyze/cli/CodyzeCliTest.kt +++ b/codyze-cli/src/test/kotlin/de/fraunhofer/aisec/codyze/cli/CodyzeCliTest.kt @@ -112,7 +112,7 @@ class CodyzeCliTest : KoinTest { val pathConfigFileResource = CodyzeCliTest::class.java.classLoader.getResource("config-files/path-config.json") assertNotNull(pathConfigFileResource) - pathConfigFile = Path(pathConfigFileResource.path) + pathConfigFile = pathConfigFileResource.toURI().toPath() assertTrue(pathConfigFile.exists()) val correctConfigFileResource = @@ -121,19 +121,19 @@ class CodyzeCliTest : KoinTest { .classLoader .getResource("config-files/correct-config.json") assertNotNull(correctConfigFileResource) - correctConfigFile = Path(correctConfigFileResource.path) + correctConfigFile = correctConfigFileResource.toURI().toPath() assertTrue(correctConfigFile.exists()) val specMarkResource = CodyzeCliTest::class.java.classLoader.getResource("config-files/spec/spec.mark") assertNotNull(specMarkResource) - specMark = Path(specMarkResource.path) + specMark = specMarkResource.toURI().toPath() assertTrue(specMark.exists()) val specMark2Resource = CodyzeCliTest::class.java.classLoader.getResource("config-files/spec2.mark") assertNotNull(specMark2Resource) - spec2Mark = Path(specMark2Resource.path) + spec2Mark = specMark2Resource.toURI().toPath() assertTrue(spec2Mark.exists()) } } diff --git a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt index 5a4325b19..810b1be18 100644 --- a/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt +++ b/codyze-specification-languages/coko/coko-dsl/src/test/kotlin/de/fraunhofer/aisec/codyze/specificationLanguages/coko/dsl/CokoCpgIntegrationTest.kt @@ -306,7 +306,7 @@ class CokoCpgIntegrationTest { ) val permutations = fileMap.permutate() for (p in permutations) { - val (specFiles, fileNames) = p.map { Path(it.path) }.map { it to it.fileName }.unzip() + val (specFiles, fileNames) = p.map { it.toURI().toPath() }.map { it to it.fileName }.unzip() stream.add( Arguments.of( specFiles,