Skip to content

Commit

Permalink
Implement an assortment of various fixes
Browse files Browse the repository at this point in the history
See #526 for more details.
  • Loading branch information
FWDekker committed Jan 16, 2024
1 parent 97c8f66 commit 13af6e6
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 78 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ assignees: FWDekker
<!-- If applicable, add screenshots to help explain your problem. -->

**Version information**
- Randomness version [e.g. 2.7.7]: <!-- Check `Settings -> Plugins` in your IDE and search for `Randomness` -->
- IDE version [e.g. IntelliJ Community 2023.1.3]: <!-- Check `Help -> About` in your IDE -->
- Operating system [e.g. Windows 11, Ubuntu 22.04.2, macOS 13.4.1]: <!-- Use a search engine for help if you don't know -->
- Java version [e.g. 17.0.5, 19.0.2]: <!-- Run `java -version` in a terminal or check https://www.java.com/en/download/help/version_manual.xml -->
- Randomness version [e.g. 3.2.0]: <!-- Check `Settings -> Plugins` in your IDE and search for `Randomness` -->
- IDE version [e.g. IntelliJ Community 2023.3.3]: <!-- Check `Help -> About` in your IDE -->
- Operating system [e.g. Windows 11, Ubuntu 22.04.3, macOS 14.2.1]: <!-- Use a search engine for help if you don't know -->
- Java version [e.g. 17.0.9, 21.0.1]: <!-- Run `java -version` in a terminal or check https://www.java.com/en/download/help/version_manual.xml -->

**Additional context**
<!-- Add any other context about the problem here. -->
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Security policy
The security of Randomness is important to me.
If you find a vulnerability in Randomness, please
[report the vulnerability](https://github.com/FWDekker/mommy/security/advisories/new) as soon as possible.
[report the vulnerability](https://github.com/FWDekker/intellij-randomness/security/advisories/new) as soon as possible.

Please note that Randomness is distinct from IntelliJ and other IDEs developed by JetBrains.
To report a vulnerability in IntelliJ or another JetBrains product, please
Expand Down
44 changes: 22 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ fun properties(key: String) = project.findProperty(key).toString()
/// Plugins
plugins {
// Compilation
id("org.jetbrains.kotlin.jvm") version "1.9.21" // Use latest version, ignoring `gradle.properties`
id("org.jetbrains.kotlin.jvm") version "1.8.0" // Set to latest version compatible with `pluginSinceBuild`, cf. https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
id("org.jetbrains.intellij") version "1.16.1"

// Tests/coverage
id("org.jetbrains.kotlinx.kover") version "0.7.5"

// Static analysis
id("io.gitlab.arturbosch.detekt") version "1.23.4" // See also `gradle.properties`
id("io.gitlab.arturbosch.detekt") version "1.23.4" // cf. `gradle.properties`

// Documentation
id("org.jetbrains.changelog") version "2.2.0"
id("org.jetbrains.dokka") version "1.9.10" // See also `buildscript { dependencies` below and `gradle.properties`
id("org.jetbrains.dokka") version "1.9.10" // cf. `buildscript { dependencies` below and `gradle.properties`
}

buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-base:1.9.10") // See also `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka:versioning-plugin:1.9.10") // See also `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka", "dokka-base", "1.9.10") // cf. `plugins` above and `gradle.properties`
classpath("org.jetbrains.dokka", "versioning-plugin", "1.9.10") // cf. `plugins` above and `gradle.properties`
}
}

Expand All @@ -45,22 +45,22 @@ repositories {
}

