Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty dotnet plugin name if title was empty string #1158

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ReSharperPluginManager private constructor(private val extractDirectory: P
val vendor = if (idParts.size > 1) idParts[0] else null
val authors = authors!!.split(',').map { it.trim() }
val pluginName = when {
title != null -> title!!
title.isNullOrBlank().not() -> title!!
idParts.size > 1 -> idParts[1]
else -> id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.nio.file.Paths
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

class DotNetInvalidPluginTest(fileSystemType: FileSystemType) : BasePluginManagerTest<ReSharperPlugin, ReSharperPluginManager>(fileSystemType) {
class DotNetPluginTest(fileSystemType: FileSystemType) : BasePluginManagerTest<ReSharperPlugin, ReSharperPluginManager>(fileSystemType) {
override fun createManager(extractDirectory: Path) =
ReSharperPluginManager.createManager(extractDirectory)

Expand Down Expand Up @@ -168,11 +168,47 @@ class DotNetInvalidPluginTest(fileSystemType: FileSystemType) : BasePluginManage
)
}

@Test
fun `id as plugin name when empty title`() {
testValidPluginXML(perfectDotNetBuilder.modify {
id = "<id>Vendor.PluginId</id>"
title = "<title></title>"
}) { plugin ->
Assert.assertEquals("PluginId", plugin.pluginName)
}
}

@Test
fun `id as plugin name when null title`() {
testValidPluginXML(perfectDotNetBuilder.modify {
id = "<id>Vendor.PluginId</id>"
title = null
}) { plugin ->
Assert.assertEquals("PluginId", plugin.pluginName)
}
}

@Test
fun `one component id without wave dependency`() {
testValidPluginXML(perfectDotNetBuilder.modify {
id = "<id>PluginId</id>"
title = "<title></title>"
dependencies = "<dependencies><dependency id=\"ReSharper\" version=\"[8.0, 8.3)\" /></dependencies>"
}) { plugin ->
Assert.assertEquals("PluginId", plugin.pluginName)
}
}

private fun `test invalid plugin xml`(pluginXmlContent: String, expectedProblems: List<PluginProblem>) {
val pluginFolder = getTempPluginArchive(pluginXmlContent)
assertProblematicPlugin(pluginFolder, expectedProblems)
}

private fun testValidPluginXML(pluginXmlContent: String, checks: (ReSharperPlugin) -> Unit) {
val pluginFolder = getTempPluginArchive(pluginXmlContent)
checks(createPluginSuccessfully(pluginFolder).plugin)
}

private fun getTempPluginArchive(pluginXmlContent: String): Path {
val pluginFile = temporaryFolder.newFile("archive.nupkg")
ZipOutputStream(Files.newOutputStream(pluginFile)).use {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data class DotNetPluginXmlBuilder(
var dotNetPluginTagOpen: String = "<package><metadata>",
var dotNetPluginTagClose: String = "</metadata></package>",
var id: String = "<id>Vendor.PluginName</id>",
var title: String = "<title>Some title</title>",
var title: String? = "<title>Some title</title>",
var version: String = "<version>10.2.55</version>",
var authors: String = "<authors>JetBrains</authors>",
var owners: String = "<owners>JetBrains</owners>",
Expand All @@ -17,22 +17,22 @@ data class DotNetPluginXmlBuilder(
var dependencies: String = "<dependencies><dependency id=\"ReSharper\" version=\"[8.0, 8.3)\" /><dependency id=\"Wave\"/></dependencies>"
) {

fun asString(): String = """
$dotNetPluginTagOpen
$id
$title
$version
$authors
$owners
$licenseUrl
$projectUrl
$description
$summary
$releaseNotes
$copyright
$dependencies
$dotNetPluginTagClose
"""
fun asString(): String = listOfNotNull(
dotNetPluginTagOpen,
id,
title,
version,
authors,
owners,
licenseUrl,
projectUrl,
description,
summary,
releaseNotes,
copyright,
dependencies,
dotNetPluginTagClose
).joinToString(separator = "\n")
}

val perfectDotNetBuilder: DotNetPluginXmlBuilder = DotNetPluginXmlBuilder().apply {
Expand Down
Loading