Skip to content

Commit

Permalink
Run spotless using root config if plugin is not applied to the submod…
Browse files Browse the repository at this point in the history
…ule (#30)

* feat: Run spotless using root config if plugin is not applied to the submodule

* feat: Change desc

---------

Co-authored-by: Dimitrii Lipiridi <dimitrii.lipiridi@delasport.com>
  • Loading branch information
lipiridi and Dimitrii Lipiridi authored Oct 10, 2024
1 parent 9ab38a4 commit 7b49912
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 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

- [#27](https://github.com/lipiridi/spotless-applier/issues/27) Run spotless using root config if plugin is not
applied to the submodule

## [1.1.2] - 2024-08-13

### Changed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginName=Spotless Applier
pluginRepositoryUrl=https://github.com/lipiridi/spotless-applier

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

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=242
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import com.intellij.notification.NotificationType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings;
import com.intellij.openapi.externalSystem.model.project.ModuleData;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Version;
import com.intellij.psi.PsiFile;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.execution.MavenRunConfigurationType;
Expand All @@ -34,6 +33,7 @@
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
import org.jetbrains.plugins.gradle.settings.GradleSettings;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.jetbrains.plugins.gradle.util.GradleUtil;

public class ReformatProcessor {

Expand Down Expand Up @@ -72,7 +72,26 @@ public ReformatProcessor(@NotNull Project project, @NotNull Document document, @
if (buildTool != null) {
this.modulePath = buildTool.getModulePath(module);
}

if (buildTool == BuildTool.GRADLE && !hasSpotlessTask(module)) {
this.modulePath = project.getBasePath();
}
}
}

@SuppressWarnings("UnstableApiUsage")
private boolean hasSpotlessTask(Module module) {
DataNode<ModuleData> gradleModuleData = GradleUtil.findGradleModuleData(module);
if (gradleModuleData == null) {
return false;
}
Collection<DataNode<?>> children = gradleModuleData.getChildren();
for (DataNode<?> child : children) {
if (child.getData().toString().equals("spotlessApply")) {
return true;
}
}
return false;
}

public void run() {
Expand Down

0 comments on commit 7b49912

Please sign in to comment.