[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
This commit is contained in:
Nikolay Chashnikov
2020-05-26 20:51:54 +03:00
committed by intellij-monorepo-bot
parent f23b5b1c85
commit 0c57485914
3 changed files with 28 additions and 11 deletions
@@ -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",
@@ -27,6 +27,16 @@
</orderEntry>
<orderEntry type="library" scope="RUNTIME" name="org.codehaus.groovy:groovy-templates" level="project" />
<orderEntry type="library" scope="RUNTIME" name="org.codehaus.groovy:groovy-xml" level="project" />
<orderEntry type="module-library" scope="RUNTIME">
<library name="org.codehaus.groovy:groovy-cli-commons" type="repository">
<properties include-transitive-deps="false" maven-id="org.codehaus.groovy:groovy-cli-commons:2.5.11" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/codehaus/groovy/groovy-cli-commons/2.5.11/groovy-cli-commons-2.5.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="RUNTIME" name="gant-groovy" level="project" />
<orderEntry type="library" scope="RUNTIME" name="gson" level="project" />
</component>
@@ -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")