use of com.intellij.ide.plugins.cl.PluginClassLoader in project intellij-community by JetBrains.
the class GuiTestRunner method loadClassesWithNewPluginClassLoader.
private void loadClassesWithNewPluginClassLoader() throws Exception {
//ensure that IDEA has been initialized.
IdeTestApplication.getInstance();
ParentPlugin testParentPluginAnnotation = getTestClass().getAnnotation(ParentPlugin.class);
assertNotNull(testParentPluginAnnotation);
String dependentPluginId = testParentPluginAnnotation.pluginId();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String classPath = getTestClass().getJavaClass().getCanonicalName().replace(".", "/").concat(".class");
URL resource = classLoader.getResource(classPath);
assertNotNull(resource);
String pathToTestClass = resource.getPath();
String containingFolderPath = pathToTestClass.substring(0, pathToTestClass.length() - classPath.length());
URL urlToTestClass = (new File(containingFolderPath)).toURI().toURL();
IdeaPluginDescriptor parentPluginDescriptor = PluginManager.getPlugin(PluginId.getId(dependentPluginId));
assertNotNull(parentPluginDescriptor);
ClassLoader parentPluginClassLoader = parentPluginDescriptor.getPluginClassLoader();
ClassLoader[] classLoaders = { parentPluginClassLoader };
String testPluginId = dependentPluginId + ".guitest";
PluginClassLoader testPluginClassLoader = new PluginClassLoader(Collections.singletonList(urlToTestClass), classLoaders, PluginId.getId(testPluginId), null, null);
Thread.currentThread().setContextClassLoader(testPluginClassLoader);
Class<?> testClass = getTestClass().getJavaClass();
myTestClass = new TestClass(testPluginClassLoader.loadClass(testClass.getName()));
}
use of com.intellij.ide.plugins.cl.PluginClassLoader in project intellij-community by JetBrains.
the class AdvancedEnhancer method getDefaultClassLoader.
protected ClassLoader getDefaultClassLoader() {
int maxIndex = -1;
ClassLoader bestLoader = null;
ClassLoader nonPluginLoader = null;
if (interfaces != null && interfaces.length > 0) {
for (final Class anInterface : interfaces) {
final ClassLoader loader = anInterface.getClassLoader();
if (loader instanceof PluginClassLoader) {
final int order = PluginManagerCore.getPluginLoadingOrder(((PluginClassLoader) loader).getPluginId());
if (maxIndex < order) {
maxIndex = order;
bestLoader = loader;
}
} else if (nonPluginLoader == null) {
nonPluginLoader = loader;
}
}
}
ClassLoader superLoader = null;
if (superclass != null) {
superLoader = superclass.getClassLoader();
if (superLoader instanceof PluginClassLoader && maxIndex < PluginManagerCore.getPluginLoadingOrder(((PluginClassLoader) superLoader).getPluginId())) {
return superLoader;
}
}
if (bestLoader != null)
return bestLoader;
return superLoader == null ? nonPluginLoader : superLoader;
}
use of com.intellij.ide.plugins.cl.PluginClassLoader in project intellij-community by JetBrains.
the class IdeErrorsDialog method diagnosePluginDetection.
@NotNull
private static String diagnosePluginDetection(String className, PluginId id) {
String msg = "Detected plugin " + id + " by class " + className;
IdeaPluginDescriptor descriptor = PluginManager.getPlugin(id);
if (descriptor != null) {
msg += "; ideaLoader=" + descriptor.getUseIdeaClassLoader();
ClassLoader loader = descriptor.getPluginClassLoader();
msg += "; loader=" + loader;
if (loader instanceof PluginClassLoader) {
msg += "; loaded class: " + ((PluginClassLoader) loader).hasLoadedClass(className);
}
}
return msg;
}
use of com.intellij.ide.plugins.cl.PluginClassLoader in project intellij-community by JetBrains.
the class FileTemplatesLoader method loadDefaultTemplates.
private void loadDefaultTemplates() {
final Set<URL> processedUrls = new HashSet<>();
for (PluginDescriptor plugin : PluginManagerCore.getPlugins()) {
if (plugin instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) plugin).isEnabled()) {
final ClassLoader loader = plugin.getPluginClassLoader();
if (loader instanceof PluginClassLoader && ((PluginClassLoader) loader).getUrls().isEmpty()) {
// development mode, when IDEA_CORE's loader contains all the classpath
continue;
}
try {
final Enumeration<URL> systemResources = loader.getResources(DEFAULT_TEMPLATES_ROOT);
if (systemResources.hasMoreElements()) {
while (systemResources.hasMoreElements()) {
final URL url = systemResources.nextElement();
if (processedUrls.contains(url)) {
continue;
}
processedUrls.add(url);
loadDefaultsFromRoot(url);
}
}
} catch (IOException e) {
LOG.error(e);
}
}
}
}
use of com.intellij.ide.plugins.cl.PluginClassLoader in project intellij-community by JetBrains.
the class PluginManagerCore method createPluginClassLoader.
@Nullable
private static ClassLoader createPluginClassLoader(@NotNull File[] classPath, @NotNull ClassLoader[] parentLoaders, @NotNull IdeaPluginDescriptor pluginDescriptor) {
if (pluginDescriptor.getUseIdeaClassLoader()) {
try {
final ClassLoader loader = PluginManagerCore.class.getClassLoader();
final Method addUrlMethod = getAddUrlMethod(loader);
for (File aClassPath : classPath) {
final File file = aClassPath.getCanonicalFile();
addUrlMethod.invoke(loader, file.toURI().toURL());
}
return loader;
} catch (IOException e) {
getLogger().warn(e);
} catch (IllegalAccessException e) {
getLogger().warn(e);
} catch (InvocationTargetException e) {
getLogger().warn(e);
}
}
PluginId pluginId = pluginDescriptor.getPluginId();
File pluginRoot = pluginDescriptor.getPath();
if (isUnitTestMode())
return null;
try {
final List<URL> urls = new ArrayList<>(classPath.length);
for (File aClassPath : classPath) {
// it is critical not to have "." and ".." in classpath elements
final File file = aClassPath.getCanonicalFile();
urls.add(file.toURI().toURL());
}
return new PluginClassLoader(urls, parentLoaders, pluginId, pluginDescriptor.getVersion(), pluginRoot);
} catch (MalformedURLException e) {
getLogger().warn(e);
} catch (IOException e) {
getLogger().warn(e);
}
return null;
}
Aggregations