Skip to content

Commit aa17651

Browse files
authored
Allow palantir-java-format idea plugin dependency configuration via idea-configuration plugin (#1286)
Allow `palantir-java-format` idea plugin dependency configuration via `idea-configuration plugin`
1 parent f9f7da0 commit aa17651

File tree

10 files changed

+24
-65
lines changed

10 files changed

+24
-65
lines changed

changelog/@unreleased/pr-1286.v2.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type: improvement
2+
improvement:
3+
description: Allow `palantir-java-format` idea plugin dependency configuration via
4+
`idea-configuration` plugin
5+
links:
6+
- https://github.com/palantir/palantir-java-format/pull/1286

eclipse_plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ p2deps {
2727

2828
dependencies {
2929
implementation project(':palantir-java-format')
30+
implementation 'com.google.code.findbugs:jsr305'
3031
}
3132

3233
tasks.named("jar", Jar) {

gradle-palantir-java-format/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
implementation project(':palantir-java-format-spi')
2121
implementation project(':palantir-java-format-jdk-bootstrap')
2222
implementation 'com.palantir.gradle.utils:platform'
23+
implementation 'com.palantir.gradle.idea-configuration:gradle-idea-configuration'
2324

2425
testImplementation project(':palantir-java-format')
2526
testImplementation 'com.netflix.nebula:nebula-test'

gradle-palantir-java-format/src/main/groovy/com/palantir/javaformat/gradle/ConfigureJavaFormatterXml.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class ConfigureJavaFormatterXml {
3737
})
3838
}
3939

40-
static void configureExternalDependencies(Node rootNode, String minVersion) {
41-
def externalDependencies = matchOrCreateChild(rootNode, 'component', [name: 'ExternalDependencies'])
42-
matchOrCreateChild(externalDependencies, 'plugin', [id: 'palantir-java-format'], [:], ['min-version' : minVersion])
43-
}
44-
4540
static void configureWorkspaceXml(Node rootNode) {
4641
configureFormatOnSave(rootNode)
4742
configureOptimizeOnSave(rootNode)

gradle-palantir-java-format/src/main/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPlugin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.common.base.Preconditions;
2020
import com.google.common.collect.ImmutableMap;
2121
import com.google.common.io.Files;
22+
import com.palantir.gradle.ideaconfiguration.IdeaConfigurationExtension;
23+
import com.palantir.gradle.ideaconfiguration.IdeaConfigurationPlugin;
2224
import groovy.util.Node;
2325
import groovy.util.XmlNodePrinter;
2426
import groovy.util.XmlParser;
@@ -59,6 +61,10 @@ public void apply(Project rootProject) {
5961
configureLegacyIdea(rootProject, implConfiguration, nativeImplConfiguration);
6062
configureIntelliJImport(rootProject, implConfiguration, nativeImplConfiguration);
6163
});
64+
65+
rootProject.getPluginManager().apply(IdeaConfigurationPlugin.class);
66+
IdeaConfigurationExtension extension = rootProject.getExtensions().getByType(IdeaConfigurationExtension.class);
67+
extension.externalDependency("palantir-java-format", MIN_IDEA_PLUGIN_VERSION);
6268
}
6369

6470
private static Optional<Configuration> maybeGetNativeImplConfiguration(Project rootProject) {
@@ -79,7 +85,6 @@ private static void configureLegacyIdea(
7985
Optional<URI> nativeUri =
8086
nativeImplConfiguration.map(conf -> conf.getSingleFile().toURI());
8187
ConfigureJavaFormatterXml.configureJavaFormat(xmlProvider.asNode(), uris, nativeUri);
82-
ConfigureJavaFormatterXml.configureExternalDependencies(xmlProvider.asNode(), MIN_IDEA_PLUGIN_VERSION);
8388
});
8489

