Search in sources :

Example 1 with XmlSerializationException

use of com.intellij.util.xmlb.XmlSerializationException in project intellij-community by JetBrains.

the class PluginManagerCore method loadDescriptorFromDir.

@Nullable
private static IdeaPluginDescriptorImpl loadDescriptorFromDir(@NotNull File file, @NotNull String fileName) {
    File descriptorFile = new File(file, META_INF + File.separator + fileName);
    if (descriptorFile.exists()) {
        try {
            IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(file);
            descriptor.readExternal(descriptorFile.toURI().toURL());
            return descriptor;
        } catch (XmlSerializationException e) {
            getLogger().info("Cannot load " + file, e);
            prepareLoadingPluginsErrorMessage(Collections.singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
        } catch (Throwable e) {
            getLogger().info("Cannot load " + file, e);
        }
    }
    return null;
}
Also used : XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) ZipFile(java.util.zip.ZipFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XmlSerializationException

use of com.intellij.util.xmlb.XmlSerializationException in project intellij-community by JetBrains.

the class PluginManagerCore method loadDescriptorFromJar.

@Nullable
private static IdeaPluginDescriptorImpl loadDescriptorFromJar(@NotNull File file, @NotNull String fileName, @NotNull JDOMXIncluder.PathResolver pathResolver) {
    try {
        URL jarURL = URLUtil.getJarEntryURL(file, META_INF + '/' + fileName);
        ZipFile zipFile = new ZipFile(file);
        try {
            ZipEntry entry = zipFile.getEntry(META_INF + '/' + fileName);
            if (entry != null) {
                Document document = JDOMUtil.loadDocument(zipFile.getInputStream(entry));
                IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(file);
                descriptor.readExternal(document, jarURL, pathResolver);
                return descriptor;
            }
        } finally {
            zipFile.close();
        }
    } catch (XmlSerializationException e) {
        getLogger().info("Cannot load " + file, e);
        prepareLoadingPluginsErrorMessage(Collections.singletonList("File '" + file.getName() + "' contains invalid plugin descriptor."));
    } catch (Throwable e) {
        getLogger().info("Cannot load " + file, e);
    }
    return null;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) Document(org.jdom.Document) URL(java.net.URL) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with XmlSerializationException

use of com.intellij.util.xmlb.XmlSerializationException in project intellij-community by JetBrains.

the class ShowSerializedXmlAction method generateAndShowXml.

private static void generateAndShowXml(final Module module, final String className) {
    final List<URL> urls = new ArrayList<>();
    final List<String> list = OrderEnumerator.orderEntries(module).recursively().runtimeOnly().getPathsList().getPathList();
    for (String path : list) {
        try {
            urls.add(new File(FileUtil.toSystemIndependentName(path)).toURI().toURL());
        } catch (MalformedURLException e1) {
            LOG.info(e1);
        }
    }
    final Project project = module.getProject();
    UrlClassLoader loader = UrlClassLoader.build().urls(urls).parent(XmlSerializer.class.getClassLoader()).get();
    final Class<?> aClass;
    try {
        aClass = Class.forName(className, true, loader);
    } catch (ClassNotFoundException e) {
        Messages.showErrorDialog(project, "Cannot find class '" + className + "'", CommonBundle.getErrorTitle());
        LOG.info(e);
        return;
    }
    final Object o;
    try {
        o = new SampleObjectGenerator().createValue(aClass, FList.<Type>emptyList());
    } catch (Exception e) {
        Messages.showErrorDialog(project, "Cannot generate class '" + className + "': " + e.getMessage(), CommonBundle.getErrorTitle());
        LOG.info(e);
        return;
    }
    final Element element;
    try {
        element = XmlSerializer.serialize(o);
    } catch (XmlSerializationException e) {
        LOG.info(e);
        Throwable cause = e.getCause();
        Messages.showErrorDialog(project, e.getMessage() + (cause != null ? ": " + cause.getMessage() : ""), CommonBundle.getErrorTitle());
        return;
    }
    final String text = JDOMUtil.writeElement(element, "\n");
    Messages.showIdeaMessageDialog(project, text, "Serialized XML for '" + className + "'", new String[] { CommonBundle.getOkButtonText() }, 0, Messages.getInformationIcon(), null);
}
Also used : MalformedURLException(java.net.MalformedURLException) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) URL(java.net.URL) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) MalformedURLException(java.net.MalformedURLException) Project(com.intellij.openapi.project.Project) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) UrlClassLoader(com.intellij.util.lang.UrlClassLoader)

Aggregations

XmlSerializationException (com.intellij.util.xmlb.XmlSerializationException)3 URL (java.net.URL)2 ZipFile (java.util.zip.ZipFile)2 Nullable (org.jetbrains.annotations.Nullable)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 UrlClassLoader (com.intellij.util.lang.UrlClassLoader)1 File (java.io.File)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 MalformedURLException (java.net.MalformedURLException)1 ZipEntry (java.util.zip.ZipEntry)1 Document (org.jdom.Document)1 Element (org.jdom.Element)1