static boolean shouldSkipPlugin( final IdeaPluginDescriptor descriptor, IdeaPluginDescriptor[] loaded) { final String idString = descriptor.getPluginId().getIdString(); if (idString.equals(CORE_PLUGIN_ID)) { return false; } //noinspection HardCodedStringLiteral final String pluginId = System.getProperty("idea.load.plugins.id"); if (pluginId == null) { if (descriptor instanceof IdeaPluginDescriptorImpl && !descriptor.isEnabled()) return true; if (!shouldLoadPlugins()) return true; } final List<String> pluginIds = pluginId == null ? null : StringUtil.split(pluginId, ","); final boolean checkModuleDependencies = !ourAvailableModules.isEmpty() && !ourAvailableModules.contains("com.intellij.modules.all"); if (checkModuleDependencies && !hasModuleDependencies(descriptor)) { return true; } boolean shouldLoad; //noinspection HardCodedStringLiteral final String loadPluginCategory = System.getProperty("idea.load.plugins.category"); if (loadPluginCategory != null) { shouldLoad = loadPluginCategory.equals(descriptor.getCategory()); } else { if (pluginIds != null) { shouldLoad = pluginIds.contains(idString); if (!shouldLoad) { Map<PluginId, IdeaPluginDescriptor> map = new HashMap<PluginId, IdeaPluginDescriptor>(); for (final IdeaPluginDescriptor pluginDescriptor : loaded) { map.put(pluginDescriptor.getPluginId(), pluginDescriptor); } addModulesAsDependents(map); final IdeaPluginDescriptor descriptorFromProperty = map.get(PluginId.getId(pluginId)); shouldLoad = descriptorFromProperty != null && isDependent( descriptorFromProperty, descriptor.getPluginId(), map, checkModuleDependencies); } } else { shouldLoad = !getDisabledPlugins().contains(idString); } if (shouldLoad && descriptor instanceof IdeaPluginDescriptorImpl) { if (isIncompatible(descriptor)) return true; } } return !shouldLoad; }
private Object instantiate(Class clazz) { ConstructorInjectionComponentAdapter adapter = new ConstructorInjectionComponentAdapter( Integer.toString(System.identityHashCode(new Object())), clazz); return adapter.getComponentInstance(getPicoContainer()); }
public static void initPlugins(@Nullable StartupProgress progress) { long start = System.currentTimeMillis(); try { initializePlugins(progress); } catch (RuntimeException e) { getLogger().error(e); throw e; } getLogger() .info( ourPlugins.length + " plugins initialized in " + (System.currentTimeMillis() - start) + " ms"); logPlugins(); ClassUtilCore.clearJarURLCache(); }
@NotNull public static List<String> getDisabledPlugins() { if (ourDisabledPlugins == null) { ourDisabledPlugins = new ArrayList<String>(); if (System.getProperty("idea.ignore.disabled.plugins") == null && !isUnitTestMode()) { loadDisabledPlugins(PathManager.getConfigPath(), ourDisabledPlugins); } } return ourDisabledPlugins; }
static boolean shouldLoadPlugins() { try { // no plugins during bootstrap Class.forName("com.intellij.openapi.extensions.Extensions"); } catch (ClassNotFoundException e) { return false; } //noinspection HardCodedStringLiteral final String loadPlugins = System.getProperty("idea.load.plugins"); return loadPlugins == null || Boolean.TRUE.toString().equals(loadPlugins); }
static BuildNumber getBuildNumber() { if (ourBuildNumber == null) { ourBuildNumber = BuildNumber.fromString(System.getProperty("idea.plugins.compatible.build")); if (ourBuildNumber == null) { ourBuildNumber = BUILD_NUMBER == null ? null : BuildNumber.fromString(BUILD_NUMBER); if (ourBuildNumber == null) { ourBuildNumber = BuildNumber.fallback(); } } } return ourBuildNumber; }
static void loadDescriptorsFromProperty(final List<IdeaPluginDescriptorImpl> result) { final String pathProperty = System.getProperty(PROPERTY_PLUGIN_PATH); if (pathProperty == null) return; for (StringTokenizer t = new StringTokenizer(pathProperty, File.pathSeparator); t.hasMoreTokens(); ) { String s = t.nextToken(); final IdeaPluginDescriptorImpl ideaPluginDescriptor = loadDescriptor(new File(s), PLUGIN_XML); if (ideaPluginDescriptor != null) { result.add(ideaPluginDescriptor); } } }
static void loadDescriptorsFromClassPath( @NotNull List<IdeaPluginDescriptorImpl> result, @Nullable StartupProgress progress) { Collection<URL> urls = getClassLoaderUrls(); String platformPrefix = System.getProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY); int i = 0; for (URL url : urls) { i++; if ("file".equals(url.getProtocol())) { File file = new File(decodeUrl(url.getFile())); IdeaPluginDescriptorImpl platformPluginDescriptor = null; if (platformPrefix != null) { platformPluginDescriptor = loadDescriptor(file, platformPrefix + "Plugin.xml"); if (platformPluginDescriptor != null && !result.contains(platformPluginDescriptor)) { platformPluginDescriptor.setUseCoreClassLoader(true); result.add(platformPluginDescriptor); } } IdeaPluginDescriptorImpl pluginDescriptor = loadDescriptor(file, PLUGIN_XML); if (platformPrefix != null && pluginDescriptor != null && pluginDescriptor.getName().equals(SPECIAL_IDEA_PLUGIN)) { continue; } if (pluginDescriptor != null && !result.contains(pluginDescriptor)) { if (platformPluginDescriptor != null) { // if we found a regular plugin.xml in the same .jar/root as a platform-prefixed // descriptor, use the core loader for it too pluginDescriptor.setUseCoreClassLoader(true); } result.add(pluginDescriptor); if (progress != null) { progress.showProgress( "Plugin loaded: " + pluginDescriptor.getName(), PLUGINS_PROGRESS_MAX_VALUE * ((float) i / urls.size())); } } } } }
static void initializePlugins(@Nullable StartupProgress progress) { configureExtensions(); final IdeaPluginDescriptorImpl[] pluginDescriptors = loadDescriptors(progress); final Class callerClass = ReflectionUtil.findCallerClass(1); assert callerClass != null; final ClassLoader parentLoader = callerClass.getClassLoader(); final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>(); final HashMap<String, String> disabledPluginNames = new HashMap<String, String>(); for (IdeaPluginDescriptorImpl descriptor : pluginDescriptors) { if (descriptor.getPluginId().getIdString().equals(CORE_PLUGIN_ID)) { final List<String> modules = descriptor.getModules(); if (modules != null) { ourAvailableModules.addAll(modules); } } if (!shouldSkipPlugin(descriptor, pluginDescriptors)) { result.add(descriptor); } else { descriptor.setEnabled(false); disabledPluginNames.put(descriptor.getPluginId().getIdString(), descriptor.getName()); initClassLoader(parentLoader, descriptor); } } prepareLoadingPluginsErrorMessage(filterBadPlugins(result, disabledPluginNames)); final Map<PluginId, IdeaPluginDescriptorImpl> idToDescriptorMap = new HashMap<PluginId, IdeaPluginDescriptorImpl>(); for (final IdeaPluginDescriptorImpl descriptor : result) { idToDescriptorMap.put(descriptor.getPluginId(), descriptor); } final IdeaPluginDescriptor corePluginDescriptor = idToDescriptorMap.get(PluginId.getId(CORE_PLUGIN_ID)); assert corePluginDescriptor != null : CORE_PLUGIN_ID + " not found; platform prefix is " + System.getProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY); for (IdeaPluginDescriptorImpl descriptor : result) { if (descriptor != corePluginDescriptor) { descriptor.insertDependency(corePluginDescriptor); } } mergeOptionalConfigs(idToDescriptorMap); // sort descriptors according to plugin dependencies Collections.sort(result, getPluginDescriptorComparator(idToDescriptorMap)); for (int i = 0; i < result.size(); i++) { ourId2Index.put(result.get(i).getPluginId(), i); } int i = 0; for (final IdeaPluginDescriptorImpl pluginDescriptor : result) { if (pluginDescriptor.getPluginId().getIdString().equals(CORE_PLUGIN_ID) || pluginDescriptor.isUseCoreClassLoader()) { pluginDescriptor.setLoader(parentLoader); } else { final List<File> classPath = pluginDescriptor.getClassPath(); final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds(); final ClassLoader[] parentLoaders = getParentLoaders(idToDescriptorMap, dependentPluginIds); final ClassLoader pluginClassLoader = createPluginClassLoader( classPath.toArray(new File[classPath.size()]), parentLoaders.length > 0 ? parentLoaders : new ClassLoader[] {parentLoader}, pluginDescriptor); pluginDescriptor.setLoader(pluginClassLoader); } if (progress != null) { progress.showProgress( "", PLUGINS_PROGRESS_MAX_VALUE + (i++ / (float) result.size()) * 0.35f); } } registerExtensionPointsAndExtensions(Extensions.getRootArea(), result); Extensions.getRootArea() .getExtensionPoint(Extensions.AREA_LISTENER_EXTENSION_POINT) .registerExtension( new AreaListener() { @Override public void areaCreated( @NotNull String areaClass, @NotNull AreaInstance areaInstance) { registerExtensionPointsAndExtensions(Extensions.getArea(areaInstance), result); } @Override public void areaDisposing( @NotNull String areaClass, @NotNull AreaInstance areaInstance) {} }); ourPlugins = pluginDescriptors; }