From cb92fa5614c2d920c946fc1a7118bb7312eb1b46 Mon Sep 17 00:00:00 2001 From: Dan Fox Date: Tue, 17 Nov 2020 16:35:15 +0000 Subject: [PATCH 1/4] Fix BaselineIdea accessing the checkstyle version --- .../baseline/plugins/BaselineIdea.groovy | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) 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 26adaf3f4..72f40f0c3 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 @@ -27,7 +27,9 @@ import java.util.function.Supplier import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.XmlProvider import org.gradle.api.file.FileTreeElement +import org.gradle.api.plugins.quality.CheckstyleExtension import org.gradle.api.specs.Spec import org.gradle.api.tasks.util.PatternFilterable import org.gradle.plugins.ide.idea.GenerateIdeaModule @@ -37,6 +39,8 @@ import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.plugins.ide.idea.model.IdeaModel 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' @@ -82,7 +86,7 @@ class BaselineIdea extends AbstractBaselinePlugin { void applyToRootProject(Project project) { // Configure Idea project IdeaModel ideaRootModel = project.extensions.findByType(IdeaModel) - ideaRootModel.project.ipr.withXml { provider -> + ideaRootModel.project.ipr.withXml {XmlProvider provider -> Node node = provider.asNode() addCodeStyle(node) addCopyright(node) @@ -97,7 +101,7 @@ class BaselineIdea extends AbstractBaselinePlugin { configureProjectForIntellijImport(project) project.afterEvaluate { - ideaRootModel.workspace.iws.withXml { provider -> + ideaRootModel.workspace.iws.withXml {XmlProvider provider -> Node node = provider.asNode() setRunManagerWorkingDirectory(node) addEditorSettings(node) @@ -108,7 +112,7 @@ class BaselineIdea extends AbstractBaselinePlugin { // 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. project.getPluginManager().withPlugin("com.palantir.java-format-idea") { - ideaRootModel.project.ipr.withXml { provider -> + ideaRootModel.project.ipr.withXml {XmlProvider provider -> Node node = provider.asNode() configureSaveActions(node) configureExternalDependencies(node) @@ -179,8 +183,8 @@ class BaselineIdea extends AbstractBaselinePlugin { /** * Extracts copyright headers from Baseline directory and adds them to Idea project XML node. */ - private void addCopyright(node) { - def copyrightManager = node.component.find { it.'@name' == 'CopyrightManager' } + private void addCopyright(Node node) { + Node copyrightManager = node.component.find {it.'@name' == 'CopyrightManager'} def copyrightDir = Paths.get("${configDir}/copyright/") def copyrightFiles = getCopyrightFiles(copyrightDir) copyrightFiles.each { File file -> @@ -240,7 +244,7 @@ class BaselineIdea extends AbstractBaselinePlugin { return copyrightFiles } - private static void addCopyrightFile(node, File file, String fileName) { + private static void addCopyrightFile(Node node, File file, String fileName) { def copyrightText = XmlUtil.escapeControlCharacters(XmlUtil.escapeXml(file.text.trim())) node.append(new XmlParser().parseText(""" @@ -273,6 +277,7 @@ class BaselineIdea extends AbstractBaselinePlugin { } project.logger.debug "Baseline: Configuring EclipseCodeFormatter plugin for Idea" + // language=xml node.append(new XmlParser().parseText("""