001    /*
002     * Copyright 2010-2014 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    
025    import java.io.File;
026    import java.util.List;
027    import java.util.Set;
028    
029    // TODO drop this temporary hack to access to PluginManagerCore methods when CoreApplicationEnvironment got similar features.
030    public class PluginManagerCoreProxy {
031        private PluginManagerCoreProxy() {}
032    
033        @Nullable
034        public static IdeaPluginDescriptorImpl loadDescriptorFromDir(@NotNull File file, @NotNull String fileName) {
035            return PluginManagerCore.loadDescriptorFromDir(file, fileName);
036        }
037    
038        @Nullable
039        public static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName) {
040            return PluginManagerCore.loadDescriptorFromJar(file, fileName);
041        }
042    
043        // copied as is from PluginManagerCore#registerExtensionPointsAndExtensions
044        public static void registerExtensionPointsAndExtensions(ExtensionsArea area, List<IdeaPluginDescriptorImpl> loadedPlugins) {
045            for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) {
046                descriptor.registerExtensionPoints(area);
047            }
048    
049            Set<String> epNames = ContainerUtil.newHashSet();
050            for (ExtensionPoint point : area.getExtensionPoints()) {
051                epNames.add(point.getName());
052            }
053    
054            for (IdeaPluginDescriptorImpl descriptor : loadedPlugins) {
055                for (String epName : epNames) {
056                    descriptor.registerExtensions(area, epName);
057                }
058            }
059        }
060    }