Skip to content

Commit

Permalink
refactor(stack): Move the model classes into a dedicated file
Browse files Browse the repository at this point in the history
While at it also extract a function for the parsing of the model.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 1, 2024
1 parent 37f4aa5 commit 1331ef7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
42 changes: 42 additions & 0 deletions plugins/package-managers/stack/src/main/kotlin/Model.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017-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.stack

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.readValue

import org.ossreviewtoolkit.model.jsonMapper

@JsonIgnoreProperties(ignoreUnknown = true)
internal data class Location(
val url: String,
val type: String
)

@JsonIgnoreProperties(ignoreUnknown = true)
internal data class Dependency(
val name: String,
val version: String,
val license: String,
val location: Location? = null,
val dependencies: List<String> = emptyList()
)

internal fun String.parseDependencies() = jsonMapper.readValue<List<Dependency>>(this)
21 changes: 1 addition & 20 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.ossreviewtoolkit.plugins.packagemanagers.stack

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.readValue

import java.io.File
import java.io.IOException

Expand All @@ -42,7 +39,6 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.jsonMapper
import org.ossreviewtoolkit.model.utils.toPurl
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.ProcessCapture
Expand Down Expand Up @@ -79,21 +75,6 @@ class Stack(
) = Stack(type, analysisRoot, analyzerConfig, repoConfig)
}

@JsonIgnoreProperties(ignoreUnknown = true)
private data class Location(
val url: String,
val type: String
)

@JsonIgnoreProperties(ignoreUnknown = true)
private data class Dependency(
val name: String,
val version: String,
val license: String,
val location: Location? = null,
val dependencies: List<String> = emptyList()
)

override fun command(workingDir: File?) = "stack"

override fun transformVersion(output: String) =
Expand Down Expand Up @@ -143,7 +124,7 @@ class Stack(
"ls", "dependencies", "json", "--global-hints", *scopeOptions.toTypedArray()
).stdout

return jsonMapper.readValue(dependenciesJson)
return dependenciesJson.parseDependencies()
}

val allDependencies = mutableSetOf<Dependency>()
Expand Down

0 comments on commit 1331ef7

Please sign in to comment.