Skip to content

Commit 9790f59

Browse files
committed
Add the ability to sync Maven Checkstyle plugin settings with the IDE settings
When the Maven sync action is triggered within the IDE, the project settings will be synced. This currently requires users to opt-in with a Checkstyle IntelliJ plugin setting.
1 parent 538dc0f commit 9790f59

File tree

10 files changed

+1040
-9
lines changed

10 files changed

+1040
-9
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ dependencies {
8585
intellijIdeaCommunity("2024.1.7")
8686

8787
bundledPlugin("com.intellij.java")
88+
bundledPlugin("org.jetbrains.idea.maven")
8889

8990
testFramework(TestFrameworkType.Platform)
91+
testFramework(TestFrameworkType.Plugin.Maven)
9092
}
9193

9294
implementation("commons-io:commons-io:2.20.0")

src/main/java/org/infernus/idea/checkstyle/config/PluginConfiguration.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PluginConfiguration {
2424
private final List<String> thirdPartyClasspath;
2525
private final SortedSet<String> activeLocationIds;
2626
private final boolean scanBeforeCheckin;
27+
private final boolean importSettingsFromMaven;
2728

2829
PluginConfiguration(@NotNull final String checkstyleVersion,
2930
@NotNull final ScanScope scanScope,
@@ -33,7 +34,8 @@ public class PluginConfiguration {
3334
@NotNull final SortedSet<ConfigurationLocation> locations,
3435
@NotNull final List<String> thirdPartyClasspath,
3536
@NotNull final SortedSet<String> activeLocationIds,
36-
final boolean scanBeforeCheckin) {
37+
final boolean scanBeforeCheckin,
38+
final boolean importSettingsFromMaven) {
3739
this.checkstyleVersion = checkstyleVersion;
3840
this.scanScope = scanScope;
3941
this.suppressErrors = suppressErrors;
@@ -45,6 +47,7 @@ public class PluginConfiguration {
4547
.filter(Objects::nonNull)
4648
.collect(Collectors.toCollection(TreeSet::new));
4749
this.scanBeforeCheckin = scanBeforeCheckin;
50+
this.importSettingsFromMaven = importSettingsFromMaven;
4851
}
4952

5053
@NotNull
@@ -103,6 +106,10 @@ public boolean isScanBeforeCheckin() {
103106
return scanBeforeCheckin;
104107
}
105108

109+
public boolean isImportSettingsFromMaven() {
110+
return importSettingsFromMaven;
111+
}
112+
106113
public boolean hasChangedFrom(final Object other) {
107114
return this.equals(other) && locationsAreEqual((PluginConfiguration) other);
108115
}
@@ -137,13 +144,14 @@ public boolean equals(final Object other) {
137144
&& Objects.equals(locations, otherDto.locations)
138145
&& Objects.equals(thirdPartyClasspath, otherDto.thirdPartyClasspath)
139146
&& Objects.equals(activeLocationIds, otherDto.activeLocationIds)
140-
&& Objects.equals(scanBeforeCheckin, otherDto.scanBeforeCheckin);
147+
&& Objects.equals(scanBeforeCheckin, otherDto.scanBeforeCheckin)
148+
&& Objects.equals(importSettingsFromMaven, otherDto.importSettingsFromMaven);
141149
}
142150

143151
@Override
144152
public int hashCode() {
145153
return Objects.hash(checkstyleVersion, scanScope, suppressErrors, copyLibs, scrollToSource,
146-
locations, thirdPartyClasspath, activeLocationIds, scanBeforeCheckin);
154+
locations, thirdPartyClasspath, activeLocationIds, scanBeforeCheckin, importSettingsFromMaven);
147155
}
148156

149157
}

src/main/java/org/infernus/idea/checkstyle/config/PluginConfigurationBuilder.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public final class PluginConfigurationBuilder {
2121
private List<String> thirdPartyClasspath;
2222
private SortedSet<String> activeLocationIds;
2323
private boolean scanBeforeCheckin;
24+
private boolean importSettingsFromMaven;
2425

2526
private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
2627
@NotNull final ScanScope scanScope,
@@ -30,7 +31,8 @@ private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
3031
@NotNull final SortedSet<ConfigurationLocation> locations,
3132
@NotNull final List<String> thirdPartyClasspath,
3233
@NotNull final SortedSet<String> activeLocationIds,
33-
final boolean scanBeforeCheckin) {
34+
final boolean scanBeforeCheckin,
35+
final boolean importSettingsFromMaven) {
3436
this.checkstyleVersion = checkstyleVersion;
3537
this.scanScope = scanScope;
3638
this.suppressErrors = suppressErrors;
@@ -40,6 +42,7 @@ private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
4042
this.thirdPartyClasspath = thirdPartyClasspath;
4143
this.activeLocationIds = activeLocationIds;
4244
this.scanBeforeCheckin = scanBeforeCheckin;
45+
this.importSettingsFromMaven = importSettingsFromMaven;
4346
}
4447

4548
public static PluginConfigurationBuilder defaultConfiguration(@NotNull final Project project) {
@@ -60,6 +63,7 @@ public static PluginConfigurationBuilder defaultConfiguration(@NotNull final Pro
6063
defaultLocations,
6164
Collections.emptyList(),
6265
Collections.emptySortedSet(),
66+
false,
6367
false);
6468
}
6569

@@ -73,6 +77,7 @@ public static PluginConfigurationBuilder testInstance(@NotNull final String chec
7377
Collections.emptySortedSet(),
7478
Collections.emptyList(),
7579
Collections.emptySortedSet(),
80+
false,
7681
false);
7782
}
7883