dependencies {
implementation("com.fasterxml.uuid:java-uuid-generator:${properties("uuidGeneratorVersion")}")
implementation("com.github.sisyphsu:dateparser:${properties("dateparserVersion")}")
implementation("com.github.curious-odd-man:rgxgen:${properties("rgxgenVersion")}")
implementation("com.vdurmont:emoji-java:${properties("emojiVersion")}")
implementation("org.eclipse.mylyn.github:org.eclipse.egit.github.core:${properties("githubCore")}")
api("org.jetbrains.kotlin:kotlin-reflect")

testImplementation("org.assertj:assertj-swing-junit:${properties("assertjSwingVersion")}")
testRuntimeOnly("org.junit.platform:junit-platform-runner:${properties("junitRunnerVersion")}")
testImplementation("org.junit.vintage:junit-vintage-engine:${properties("junitVersion")}")
testImplementation("io.kotest:kotest-assertions-core:${properties("kotestVersion")}")
testImplementation("io.kotest:kotest-framework-datatest:${properties("kotestVersion")}")
testImplementation("io.kotest:kotest-runner-junit5:${properties("kotestVersion")}")

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:${properties("detektVersion")}")
dokkaHtmlPlugin("org.jetbrains.dokka:versioning-plugin:${properties("dokkaVersion")}")
implementation("com.fasterxml.uuid", "java-uuid-generator", properties("uuidGeneratorVersion"))
implementation("com.github.sisyphsu", "dateparser", properties("dateparserVersion")) {
exclude(group = "org.projectlombok", module = "lombok") // cf. https://github.com/sisyphsu/dateparser/issues/30
}
implementation("com.github.curious-odd-man", "rgxgen", properties("rgxgenVersion"))
implementation("org.eclipse.mylyn.github", "org.eclipse.egit.github.core", properties("githubCore"))

testImplementation("org.assertj", "assertj-swing-junit", properties("assertjSwingVersion"))
testRuntimeOnly("org.junit.platform", "junit-platform-runner", properties("junitRunnerVersion"))
testImplementation("org.junit.vintage", "junit-vintage-engine", properties("junitVersion"))
testImplementation("io.kotest", "kotest-assertions-core", properties("kotestVersion"))
testImplementation("io.kotest", "kotest-framework-datatest", properties("kotestVersion"))
testImplementation("io.kotest", "kotest-runner-junit5", properties("kotestVersion"))

detektPlugins("io.gitlab.arturbosch.detekt", "detekt-formatting", properties("detektVersion"))
dokkaHtmlPlugin("org.jetbrains.dokka", "versioning-plugin", properties("dokkaVersion"))
}


Expand All @@ -74,7 +74,7 @@ tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = properties("javaVersion")
apiVersion = properties("kotlinApiVersion")
apiVersion = properties("kotlinVersion")
languageVersion = properties("kotlinVersion")
}
}
Expand Down
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ pluginVerifierIdeVersions=IC-2023.1.5, IC-2023.2.5, IC-2023.3, CL-2023.1.5, CL-2
# Java version should be the one used by the oldest Randomness-supported version of IntelliJ. See also
# https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html#platformVersions.
#
# * Kotlin
# * `kotlinVersion` is the same as `kotlinApiVersion`.
# * Kotlin version should be bundled stdlib version of oldest supported IntelliJ version. See also
# https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library.
# * Kotlin:
# * Kotlin version should be bundled stdlib version of oldest supported IntelliJ version. See also
# https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library.
# * Ensure the version of the `org.jetbrains.kotlin.jvm` in `build.gradle.kts` is updated accordingly.
javaVersion=17
kotlinVersion=1.8
kotlinApiVersion=1.8

