Skip to content

Commit afd2438

Browse files
committed
Rough draft of configuring the plugin based on the Maven plugin configuration
1 parent 8d27ec0 commit afd2438

File tree

9 files changed

+320
-11
lines changed

9 files changed

+320
-11
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dependencies {
8585
intellijIdeaCommunity("2024.1.7")
8686

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

8990
testFramework(TestFrameworkType.Platform)
9091
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class PluginConfiguration {
2525
private final SortedSet<String> activeLocationIds;
2626
private final boolean scanBeforeCheckin;
2727
private final String lastActivePluginVersion;
28+
private final boolean importSettingsFromMaven;
2829

2930
PluginConfiguration(@NotNull final String checkstyleVersion,
3031
@NotNull final ScanScope scanScope,
@@ -34,7 +35,8 @@ public class PluginConfiguration {
3435
@NotNull final List<String> thirdPartyClasspath,
3536
@NotNull final SortedSet<String> activeLocationIds,
3637
final boolean scanBeforeCheckin,
37-
@Nullable final String lastActivePluginVersion) {
38+
@Nullable final String lastActivePluginVersion,
39+
final boolean importSettingsFromMaven) {
3840
this.checkstyleVersion = checkstyleVersion;
3941
this.scanScope = scanScope;
4042
this.suppressErrors = suppressErrors;
@@ -46,6 +48,7 @@ public class PluginConfiguration {
4648
.collect(Collectors.toCollection(TreeSet::new));
4749
this.scanBeforeCheckin = scanBeforeCheckin;
4850
this.lastActivePluginVersion = lastActivePluginVersion;
51+
this.importSettingsFromMaven = importSettingsFromMaven;
4952
}
5053

5154
@NotNull
@@ -105,6 +108,10 @@ public boolean isScanBeforeCheckin() {
105108
return scanBeforeCheckin;
106109
}
107110

111+
public boolean isImportSettingsFromMaven() {
112+
return importSettingsFromMaven;
113+
}
114+
108115
public boolean hasChangedFrom(final Object other) {
109116
return this.equals(other) && locationsAreEqual((PluginConfiguration) other);
110117
}
@@ -139,13 +146,14 @@ public boolean equals(final Object other) {
139146
&& Objects.equals(thirdPartyClasspath, otherDto.thirdPartyClasspath)
140147
&& Objects.equals(activeLocationIds, otherDto.activeLocationIds)
141148
&& Objects.equals(scanBeforeCheckin, otherDto.scanBeforeCheckin)
142-
&& Objects.equals(lastActivePluginVersion, otherDto.lastActivePluginVersion);
149+
&& Objects.equals(lastActivePluginVersion, otherDto.lastActivePluginVersion)
150+
&& Objects.equals(importSettingsFromMaven, otherDto.importSettingsFromMaven);
143151
}
144152

145153
@Override
146154
public int hashCode() {
147155
return Objects.hash(checkstyleVersion, scanScope, suppressErrors, copyLibs, locations, thirdPartyClasspath,
148-
activeLocationIds, scanBeforeCheckin, lastActivePluginVersion);
156+
activeLocationIds, scanBeforeCheckin, lastActivePluginVersion, importSettingsFromMaven);
149157
}
150158

151159
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class PluginConfigurationBuilder {
2323
private SortedSet<String> activeLocationIds;
2424
private boolean scanBeforeCheckin;
2525
private String lastActivePluginVersion;
26+
private boolean importSettingsFromMaven;
2627

2728
private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
2829
@NotNull final ScanScope scanScope,
@@ -32,7 +33,8 @@ private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
3233
@NotNull final List<String> thirdPartyClasspath,
3334
@NotNull final SortedSet<String> activeLocationIds,
3435
final boolean scanBeforeCheckin,
35-
@Nullable final String lastActivePluginVersion) {
36+
@Nullable final String lastActivePluginVersion,
37+
final boolean importSettingsFromMaven) {
3638
this.checkstyleVersion = checkstyleVersion;
3739
this.scanScope = scanScope;
3840
this.suppressErrors = suppressErrors;
@@ -42,6 +44,7 @@ private PluginConfigurationBuilder(@NotNull final String checkstyleVersion,
4244
this.activeLocationIds = activeLocationIds;
4345
this.scanBeforeCheckin = scanBeforeCheckin;
4446
this.lastActivePluginVersion = lastActivePluginVersion;
47+
this.importSettingsFromMaven = importSettingsFromMaven;
4548
}
4649

4750
public static PluginConfigurationBuilder defaultConfiguration(@NotNull final Project project) {
@@ -62,7 +65,8 @@ public static PluginConfigurationBuilder defaultConfiguration(@NotNull final Pro
6265
Collections.emptyList(),
6366
Collections.emptySortedSet(),
6467
false,
65-
CheckStylePlugin.version());
68+
CheckStylePlugin.version(),
69+
false);
6670
}
6771

6872
public static PluginConfigurationBuilder testInstance(@NotNull final String checkstyleVersion) {
@@ -75,7 +79,8 @@ public static PluginConfigurationBuilder testInstance(@NotNull final String chec
7579
Collections.emptyList(),
7680
Collections.emptySortedSet(),
7781
false,
78-
"aVersion");
82+
"aVersion",
83+
false);
7984
}
8085

8186
public static PluginConfigurationBuilder from(@NotNull final PluginConfiguration source) {
@@ -87,7 +92,8 @@ public static PluginConfigurationBuilder from(@NotNull final PluginConfiguration
8792
source.getThirdPartyClasspath(),
8893
source.getActiveLocationIds(),
8994
source.isScanBeforeCheckin(),
90-
source.getLastActivePluginVersion());
95+
source.getLastActivePluginVersion(),
96+
source.isImportSettingsFromMaven());
9197
}
9298

9399
public PluginConfigurationBuilder withCheckstyleVersion(@NotNull final String newCheckstyleVersion) {
@@ -135,6 +141,11 @@ public PluginConfigurationBuilder withLastActivePluginVersion(final String newLa
135141
return this;
136142
}
137143

144+
public PluginConfigurationBuilder withImportSettingsFromMaven(final boolean importSettingsFromMaven) {
145+
this.importSettingsFromMaven = importSettingsFromMaven;
146+
return this;
147+
}
148+
138149
public PluginConfiguration build() {
139150
return new PluginConfiguration(
140151
checkstyleVersion,
@@ -145,7 +156,8 @@ public PluginConfiguration build() {
145156
Objects.requireNonNullElseGet(thirdPartyClasspath, ArrayList::new),
146157
Objects.requireNonNullElseGet(activeLocationIds, TreeSet::new),
147158
scanBeforeCheckin,
148-
lastActivePluginVersion);
159+
lastActivePluginVersion,
160+
importSettingsFromMaven);
149161
}
150162

151163
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
@@ -82,6 +82,8 @@ static class ProjectSettings {
8282
private boolean copyLibs;
8383
@Tag
8484
private boolean scanBeforeCheckin;
85+
@Tag
86+
private boolean importSettingsFromMaven;
8587
@XCollection
8688
private List<String> thirdPartyClasspath;
8789
@XCollection
@@ -102,6 +104,7 @@ static ProjectSettings create(@NotNull final PluginConfiguration currentPluginCo
102104
projectSettings.suppressErrors = currentPluginConfig.isSuppressErrors();
103105
projectSettings.copyLibs = currentPluginConfig.isCopyLibs();
104106
projectSettings.scanBeforeCheckin = currentPluginConfig.isScanBeforeCheckin();
107+
projectSettings.importSettingsFromMaven = currentPluginConfig.isImportSettingsFromMaven();
105108

106109
projectSettings.thirdPartyClasspath = new ArrayList<>(currentPluginConfig.getThirdPartyClasspath());
107110
projectSettings.activeLocationIds = new ArrayList<>(currentPluginConfig.getActiveLocationIds());
@@ -147,7 +150,8 @@ PluginConfigurationBuilder populate(@NotNull final PluginConfigurationBuilder bu
147150
.withScanBeforeCheckin(scanBeforeCheckin)
148151
.withThirdPartyClassPath(requireNonNullElseGet(thirdPartyClasspath, ArrayList::new))
149152
.withLocations(deserialiseLocations(project))
150-
.withActiveLocationIds(new TreeSet<>(requireNonNullElseGet(activeLocationIds, ArrayList::new)));
153+
.withActiveLocationIds(new TreeSet<>(requireNonNullElseGet(activeLocationIds, ArrayList::new)))
154+
.withImportSettingsFromMaven(importSettingsFromMaven);
151155
}
152156

153157
return new LegacyProjectConfigurationStateDeserialiser(project)

0 commit comments

Comments
 (0)