From 0c57485914332c658f2bf072c46d54034bd1ca64 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Tue, 26 May 2020 20:51:21 +0300 Subject: [PATCH] [devkit] fix "Update IDE from Sources" action: add proper groovy version to classpath The action was broken after updating to Groovy 2.5 because paths to libraries were hardcoded. Now they are taken from the project configuration, and groovy-cli-commons is added to classpath (it contains groovy.util.CliBuilder which is used by Gant). (Dependency on groovy-cli-commons in intellij.idea.ultimate.build should be removed after we update jps-build-script-dependencies-bootstrap library.) GitOrigin-RevId: 728ca2e1a00f920d4d8203436d57c984d8daf57d --- .../build/CommunityLibraryLicenses.groovy | 2 ++ ...llij.tools.jps.buildScriptDependencies.iml | 10 +++++++ .../UpdateIdeFromSourcesAction.kt | 27 +++++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy index b57b4b150de9..9d5bd66b06f3 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy @@ -247,6 +247,8 @@ class CommunityLibraryLicenses { license: "Apache 2.0", url: "https://groovy-lang.org/"), new LibraryLicense(name: "Groovy Ant", libraryName: "org.codehaus.groovy:groovy-ant", license: "Apache 2.0", url: "https://groovy-lang.org/"), + new LibraryLicense(name: "Groovy CLI Commons", libraryName: "org.codehaus.groovy:groovy-cli-commons", + license: "Apache 2.0", url: "https://groovy-lang.org/"), new LibraryLicense(name: "Groovy JSON", libraryName: "org.codehaus.groovy:groovy-json", license: "Apache 2.0", url: "https://groovy-lang.org/"), new LibraryLicense(name: "Groovy JSR-223", libraryName: "org.codehaus.groovy:groovy-jsr223", diff --git a/platform/build-scripts/intellij.tools.jps.buildScriptDependencies.iml b/platform/build-scripts/intellij.tools.jps.buildScriptDependencies.iml index eac94def2eab..21200c4c8591 100644 --- a/platform/build-scripts/intellij.tools.jps.buildScriptDependencies.iml +++ b/platform/build-scripts/intellij.tools.jps.buildScriptDependencies.iml @@ -27,6 +27,16 @@ + + + + + + + + + + diff --git a/plugins/devkit/devkit-core/src/actions/updateFromSources/UpdateIdeFromSourcesAction.kt b/plugins/devkit/devkit-core/src/actions/updateFromSources/UpdateIdeFromSourcesAction.kt index 34c25f7db643..8cdc3e8d9379 100644 --- a/plugins/devkit/devkit-core/src/actions/updateFromSources/UpdateIdeFromSourcesAction.kt +++ b/plugins/devkit/devkit-core/src/actions/updateFromSources/UpdateIdeFromSourcesAction.kt @@ -23,13 +23,16 @@ import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.IndexNotReadyException import com.intellij.openapi.project.Project import com.intellij.openapi.roots.OrderEnumerator +import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.roots.libraries.LibraryUtil import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.Key import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.systemIndependentPath import com.intellij.task.ProjectTaskManager +import com.intellij.util.PathUtil import com.intellij.util.Restarter import com.intellij.util.SystemProperties import org.jetbrains.idea.devkit.util.PsiUtil @@ -290,17 +293,6 @@ internal open class UpdateIdeFromSourcesAction params.isUseClasspathJar = true params.setDefaultCharset(project) params.jdk = sdk - //todo use org.jetbrains.idea.maven.utils.MavenUtil.resolveLocalRepository instead - val m2Repo = File(SystemProperties.getUserHome(), ".m2/repository").systemIndependentPath - - //todo get from project configuration - val coreClassPath = listOf( - "$m2Repo/org/codehaus/groovy/groovy-all/2.4.17/groovy-all-2.4.17.jar", - "$m2Repo/commons-cli/commons-cli/1.2/commons-cli-1.2.jar", - "$devIdeaHome/community/lib/ant/lib/ant.jar", - "$devIdeaHome/community/lib/ant/lib/ant-launcher.jar" - ) - params.classPath.addAll(coreClassPath) params.mainClass = "org.codehaus.groovy.tools.GroovyStarter" params.programParametersList.add("--classpath") @@ -312,7 +304,20 @@ internal open class UpdateIdeFromSourcesAction } val classpath = OrderEnumerator.orderEntries(buildScriptsModule) .recursively().withoutSdk().runtimeOnly().productionOnly().classes().pathsList + + val classesFromCoreJars = listOf( + params.mainClass, + "org.apache.tools.ant.BuildException", //ant + "org.apache.tools.ant.launch.AntMain", //ant-launcher + "org.apache.commons.cli.ParseException", //commons-cli + "groovy.util.CliBuilder" //groovy-cli-commons + ) + val coreClassPath = classpath.rootDirs.filter { root -> + classesFromCoreJars.any { LibraryUtil.isClassAvailableInLibrary(listOf(root), it) } + }.mapNotNull { PathUtil.getLocalPath(it) } + params.classPath.addAll(coreClassPath) coreClassPath.forEach { classpath.remove(FileUtil.toSystemDependentName(it)) } + params.programParametersList.add(classpath.pathsString) params.programParametersList.add("--main") params.programParametersList.add("gant.Gant")