# Dependencies
# * Detekt should also be updated in `plugins` block.
Expand Down
44 changes: 30 additions & 14 deletions src/main/kotlin/com/fwdekker/randomness/ErrorReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import javax.crypto.spec.SecretKeySpec
* Heavily inspired by [Patrick Scheibe's error reporter](https://github.com/halirutan/Wolfram-Language-IntelliJ-Plugin-Archive/tree/e3dd72f9cd344d678ac892aaa7bf59abd84871e8/src/de/halirutan/mathematica/errorreporting).
*/
@Suppress("detekt:MaxLineLength") // Necessary because of the long link in the docs above
class ErrorReporter : ErrorReportSubmitter() {
internal class ErrorReporter : ErrorReportSubmitter() {
/**
* Interacts with GitHub.
*/
Expand Down Expand Up @@ -150,7 +150,7 @@ private class GitHubReporter {
fun report(issueData: IssueData): SubmittedReportInfo =
try {
synchronized(this) {
val duplicate = issueService.pageIssues(repo).flatSequence().firstOrNull(issueData::isDuplicateOf)
val duplicate = issueService.pageIssues(repo).flatSequence().firstOrNull { issueData.isDuplicateOf(it) }

val context: Issue
if (duplicate == null) {
Expand Down Expand Up @@ -241,7 +241,7 @@ private object GitHubScrambler {
* The URL at which a newer token may be available.
*/
private val URL =
URL("http://raw.githubusercontent.com/FWDekker/intellij-randomness/main/src/main/resources/reporter/token.bin")
URL("https://raw.githubusercontent.com/FWDekker/intellij-randomness/main/src/main/resources/reporter/token.bin")


/**
Expand Down Expand Up @@ -340,16 +340,27 @@ private class IssueData(
*/
val body: String =
emptySequence<Pair<String, String>>()
.plus("User-supplied comments" to additionalInfo.ifNullOrBlank { "_No comments supplied._" }.trim())
.plus(
Bundle("reporter.issue.body.comments.title") to
additionalInfo.ifNullOrBlank { italic(Bundle("reporter.issue.body.comments.body_empty")) }.trim()
)
.plus(
events
.map { it.throwableText }
.filterNot { it.isBlank() }
.mapIndexed { idx: Int, body: String -> "Stacktrace ${idx + 1}" to spoiler(code(body, "java")) }
.mapIndexed { idx: Int, body: String ->
Bundle("reporter.issue.body.stacktrace.title", idx + 1) to
spoiler(code(body, "java"))
}
)
.plus(
attachments.map {
Bundle("reporter.issue.body.attachment.title", it.name) to
spoiler(code(it.displayText))
}
)
.plus(attachments.map { "Attachment: `${it.name}`" to spoiler(code(it.displayText)) })
.plus(
"Version information" to
Bundle("reporter.issue.body.version.title") to
"""
- Randomness version: ${pluginDescriptor.version ?: "_Unknown_"}
- IDE version: ${ApplicationInfo.getInstance().apiVersion}
Expand All @@ -358,7 +369,7 @@ private class IssueData(
""".trimIndent()
)
.joinToString(separator = "\n\n") { section(it.first, it.second) }
.plus("\n\n---\n\n_This issue report was generated automatically for an anonymous user._")
.let { italic(Bundle("reporter.issue.body.header")) + "\n\n---\n\n" + it }


/**
Expand All @@ -382,6 +393,17 @@ private class IssueData(
* Holds constants.
*/
companion object {
/**
* Creates a Markdown code block containing [body] and using the given [language].
*/
private fun code(body: String, language: String = ""): String =
"```$language\n$body\n```"

/**
* Creates an italicized piece of Markdown.
*/
private fun italic(body: String) = "_${body}_"

/**
* Creates a Markdown section with the given [title] and [body].
*/
Expand All @@ -394,12 +416,6 @@ private class IssueData(
private fun spoiler(body: String, heading: String = "Click to show"): String =
"<details>\n <summary>${heading.trim()}</summary>\n\n${body.prependIndent(" ")}\n\n</details>"

/**
* Creates a Markdown code block containing [body] and using the given [language].
*/
private fun code(body: String, language: String = ""): String =
"```$language\n$body\n```"


/**
* Returns [this] if [this] is neither `null` nor blank, and returns the output of [then] otherwise.
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/com/fwdekker/randomness/InsertAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.options.newEditor.SettingsDialogFactory
import com.intellij.util.alsoIfNull
import javax.swing.Icon


Expand Down Expand Up @@ -66,8 +67,10 @@ abstract class InsertAction(
val project = event.getData(CommonDataKeys.PROJECT) ?: return

configurable?.also {
if (!SettingsDialogFactory.getInstance().create(project, text, it, false, false).showAndGet())
return
SettingsDialogFactory.getInstance()
.create(project, text, it, false, false)
.showAndGet()
.alsoIfNull { return }
}

val data =
Expand All @@ -89,7 +92,7 @@ abstract class InsertAction(
return
}

WriteCommandAction.runWriteCommandAction(project) {
WriteCommandAction.runWriteCommandAction(project, Bundle("misc.insert_command_name"), null, {
editor.caretModel.allCarets.forEachIndexed { i, caret ->
val start = caret.selectionStart
val end = caret.selectionEnd
Expand All @@ -98,7 +101,7 @@ abstract class InsertAction(
editor.document.replaceString(start, end, data[i])
caret.setSelection(start, newEnd)
}
}
})
}


Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/fwdekker/randomness/Notifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.ui.MessageDialogBuilder


/**
* Displays notifications when a project is opened.
*/
class Notifier : StartupActivity {
internal class Notifier : ProjectActivity {
/**
* Shows startup notifications.
*/
override fun runActivity(project: Project) = showWelcomeToV3(project)
override suspend fun execute(project: Project) = showWelcomeToV3(project)

/**
* Shows a notification introducing the user to version 3 of Randomness.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fwdekker/randomness/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ data class Settings(
],
category = SettingsCategory.PLUGINS,
)
class PersistentSettings : PersistentStateComponent<Element> {
internal class PersistentSettings : PersistentStateComponent<Element> {
/**
* The [Settings] that should be persisted.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/fwdekker/randomness/Timely.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Timely {
try {
return executor.submit<T> { generator() }.get(GENERATOR_TIMEOUT, TimeUnit.MILLISECONDS)
} catch (exception: TimeoutException) {
throw DataGenerationException(Bundle("helpers.error.timed_out"), exception)
throw DataGenerationException(Bundle("misc.timed_out"), exception)
} catch (exception: ExecutionException) {
throw DataGenerationException(exception.cause?.message ?: exception.message, exception)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ data class StringScheme(
/**
* The default value of the [capitalization] field.
*/
val DEFAULT_CAPITALIZATION get() = CapitalizationMode.RETAIN
val DEFAULT_CAPITALIZATION = CapitalizationMode.RETAIN

/**
* The default value of the [removeLookAlikeSymbols] field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ open class TemplateActionLoader(
/**
* Constructor-less version of [TemplateActionLoader], as is required in `plugin.xml`.
*/
class DefaultTemplateActionLoader : TemplateActionLoader()
internal class DefaultTemplateActionLoader : TemplateActionLoader()
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.swing.JComponent
*
* @see TemplateSettingsAction
*/
class TemplateListConfigurable : Configurable, Disposable {
internal class TemplateListConfigurable : Configurable, Disposable {
/**
* The user interface for changing the settings, displayed in IntelliJ's settings window.
*/
Expand All @@ -40,7 +40,7 @@ class TemplateListConfigurable : Configurable, Disposable {
/**
* Returns the name of the configurable as displayed in the settings window.
*/
override fun getDisplayName() = "Randomness"
override fun getDisplayName() = Bundle("randomness")

/**
* Creates a new editor and returns the root pane of the created editor.
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<applicationConfigurable parentId="tools"
instance="com.fwdekker.randomness.template.TemplateListConfigurable"
id="com.fwdekker.randomness.template.TemplateListConfigurable"
displayName="Randomness" />
bundle="randomness"
key="randomness" />

<!-- Dynamically loads, unloads, and updates template actions -->
<dynamicActionConfigurationCustomizer
Expand All @@ -30,9 +31,8 @@
</extensions>

<!-- Non-dynamic actions -->
<actions>
<actions resource-bundle="randomness">
<action id="com.fwdekker.randomness.PopupAction" class="com.fwdekker.randomness.PopupAction"
text="Randomness" description="Opens the Randomness popup."
icon="/icons/randomness.svg">
<keyboard-shortcut first-keystroke="alt R" keymap="$default" />
<add-to-group group-id="GenerateGroup" anchor="last" />
Expand Down
Loading

0 comments on commit 13af6e6

Please sign in to comment.