Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop suggesting the save actions plugin #2547

Merged
merged 2 commits into from
Apr 6, 2023
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
8 changes: 8 additions & 0 deletions changelog/@unreleased/pr-2547.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down