Skip to content
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
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-1286.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Allow `palantir-java-format` idea plugin dependency configuration via
`idea-configuration` plugin
links:
- https://github.com/palantir/palantir-java-format/pull/1286
1 change: 1 addition & 0 deletions eclipse_plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ p2deps {

dependencies {
implementation project(':palantir-java-format')
implementation 'com.google.code.findbugs:jsr305'
}

tasks.named("jar", Jar) {
Expand Down
1 change: 1 addition & 0 deletions gradle-palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
implementation project(':palantir-java-format-spi')
implementation project(':palantir-java-format-jdk-bootstrap')
implementation 'com.palantir.gradle.utils:platform'
implementation 'com.palantir.gradle.idea-configuration:gradle-idea-configuration'

testImplementation project(':palantir-java-format')
testImplementation 'com.netflix.nebula:nebula-test'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class ConfigureJavaFormatterXml {
})
}

static void configureExternalDependencies(Node rootNode, String minVersion) {
def externalDependencies = matchOrCreateChild(rootNode, 'component', [name: 'ExternalDependencies'])
matchOrCreateChild(externalDependencies, 'plugin', [id: 'palantir-java-format'], [:], ['min-version' : minVersion])
}

static void configureWorkspaceXml(Node rootNode) {
configureFormatOnSave(rootNode)
configureOptimizeOnSave(rootNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import com.palantir.gradle.ideaconfiguration.IdeaConfigurationExtension;
import com.palantir.gradle.ideaconfiguration.IdeaConfigurationPlugin;
import groovy.util.Node;
import groovy.util.XmlNodePrinter;
import groovy.util.XmlParser;
Expand Down Expand Up @@ -59,6 +61,10 @@ public void apply(Project rootProject) {
configureLegacyIdea(rootProject, implConfiguration, nativeImplConfiguration);
configureIntelliJImport(rootProject, implConfiguration, nativeImplConfiguration);
});

rootProject.getPluginManager().apply(IdeaConfigurationPlugin.class);
IdeaConfigurationExtension extension = rootProject.getExtensions().getByType(IdeaConfigurationExtension.class);
extension.externalDependency("palantir-java-format", MIN_IDEA_PLUGIN_VERSION);
}

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

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

