Skip to content

Commit fc87ea0

Browse files
authored
feat: configurations for Spotless Gradle daemon version and jar (#129)
1 parent eabd423 commit fc87ea0

10 files changed

Lines changed: 122 additions & 14 deletions

File tree

.idea/.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scopes/spellcheck.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/SpotlessIntegration/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### Added
88

9+
- configuration options for Spotless Gradle daemon version and
10+
jar [#127](https://github.com/ghostflyby/IntelliJ-Plugins/pull/127)
11+
912
### Changed
1013

1114
### Deprecated
@@ -34,5 +37,7 @@
3437
- Support for automatic code formatting using Spotless.
3538

3639
[Unreleased]: https://github.com/ghostflyby/IntelliJ-Plugins/compare/v0.1.1...HEAD
40+
3741
[0.1.1]: https://github.com/ghostflyby/IntelliJ-Plugins/compare/v0.0.1...v0.1.1
42+
3843
[0.0.1]: https://github.com/ghostflyby/IntelliJ-Plugins/commits/v0.0.1

plugins/SpotlessIntegration/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ plugins {
2828
id("repo.intellij-plugin")
2929
}
3030

31-
version = "0.1.1"
31+
version = "0.2.0"
3232

3333
buildLogic {
3434
pluginVersion = version.toString()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2025 ghostflyby
3+
* SPDX-FileCopyrightText: 2025 ghostflyby
4+
* SPDX-License-Identifier: LGPL-3.0-or-later
5+
*
6+
* This file is part of IntelliJ-Plugins by ghostflyby
7+
*
8+
* IntelliJ-Plugins by ghostflyby is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 3.0 of the License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, see
20+
* <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package dev.ghostflyby.spotless.gradle
24+
25+
import com.intellij.openapi.components.service
26+
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
27+
import com.intellij.openapi.options.BoundConfigurable
28+
import com.intellij.openapi.project.Project
29+
import com.intellij.ui.dsl.builder.bindText
30+
import com.intellij.ui.dsl.builder.panel
31+
import dev.ghostflyby.spotless.Bundle
32+
33+
internal class SpotlessGradleConfigurable(private val project: Project) :
34+
BoundConfigurable(Bundle.message("spotless.configuration.title.workspace")) {
35+
36+
private val settings = project.service<SpotlessGradleStateHolder>()
37+
38+
override fun createPanel() = panel {
39+
row(Bundle.message("spotless.configuration.daemonVersion.label")) {
40+
textField()
41+
.bindText(settings::gradleDaemonVersion)
42+
.comment(Bundle.message("spotless.configuration.daemonVersion.comment"))
43+
}
44+
row(Bundle.message("spotless.configuration.daemonJar.label")) {
45+
@Suppress("UnstableApiUsage")
46+
textFieldWithBrowseButton(
47+
project = project,
48+
fileChooserDescriptor = FileChooserDescriptorFactory.singleFile()
49+
.withTitle(Bundle.message("spotless.configuration.daemonJar.title")),
50+
)
51+
.bindText(settings::gradleDaemonJar)
52+
.comment(Bundle.message("spotless.configuration.daemonJar.comment"))
53+
}
54+
}
55+
}

plugins/SpotlessIntegration/src/main/kotlin/dev/ghostflyby/spotless/gradle/SpotlessGradleTaskManagerExtension.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package dev.ghostflyby.spotless.gradle
2525
import com.intellij.openapi.components.service
2626
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
2727
import org.gradle.util.GradleVersion
28+
import org.jetbrains.plugins.gradle.service.execution.toGroovyStringLiteral
2829
import org.jetbrains.plugins.gradle.service.task.GradleTaskManagerExtension
2930
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings
3031
import kotlin.io.path.Path
@@ -38,25 +39,37 @@ internal class SpotlessGradleTaskManagerExtension : GradleTaskManagerExtension {
3839
gradleVersion: GradleVersion?,
3940
) {
4041
id.project.service<SpotlessGradleStateHolder>().isSpotlessEnabledForProjectDir(Path(projectPath)) || return
41-
settings.addInitScript(
42-
"dev.ghostflyby.spotless.daemon",
43-
@Suppress("SpellCheckingInspection")
44-
"""
42+
val persistent = id.project.service<SpotlessGradleStateHolder>()
43+
val daemonVersion = persistent.gradleDaemonVersion.trim()
44+
val daemonJar = persistent.gradleDaemonJar.trim()
45+
46+
val s = @Suppress("SpellCheckingInspection")
47+
$$"""
4548
gradle.allprojects { proj ->
4649
proj.buildscript {
4750
repositories {
4851
gradlePluginPortal()
4952
}
5053
dependencies {
51-
classpath "dev.ghostflyby.spotless.daemon:dev.ghostflyby.spotless.daemon.gradle.plugin:0.4.0"
54+
def daemonJar = $${daemonJar.toGroovyStringLiteral()}
55+
def daemonVersion = $${daemonVersion.toGroovyStringLiteral()}
56+
if (daemonJar) {
57+
classpath files(daemonJar)
58+
} else {
59+
def resolved = daemonVersion ? daemonVersion : '0.4.0'
60+
classpath "dev.ghostflyby.spotless.daemon:dev.ghostflyby.spotless.daemon.gradle.plugin:$resolved"
61+
}
5262
}
5363
}
5464
5565
proj.pluginManager.withPlugin("com.diffplug.spotless") {
5666
proj.apply plugin: "dev.ghostflyby.spotless.daemon"
5767
}
5868
}
59-
""".trimIndent(),
69+
""".trimIndent()
70+
settings.addInitScript(
71+
"dev.ghostflyby.spotless.daemon",
72+
s
6073
)
6174
}
6275
}

plugins/SpotlessIntegration/src/main/kotlin/dev/ghostflyby/spotless/gradle/ToolingExtension.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjec
3939
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil
4040
import com.intellij.openapi.externalSystem.util.task.TaskExecutionSpec
4141
import com.intellij.openapi.util.Disposer
42+
import com.intellij.openapi.util.NlsSafe
4243
import dev.ghostflyby.spotless.Spotless
4344
import dev.ghostflyby.spotless.SpotlessDaemonHost
4445
import org.gradle.api.Project
@@ -119,17 +120,17 @@ internal class SpotlessGradleStateDataService : AbstractProjectDataService<Spotl
119120
storages = [Storage(StoragePathMacros.WORKSPACE_FILE, roamingType = RoamingType.DISABLED)],
120121
)
121122
internal class SpotlessGradleStateHolder
122-
: SerializablePersistentStateComponent<SpotlessGradleStateHolder.PathsState>(PathsState()) {
123+
: SerializablePersistentStateComponent<SpotlessGradleStateHolder.State>(State()) {
123124
fun isSpotlessEnabledForProjectDir(path: Path): Boolean {
124125
return state.paths.contains(path.absolutePathString())
125126
}
126127

127128
val daemons = mutableListOf<SpotlessDaemonHost>()
128129

129130
fun updateFrom(nodes: Collection<DataNode<SpotlessGradleStateData>>) {
130-
updateState {
131-
PathsState(
132-
nodes.asSequence()
131+
updateState { state ->
132+
state.copy(
133+
paths = nodes.asSequence()
133134
.filter { it.data.spotless }
134135
.map { it.data.projectDirectory.absolutePathString() }
135136
.toSet(),
@@ -140,8 +141,22 @@ internal class SpotlessGradleStateHolder
140141
daemons.clear()
141142
}
142143

143-
internal data class PathsState(
144+
var gradleDaemonVersion: @NlsSafe String
145+
get() = state.gradleDaemonVersion
146+
set(value) {
147+
state = state.copy(gradleDaemonVersion = value)
148+
}
149+
150+
var gradleDaemonJar: @NlsSafe String
151+
get() = state.gradleDaemonJar
152+
set(value) {
153+
state = state.copy(gradleDaemonJar = value)
154+
}
155+
156+
internal data class State(
144157
@JvmField val paths: Set<String> = emptySet(),
158+
@JvmField val gradleDaemonVersion: String = "",
159+
@JvmField val gradleDaemonJar: String = "",
145160
)
146161
}
147162

plugins/SpotlessIntegration/src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<!-- <checkinHandlerFactory implementation="dev.ghostflyby.spotless.SpotlessCommitHandlerFactory"/>-->
1414
<formattingService implementation="dev.ghostflyby.spotless.SpotlessFormatingService"/>
1515
<!-- <fileEncodingProvider implementation="dev.ghostflyby.spotless.SpotlessFileEncodingProvider"/>-->
16+
<projectConfigurable bundle="messages.Bundle" id="dev.ghostflyby.spotless.workspace"
17+
instance="dev.ghostflyby.spotless.gradle.SpotlessGradleConfigurable"
18+
key="spotless.configuration.title.workspace"
19+
parentId="build"/>
1620
</extensions>
1721

1822
<extensionPoints>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# SPDX-FileCopyrightText: 2025 ghostflyby
22
# SPDX-License-Identifier: LGPL-3.0-or-later
3-
spotless.format.notification.error.title=Spotless Formatting Error
3+
spotless.format.notification.error.title=Spotless Formatting Error
4+
spotless.configuration.title.workspace=Spotless Integration
5+
spotless.configuration.daemonVersion.label=Gradle Spotless daemon version override
6+
spotless.configuration.daemonVersion.comment=Leave blank to use the bundled daemon plugin version.
7+
spotless.configuration.daemonJar.label=Local daemon plugin jar
8+
spotless.configuration.daemonJar.title=Select Spotless daemon plugin jar
9+
spotless.configuration.daemonJar.comment=Absolute path to dev.ghostflyby.spotless.daemon Gradle plugin jar; overrides the version when set.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# SPDX-FileCopyrightText: 2025 ghostflyby
22
# SPDX-License-Identifier: LGPL-3.0-or-later
3-
spotless.format.notification.error.title=Spotless格式化错误
3+
spotless.format.notification.error.title=Spotless格式化错误
4+
spotless.configuration.title.workspace=Spotless集成
5+
spotless.configuration.daemonVersion.label=Gradle Spotless daemon版本覆盖
6+
spotless.configuration.daemonVersion.comment=留空以使用插件内置版本。
7+
spotless.configuration.daemonJar.label=本地daemon插件jar
8+
spotless.configuration.daemonJar.title=选择Spotless daemon插件jar
9+
spotless.configuration.daemonJar.comment=dev.ghostflyby.spotless.daemon Gradle插件jar的绝对路径;填写后优先生效。

0 commit comments

Comments
 (0)