Skip to content

Commit

Permalink
Merge pull request #24 from lipiridi/fix/gradle-modality
Browse files Browse the repository at this point in the history
Gradle task in async mode
  • Loading branch information
lipiridi authored Aug 13, 2024
2 parents 2388af7 + b43ade9 commit 051360e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
java-version: 21

# Setup Gradle
- name: Setup Gradle
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
java-version: 21

# Setup Gradle
- name: Setup Gradle
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
java-version: 21

# Setup Gradle
- name: Setup Gradle
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
java-version: 21

# Setup Gradle
- name: Setup Gradle
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
java-version: 21

# Setup Gradle
- name: Setup Gradle
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## [Unreleased]

### Changed

- Gradle task for the entire project is again called in background (async)
- Pre-commit hook added in version 1.0.5 is no more supported for gradle projects

## [1.1.1] - 2024-08-11

### Changed
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
[![Downloads](https://img.shields.io/jetbrains/plugin/d/22455.svg)](https://plugins.jetbrains.com/plugin/22455)

<!-- Plugin description -->
> ⚠️ Version 1.1.2 is built for Intellij IDEA 2024.2 and doesn't support the pre-commit feature for Gradle projects due to this bug https://youtrack.jetbrains.com/issue/IDEA-327879
>
> Version 1.1.1 supports the pre-commit check properly but is only compatible with Intellij IDEA 2024.1.* versions.
The Spotless Applier IntelliJ Plugin enhances your development workflow
by seamlessly integrating [Spotless](https://github.com/diffplug/spotless) Gradle and Maven tasks directly within the IntelliJ IDE.
With this plugin, you can easily apply code formatting and style enforcement to your projects,
Expand All @@ -17,7 +21,7 @@ either for the current file you're working on or for the entire project.
| <kbd>Code</kbd> > <kbd>Reformat Project With Spotless</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> | <kbd>⌘Сmd</kbd>+<kbd>⌥Opt</kbd>+<kbd>⇧Shift</kbd>+<kbd>;</kbd> |

> ✔️ **Supports multi-module projects**
>
### Commit check
The plugin offers a commit check to automatically apply Spotless formatting.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version = providers.gradleProperty("pluginVersion").get()

// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(17)
jvmToolchain(21)
}

repositories {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pluginName=Spotless Applier
pluginRepositoryUrl=https://github.com/lipiridi/spotless-applier

# SemVer format -> https://semver.org
pluginVersion=1.1.1
pluginVersion=1.1.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=241
pluginSinceBuild=242
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
platformVersion=2024.2

# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.util.GradleConstants;

public final class ToolEnvExternalSystemUtil {
private static final Logger LOG = Logger.getInstance(ToolEnvExternalSystemUtil.class);
Expand Down Expand Up @@ -52,15 +53,22 @@ public static void runTask(

final String title = moduleName + " " + taskSettings.getTaskNames();

Task task = getTask(project, document, title, taskUnderProgress);
Task task = getTask(project, document, title, taskUnderProgress, externalSystemId);

task.queue();
}

@NotNull private static Task getTask(
@NotNull Project project, Document document, String title, TaskUnderProgress taskUnderProgress) {
if (document == null) {
return new Task.Modal(project, title, true) {
@NotNull Project project,
Document document,
String title,
TaskUnderProgress taskUnderProgress,
ProjectSystemId externalSystemId) {
// Currently not found the way to run gradle task synchronously
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/12849664786322-Execute-Gradle-task-in-ProgressExecutionMode-MODAL-SYNC
// https://youtrack.jetbrains.com/issue/IDEA-327879
if (document == null && !externalSystemId.equals(GradleConstants.SYSTEM_ID)) {
return new Task.Modal(project, title, false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
taskUnderProgress.execute(indicator);
Expand All @@ -70,7 +78,9 @@ public void run(@NotNull ProgressIndicator indicator) {
return new Task.Backgroundable(project, title) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
document.setReadOnly(true);
if (document != null) {
document.setReadOnly(true);
}
taskUnderProgress.execute(indicator);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.lipiridi.spotless.applier.ModuleInfo;
import com.github.lipiridi.spotless.applier.ReformatProcessor;
import com.github.lipiridi.spotless.applier.enums.BuildTool;
import com.github.lipiridi.spotless.applier.ui.settings.SpotlessApplierSettingsState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
Expand All @@ -16,12 +17,10 @@
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PairConsumer;
import java.awt.*;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.swing.*;
import org.jetbrains.annotations.Nullable;

public class SpotlessCheckinHandler extends CheckinHandler {
Expand Down Expand Up @@ -89,6 +88,12 @@ public Set<ModuleInfo> findAffectedModules() {
continue;
}

// Commiting is a synchronous flow. Currently, gradle has issues with that
// https://youtrack.jetbrains.com/issue/IDEA-327879
if (moduleInfo.buildTool() == BuildTool.GRADLE) {
continue;
}

if (moduleInfo.rootModule()) {
return Set.of(moduleInfo);
}
Expand Down

0 comments on commit 051360e

Please sign in to comment.