// Still configure legacy idea if using intellij import
updateIdeaXmlFileIfExists(project.file(project.getName() + ".ipr"), node -> {
ConfigureJavaFormatterXml.configureJavaFormat(node, uris, nativeImageUri);
ConfigureJavaFormatterXml.configureExternalDependencies(node, MIN_IDEA_PLUGIN_VERSION);
});
updateIdeaXmlFileIfExists(
project.file(project.getName() + ".iws"), ConfigureJavaFormatterXml::configureWorkspaceXml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,6 @@ import spock.lang.Unroll

class ConfigureJavaFormatterXmlTest extends Specification {

private static final String EXTERNAL_DEPENDENCIES_NO_PJF = """\
<project version="4">
<component name="ExternalDependencies">
<plugin id="CheckStyle-IDEA"/>
</component>
</project>
""".stripIndent(true)

private static final String EXTERNAL_DEPENDENCIES_WITH_PJF = """\
<project version="4">
<component name="ExternalDependencies">
<plugin id="CheckStyle-IDEA"/>
<plugin id="palantir-java-format"/>
</component>
</project>
""".stripIndent(true)

private static final String EXTERNAL_DEPENDENCIES_WITH_PINNED_PJF = """\
<project version="4">
<component name="ExternalDependencies">
<plugin id="CheckStyle-IDEA"/>
<plugin id="palantir-java-format" min-version="1.0.0"/>
</component>
</project>
""".stripIndent(true)


private static final String EXPECTED_EXTERNAL_DEPENDENCIES = """\
<project version="4">
<component name="ExternalDependencies">
<plugin id="CheckStyle-IDEA"/>
<plugin id="palantir-java-format" min-version="9.9.9"/>
</component>
</project>
""".stripIndent(true)

private static final String EXISTING_CLASS_PATH = """
<root>
<component name="PalantirJavaFormatSettings">
Expand Down Expand Up @@ -312,20 +276,6 @@ class ConfigureJavaFormatterXmlTest extends Specification {
action << ACTIONS_ON_SAVE
}

@Unroll
def 'can update externalDependencies file'(input) {
def node = new XmlParser().parseText(input)

when:
ConfigureJavaFormatterXml.configureExternalDependencies(node, "9.9.9")

then:
xmlToString(node) == EXPECTED_EXTERNAL_DEPENDENCIES

where:
input << [EXTERNAL_DEPENDENCIES_NO_PJF, EXTERNAL_DEPENDENCIES_WITH_PINNED_PJF, EXTERNAL_DEPENDENCIES_WITH_PJF]
}

private static String xmlSubcomponentToString(Node node, String name) {
xmlToString(node.children().find { it.@name == name }).strip()
}
Expand Down
1 change: 1 addition & 0 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.junit.platform:junit-platform-launcher'
implementation 'com.google.code.findbugs:jsr305'
}

// Javadoc fails if there are no public classes to javadoc, so make it stop complaining.
Expand Down
1 change: 1 addition & 0 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {

compileOnly 'org.derive4j:derive4j-annotation'
annotationProcessor 'org.derive4j:derive4j'
implementation 'com.google.code.findbugs:jsr305'
}

moduleJvmArgs {
Expand Down
10 changes: 6 additions & 4 deletions versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ com.fasterxml.jackson.module:jackson-module-parameter-names:2.18.3 (1 constraint
com.google.auto:auto-common:1.2.1 (2 constraints: b321cc9d)
com.google.auto.service:auto-service:1.1.1 (1 constraints: 0505f435)
com.google.auto.service:auto-service-annotations:1.1.1 (1 constraints: 9c0f6a86)
com.google.code.findbugs:jsr305:3.0.2 (3 constraints: 571ca3f6)
com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 4112851c)
com.google.errorprone:error_prone_annotations:2.36.0 (4 constraints: 4b27bf7b)
com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4)
com.google.guava:guava:33.4.0-jre (8 constraints: 3e85a804)
com.google.guava:failureaccess:1.0.3 (1 constraints: 160ae3b4)
com.google.guava:guava:33.4.8-jre (9 constraints: 5ea13c2f)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:3.0.0 (2 constraints: ee163332)
com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da)
com.googlecode.javaewah:JavaEWAH:1.2.3 (1 constraints: 460e7e50)
com.palantir.gradle.idea-configuration:gradle-idea-configuration:0.2.0 (1 constraints: 0405f135)
com.palantir.gradle.utils:platform:0.10.0 (1 constraints: 3305233b)
com.squareup.okhttp3:okhttp:4.12.0 (1 constraints: f6093eb3)
com.squareup.okio:okio:3.6.0 (1 constraints: 530c38fd)
Expand All @@ -31,7 +32,6 @@ commons-codec:commons-codec:1.16.0 (1 constraints: 780efe5e)
dev.equo.ide:solstice:1.7.5 (1 constraints: 7a1168da)
net.sf.jopt-simple:jopt-simple:5.0.4 (1 constraints: be0ad6cc)
org.apache.commons:commons-math3:3.6.1 (1 constraints: bf0adbcc)
org.checkerframework:checker-qual:3.43.0 (4 constraints: 6734e847)
org.derive4j:derive4j-annotation:1.1.1 (1 constraints: 0505f435)
org.eclipse.jdt:org.eclipse.jdt.core:3.23.0 (1 constraints: 3a05423b)
org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r (2 constraints: f22a55d9)
Expand All @@ -56,6 +56,7 @@ org.jetbrains.kotlin:kotlin-stdlib:1.9.10 (2 constraints: c2210fe1)
org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10 (2 constraints: 3f1b4b83)
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10 (1 constraints: e210ffd2)
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10 (2 constraints: 8118c1c5)
org.jspecify:jspecify:1.0.0 (1 constraints: 130ae0b4)
org.openjdk.jmh:jmh-core:1.37 (5 constraints: 52476be6)
org.openjdk.jmh:jmh-generator-annprocess:1.37 (1 constraints: df04fc30)
org.slf4j:slf4j-api:1.7.36 (2 constraints: 801849c0)
Expand All @@ -74,6 +75,7 @@ junit:junit:4.13.2 (7 constraints: da62ac41)
net.bytebuddy:byte-buddy:1.14.11 (1 constraints: 7e0bc5ea)
org.apiguardian:apiguardian-api:1.1.2 (10 constraints: 8fb0f648)
org.assertj:assertj-core:3.25.3 (1 constraints: 3f054b3b)
org.checkerframework:checker-qual:3.42.0 (3 constraints: 1c2a3b96)
org.codehaus.groovy:groovy:3.0.6 (2 constraints: 1e1b476d)
org.graalvm.buildtools:junit-platform-native:0.10.4 (1 constraints: 3705273b)
org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04)
Expand Down
3 changes: 2 additions & 1 deletion versions.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
com.diffplug.spotless:spotless-plugin-gradle = 6.25.0
com.github.ben-manes.caffeine:caffeine = 3.1.8
com.google.auto.service:auto-service = 1.1.1
com.google.code.findbugs:jsr305 = 3.0.2
com.google.code.findbugs:* = 3.0.2
com.google.errorprone:error_prone_annotations = 2.11.0
com.google.guava:guava = 33.0.0-jre
com.google.guava:guava-testlib = 27.0.1-jre
Expand All @@ -22,3 +22,4 @@ com.fasterxml.jackson.*:* = 2.18.3
com.fasterxml.jackson.core:jackson-databind = 2.18.3
org.openjdk.jmh:* = 1.37
com.palantir.gradle.utils:* = 0.10.0
com.palantir.gradle.idea-configuration:gradle-idea-configuration = 0.2.0