Switch to the new(right) API for register extension points and extensions.

This commit is contained in:
Zalim Bashorov
2015-03-14 00:57:44 +03:00
parent 11ce50f0d6
commit 5e782dd547
2 changed files with 17 additions and 85 deletions
@@ -1,69 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.plugins;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.ExtensionsArea;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.utils.UtilsPackage;
import java.io.File;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
// TODO drop this temporary hack to access to PluginManagerCore methods when CoreApplicationEnvironment got similar features.
public class PluginManagerCoreProxy {
private PluginManagerCoreProxy() {}
@Nullable
public static IdeaPluginDescriptorImpl loadDescriptorFromDir(@NotNull File file, @NotNull String fileName) {
return PluginManagerCore.loadDescriptorFromDir(file, fileName);
}
@Nullable
public static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName) {
try {
Method loadDescriptorFromJar = PluginManagerCore.class.getDeclaredMethod("loadDescriptorFromJar", File.class, String.class);
loadDescriptorFromJar.setAccessible(true);
return (IdeaPluginDescriptorImpl) loadDescriptorFromJar.invoke(null, file, fileName);
}
catch (Exception e) {
throw UtilsPackage.rethrow(e);
}
}
// copied as is from PluginManagerCore#registerExtensionPointsAndExtensions
public static void registerExtensionPointsAndExtensions(ExtensionsArea area, List<IdeaPluginDescriptorImpl> loadedPlugins) {
for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) {
descriptor.registerExtensionPoints(area);
}
Set<String> epNames = ContainerUtil.newHashSet();
for (ExtensionPoint point : area.getExtensionPoints()) {
epNames.add(point.getName());
}
for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) {
for (String epName : epNames) {
descriptor.registerExtensions(area, epName);
}
}
}
}
@@ -24,12 +24,12 @@ import com.intellij.core.CoreApplicationEnvironment;
import com.intellij.core.CoreJavaFileManager;
import com.intellij.core.JavaCoreApplicationEnvironment;
import com.intellij.core.JavaCoreProjectEnvironment;
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
import com.intellij.ide.plugins.PluginManagerCoreProxy;
import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.mock.MockApplication;
import com.intellij.mock.MockProject;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.extensions.ExtensionsArea;
@@ -38,6 +38,7 @@ import com.intellij.openapi.fileTypes.FileTypeExtensionPoint;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.FileContextProvider;
import com.intellij.psi.PsiElementFinder;
@@ -56,8 +57,6 @@ import kotlin.Function1;
import kotlin.Unit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.kotlin.extensions.ExternalDeclarationsProvider;
import org.jetbrains.kotlin.asJava.JavaElementFinder;
import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage;
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport;
@@ -66,9 +65,11 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
import org.jetbrains.kotlin.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar;
import org.jetbrains.kotlin.config.CommonConfigurationKeys;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.extensions.ExternalDeclarationsProvider;
import org.jetbrains.kotlin.idea.JetFileType;
import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache;
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory;
@@ -200,22 +201,22 @@ public class JetCoreEnvironment {
}
private static void registerApplicationExtensionPointsAndExtensionsFrom(@NotNull CompilerConfiguration configuration, @NotNull String configFilePath) {
IdeaPluginDescriptorImpl descriptor;
CompilerJarLocator locator = configuration.get(JVMConfigurationKeys.COMPILER_JAR_LOCATOR);
File jar = locator == null ? PathUtil.getPathUtilJar() : locator.getCompilerJar();
if (jar.isFile()) {
descriptor = PluginManagerCoreProxy.loadDescriptorFromJar(jar, configFilePath);
}
else {
File pluginRoot = locator == null ? PathUtil.getPathUtilJar() : locator.getCompilerJar();
Application app = ApplicationManager.getApplication();
File parentFile = pluginRoot.getParentFile();
if (pluginRoot.isDirectory() &&
app != null && app.isUnitTestMode() &&
FileUtil.toCanonicalPath(parentFile.getPath()).endsWith("out/production")
) {
// hack for load extensions when compiler run directly from out directory(e.g. in tests)
File srcDir = jar.getParentFile().getParentFile().getParentFile();
File pluginDir = new File(srcDir, "idea/src");
descriptor = PluginManagerCoreProxy.loadDescriptorFromDir(pluginDir, configFilePath);
File srcDir = parentFile.getParentFile().getParentFile();
pluginRoot = new File(srcDir, "idea/src");
}
assert descriptor != null : "Can not load descriptor from " + configFilePath + " relative to " + jar;
PluginManagerCoreProxy.registerExtensionPointsAndExtensions(Extensions.getRootArea(), Collections.singletonList(descriptor));
CoreApplicationEnvironment.registerExtensionPointAndExtensions(pluginRoot, configFilePath, Extensions.getRootArea());
}
private static void registerApplicationServicesForCLI(@NotNull JavaCoreApplicationEnvironment applicationEnvironment) {