@Nullable public static Configuration load(final InputStream is) throws IOException, JDOMException { try { final Document document = JDOMUtil.loadDocument(is); final ArrayList<Element> elements = new ArrayList<Element>(); elements.add(document.getRootElement()); elements.addAll(document.getRootElement().getChildren("component")); final Element element = ContainerUtil.find( elements, new Condition<Element>() { public boolean value(final Element element) { return "component".equals(element.getName()) && COMPONENT_NAME.equals(element.getAttributeValue("name")); } }); if (element != null) { final Configuration cfg = new Configuration(); cfg.loadState(element, false); return cfg; } return null; } finally { is.close(); } }
@Nullable static IdeaPluginDescriptorImpl loadDescriptorFromJar(File file, @NonNls String fileName) { try { URI fileURL = file.toURI(); URL jarURL = new URL( "jar:" + StringUtil.replace(fileURL.toASCIIString(), "!", "%21") + "!/META-INF/" + fileName); IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(file); FileInputStream in = new FileInputStream(file); ZipInputStream zipStream = new ZipInputStream(in); try { ZipEntry entry = zipStream.getNextEntry(); if (entry.getName().equals(JarMemoryLoader.SIZE_ENTRY)) { entry = zipStream.getNextEntry(); if (entry.getName().equals("META-INF/" + fileName)) { byte[] content = FileUtil.loadBytes(zipStream, (int) entry.getSize()); Document document = JDOMUtil.loadDocument(new ByteArrayInputStream(content)); descriptor.readExternal(document, jarURL); return descriptor; } } } finally { zipStream.close(); in.close(); } descriptor.readExternal(jarURL); return descriptor; } catch (XmlSerializationException e) { getLogger().info("Cannot load " + file, e); prepareLoadingPluginsErrorMessage( "Plugin file " + file.getName() + " contains invalid plugin descriptor file."); } catch (FileNotFoundException e) { return null; } catch (Exception e) { getLogger().info("Cannot load " + file, e); } catch (Throwable e) { getLogger().info("Cannot load " + file, e); } return null; }