diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e6cb6d7..43bf9f6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -20,6 +20,10 @@ on:
# Trigger the workflow on any pull request
pull_request:
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
jobs:
# Prepare environment and build the plugin
@@ -32,24 +36,24 @@ jobs:
pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }}
steps:
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
# Validate wrapper
- name: Gradle Wrapper Validation
- uses: gradle/wrapper-validation-action@v1.1.0
+ uses: gradle/actions/wrapper-validation@v3
# Set up Java environment for the next steps
- name: Setup Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
# Setup Gradle
- name: Setup Gradle
- uses: gradle/gradle-build-action@v2
+ uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
@@ -69,8 +73,6 @@ jobs:
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
-
# Build plugin
- name: Build plugin
run: ./gradlew buildPlugin
@@ -88,7 +90,7 @@ jobs:
# Store already-built plugin as an artifact for downloading
- name: Upload artifact
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact.outputs.filename }}
path: ./build/distributions/content/*/*
@@ -100,20 +102,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
# Set up Java environment for the next steps
- name: Setup Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
# Setup Gradle
- name: Setup Gradle
- uses: gradle/gradle-build-action@v2
+ uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
@@ -124,14 +126,14 @@ jobs:
# Collect Tests Result of failed tests
- name: Collect Tests Result
if: ${{ failure() }}
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests
# Upload the Kover report to CodeCov
- name: Upload Code Coverage Report
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v4
with:
files: ${{ github.workspace }}/build/reports/kover/report.xml
@@ -149,38 +151,38 @@ jobs:
tool-cache: false
large-packages: false
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
# Set up Java environment for the next steps
- name: Setup Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
# Setup Gradle
- name: Setup Gradle
- uses: gradle/gradle-build-action@v2
+ uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
# Cache Plugin Verifier IDEs
- name: Setup Plugin Verifier IDEs Cache
- uses: actions/cache@v3
+ uses: actions/cache@v4
with:
path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides
key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}
# Run Verify Plugin task and IntelliJ Plugin Verifier tool
- name: Run Plugin Verification tasks
- run: ./gradlew runPluginVerifier -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }}
+ run: ./gradlew verifyPlugin -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }}
# Collect Plugin Verifier Result
- name: Collect Plugin Verifier Result
if: ${{ always() }}
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: pluginVerifier-result
path: ${{ github.workspace }}/build/reports/pluginVerifier
@@ -196,16 +198,9 @@ jobs:
contents: write
steps:
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
-
- # Set up Java environment for the next steps
- - name: Setup Java
- uses: actions/setup-java@v3
- with:
- distribution: zulu
- java-version: 17
+ uses: actions/checkout@v4
# Remove old release drafts by using the curl request for the available releases with a draft flag
- name: Remove Old Release Drafts
@@ -221,7 +216,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- gh release create v${{ needs.build.outputs.version }} \
+ gh release create "v${{ needs.build.outputs.version }}" \
--draft \
--title "v${{ needs.build.outputs.version }}" \
--notes "$(cat << 'EOM'
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index db1ff9a..aa06cb2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -18,22 +18,22 @@ jobs:
pull-requests: write
steps:
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
# Set up Java environment for the next steps
- name: Setup Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
# Setup Gradle
- name: Setup Gradle
- uses: gradle/gradle-build-action@v2
+ uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
@@ -51,7 +51,7 @@ jobs:
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- # Update Unreleased section with the current release note
+ # Update the Unreleased section with the current release note
- name: Patch Changelog
if: ${{ steps.properties.outputs.changelog != '' }}
env:
@@ -93,6 +93,7 @@ jobs:
gh label create "$LABEL" \
--description "Pull requests with release changelog update" \
+ --force \
|| true
gh pr create \
diff --git a/.github/workflows/run-ui-tests.yml b/.github/workflows/run-ui-tests.yml
index cadd24f..6b60acd 100644
--- a/.github/workflows/run-ui-tests.yml
+++ b/.github/workflows/run-ui-tests.yml
@@ -31,20 +31,20 @@ jobs:
steps:
- # Check out current repository
+ # Check out the current repository
- name: Fetch Sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
# Set up Java environment for the next steps
- name: Setup Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
# Setup Gradle
- name: Setup Gradle
- uses: gradle/gradle-build-action@v2
+ uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
@@ -54,7 +54,7 @@ jobs:
# Wait for IDEA to be started
- name: Health Check
- uses: jtalk/url-health-check-action@v3
+ uses: jtalk/url-health-check-action@v4
with:
url: http://127.0.0.1:8082
max-attempts: 15
diff --git a/.gitignore b/.gitignore
index fd00d92..13e2453 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
+.intellijPlatform
### IntelliJ IDEA ###
.idea
@@ -36,4 +37,4 @@ bin/
.vscode/
### Mac OS ###
-.DS_Store
\ No newline at end of file
+.DS_Store
diff --git a/.run/Run IDE for UI Tests.run.xml b/.run/Run IDE for UI Tests.run.xml
deleted file mode 100644
index ee99b7e..0000000
--- a/.run/Run IDE for UI Tests.run.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- true
- true
- false
- false
-
-
-
\ No newline at end of file
diff --git a/.run/Run Tests.run.xml b/.run/Run Tests.run.xml
index 132d9ad..f281bdc 100644
--- a/.run/Run Tests.run.xml
+++ b/.run/Run Tests.run.xml
@@ -19,6 +19,7 @@
true
true
false
+ true
diff --git a/.run/Run Verifications.run.xml b/.run/Run Verifications.run.xml
index 3a8d688..b51e78c 100644
--- a/.run/Run Verifications.run.xml
+++ b/.run/Run Verifications.run.xml
@@ -11,7 +11,7 @@
-
+
@@ -19,8 +19,7 @@
true
true
false
-
-
-
+ false
+
-
\ No newline at end of file
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f8c8cd..6b35f30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@
## [Unreleased]
+### Changed
+
+- Fix commit checkin handler for multi-module projects
+- isAllowedGradleCache replaced with isProhibitGradleCache, as by default we don't have to pass any args to the gradle command
+
## [1.1.0] - 2024-06-02
### Added
diff --git a/README.md b/README.md
index 2f5762d..d95ce5d 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ To enable this feature, navigate to `Settings` > `Tools` > `Actions on Save` and
### Settings
To access plugin settings, go to: `Settings` > `Tools` > `Spotless Applier`
-* `Allow Gradle cache for 'apply' task` > Starting from version 6.0.0, Spotless supports Gradle's configuration cache. If you want to use it, please enable this checkbox.
+* `Prohibit Gradle cache for 'apply' task` > Starting from version 6.6.0, Spotless supports Gradle's configuration cache. If you want to prohibit it, please enable this checkbox.
* `Optimize imports before applying` > Enable this option to additionally execute IntelliJ IDEA's default "optimize imports" task before applying Spotless formatting.
* `Prohibit imports with asterisk '*'` > Prevents imports with the asterisk symbol during the "optimize imports" task. When enabled, any imports that use the '*' symbol to import all classes from a package will be replaced with FQN.
@@ -40,7 +40,7 @@ To access plugin settings, go to: `Settings` > `Tools` > `Spotless Applier`
### Media
![spotlessdemo](https://github.com/lipiridi/spotless-applier/assets/60580660/990e7bb9-8b75-4ca4-8973-f1fb2cf74e78)
-![image](https://github.com/lipiridi/spotless-applier/assets/60580660/0d6ba567-e955-4193-b85b-f06e0541c790)
+![image](https://github.com/user-attachments/assets/e7c65f78-1ed6-41b0-85e9-4011f28de340)
![image](https://github.com/lipiridi/spotless-applier/assets/60580660/f6980124-c3e1-45fe-a7be-51dd4f108e81)
![image](https://github.com/lipiridi/spotless-applier/assets/60580660/fbd26155-c7f9-4837-9e97-d48530d0ae39)
diff --git a/build.gradle.kts b/build.gradle.kts
index 7d81d0a..cb89251 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,76 +1,63 @@
import com.diffplug.spotless.LineEnding
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
-
-fun properties(key: String) = providers.gradleProperty(key)
-fun environment(key: String) = providers.environmentVariable(key)
+import org.jetbrains.intellij.platform.gradle.TestFrameworkType
plugins {
id("java")
- id("org.jetbrains.kotlin.jvm") version "1.9.23"
- id("org.jetbrains.intellij") version "1.17.3"
- id("org.jetbrains.changelog") version "2.2.0"
- id("org.jetbrains.kotlinx.kover") version "0.7.6"
+ id("org.jetbrains.kotlin.jvm") version "2.0.10"
+ id("org.jetbrains.intellij.platform") version "2.0.1"
+ id("org.jetbrains.changelog") version "2.2.1"
+ id("org.jetbrains.kotlinx.kover") version "0.8.3"
id("com.diffplug.spotless") version "6.25.0"
}
-group = properties("pluginGroup").get()
-version = properties("pluginVersion").get()
+group = providers.gradleProperty("pluginGroup").get()
+version = providers.gradleProperty("pluginVersion").get()
-repositories {
- mavenCentral()
+// Set the JVM language level used to build the project.
+kotlin {
+ jvmToolchain(17)
}
-// Configure Gradle IntelliJ Plugin
-// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
-intellij {
- pluginName = properties("pluginName")
- version = properties("platformVersion")
- type = properties("platformType")
+repositories {
+ mavenCentral()
- plugins.set(listOf("maven", "gradle", "com.intellij.java"))
+ // IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
+ intellijPlatform {
+ defaultRepositories()
+ }
}
-// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
-changelog {
- groups.empty()
- repositoryUrl = properties("pluginRepositoryUrl")
-}
+dependencies {
+ // IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
+ intellijPlatform {
+ create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
-// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
-koverReport {
- defaults {
- xml {
- onCheck = true
- }
- }
-}
+ // Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins.
+ bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') })
-tasks {
- // Set the JVM compatibility versions
- withType {
- sourceCompatibility = properties("javaVersion").get()
- targetCompatibility = properties("javaVersion").get()
- }
- withType {
- kotlinOptions.jvmTarget = properties("javaVersion").get()
- }
+ // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
+ plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })
- wrapper {
- gradleVersion = properties("gradleVersion").get()
+ instrumentationTools()
+ pluginVerifier()
+ zipSigner()
+ testFramework(TestFrameworkType.Platform)
}
+}
- patchPluginXml {
- version = properties("pluginVersion")
- sinceBuild = properties("pluginSinceBuild")
- untilBuild = ""
+// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
+intellijPlatform {
+ pluginConfiguration {
+ version = providers.gradleProperty("pluginVersion")
// Extract the section from README.md and provide for the plugin's manifest
- pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
+ description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = ""
val end = ""
- with (it.lines()) {
+ with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
@@ -80,7 +67,7 @@ tasks {
val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
- changeNotes = properties("pluginVersion").map { pluginVersion ->
+ changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
@@ -90,26 +77,75 @@ tasks {
)
}
}
+
+ ideaVersion {
+ sinceBuild = providers.gradleProperty("pluginSinceBuild")
+ untilBuild = providers.gradleProperty("pluginUntilBuild")
+ }
+ }
+
+ signing {
+ certificateChain = providers.environmentVariable("CERTIFICATE_CHAIN")
+ privateKey = providers.environmentVariable("PRIVATE_KEY")
+ password = providers.environmentVariable("PRIVATE_KEY_PASSWORD")
+ }
+
+ publishing {
+ token = providers.environmentVariable("PUBLISH_TOKEN")
+ }
+
+ pluginVerification {
+ ides {
+ recommended()
+ }
}
+}
+
+// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
+changelog {
+ groups.empty()
+ repositoryUrl = providers.gradleProperty("pluginRepositoryUrl")
+}
- // Configure UI tests plugin
- // Read more: https://github.com/JetBrains/intellij-ui-test-robot
- runIdeForUiTests {
- systemProperty("robot-server.port", "8082")
- systemProperty("ide.mac.message.dialogs.as.sheets", "false")
- systemProperty("jb.privacy.policy.text", "")
- systemProperty("jb.consents.confirmation.enabled", "false")
+// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
+kover {
+ reports {
+ total {
+ xml {
+ onCheck = true
+ }
+ }
}
+}
- signPlugin {
- certificateChain = environment("CERTIFICATE_CHAIN")
- privateKey = environment("PRIVATE_KEY")
- password = environment("PRIVATE_KEY_PASSWORD")
+tasks {
+ wrapper {
+ gradleVersion = providers.gradleProperty("gradleVersion").get()
}
publishPlugin {
dependsOn("patchChangelog")
- token = environment("PUBLISH_TOKEN")
+ }
+}
+
+intellijPlatformTesting {
+ runIde {
+ register("runIdeForUiTests") {
+ task {
+ jvmArgumentProviders += CommandLineArgumentProvider {
+ listOf(
+ "-Drobot-server.port=8082",
+ "-Dide.mac.message.dialogs.as.sheets=false",
+ "-Djb.privacy.policy.text=",
+ "-Djb.consents.confirmation.enabled=false",
+ )
+ }
+ }
+
+ plugins {
+ robotServerPlugin()
+ }
+ }
}
}
diff --git a/gradle.properties b/gradle.properties
index f5cd1a7..2d4045e 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,21 +4,24 @@ pluginName=Spotless Applier
pluginRepositoryUrl=https://github.com/lipiridi/spotless-applier
# SemVer format -> https://semver.org
-pluginVersion=1.1.0
+pluginVersion=1.1.1
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=241
-pluginUntilBuild=
+pluginUntilBuild=242.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType=IC
platformVersion=2024.1.2
-# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
-javaVersion=17
+# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
+# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP
+platformPlugins=
+# Example: platformBundledPlugins = com.intellij.java
+platformBundledPlugins=com.intellij.java,com.intellij.gradle,org.jetbrains.idea.maven
# Gradle Releases -> https://github.com/gradle/gradle/releases
-gradleVersion=8.7
+gradleVersion=8.9
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency=false
@@ -28,3 +31,5 @@ org.gradle.configuration-cache=true
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching=true
+
+org.jetbrains.intellij.platform.buildSearchableOptions=false
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index b82aa23..09523c0 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/ModuleInfo.java b/src/main/java/com/github/lipiridi/spotless/applier/ModuleInfo.java
index 760d091..5a94d00 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/ModuleInfo.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/ModuleInfo.java
@@ -11,7 +11,7 @@
public record ModuleInfo(Module module, String path, BuildTool buildTool, boolean rootModule) {
@SuppressWarnings("DataFlowIssue")
- public static ModuleInfo create(Project project, String projectBasePath, Module module) {
+ public static ModuleInfo create(Project project, Module module) {
BuildTool buildTool = BuildTool.resolveBuildTool(module);
if (buildTool == null) {
return null;
@@ -22,7 +22,7 @@ public static ModuleInfo create(Project project, String projectBasePath, Module
return null;
}
- boolean isRootModule = modulePath.equals(projectBasePath);
+ boolean isRootModule = modulePath.equals(project.getBasePath());
Module rootModule =
switch (buildTool) {
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/ReformatProcessor.java b/src/main/java/com/github/lipiridi/spotless/applier/ReformatProcessor.java
index cdfa7f4..e73dd1d 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/ReformatProcessor.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/ReformatProcessor.java
@@ -126,7 +126,7 @@ private ExternalSystemTaskExecutionSettings getGradleSystemTaskExecutionSettings
}
private boolean shouldAddNoConfigCacheOption() {
- if (spotlessSettings.allowGradleCache) {
+ if (!spotlessSettings.prohibitGradleCache) {
return false;
}
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/actions/ReformatProjectAction.java b/src/main/java/com/github/lipiridi/spotless/applier/actions/ReformatProjectAction.java
index e2aec95..8af0c66 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/actions/ReformatProjectAction.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/actions/ReformatProjectAction.java
@@ -68,10 +68,9 @@ private void showModuleSelectionDialog(Map availableModules,
private Map findAvailableModules(Project project) {
Module[] modules = ProjectUtil.getModules(project);
- String projectBasePath = project.getBasePath();
return Arrays.stream(modules)
- .map(module -> ModuleInfo.create(project, projectBasePath, module))
+ .map(module -> ModuleInfo.create(project, module))
.filter(Objects::nonNull)
.collect(Collectors.toMap(
moduleInfo -> moduleInfo.module().getName(),
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/trigger/SpotlessCheckinHandler.java b/src/main/java/com/github/lipiridi/spotless/applier/trigger/SpotlessCheckinHandler.java
index 749db0c..f496301 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/trigger/SpotlessCheckinHandler.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/trigger/SpotlessCheckinHandler.java
@@ -5,17 +5,22 @@
import com.github.lipiridi.spotless.applier.ui.settings.SpotlessApplierSettingsState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.vcs.changes.Change;
+import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.CommitExecutor;
import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
+import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PairConsumer;
import java.awt.*;
-import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
import java.util.Objects;
+import java.util.Set;
import javax.swing.*;
import org.jetbrains.annotations.Nullable;
@@ -46,8 +51,10 @@ public ReturnResult beforeCheckin(
return ReturnResult.COMMIT;
}
+ Set affectedModules = findAffectedModules();
+
try {
- new ReformatProcessor(project, findRootModule()).run();
+ affectedModules.forEach(module -> new ReformatProcessor(project, module).run());
return ReturnResult.COMMIT;
} catch (Exception e) {
handleError(e);
@@ -55,18 +62,6 @@ public ReturnResult beforeCheckin(
}
}
- private ModuleInfo findRootModule() {
- Module[] modules = ProjectUtil.getModules(project);
- String projectBasePath = project.getBasePath();
-
- return Arrays.stream(modules)
- .map(module -> ModuleInfo.create(project, projectBasePath, module))
- .filter(Objects::nonNull)
- .filter(ModuleInfo::rootModule)
- .findFirst()
- .orElse(null);
- }
-
private void handleError(Exception e) {
var msg = "Error while reformatting code with Spotless";
if (e.getMessage() != null) {
@@ -75,4 +70,33 @@ private void handleError(Exception e) {
LOGGER.info(msg, e);
Messages.showErrorDialog(project, msg, "Error Reformatting Code with Spotless");
}
+
+ public Set findAffectedModules() {
+ ChangeListManager changeListManager = ChangeListManager.getInstance(project);
+ List affectedFiles = changeListManager.getAllChanges().stream()
+ .filter(change -> change.getType() != Change.Type.DELETED)
+ .map(Change::getVirtualFile)
+ .filter(Objects::nonNull)
+ .toList();
+
+ Set moduleInfos = new HashSet<>();
+ Set modules = new HashSet<>();
+ for (VirtualFile affectedFile : affectedFiles) {
+ Module moduleForFile = ModuleUtil.findModuleForFile(affectedFile, project);
+ if (modules.add(moduleForFile)) {
+ ModuleInfo moduleInfo = ModuleInfo.create(project, moduleForFile);
+ if (moduleInfo == null) {
+ continue;
+ }
+
+ if (moduleInfo.rootModule()) {
+ return Set.of(moduleInfo);
+ }
+
+ moduleInfos.add(moduleInfo);
+ }
+ }
+
+ return moduleInfos;
+ }
}
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/ui/SpotlessApplierSettingsComponent.java b/src/main/java/com/github/lipiridi/spotless/applier/ui/SpotlessApplierSettingsComponent.java
index e6d8f6c..51cc600 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/ui/SpotlessApplierSettingsComponent.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/ui/SpotlessApplierSettingsComponent.java
@@ -7,7 +7,7 @@
public class SpotlessApplierSettingsComponent {
private final JPanel myMainPanel;
- private final JCheckBox allowGradleCacheCheckBox = new JBCheckBox("Allow Gradle cache for 'apply' task");
+ private final JCheckBox prohibitGradleCacheCheckBox = new JBCheckBox("Prohibit Gradle cache for 'apply' task");
private final JCheckBox optimizeImportsBeforeApplyingCheckBox = new JBCheckBox("Optimize imports before applying");
private final JCheckBox prohibitImportsWithAsteriskCheckBox = new JBCheckBox("Prohibit imports with asterisk '*'");
@@ -26,11 +26,11 @@ public SpotlessApplierSettingsComponent() {
.addComponent(prohibitImportsWithAsteriskCheckBox)
.getPanel();
- allowGradleCacheCheckBox.setToolTipText(
+ prohibitGradleCacheCheckBox.setToolTipText(
"Starting from version 6.0.0, Spotless supports Gradle's configuration cache. If you want to use it, please enable this checkbox.");
myMainPanel = FormBuilder.createFormBuilder()
- .addComponent(allowGradleCacheCheckBox)
+ .addComponent(prohibitGradleCacheCheckBox)
.addComponent(optimizeImportsBeforeApplyingCheckBox)
.addComponent(secondRow)
.addComponentFillVertically(new JPanel(), 0)
@@ -41,12 +41,12 @@ public JPanel getPanel() {
return myMainPanel;
}
- public boolean isAllowGradleCache() {
- return allowGradleCacheCheckBox.isSelected();
+ public boolean isProhibitGradleCache() {
+ return prohibitGradleCacheCheckBox.isSelected();
}
- public void setAllowGradleCache(boolean value) {
- allowGradleCacheCheckBox.setSelected(value);
+ public void setProhibitGradleCache(boolean value) {
+ prohibitGradleCacheCheckBox.setSelected(value);
}
public boolean isOptimizeImportsBeforeApplying() {
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsConfigurable.java b/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsConfigurable.java
index d3108ed..065b6f3 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsConfigurable.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsConfigurable.java
@@ -30,7 +30,7 @@ public String getDisplayName() {
public boolean isModified() {
SpotlessApplierSettingsState settings = SpotlessApplierSettingsState.getInstance();
- return spotlessApplierSettingsComponent.isAllowGradleCache() != settings.allowGradleCache
+ return spotlessApplierSettingsComponent.isProhibitGradleCache() != settings.prohibitGradleCache
|| spotlessApplierSettingsComponent.isOptimizeImportsBeforeApplying()
!= settings.optimizeImportsBeforeApplying
|| spotlessApplierSettingsComponent.isProhibitAsteriskImports() != settings.prohibitImportsWithAsterisk;
@@ -39,7 +39,7 @@ public boolean isModified() {
@Override
public void apply() {
SpotlessApplierSettingsState settings = SpotlessApplierSettingsState.getInstance();
- settings.allowGradleCache = spotlessApplierSettingsComponent.isAllowGradleCache();
+ settings.prohibitGradleCache = spotlessApplierSettingsComponent.isProhibitGradleCache();
settings.optimizeImportsBeforeApplying = spotlessApplierSettingsComponent.isOptimizeImportsBeforeApplying();
settings.prohibitImportsWithAsterisk = spotlessApplierSettingsComponent.isProhibitAsteriskImports();
}
@@ -47,7 +47,7 @@ public void apply() {
@Override
public void reset() {
SpotlessApplierSettingsState settings = SpotlessApplierSettingsState.getInstance();
- spotlessApplierSettingsComponent.setAllowGradleCache(settings.allowGradleCache);
+ spotlessApplierSettingsComponent.setProhibitGradleCache(settings.prohibitGradleCache);
spotlessApplierSettingsComponent.setOptimizeImportsBeforeApplying(settings.optimizeImportsBeforeApplying);
spotlessApplierSettingsComponent.setProhibitAsteriskImports(settings.prohibitImportsWithAsterisk);
}
diff --git a/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsState.java b/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsState.java
index 97c2847..3a643c5 100644
--- a/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsState.java
+++ b/src/main/java/com/github/lipiridi/spotless/applier/ui/settings/SpotlessApplierSettingsState.java
@@ -14,7 +14,7 @@
storages = {@Storage("spotless-applier.xml")})
public final class SpotlessApplierSettingsState implements PersistentStateComponent {
- public boolean allowGradleCache;
+ public boolean prohibitGradleCache;
public boolean optimizeImportsBeforeApplying;
public boolean prohibitImportsWithAsterisk;
public boolean preCommitSpotlessFormating;