Skip to content

Commit b98668f

Browse files
committed
refactor(clearly-defined): Bundle coordinate-related code
Move all model code related to coordinates to a new file for a better overview. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 8100dcb commit b98668f

File tree

4 files changed

+90
-88
lines changed

4 files changed

+90
-88
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (C) 2020 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.clients.clearlydefined
21+
22+
import kotlinx.serialization.Serializable
23+
24+
/**
25+
* See https://github.com/clearlydefined/service/blob/b339cb7/schemas/curations-1.0.json#L64-L83 and
26+
* https://docs.clearlydefined.io/using-data#a-note-on-definition-coordinates.
27+
*/
28+
@Serializable(CoordinatesSerializer::class)
29+
data class Coordinates(
30+
/**
31+
* The type of the component. For example, npm, git, nuget, maven, etc. This talks about the shape of the
32+
* component.
33+
*/
34+
val type: ComponentType,
35+
36+
/**
37+
* Where the component can be found. Examples include npmjs, mavencentral, github, nuget, etc.
38+
*/
39+
val provider: Provider,
40+
41+
/**
42+
* Many component systems have namespaces: GitHub orgs, NPM namespace, Maven group id, etc. This segment must be
43+
* supplied. If your component does not have a namespace, use '-' (ASCII hyphen).
44+
*/
45+
val namespace: String? = null,
46+
47+
/**
48+
* The name of the component. Given the mentioned [namespace] segment, this is just the simple name.
49+
*/
50+
val name: String,
51+
52+
/**
53+
* Components typically have some differentiator like a version or commit id. Use that here. If this segment is
54+
* omitted, the latest revision is used (if that makes sense for the provider).
55+
*/
56+
val revision: String? = null
57+
) {
58+
constructor(value: String) : this(value.split('/', limit = 5))
59+
60+
private constructor(parts: List<String>) : this(
61+
type = ComponentType.fromString(parts[0]),
62+
provider = Provider.fromString(parts[1]),
63+
namespace = parts[2].takeUnless { it == "-" },
64+
name = parts[3],
65+
revision = parts.getOrNull(4)
66+
)
67+
68+
override fun toString() = listOfNotNull(type, provider, namespace ?: "-", name, revision).joinToString("/")
69+
}
70+
71+
/**
72+
* See https://github.com/clearlydefined/service/blob/4917725/schemas/definition-1.0.json#L211-L235.
73+
*/
74+
@Serializable
75+
data class SourceLocation(
76+
// The following properties match those of Coordinates, except that the revision is mandatory here.
77+
val type: ComponentType,
78+
val provider: Provider,
79+
val namespace: String? = null,
80+
val name: String,
81+
val revision: String,
82+
83+
val path: String? = null,
84+
val url: String? = null
85+
)
86+
87+
/**
88+
* Convert a [SourceLocation] to a [Coordinates] object.
89+
*/
90+
fun SourceLocation.toCoordinates(): Coordinates = Coordinates(type, provider, namespace, name, revision)

clients/clearly-defined/src/main/kotlin/Curation.kt

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -94,50 +94,3 @@ data class Patch(
9494
val coordinates: Coordinates,
9595
val revisions: Map<String, Curation>
9696
)
97-
98-
/**
99-
* See https://github.com/clearlydefined/service/blob/b339cb7/schemas/curations-1.0.json#L64-L83 and
100-
* https://docs.clearlydefined.io/using-data#a-note-on-definition-coordinates.
101-
*/
102-
@Serializable(CoordinatesSerializer::class)
103-
data class Coordinates(
104-
/**
105-
* The type of the component. For example, npm, git, nuget, maven, etc. This talks about the shape of the
106-
* component.
107-
*/
108-
val type: ComponentType,
109-
110-
/**
111-
* Where the component can be found. Examples include npmjs, mavencentral, github, nuget, etc.
112-
*/
113-
val provider: Provider,
114-
115-
/**
116-
* Many component systems have namespaces: GitHub orgs, NPM namespace, Maven group id, etc. This segment must be
117-
* supplied. If your component does not have a namespace, use '-' (ASCII hyphen).
118-
*/
119-
val namespace: String? = null,
120-
121-
/**
122-
* The name of the component. Given the mentioned [namespace] segment, this is just the simple name.
123-
*/
124-
val name: String,
125-
126-
/**
127-
* Components typically have some differentiator like a version or commit id. Use that here. If this segment is
128-
* omitted, the latest revision is used (if that makes sense for the provider).
129-
*/
130-
val revision: String? = null
131-
) {
132-
constructor(value: String) : this(value.split('/', limit = 5))
133-
134-
private constructor(parts: List<String>) : this(
135-
type = ComponentType.fromString(parts[0]),
136-
provider = Provider.fromString(parts[1]),
137-
namespace = parts[2].takeUnless { it == "-" },
138-
name = parts[3],
139-
revision = parts.getOrNull(4)
140-
)
141-
142-
override fun toString() = listOfNotNull(type, provider, namespace ?: "-", name, revision).joinToString("/")
143-
}

clients/clearly-defined/src/main/kotlin/Definition.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,6 @@ data class LicensedScore(
111111
val texts: Int
112112
)
113113

114-
/**
115-
* See https://github.com/clearlydefined/service/blob/4917725/schemas/definition-1.0.json#L211-L235.
116-
*/
117-
@Serializable
118-
data class SourceLocation(
119-
// The following properties match those of Coordinates, except that the revision is mandatory here.
120-
val type: ComponentType,
121-
val provider: Provider,
122-
val namespace: String? = null,
123-
val name: String,
124-
val revision: String,
125-
126-
val path: String? = null,
127-
val url: String? = null
128-
)
129-
130114
/**
131115
* See https://github.com/clearlydefined/service/blob/4917725/schemas/definition-1.0.json#L236-L253.
132116
*/

clients/clearly-defined/src/main/kotlin/Extensions.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)