From 201e0dea792d0c927ec6c648d2be4b19793d32a9 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 17 Oct 2024 14:32:45 +0200 Subject: [PATCH] refactor(pub): Only use a single shared YAML instance Signed-off-by: Sebastian Schuberth --- .../pub/src/main/kotlin/model/Lockfile.kt | 4 --- .../pub/src/main/kotlin/model/Pubspec.kt | 4 --- .../pub/src/main/kotlin/model/Yaml.kt | 25 +++++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 plugins/package-managers/pub/src/main/kotlin/model/Yaml.kt diff --git a/plugins/package-managers/pub/src/main/kotlin/model/Lockfile.kt b/plugins/package-managers/pub/src/main/kotlin/model/Lockfile.kt index ea360f69c4a8c..75c0790626813 100644 --- a/plugins/package-managers/pub/src/main/kotlin/model/Lockfile.kt +++ b/plugins/package-managers/pub/src/main/kotlin/model/Lockfile.kt @@ -19,8 +19,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.pub.model -import com.charleskorn.kaml.Yaml -import com.charleskorn.kaml.YamlConfiguration import com.charleskorn.kaml.YamlInput import com.charleskorn.kaml.YamlScalar @@ -41,8 +39,6 @@ import kotlinx.serialization.encoding.Decoder import org.ossreviewtoolkit.plugins.packagemanagers.pub.model.PackageInfo.Description -private val YAML = Yaml(configuration = YamlConfiguration(strictMode = false)) - internal fun parseLockfile(lockfile: File) = YAML.decodeFromString(lockfile.readText()) /** diff --git a/plugins/package-managers/pub/src/main/kotlin/model/Pubspec.kt b/plugins/package-managers/pub/src/main/kotlin/model/Pubspec.kt index 50cc8334bbdfc..cf50f79b9db63 100644 --- a/plugins/package-managers/pub/src/main/kotlin/model/Pubspec.kt +++ b/plugins/package-managers/pub/src/main/kotlin/model/Pubspec.kt @@ -19,8 +19,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.pub.model -import com.charleskorn.kaml.Yaml -import com.charleskorn.kaml.YamlConfiguration import com.charleskorn.kaml.YamlInput import com.charleskorn.kaml.YamlMap import com.charleskorn.kaml.YamlNode @@ -44,8 +42,6 @@ import org.ossreviewtoolkit.plugins.packagemanagers.pub.model.Pubspec.HostedDepe import org.ossreviewtoolkit.plugins.packagemanagers.pub.model.Pubspec.PathDependency import org.ossreviewtoolkit.plugins.packagemanagers.pub.model.Pubspec.SdkDependency -private val YAML = Yaml(configuration = YamlConfiguration(strictMode = false)) - internal fun parsePubspec(pubspecFile: File): Pubspec = parsePubspec(pubspecFile.readText()) internal fun parsePubspec(pubspecYaml: String): Pubspec = YAML.decodeFromString(pubspecYaml) diff --git a/plugins/package-managers/pub/src/main/kotlin/model/Yaml.kt b/plugins/package-managers/pub/src/main/kotlin/model/Yaml.kt new file mode 100644 index 0000000000000..469d6febd539a --- /dev/null +++ b/plugins/package-managers/pub/src/main/kotlin/model/Yaml.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 The ORT Project Authors (see ) + * + * 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 + * + * https://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 + * License-Filename: LICENSE + */ + +package org.ossreviewtoolkit.plugins.packagemanagers.pub.model + +import com.charleskorn.kaml.Yaml +import com.charleskorn.kaml.YamlConfiguration + +internal val YAML = Yaml(configuration = YamlConfiguration(strictMode = false))