Skip to content

Commit

Permalink
Gradle task in async mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lipiridi committed Aug 13, 2024
1 parent 5197435 commit b43ade9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
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
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 b43ade9

Please sign in to comment.