mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] plugin descriptor validation (corrected)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<idea-plugin/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<idea-plugin>
|
||||
<id>griffins</id>
|
||||
<depends optional="true" config-file="brian.xml">pets.allowed</depends>
|
||||
</idea-plugin>
|
||||
@@ -633,15 +633,14 @@ public class PluginManagerCore {
|
||||
try {
|
||||
IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(notNull(pluginPath, file), bundled);
|
||||
descriptor.readExternal(descriptorFile.toURI().toURL());
|
||||
validateDescriptor(descriptor);
|
||||
return descriptor;
|
||||
}
|
||||
catch (XmlSerializationException e) {
|
||||
getLogger().info("Cannot load " + file, e);
|
||||
catch (XmlSerializationException | InvalidDataException e) {
|
||||
getLogger().info("Cannot load " + descriptorFile, e);
|
||||
prepareLoadingPluginsErrorMessage(singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
getLogger().info("Cannot load " + file, e);
|
||||
getLogger().info("Cannot load " + descriptorFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,33 +669,21 @@ public class PluginManagerCore {
|
||||
Document document = JDOMUtil.loadDocument(zipFile.getInputStream(entry));
|
||||
IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(notNull(pluginPath, file), bundled);
|
||||
descriptor.readExternal(document, jarURL, pathResolver);
|
||||
validateDescriptor(descriptor);
|
||||
context.myLastZipFileContainingDescriptor = file;
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
catch (XmlSerializationException e) {
|
||||
getLogger().info("Cannot load " + file, e);
|
||||
catch (XmlSerializationException | InvalidDataException e) {
|
||||
getLogger().info("Cannot load " + file + "!/META-INF/" + fileName, e);
|
||||
prepareLoadingPluginsErrorMessage(singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
getLogger().info("Cannot load " + file, e);
|
||||
getLogger().info("Cannot load " + file + "!/META-INF/" + fileName, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void validateDescriptor(IdeaPluginDescriptorImpl descriptor) {
|
||||
/*
|
||||
if (descriptor.getPluginId() == null) {
|
||||
throw new IllegalStateException("Skipped plugin with null ID: " + descriptor);
|
||||
}
|
||||
else if (descriptor.getName() == null) {
|
||||
throw new IllegalStateException("Skipped plugin without name: " + descriptor);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IdeaPluginDescriptorImpl loadDescriptor(@NotNull File file, @NotNull String fileName) {
|
||||
return loadDescriptor(file, fileName, false);
|
||||
@@ -780,6 +767,12 @@ public class PluginManagerCore {
|
||||
}
|
||||
|
||||
if (descriptor != null) {
|
||||
if (PLUGIN_XML.equals(pathName) && (descriptor.getPluginId() == null || descriptor.getName() == null)) {
|
||||
getLogger().info("Cannot load descriptor from " + file + ": ID or name missing");
|
||||
prepareLoadingPluginsErrorMessage(singletonList("'" + file.getName() + "' contains invalid plugin descriptor."));
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveOptionalDescriptors(pathName, descriptor, (@SystemIndependent String optPathName) -> {
|
||||
IdeaPluginDescriptorImpl optionalDescriptor = null;
|
||||
if (context.myLastZipFileContainingDescriptor != null) { // try last file that had the descriptor that worked
|
||||
@@ -1491,11 +1484,7 @@ public class PluginManagerCore {
|
||||
|
||||
@NotNull
|
||||
public static Logger getLogger() {
|
||||
return LoggerHolder.ourLogger;
|
||||
}
|
||||
|
||||
private static class LoggerHolder {
|
||||
private static final Logger ourLogger = Logger.getInstance("#com.intellij.ide.plugins.PluginManager");
|
||||
return Logger.getInstance("#com.intellij.ide.plugins.PluginManager");
|
||||
}
|
||||
|
||||
static class EssentialPluginMissingException extends RuntimeException {
|
||||
|
||||
@@ -30,6 +30,13 @@ public class PluginDescriptorTest {
|
||||
assertEquals("ASP", descriptor.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalDescriptors() {
|
||||
IdeaPluginDescriptorImpl descriptor = loadDescriptor("family");
|
||||
assertNotNull(descriptor);
|
||||
assertEquals(1, descriptor.getOptionalDescriptors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMalformedDescriptor() {
|
||||
assertNull(loadDescriptor("malformed"));
|
||||
@@ -118,8 +125,14 @@ public class PluginDescriptorTest {
|
||||
}
|
||||
|
||||
private static IdeaPluginDescriptorImpl loadDescriptor(String dirName) {
|
||||
File dir = new File(getTestDataPath(), dirName);
|
||||
assertTrue(dir + " does not exist", dir.exists());
|
||||
return PluginManagerCore.loadDescriptor(dir, PluginManagerCore.PLUGIN_XML);
|
||||
try {
|
||||
File dir = new File(getTestDataPath(), dirName);
|
||||
assertTrue(dir + " does not exist", dir.exists());
|
||||
return PluginManagerCore.loadDescriptor(dir, PluginManagerCore.PLUGIN_XML);
|
||||
}
|
||||
catch (AssertionError e) {
|
||||
assertTrue(e.getMessage(), e.getMessage().contains("Problems found loading plugins"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user