From d30b768679d4f9121d793388e1998ddf76265c41 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Fri, 30 Jul 2021 18:47:10 +0300 Subject: [PATCH] [build scripts] don't disable a plugin in IDE started from build scripts, if the plugin is explicitly added ... via getAdditionalPluginPaths. We had to add kotlin.idea module to compatiblePluginsToIgnore path because it's layout isn't specified (KTIJ-11539), but we need to have it while building provided modules list, otherwise non-bundled plugins which depend on Kotlin plugin won't be built. GitOrigin-RevId: ac64ba9bc3c1036b395057946c30cb2b48c43218 --- .../intellij/build/impl/ArchiveUtils.groovy | 18 +++++++++++---- .../intellij/build/impl/BuildTasksImpl.groovy | 23 ++++++++++++++++--- .../intellij/build/impl/BuildUtils.groovy | 16 +++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/ArchiveUtils.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/ArchiveUtils.groovy index f9838e1b1f61..1b17712bc2cc 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/ArchiveUtils.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/ArchiveUtils.groovy @@ -14,13 +14,14 @@ import java.util.zip.ZipFile class ArchiveUtils { static boolean archiveContainsEntry(String archivePath, String entryPath) { File archiveFile = new File(archivePath) - if (archiveFile.name.endsWith(".zip")) { + String fileName = archiveFile.name + if (isZipFile(fileName)) { return new ZipFile(archiveFile).withCloseable { it.getEntry(entryPath) != null } } - if (archiveFile.name.endsWith(".tar.gz")) { + if (fileName.endsWith(".tar.gz")) { return archiveFile.withInputStream { TarInputStream inputStream = new TarInputStream(new GZIPInputStream(it)) TarEntry entry @@ -37,17 +38,20 @@ class ArchiveUtils { } static @Nullable String loadEntry(Path archiveFile, String entryPath) { - if (archiveFile.fileName.toString().endsWith(".zip")) { + String fileName = archiveFile.fileName.toString() + if (isZipFile(fileName)) { ZipFile zipFile = new ZipFile(archiveFile.toFile()) try { - InputStream inputStream = zipFile.getInputStream(zipFile.getEntry(entryPath)) + def zipEntry = zipFile.getEntry(entryPath) + if (zipEntry == null) return null + InputStream inputStream = zipFile.getInputStream(zipEntry) return inputStream == null ? null : new String(inputStream.readAllBytes(), StandardCharsets.UTF_8) } finally { zipFile.close() } } - else if (archiveFile.fileName.toString().endsWith(".tar.gz")) { + else if (fileName.endsWith(".tar.gz")) { TarInputStream inputStream = new TarInputStream(new GZIPInputStream(Files.newInputStream(archiveFile))) try { TarEntry entry @@ -64,4 +68,8 @@ class ArchiveUtils { } return null } + + private static boolean isZipFile(String fileName) { + fileName.endsWith(".zip") || fileName.endsWith(".jar") + } } diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy index ac5c84cd5df6..723d3087250b 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy @@ -9,6 +9,7 @@ import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.Formats import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.Strings +import com.intellij.util.containers.ContainerUtil import com.intellij.util.system.CpuArch import groovy.io.FileType import groovy.transform.CompileStatic @@ -223,6 +224,14 @@ final class BuildTasksImpl extends BuildTasks { } } + //todo remove this when KTIJ-11539 is fixed; currently if we add kotlin.idea module to the classpath as a transitive dependency of some other module, + // it'll cause conflicts with Kotlin plugin loaded from JAR + String pathToIgnore = new File(context.projectOutputDirectory, "production/kotlin.idea").absolutePath + if (ideClasspath.remove(pathToIgnore)) { + context.messages.debug(" remove $pathToIgnore from classpath to avoid conflicts") + } + + List jvmArgs = new ArrayList<>(BuildUtils.propertiesToJvmArgs(new HashMap([ "idea.home.path" : context.paths.projectHome, "idea.system.path" : "${FileUtilRt.toSystemIndependentName(tempDir.toString())}/system", @@ -236,16 +245,18 @@ final class BuildTasksImpl extends BuildTasks { jvmArgs.addAll(vmOptions) List additionalPluginPaths = context.productProperties.getAdditionalPluginPaths(context) + Set additionalPluginIds = new HashSet<>() for (Path pluginPath : additionalPluginPaths) { for (File jarFile : BuildUtils.getPluginJars(pluginPath.toString())) { if (ideClasspath.add(jarFile.absolutePath)) { context.messages.debug("$jarFile from plugin $pluginPath") + ContainerUtil.addIfNotNull(additionalPluginIds, BuildUtils.readPluginId(jarFile)) } } } ideClasspath = classpathCustomizer.customize(ideClasspath) - disableCompatibleIgnoredPlugins(context, tempDir.resolve("config")) + disableCompatibleIgnoredPlugins(context, tempDir.resolve("config"), additionalPluginIds) BuildHelper.runJava( context, @@ -256,11 +267,17 @@ final class BuildTasksImpl extends BuildTasks { timeoutMillis) } - private static void disableCompatibleIgnoredPlugins(@NotNull BuildContext context, @NotNull Path configDir) { + private static void disableCompatibleIgnoredPlugins(@NotNull BuildContext context, + @NotNull Path configDir, + @NotNull Set explicitlyEnabledPlugins) { Set toDisable = new HashSet<>() for (String moduleName : context.productProperties.productLayout.compatiblePluginsToIgnore) { Path pluginXml = context.findFileInModuleSources(moduleName, "META-INF/plugin.xml") - toDisable.add(JDOMUtil.load(pluginXml).getChildTextTrim("id")) + def pluginId = JDOMUtil.load(pluginXml).getChildTextTrim("id") + if (!explicitlyEnabledPlugins.contains(pluginId)) { + toDisable.add(pluginId) + context.messages.debug("runApplicationStarter: '$pluginId' will be disabled, because it's mentioned in 'compatiblePluginsToIgnore'") + } } if (!toDisable.isEmpty()) { Files.createDirectories(configDir) diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy index 15beabd6d77a..10adaf9b1c51 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.intellij.build.impl +import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtilRt import groovy.transform.CompileDynamic @@ -10,7 +11,9 @@ import org.apache.tools.ant.BuildException import org.apache.tools.ant.Main import org.apache.tools.ant.Project import org.apache.tools.ant.util.SplitClassLoader +import org.jdom.JDOMException import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable import org.jetbrains.intellij.build.BuildContext import org.jetbrains.intellij.build.BuildOptions import org.jetbrains.jps.model.library.JpsOrderRootType @@ -186,4 +189,17 @@ final class BuildUtils { new File(libFile, jarName) } } + + @Nullable + static String readPluginId(File pluginJar) { + if (!pluginJar.isFile() || !FileUtil.extensionEquals(pluginJar.name, "jar")) return null + String pluginXmlText = ArchiveUtils.loadEntry(pluginJar.toPath(), "META-INF/plugin.xml") + if (pluginXmlText == null) return null + try { + return JDOMUtil.load(pluginXmlText).getChildTextTrim("id") + } + catch (JDOMException ignored) { + return null + } + } } \ No newline at end of file