Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run spotless using root config if plugin is not applied to the submodule #30

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading