Search in sources :

Example 26 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.

the class RunInspectionIntention method createProfile.

@NotNull
public static InspectionProfileImpl createProfile(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionManagerEx managerEx, @Nullable PsiElement psiElement) {
    InspectionProfileImpl rootProfile = InspectionProfileManager.getInstance().getCurrentProfile();
    LinkedHashSet<InspectionToolWrapper<?, ?>> allWrappers = new LinkedHashSet<>();
    allWrappers.add(toolWrapper);
    rootProfile.collectDependentInspections(toolWrapper, allWrappers, managerEx.getProject());
    List<InspectionToolWrapper<?, ?>> toolWrappers = allWrappers.size() == 1 ? Collections.singletonList(allWrappers.iterator().next()) : new ArrayList<>(allWrappers);
    InspectionProfileImpl model = InspectionProfileKt.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(), toolWrappers);
    try {
        Element element = new Element("toCopy");
        for (InspectionToolWrapper wrapper : toolWrappers) {
            wrapper.getTool().writeSettings(element);
            InspectionToolWrapper tw = psiElement == null ? model.getInspectionTool(wrapper.getShortName(), managerEx.getProject()) : model.getInspectionTool(wrapper.getShortName(), psiElement);
            tw.getTool().readSettings(element);
        }
    } catch (WriteExternalException | InvalidDataException ignored) {
    }
    model.setSingleTool(toolWrapper.getShortName());
    return model;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.

the class IdeaPluginDescriptorImpl method readExternal.

public void readExternal(@NotNull URL url) throws InvalidDataException, FileNotFoundException {
    try {
        Document document = JDOMUtil.loadDocument(url);
        readExternal(document, url, JDOMXIncluder.DEFAULT_PATH_RESOLVER);
    } catch (FileNotFoundException e) {
        throw e;
    } catch (IOException e) {
        throw new InvalidDataException(e);
    } catch (JDOMException e) {
        throw new InvalidDataException(e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 28 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.

the class ProjectUtil method openProject.

@Nullable
public static Project openProject(final String path, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
    File file = new File(path);
    if (!file.exists()) {
        Messages.showErrorDialog(IdeBundle.message("error.project.file.does.not.exist", path), CommonBundle.getErrorTitle());
        return null;
    }
    if (file.isDirectory()) {
        File dir = new File(file, Project.DIRECTORY_STORE_FOLDER);
        if (!dir.exists()) {
            String message = IdeBundle.message("error.project.file.does.not.exist", dir.getPath());
            Messages.showErrorDialog(message, CommonBundle.getErrorTitle());
            return null;
        }
    }
    Project existing = findAndFocusExistingProjectForPath(path);
    if (existing != null)
        return existing;
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    if (!forceOpenInNewFrame && openProjects.length > 0) {
        int exitCode = confirmOpenNewProject(false);
        if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) {
            final Project toClose = projectToClose != null ? projectToClose : openProjects[openProjects.length - 1];
            if (!closeAndDispose(toClose))
                return null;
        } else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) {
            return null;
        }
    }
    if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) {
        if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) {
            return null;
        }
    }
    ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
    Project project = null;
    try {
        project = projectManager.loadAndOpenProject(path);
    } catch (IOException e) {
        Messages.showMessageDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
    } catch (JDOMException | InvalidDataException e) {
        LOG.info(e);
        Messages.showMessageDialog(IdeBundle.message("error.project.file.is.corrupted"), IdeBundle.message("title.cannot.load.project"), Messages.getErrorIcon());
    }
    return project;
}
Also used : Project(com.intellij.openapi.project.Project) InvalidDataException(com.intellij.openapi.util.InvalidDataException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.

the class LibraryTableImplUtil method loadLibrary.

public static Library loadLibrary(@NotNull Element rootElement, @NotNull RootModelImpl rootModel) throws InvalidDataException {
    final List children = rootElement.getChildren(LibraryImpl.ELEMENT);
    if (children.size() != 1)
        throw new InvalidDataException();
    Element element = (Element) children.get(0);
    return new LibraryImpl(null, element, rootModel);
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) List(java.util.List)

Example 30 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.

the class DeployToServerRunConfiguration method clone.

@Override
public RunConfiguration clone() {
    Element element = new Element("tag");
    try {
        writeExternal(element);
    } catch (WriteExternalException e) {
        LOG.error(e);
    }
    DeployToServerRunConfiguration result = (DeployToServerRunConfiguration) super.clone();
    try {
        result.readExternal(element);
    } catch (InvalidDataException e) {
        LOG.error(e);
    }
    return result;
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Aggregations

InvalidDataException (com.intellij.openapi.util.InvalidDataException)36 Element (org.jdom.Element)24 WriteExternalException (com.intellij.openapi.util.WriteExternalException)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 JDOMException (org.jdom.JDOMException)5 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 List (java.util.List)4 TreeState (com.intellij.ide.util.treeView.TreeState)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 DescriptionAwareSchemeActions (com.intellij.application.options.schemes.DescriptionAwareSchemeActions)1 InspectionProfileImpl (com.intellij.codeInspection.ex.InspectionProfileImpl)1 InspectionProfileModifiableModel (com.intellij.codeInspection.ex.InspectionProfileModifiableModel)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 UnsupportedExpressionException (com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException)1 ExecutionException (com.intellij.execution.ExecutionException)1