Skip to content

Commit 0dbb35c

Browse files
committed
DotNet/NuGet: Move class defintions out of the companion object
It does not really make sense to put class definitions into a static object. Move them to the class level, and also add a documentation link to each. Signed-off-by: Sebastian Schuberth <sebastian.schuberth@here.com>
1 parent e606fa0 commit 0dbb35c

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

analyzer/src/funTest/kotlin/DotNetTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DotNetTest : StringSpec() {
6969

7070
"Definition File is correctly mapped" {
7171
val mapper = XmlMapper().registerKotlinModule()
72-
val result = mapper.readValue<List<DotNet.Companion.ItemGroup>>(packageFile)
72+
val result = mapper.readValue<List<DotNet.ItemGroup>>(packageFile)
7373

7474
result shouldNotBe null
7575
result.size shouldBe 4

analyzer/src/funTest/kotlin/NuGetTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class NuGetTest : StringSpec() {
6969

7070
"Definition File is correctly mapped" {
7171
val mapper = XmlMapper().registerKotlinModule()
72-
val result = mapper.readValue<NuGet.Companion.PackagesConfig>(packageFile)
72+
val result = mapper.readValue<NuGet.PackagesConfig>(packageFile)
7373

7474
result shouldNotBe null
7575
result.packages shouldNotBe null

analyzer/src/main/kotlin/managers/DotNet.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,6 @@ class DotNet(
6666

6767
return map
6868
}
69-
70-
@JsonIgnoreProperties(ignoreUnknown = true)
71-
data class ItemGroup(
72-
@JsonProperty(value = "PackageReference")
73-
@JacksonXmlElementWrapper(useWrapping = false)
74-
val packageReference: List<PackageReference>?
75-
)
76-
77-
@JsonIgnoreProperties(ignoreUnknown = true)
78-
data class PackageReference(
79-
@JacksonXmlProperty(isAttribute = true, localName = "Include")
80-
val include: String?,
81-
@JacksonXmlProperty(isAttribute = true, localName = "Version")
82-
val version: String?
83-
)
8469
}
8570

8671
class Factory : AbstractPackageManagerFactory<DotNet>("DotNet") {
@@ -94,6 +79,22 @@ class DotNet(
9479
DotNet(managerName, analyzerRoot, analyzerConfig, repoConfig)
9580
}
9681

82+
// See https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files.
83+
@JsonIgnoreProperties(ignoreUnknown = true)
84+
data class ItemGroup(
85+
@JsonProperty(value = "PackageReference")
86+
@JacksonXmlElementWrapper(useWrapping = false)
87+
val packageReference: List<PackageReference>?
88+
)
89+
90+
@JsonIgnoreProperties(ignoreUnknown = true)
91+
data class PackageReference(
92+
@JacksonXmlProperty(isAttribute = true, localName = "Include")
93+
val include: String?,
94+
@JacksonXmlProperty(isAttribute = true, localName = "Version")
95+
val version: String?
96+
)
97+
9798
override fun resolveDependencies(definitionFile: File): ProjectAnalyzerResult? {
9899
val workingDir = definitionFile.parentFile
99100
val dotnet = DotNetSupport(mapPackageReferences(definitionFile), workingDir)

analyzer/src/main/kotlin/managers/NuGet.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ class NuGet(
6262

6363
return map
6464
}
65-
66-
@JsonIgnoreProperties(ignoreUnknown = true)
67-
data class PackagesConfig(
68-
@JsonProperty(value = "package")
69-
@JacksonXmlElementWrapper(useWrapping = false)
70-
val packages: List<Package>?
71-
)
72-
73-
@JsonIgnoreProperties(ignoreUnknown = true)
74-
data class Package(
75-
@JacksonXmlProperty(isAttribute = true)
76-
val id: String,
77-
@JacksonXmlProperty(isAttribute = true)
78-
val version: String
79-
)
8065
}
8166

8267
class Factory : AbstractPackageManagerFactory<NuGet>("NuGet") {
@@ -90,6 +75,22 @@ class NuGet(
9075
NuGet(managerName, analyzerRoot, analyzerConfig, repoConfig)
9176
}
9277

78+
// See https://docs.microsoft.com/en-us/nuget/reference/packages-config.
79+
@JsonIgnoreProperties(ignoreUnknown = true)
80+
data class PackagesConfig(
81+
@JsonProperty(value = "package")
82+
@JacksonXmlElementWrapper(useWrapping = false)
83+
val packages: List<Package>?
84+
)
85+
86+
@JsonIgnoreProperties(ignoreUnknown = true)
87+
data class Package(
88+
@JacksonXmlProperty(isAttribute = true)
89+
val id: String,
90+
@JacksonXmlProperty(isAttribute = true)
91+
val version: String
92+
)
93+
9394
override fun resolveDependencies(definitionFile: File): ProjectAnalyzerResult? {
9495
val workingDir = definitionFile.parentFile
9596
val nuget = DotNetSupport(mapPackageReferences(definitionFile), workingDir)

0 commit comments

Comments
 (0)