001 /* 002 * Copyright 2010-2015 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package com.intellij.ide.plugins; 018 019 import com.intellij.openapi.extensions.ExtensionPoint; 020 import com.intellij.openapi.extensions.ExtensionsArea; 021 import com.intellij.util.containers.ContainerUtil; 022 import org.jetbrains.annotations.NotNull; 023 import org.jetbrains.annotations.Nullable; 024 import org.jetbrains.kotlin.utils.UtilsPackage; 025 026 import java.io.File; 027 import java.lang.reflect.Method; 028 import java.util.List; 029 import java.util.Set; 030 031 // TODO drop this temporary hack to access to PluginManagerCore methods when CoreApplicationEnvironment got similar features. 032 public class PluginManagerCoreProxy { 033 private PluginManagerCoreProxy() {} 034 035 @Nullable 036 public static IdeaPluginDescriptorImpl loadDescriptorFromDir(@NotNull File file, @NotNull String fileName) { 037 return PluginManagerCore.loadDescriptorFromDir(file, fileName); 038 } 039 040 @Nullable 041 public static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName) { 042 try { 043 Method loadDescriptorFromJar = PluginManagerCore.class.getDeclaredMethod("loadDescriptorFromJar", File.class, String.class); 044 loadDescriptorFromJar.setAccessible(true); 045 return (IdeaPluginDescriptorImpl) loadDescriptorFromJar.invoke(null, file, fileName); 046 } 047 catch (Exception e) { 048 throw UtilsPackage.rethrow(e); 049 } 050 } 051 052 // copied as is from PluginManagerCore#registerExtensionPointsAndExtensions 053 public static void registerExtensionPointsAndExtensions(ExtensionsArea area, List<IdeaPluginDescriptorImpl> loadedPlugins) { 054 for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) { 055 descriptor.registerExtensionPoints(area); 056 } 057 058 Set<String> epNames = ContainerUtil.newHashSet(); 059 for (ExtensionPoint point : area.getExtensionPoints()) { 060 epNames.add(point.getName()); 061 } 062 063 for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) { 064 for (String epName : epNames) { 065 descriptor.registerExtensions(area, epName); 066 } 067 } 068 } 069 }