diff --git a/changelog/@unreleased/pr-2547.v2.yml b/changelog/@unreleased/pr-2547.v2.yml new file mode 100644 index 000000000..7a08e3149 --- /dev/null +++ b/changelog/@unreleased/pr-2547.v2.yml @@ -0,0 +1,8 @@ +type: fix +fix: + description: No longer suggest the "Save Actions" IntelliJ plugin which does not + work in IntelliJ 2023.1 for use with Palantir Java Format. Instead, Palantir Java + Format will support the IntelliJ native "Actions on save" reformat capability + in a future release. + links: + - https://github.com/palantir/gradle-baseline/pull/2547 diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineIdea.groovy b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineIdea.groovy index 40821e54e..9c6d92bfa 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineIdea.groovy +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineIdea.groovy @@ -47,9 +47,6 @@ import org.gradle.plugins.ide.idea.model.ModuleDependency // TODO(dfox): separate the xml manipulation (which really benefits from groovy syntax) from typed things //@CompileStatic class BaselineIdea extends AbstractBaselinePlugin { - - static SAVE_ACTIONS_PLUGIN_MINIMUM_VERSION = '1.9.0' - void apply(Project project) { this.project = project @@ -111,18 +108,6 @@ class BaselineIdea extends AbstractBaselinePlugin { addEditorSettings(node) } } - - // Suggest and configure the "save actions" plugin if Palantir Java Format is turned on. - // This plugin can only be applied to the root project, and it applied as a side-effect of applying - // 'com.palantir.java-format' to any subproject. - rootProject.getPluginManager().withPlugin("com.palantir.java-format-idea") { - ideaRootModel.project.ipr.withXml {XmlProvider provider -> - Node node = provider.asNode() - configureSaveActions(node) - configureExternalDependencies(node) - } - configureSaveActionsForIntellijImport(rootProject) - } } @CompileStatic @@ -522,18 +507,6 @@ class BaselineIdea extends AbstractBaselinePlugin { '''.stripIndent())) } - private static void configureSaveActionsForIntellijImport(Project project) { - if (!IntellijSupport.isRunningInIntellij()) { - return - } - XmlUtils.createOrUpdateXmlFile( - project.file(".idea/externalDependencies.xml"), - BaselineIdea.&configureExternalDependencies) - XmlUtils.createOrUpdateXmlFile( - project.file(".idea/saveactions_settings.xml"), - BaselineIdea.&configureSaveActions) - } - /** * Configure the default working directory of RunManager configurations to be the module directory. */ @@ -573,36 +546,4 @@ class BaselineIdea extends AbstractBaselinePlugin { module.dependencies.addAll(projectRefs) } } - - /** - * Configures some defaults on the save-actions plugin, but only if it hasn't been configured before. - */ - private static void configureSaveActions(Node rootNode) { - GroovyXmlUtils.matchOrCreateChild(rootNode, 'component', [name: 'SaveActionSettings'], [:]) { - // Configure defaults if this plugin is configured for the first time only - appendNode('option', [name: 'actions']).appendNode('set').with { - appendNode('option', [value: 'activate']) - appendNode('option', [value: 'noActionIfCompileErrors']) - appendNode('option', [value: 'organizeImports']) - appendNode('option', [value: 'reformat']) - } - appendNode('option', [name: 'configurationPath', value: '']) - appendNode('option', [name: 'inclusions']).appendNode('set').with { - appendNode('option', [value: "src${File.separator}.*\\.java"]) - } - } - } - - private static void configureExternalDependencies(Node rootNode) { - def externalDependencies = - GroovyXmlUtils.matchOrCreateChild(rootNode, 'component', [name: 'ExternalDependencies']) - // I kid you not, this is the id for the save actions plugin: - // https://github.com/dubreuia/intellij-plugin-save-actions/blob/v1.9.0/src/main/resources/META-INF/plugin.xml#L5 - // https://plugins.jetbrains.com/plugin/7642-save-actions/ - GroovyXmlUtils.matchOrCreateChild( - externalDependencies, - 'plugin', - [id: 'com.dubreuia'], - ['min-version': SAVE_ACTIONS_PLUGIN_MINIMUM_VERSION]) - } } diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineIdeaIntegrationTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineIdeaIntegrationTest.groovy index e35c3a823..de2160a42 100644 --- a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineIdeaIntegrationTest.groovy +++ b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineIdeaIntegrationTest.groovy @@ -313,56 +313,6 @@ class BaselineIdeaIntegrationTest extends AbstractPluginTest { !otherSubprojectIml.exists() } - def "idea configures the save-action plugin when PJF is enabled on a subproject"() { - buildFile << standardBuildFile - multiProject.addSubproject('formatted-project', """ - apply plugin: 'com.palantir.java-format' - """.stripIndent()) - - when: - with('idea').build() - - then: - def iprFile = new File(projectDir, "${moduleName}.ipr") - def ipr = new XmlSlurper().parse(iprFile) - ipr.component.find { it.@name == "ExternalDependencies" } - ipr.component.find { it.@name == "SaveActionSettings" } - } - - def "idea does not configure the save-action plugin when PJF is not enabled"() { - buildFile << standardBuildFile - - when: - with('idea').build() - - then: - def iprFile = new File(projectDir, "${moduleName}.ipr") - def ipr = new XmlSlurper().parse(iprFile) - !ipr.component.find { it.@name == "ExternalDependencies" } - !ipr.component.find { it.@name == "SaveActionSettings" } - } - - @RestoreSystemProperties - def "idea configures the save-action plugin for IntelliJ import"() { - buildFile << standardBuildFile - multiProject.addSubproject('formatted-project', """ - apply plugin: 'com.palantir.java-format' - """.stripIndent()) - - when: - System.setProperty("idea.active", "true") - with().build() - - then: - def saveActionsSettingsFile = new File(projectDir, ".idea/saveactions_settings.xml") - def settings = new XmlSlurper().parse(saveActionsSettingsFile) - settings.component.find { it.@name == "SaveActionSettings" } - - def externalDepsSettingsFile = new File(projectDir, ".idea/externalDependencies.xml") - def deps = new XmlSlurper().parse(externalDepsSettingsFile) - deps.component.find { it.@name == "ExternalDependencies" } - } - def 'Idea files use versions derived from the baseline-java-versions plugin'() { when: buildFile << standardBuildFile