From e31ba87fc1701d9a123f906e567aef5e9530206e Mon Sep 17 00:00:00 2001 From: Dimitrii Lipiridi Date: Sun, 4 Aug 2024 20:09:24 +0300 Subject: [PATCH 1/9] Add CommitCheck implementation --- CHANGELOG.md | 4 +++ build.gradle.kts | 2 +- gradle.properties | 2 +- .../trigger/SpotlessCheckinHandler.java | 26 ++++++++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8c8cd..cdca320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] +### Changed + +- Fix commit checkin handler for multi-module projects + ## [1.1.0] - 2024-06-02 ### Added diff --git a/build.gradle.kts b/build.gradle.kts index 7d81d0a..a5a9445 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ fun environment(key: String) = providers.environmentVariable(key) plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.9.23" - id("org.jetbrains.intellij") version "1.17.3" + id("org.jetbrains.intellij") version "1.17.4" id("org.jetbrains.changelog") version "2.2.0" id("org.jetbrains.kotlinx.kover") version "0.7.6" id("com.diffplug.spotless") version "6.25.0" diff --git a/gradle.properties b/gradle.properties index f5cd1a7..27595ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ 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 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..f2e555b 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 @@ -8,18 +8,25 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vcs.changes.ChangesUtil; 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.checkin.CommitCheck; +import com.intellij.openapi.vcs.checkin.CommitInfo; +import com.intellij.openapi.vcs.checkin.CommitProblem; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.util.PairConsumer; import java.awt.*; import java.util.Arrays; import java.util.Objects; import javax.swing.*; +import kotlin.coroutines.Continuation; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class SpotlessCheckinHandler extends CheckinHandler { +@SuppressWarnings("UnstableApiUsage") +public class SpotlessCheckinHandler extends CheckinHandler implements CommitCheck { private static final Logger LOGGER = Logger.getInstance(SpotlessCheckinHandler.class); private final SpotlessApplierSettingsState spotlessSettings = SpotlessApplierSettingsState.getInstance(); private final Project project; @@ -75,4 +82,21 @@ private void handleError(Exception e) { LOGGER.info(msg, e); Messages.showErrorDialog(project, msg, "Error Reformatting Code with Spotless"); } + + @NotNull @Override + public ExecutionOrder getExecutionOrder() { + return CommitCheck.ExecutionOrder.MODIFICATION; + } + + @Override + public boolean isEnabled() { + return spotlessSettings.preCommitSpotlessFormating; + } + + @Nullable @Override + public Object runCheck(@NotNull CommitInfo commitInfo, @NotNull Continuation continuation) { + var affectedFiles = + ChangesUtil.iterateFiles(commitInfo.getCommittedChanges()).toList(); + return null; + } } From 822ad235c9a3acd9c00a77f0c2dbd872556a9521 Mon Sep 17 00:00:00 2001 From: Dimitrii Lipiridi Date: Sun, 11 Aug 2024 18:13:48 +0300 Subject: [PATCH 2/9] Fill main logic for runCheck --- .../lipiridi/spotless/applier/ModuleInfo.java | 4 +- .../actions/ReformatProjectAction.java | 3 +- .../trigger/SpotlessCheckinHandler.java | 38 +++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) 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/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 f2e555b..003f447 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,6 +5,7 @@ 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; @@ -16,10 +17,13 @@ import com.intellij.openapi.vcs.checkin.CommitInfo; import com.intellij.openapi.vcs.checkin.CommitProblem; 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.Objects; +import java.util.Set; import javax.swing.*; import kotlin.coroutines.Continuation; import org.jetbrains.annotations.NotNull; @@ -54,7 +58,13 @@ public ReturnResult beforeCheckin( } try { - new ReformatProcessor(project, findRootModule()).run(); + ModuleInfo rootModule = findRootModule(); + if (rootModule == null) { + Messages.showWarningDialog( + project, "No root project was found", "Error Reformatting Code with Spotless"); + } else { + new ReformatProcessor(project, rootModule).run(); + } return ReturnResult.COMMIT; } catch (Exception e) { handleError(e); @@ -64,10 +74,9 @@ 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)) + .map(module -> ModuleInfo.create(project, module)) .filter(Objects::nonNull) .filter(ModuleInfo::rootModule) .findFirst() @@ -97,6 +106,29 @@ public boolean isEnabled() { public Object runCheck(@NotNull CommitInfo commitInfo, @NotNull Continuation continuation) { var affectedFiles = ChangesUtil.iterateFiles(commitInfo.getCommittedChanges()).toList(); + + Set moduleInfos = new HashSet<>(); + Set modules = new HashSet<>(); + for (VirtualFile affectedFile : affectedFiles) { + Module moduleForFile = ModuleUtil.findModuleForFile(affectedFile, project); + if (!modules.add(moduleForFile)) { + continue; + } + + ModuleInfo moduleInfo = ModuleInfo.create(project, moduleForFile); + if (moduleInfo == null) { + continue; + } + + if (moduleInfo.rootModule()) { + new ReformatProcessor(project, moduleInfo).run(); + return null; + } + + moduleInfos.add(moduleInfo); + } + + moduleInfos.forEach(module -> new ReformatProcessor(project, module).run()); return null; } } From 9c1126d6d3a2784d1813c149ffbd69b78321fb3c Mon Sep 17 00:00:00 2001 From: Dimitrii Lipiridi Date: Sun, 11 Aug 2024 20:05:00 +0300 Subject: [PATCH 3/9] Remove commit CommitCheck and use ChangeListManager for resolving changes --- .../trigger/SpotlessCheckinHandler.java | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) 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 003f447..cb9956c 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 @@ -7,36 +7,33 @@ 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.ChangesUtil; +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.checkin.CommitCheck; -import com.intellij.openapi.vcs.checkin.CommitInfo; -import com.intellij.openapi.vcs.checkin.CommitProblem; 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 kotlin.coroutines.Continuation; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @SuppressWarnings("UnstableApiUsage") -public class SpotlessCheckinHandler extends CheckinHandler implements CommitCheck { +public class SpotlessCheckinHandler extends CheckinHandler { private static final Logger LOGGER = Logger.getInstance(SpotlessCheckinHandler.class); private final SpotlessApplierSettingsState spotlessSettings = SpotlessApplierSettingsState.getInstance(); private final Project project; + private final ChangeListManager changeListManager; public SpotlessCheckinHandler(Project project) { this.project = project; + changeListManager = ChangeListManager.getInstance(project); } @Override @@ -57,14 +54,10 @@ public ReturnResult beforeCheckin( return ReturnResult.COMMIT; } + Set affectedModules = findAffectedModules(); + try { - ModuleInfo rootModule = findRootModule(); - if (rootModule == null) { - Messages.showWarningDialog( - project, "No root project was found", "Error Reformatting Code with Spotless"); - } else { - new ReformatProcessor(project, rootModule).run(); - } + affectedModules.forEach(module -> new ReformatProcessor(project, module).run()); return ReturnResult.COMMIT; } catch (Exception e) { handleError(e); @@ -72,17 +65,6 @@ public ReturnResult beforeCheckin( } } - private ModuleInfo findRootModule() { - Module[] modules = ProjectUtil.getModules(project); - - return Arrays.stream(modules) - .map(module -> ModuleInfo.create(project, 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) { @@ -92,43 +74,31 @@ private void handleError(Exception e) { Messages.showErrorDialog(project, msg, "Error Reformatting Code with Spotless"); } - @NotNull @Override - public ExecutionOrder getExecutionOrder() { - return CommitCheck.ExecutionOrder.MODIFICATION; - } - - @Override - public boolean isEnabled() { - return spotlessSettings.preCommitSpotlessFormating; - } - - @Nullable @Override - public Object runCheck(@NotNull CommitInfo commitInfo, @NotNull Continuation continuation) { - var affectedFiles = - ChangesUtil.iterateFiles(commitInfo.getCommittedChanges()).toList(); + public Set findAffectedModules() { + 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)) { - continue; - } + if (modules.add(moduleForFile)) { + ModuleInfo moduleInfo = ModuleInfo.create(project, moduleForFile); + if (moduleInfo == null) { + continue; + } - ModuleInfo moduleInfo = ModuleInfo.create(project, moduleForFile); - if (moduleInfo == null) { - continue; - } + if (moduleInfo.rootModule()) { + return Set.of(moduleInfo); + } - if (moduleInfo.rootModule()) { - new ReformatProcessor(project, moduleInfo).run(); - return null; + moduleInfos.add(moduleInfo); } - - moduleInfos.add(moduleInfo); } - moduleInfos.forEach(module -> new ReformatProcessor(project, module).run()); - return null; + return moduleInfos; } } From dddcc837d5561fcd3d2ace4c2b3727996ed01729 Mon Sep 17 00:00:00 2001 From: Dimitrii Lipiridi Date: Sun, 11 Aug 2024 20:40:22 +0300 Subject: [PATCH 4/9] isAllowedGradleCache replaced with isProhibitGradleCache --- CHANGELOG.md | 1 + README.md | 2 +- .../spotless/applier/ReformatProcessor.java | 2 +- .../applier/trigger/SpotlessCheckinHandler.java | 1 - .../ui/SpotlessApplierSettingsComponent.java | 14 +++++++------- .../SpotlessApplierSettingsConfigurable.java | 6 +++--- .../ui/settings/SpotlessApplierSettingsState.java | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdca320..6b35f30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 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 diff --git a/README.md b/README.md index 2f5762d..870f939 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. 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/trigger/SpotlessCheckinHandler.java b/src/main/java/com/github/lipiridi/spotless/applier/trigger/SpotlessCheckinHandler.java index cb9956c..a3cfce4 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 @@ -24,7 +24,6 @@ import javax.swing.*; import org.jetbrains.annotations.Nullable; -@SuppressWarnings("UnstableApiUsage") public class SpotlessCheckinHandler extends CheckinHandler { private static final Logger LOGGER = Logger.getInstance(SpotlessCheckinHandler.class); private final SpotlessApplierSettingsState spotlessSettings = SpotlessApplierSettingsState.getInstance(); 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; From 1a7541630bea264147eac5485c8930d725f44486 Mon Sep 17 00:00:00 2001 From: Dimitrii Lipiridi Date: Sun, 11 Aug 2024 20:40:32 +0300 Subject: [PATCH 5/9] Update plugin build --- .github/workflows/build.yml | 57 ++++---- .github/workflows/release.yml | 11 +- .github/workflows/run-ui-tests.yml | 10 +- .gitignore | 3 +- .run/Run IDE for UI Tests.run.xml | 25 ---- .run/Run Tests.run.xml | 1 + .run/Run Verifications.run.xml | 9 +- build.gradle.kts | 158 ++++++++++++++--------- gradle.properties | 9 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 10 files changed, 148 insertions(+), 137 deletions(-) delete mode 100644 .run/Run IDE for UI Tests.run.xml 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 @@