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

Add check of release date in the future #1119

Merged
merged 1 commit into from
Jul 11, 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 @@ -598,7 +598,10 @@ internal class PluginCreator private constructor(
registerProblem(PropertyNotSpecified("release-date", descriptorPath))
} else {
try {
LocalDate.parse(releaseDate, releaseDateFormatter)
val date = LocalDate.parse(releaseDate, releaseDateFormatter)
if (date > LocalDate.now().plusDays(5)) {
registerProblem(ReleaseDateInFuture(descriptorPath))
}
} catch (e: DateTimeParseException) {
registerProblem(ReleaseDateWrongFormat(descriptorPath))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ class ReleaseDateWrongFormat(descriptorPath: String) : InvalidDescriptorProblem(
get() = Level.ERROR
}

class ReleaseDateInFuture(descriptorPath: String) : InvalidDescriptorProblem(
descriptorPath = descriptorPath,
detailedMessage = "The <release-date> parameter must be set to a date that is no more than five days in the future from today's date."
) {
override val level
get() = Level.ERROR
}

class UnableToFindTheme(descriptorPath: String, themePath: String) : InvalidDescriptorProblem(
descriptorPath = descriptorPath,
detailedMessage = "The theme description file cannot be found by the path '$themePath'. Ensure the theme description " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class IntelliJPluginCreationResultResolver : PluginCreationResultResolver {
XIncludeResolutionErrors::class,
TooLongPropertyValue::class,
ReleaseDateWrongFormat::class,
ReleaseDateInFuture::class,
UnableToFindTheme::class,
UnableToReadTheme::class,
OptionalDependencyDescriptorCycleProblem::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"com.jetbrains.plugin.structure.intellij.problems.TemplateWordInPluginName": "ignore",
"com.jetbrains.plugin.structure.intellij.problems.ServiceExtensionPointPreloadNotSupported": "warning",
"com.jetbrains.plugin.structure.intellij.problems.InvalidUntilBuildWithJustBranch": "unacceptable-warning",
"com.jetbrains.plugin.structure.intellij.problems.InvalidUntilBuildWithMagicNumber": "unacceptable-warning"
"com.jetbrains.plugin.structure.intellij.problems.InvalidUntilBuildWithMagicNumber": "unacceptable-warning",
"com.jetbrains.plugin.structure.intellij.problems.ReleaseDateInFuture": "warning"
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package com.jetbrains.plugin.structure.mocks

import com.jetbrains.plugin.structure.base.plugin.PluginCreationSuccess
import com.jetbrains.plugin.structure.base.problems.ContainsNewlines
import com.jetbrains.plugin.structure.base.problems.IncorrectZipOrJarFile
import com.jetbrains.plugin.structure.base.problems.MultiplePluginDescriptors
import com.jetbrains.plugin.structure.base.problems.NotBoolean
import com.jetbrains.plugin.structure.base.problems.NotNumber
import com.jetbrains.plugin.structure.base.problems.PluginDescriptorIsNotFound
import com.jetbrains.plugin.structure.base.problems.PluginProblem
import com.jetbrains.plugin.structure.base.problems.PropertyNotSpecified
import com.jetbrains.plugin.structure.base.problems.TooLongPropertyValue
import com.jetbrains.plugin.structure.base.problems.UnableToExtractZip
import com.jetbrains.plugin.structure.base.problems.UnexpectedDescriptorElements
import com.jetbrains.plugin.structure.base.problems.VendorCannotBeEmpty
import com.jetbrains.plugin.structure.base.problems.*
import com.jetbrains.plugin.structure.base.utils.contentBuilder.buildDirectory
import com.jetbrains.plugin.structure.base.utils.contentBuilder.buildZipFile
import com.jetbrains.plugin.structure.base.utils.simpleName
Expand All @@ -28,6 +17,8 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import java.nio.file.Path
import java.nio.file.Paths
import java.time.LocalDate
import java.time.format.DateTimeFormatter

class InvalidPluginsTest(fileSystemType: FileSystemType) : BasePluginManagerTest<IdePlugin, IdePluginManager>(fileSystemType) {
private val DEFAULT_TEMPLATE_NAMES = setOf("Plugin display name here", "My Framework Support", "Template", "Demo")
Expand Down Expand Up @@ -814,6 +805,18 @@ class InvalidPluginsTest(fileSystemType: FileSystemType) : BasePluginManagerTest
NotBoolean("optional", "plugin.xml")
)
)

val releaseDateInFuture = LocalDate.now().plusMonths(1)
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
val releaseDateInFutureString = releaseDateInFuture.format(formatter)
`test invalid plugin xml`(
perfectXmlBuilder.modify {
productDescriptor = """<product-descriptor code="ABC" release-date="$releaseDateInFutureString" release-version="12"/>"""
},
listOf(
ReleaseDateInFuture("plugin.xml")
)
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.slf4j.LoggerFactory
import java.time.LocalDate
import java.time.format.DateTimeFormatter


class ExistingPluginValidationTest : BasePluginTest() {
Expand Down Expand Up @@ -362,6 +364,43 @@ class ExistingPluginValidationTest : BasePluginTest() {
Assert.assertNotNull("Expected 'Service Extension Point Preload Not Supported' plugin error", warning)
}

@Test
fun `internal plugin is built despite having release date in the future because it is remapped`() {
val releaseDateInFuture = LocalDate.now().plusMonths(1)
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
val releaseDateInFutureString = releaseDateInFuture.format(formatter)
val header = ideaPlugin(vendor = "JetBrains")
val delegateResolver = IntelliJPluginCreationResultResolver()

val levelRemappingDefinition = levelRemappingFromClassPathJson().load()
val jetBrainsPluginLevelRemapping = levelRemappingDefinition[JETBRAINS_PLUGIN_REMAPPING_SET]
?: emptyLevelRemapping(JETBRAINS_PLUGIN_REMAPPING_SET)
val problemResolver = JetBrainsPluginCreationResultResolver(
LevelRemappingPluginCreationResultResolver(delegateResolver, error<TemplateWordInPluginName>()),
jetBrainsPluginLevelRemapping)

val result = buildPluginWithResult(problemResolver) {
dir("META-INF") {
file("plugin.xml") {
"""
<idea-plugin>
$header
<product-descriptor code="ABC" release-date="$releaseDateInFutureString" release-version="12"/>
</idea-plugin>
"""
}
}
}
assertThat(result, instanceOf(PluginCreationSuccess::class.java))
val creationSuccess = result as PluginCreationSuccess

assertThat(creationSuccess.unacceptableWarnings.size, `is`(0))
assertThat(creationSuccess.warnings.size, `is`(1))
val warning = creationSuccess.warnings.map { it.unwrapped }.filterIsInstance<ReleaseDateInFuture>()
.singleOrNull()
Assert.assertNotNull("Expected 'ReleaseDateInFuture' plugin warning", warning)
}

private fun pluginOf(header: String): ContentBuilder.() -> Unit = {
dir("META-INF") {
file("plugin.xml") {
Expand Down
Loading