@@ -85,7 +90,8 @@ public static PluginConfigurationBuilder from(@NotNull final PluginConfiguration
8590
source.getLocations(),
8691
source.getThirdPartyClasspath(),
8792
source.getActiveLocationIds(),
88-
source.isScanBeforeCheckin());
93+
source.isScanBeforeCheckin(),
94+
source.isImportSettingsFromMaven());
8995
}
9096

9197
public PluginConfigurationBuilder withCheckstyleVersion(@NotNull final String newCheckstyleVersion) {
@@ -133,6 +139,11 @@ public PluginConfigurationBuilder withScanScope(@NotNull final ScanScope newScan
133139
return this;
134140
}
135141

142+
public PluginConfigurationBuilder withImportSettingsFromMaven(final boolean importSettingsFromMaven) {
143+
this.importSettingsFromMaven = importSettingsFromMaven;
144+
return this;
145+
}
146+
136147
public PluginConfiguration build() {
137148
return new PluginConfiguration(
138149
checkstyleVersion,
@@ -143,7 +154,8 @@ public PluginConfiguration build() {
143154
Objects.requireNonNullElseGet(locations, TreeSet::new),
144155
Objects.requireNonNullElseGet(thirdPartyClasspath, ArrayList::new),
145156
Objects.requireNonNullElseGet(activeLocationIds, TreeSet::new),
146-
scanBeforeCheckin);
157+
scanBeforeCheckin,
158+
importSettingsFromMaven);
147159
}
148160

149161
private static ConfigurationLocationFactory configurationLocationFactory(final Project project) {

src/main/java/org/infernus/idea/checkstyle/config/ProjectConfigurationState.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ static class ProjectSettings {
8484
private boolean scrollToSource;
8585
@Tag
8686
private boolean scanBeforeCheckin;
87+
@Tag
88+
private boolean importSettingsFromMaven;
8789
@XCollection
8890
private List<String> thirdPartyClasspath;
8991
@XCollection
@@ -105,6 +107,7 @@ static ProjectSettings create(@NotNull final PluginConfiguration currentPluginCo
105107
projectSettings.copyLibs = currentPluginConfig.isCopyLibs();
106108
projectSettings.scrollToSource = currentPluginConfig.isScrollToSource();
107109
projectSettings.scanBeforeCheckin = currentPluginConfig.isScanBeforeCheckin();
110+
projectSettings.importSettingsFromMaven = currentPluginConfig.isImportSettingsFromMaven();
108111

109112
projectSettings.thirdPartyClasspath = new ArrayList<>(currentPluginConfig.getThirdPartyClasspath());
110113
projectSettings.activeLocationIds = new ArrayList<>(currentPluginConfig.getActiveLocationIds());
@@ -151,7 +154,8 @@ PluginConfigurationBuilder populate(@NotNull final PluginConfigurationBuilder bu
151154
.withScanBeforeCheckin(scanBeforeCheckin)
152155
.withThirdPartyClassPath(requireNonNullElseGet(thirdPartyClasspath, ArrayList::new))
153156
.withLocations(deserialiseLocations(project))
154-
.withActiveLocationIds(new TreeSet<>(requireNonNullElseGet(activeLocationIds, ArrayList::new)));
157+
.withActiveLocationIds(new TreeSet<>(requireNonNullElseGet(activeLocationIds, ArrayList::new)))
158+
.withImportSettingsFromMaven(importSettingsFromMaven);
155159
}
156160

157161
return new LegacyProjectConfigurationStateDeserialiser(project)

0 commit comments

Comments
 (0)