Skip to content

Commit

Permalink
refactor(pub): Only use a single shared YAML instance
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Oct 21, 2024
1 parent 0efd79b commit 201e0de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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>(lockfile.readText())

/**
Expand Down
4 changes: 0 additions & 4 deletions plugins/package-managers/pub/src/main/kotlin/model/Pubspec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions plugins/package-managers/pub/src/main/kotlin/model/Yaml.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2024 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
*
* 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))

0 comments on commit 201e0de

Please sign in to comment.