8590
ideaModel.getWorkspace().getIws().withXml(xmlProvider -> {
@@ -106,16 +111,12 @@ private static void configureIntelliJImport(
106111
createOrUpdateIdeaXmlFile(
107112
project.file(".idea/palantir-java-format.xml"),
108113
node -> ConfigureJavaFormatterXml.configureJavaFormat(node, uris, nativeImageUri));
109-
createOrUpdateIdeaXmlFile(
110-
project.file(".idea/externalDependencies.xml"),
111-
node -> ConfigureJavaFormatterXml.configureExternalDependencies(node, MIN_IDEA_PLUGIN_VERSION));
112114
createOrUpdateIdeaXmlFile(
113115
project.file(".idea/workspace.xml"), ConfigureJavaFormatterXml::configureWorkspaceXml);
114116

115117
// Still configure legacy idea if using intellij import
116118
updateIdeaXmlFileIfExists(project.file(project.getName() + ".ipr"), node -> {
117119
ConfigureJavaFormatterXml.configureJavaFormat(node, uris, nativeImageUri);
118-
ConfigureJavaFormatterXml.configureExternalDependencies(node, MIN_IDEA_PLUGIN_VERSION);
119120
});
120121
updateIdeaXmlFileIfExists(
121122
project.file(project.getName() + ".iws"), ConfigureJavaFormatterXml::configureWorkspaceXml);

gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/ConfigureJavaFormatterXmlTest.groovy

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,6 @@ import spock.lang.Unroll
2121

2222
class ConfigureJavaFormatterXmlTest extends Specification {
2323

24-
private static final String EXTERNAL_DEPENDENCIES_NO_PJF = """\
25-
<project version="4">
26-
<component name="ExternalDependencies">
27-
<plugin id="CheckStyle-IDEA"/>
28-
</component>
29-
</project>
30-
""".stripIndent(true)
31-
32-
private static final String EXTERNAL_DEPENDENCIES_WITH_PJF = """\
33-
<project version="4">
34-
<component name="ExternalDependencies">
35-
<plugin id="CheckStyle-IDEA"/>
36-
<plugin id="palantir-java-format"/>
37-
</component>
38-
</project>
39-
""".stripIndent(true)
40-
41-
private static final String EXTERNAL_DEPENDENCIES_WITH_PINNED_PJF = """\
42-
<project version="4">
43-
<component name="ExternalDependencies">
44-
<plugin id="CheckStyle-IDEA"/>
45-
<plugin id="palantir-java-format" min-version="1.0.0"/>
46-
</component>
47-
</project>
48-
""".stripIndent(true)
49-
50-
51-
private static final String EXPECTED_EXTERNAL_DEPENDENCIES = """\
52-
<project version="4">
53-
<component name="ExternalDependencies">
54-
<plugin id="CheckStyle-IDEA"/>
55-
<plugin id="palantir-java-format" min-version="9.9.9"/>
56-
</component>
57-
</project>
58-
""".stripIndent(true)
59-
6024
private static final String EXISTING_CLASS_PATH = """
6125
<root>
6226
<component name="PalantirJavaFormatSettings">
@@ -312,20 +276,6 @@ class ConfigureJavaFormatterXmlTest extends Specification {
312276
action << ACTIONS_ON_SAVE
313277
}
314278

315-
@Unroll
316-
def 'can update externalDependencies file'(input) {
317-
def node = new XmlParser().parseText(input)
318-
319-
when:
320-
ConfigureJavaFormatterXml.configureExternalDependencies(node, "9.9.9")
321-
322-
then:
323-
xmlToString(node) == EXPECTED_EXTERNAL_DEPENDENCIES
324-
325-
where:
326-
input << [EXTERNAL_DEPENDENCIES_NO_PJF, EXTERNAL_DEPENDENCIES_WITH_PINNED_PJF, EXTERNAL_DEPENDENCIES_WITH_PJF]
327-
}
328-
329279
private static String xmlSubcomponentToString(Node node, String name) {
330280
xmlToString(node.children().find { it.@name == name }).strip()
331281
}

idea-plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ dependencies {
6868
testImplementation 'org.assertj:assertj-core'
6969
testImplementation 'org.junit.jupiter:junit-jupiter'
7070
testImplementation 'org.junit.platform:junit-platform-launcher'
71+
implementation 'com.google.code.findbugs:jsr305'
7172
}
7273

7374
// Javadoc fails if there are no public classes to javadoc, so make it stop complaining.

palantir-java-format/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828

2929
compileOnly 'org.derive4j:derive4j-annotation'
3030
annotationProcessor 'org.derive4j:derive4j'
31+
implementation 'com.google.code.findbugs:jsr305'
3132
}
3233

3334
moduleJvmArgs {

versions.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ com.fasterxml.jackson.module:jackson-module-parameter-names:2.18.3 (1 constraint
1515
com.google.auto:auto-common:1.2.1 (2 constraints: b321cc9d)
1616
com.google.auto.service:auto-service:1.1.1 (1 constraints: 0505f435)
1717
com.google.auto.service:auto-service-annotations:1.1.1 (1 constraints: 9c0f6a86)
18-
com.google.code.findbugs:jsr305:3.0.2 (3 constraints: 571ca3f6)
18+
com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 4112851c)
1919
com.google.errorprone:error_prone_annotations:2.36.0 (4 constraints: 4b27bf7b)
20-
com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4)
21-
com.google.guava:guava:33.4.0-jre (8 constraints: 3e85a804)
20+
com.google.guava:failureaccess:1.0.3 (1 constraints: 160ae3b4)
21+
com.google.guava:guava:33.4.8-jre (9 constraints: 5ea13c2f)
2222
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
2323
com.google.j2objc:j2objc-annotations:3.0.0 (2 constraints: ee163332)
2424
com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da)
2525
com.googlecode.javaewah:JavaEWAH:1.2.3 (1 constraints: 460e7e50)
26+
com.palantir.gradle.idea-configuration:gradle-idea-configuration:0.2.0 (1 constraints: 0405f135)
2627
com.palantir.gradle.utils:platform:0.10.0 (1 constraints: 3305233b)
2728
com.squareup.okhttp3:okhttp:4.12.0 (1 constraints: f6093eb3)
2829
com.squareup.okio:okio:3.6.0 (1 constraints: 530c38fd)
@@ -31,7 +32,6 @@ commons-codec:commons-codec:1.16.0 (1 constraints: 780efe5e)
3132
dev.equo.ide:solstice:1.7.5 (1 constraints: 7a1168da)
3233
net.sf.jopt-simple:jopt-simple:5.0.4 (1 constraints: be0ad6cc)
3334
org.apache.commons:commons-math3:3.6.1 (1 constraints: bf0adbcc)
34-
org.checkerframework:checker-qual:3.43.0 (4 constraints: 6734e847)
3535
org.derive4j:derive4j-annotation:1.1.1 (1 constraints: 0505f435)
3636
org.eclipse.jdt:org.eclipse.jdt.core:3.23.0 (1 constraints: 3a05423b)
3737
org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r (2 constraints: f22a55d9)
@@ -56,6 +56,7 @@ org.jetbrains.kotlin:kotlin-stdlib:1.9.10 (2 constraints: c2210fe1)
5656
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10 (2 constraints: 3f1b4b83)
5757
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10 (1 constraints: e210ffd2)
5858
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10 (2 constraints: 8118c1c5)
59+
org.jspecify:jspecify:1.0.0 (1 constraints: 130ae0b4)
5960
org.openjdk.jmh:jmh-core:1.37 (5 constraints: 52476be6)
6061
org.openjdk.jmh:jmh-generator-annprocess:1.37 (1 constraints: df04fc30)
6162
org.slf4j:slf4j-api:1.7.36 (2 constraints: 801849c0)
@@ -74,6 +75,7 @@ junit:junit:4.13.2 (7 constraints: da62ac41)
7475
net.bytebuddy:byte-buddy:1.14.11 (1 constraints: 7e0bc5ea)
7576
org.apiguardian:apiguardian-api:1.1.2 (10 constraints: 8fb0f648)
7677
org.assertj:assertj-core:3.25.3 (1 constraints: 3f054b3b)
78+
org.checkerframework:checker-qual:3.42.0 (3 constraints: 1c2a3b96)
7779
org.codehaus.groovy:groovy:3.0.6 (2 constraints: 1e1b476d)
7880
org.graalvm.buildtools:junit-platform-native:0.10.4 (1 constraints: 3705273b)
7981
org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04)

versions.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
com.diffplug.spotless:spotless-plugin-gradle = 6.25.0
22
com.github.ben-manes.caffeine:caffeine = 3.1.8
33
com.google.auto.service:auto-service = 1.1.1
4-
com.google.code.findbugs:jsr305 = 3.0.2
4+
com.google.code.findbugs:* = 3.0.2
55
com.google.errorprone:error_prone_annotations = 2.11.0
66
com.google.guava:guava = 33.0.0-jre
77
com.google.guava:guava-testlib = 27.0.1-jre
@@ -22,3 +22,4 @@ com.fasterxml.jackson.*:* = 2.18.3
2222
com.fasterxml.jackson.core:jackson-databind = 2.18.3
2323
org.openjdk.jmh:* = 1.37
2424
com.palantir.gradle.utils:* = 0.10.0
25+
com.palantir.gradle.idea-configuration:gradle-idea-configuration = 0.2.0

0 commit comments

Comments
 (0)