Search in sources :

Example 16 with InvalidDataException

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

the class ProjectLevelVcsManagerImpl method readDirectoryMappings.

void readDirectoryMappings(final Element element) {
    myMappings.clear();
    final List<VcsDirectoryMapping> mappingsList = new ArrayList<>();
    boolean haveNonEmptyMappings = false;
    for (Element child : element.getChildren(ELEMENT_MAPPING)) {
        final String vcs = child.getAttributeValue(ATTRIBUTE_VCS);
        if (vcs != null && !vcs.isEmpty()) {
            haveNonEmptyMappings = true;
        }
        VcsDirectoryMapping mapping = new VcsDirectoryMapping(child.getAttributeValue(ATTRIBUTE_DIRECTORY), vcs);
        mappingsList.add(mapping);
        Element rootSettingsElement = child.getChild(ELEMENT_ROOT_SETTINGS);
        if (rootSettingsElement != null) {
            String className = rootSettingsElement.getAttributeValue(ATTRIBUTE_CLASS);
            AbstractVcs vcsInstance = findVcsByName(mapping.getVcs());
            if (vcsInstance != null && className != null) {
                final VcsRootSettings rootSettings = vcsInstance.createEmptyVcsRootSettings();
                if (rootSettings != null) {
                    try {
                        rootSettings.readExternal(rootSettingsElement);
                        mapping.setRootSettings(rootSettings);
                    } catch (InvalidDataException e) {
                        LOG.error("Failed to load VCS root settings class " + className + " for VCS " + vcsInstance.getClass().getName(), e);
                    }
                }
            }
        }
    }
    boolean defaultProject = Boolean.TRUE.toString().equals(element.getAttributeValue(ATTRIBUTE_DEFAULT_PROJECT));
    // run autodetection if there's no VCS in default project and 
    if (haveNonEmptyMappings || !defaultProject) {
        myMappingsLoaded = true;
    }
    myMappings.setDirectoryMappings(mappingsList);
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException)

Example 17 with InvalidDataException

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

the class FlexModuleConverter method isApplicableLibrary.

static boolean isApplicableLibrary(final Element library, Function<String, String> pathExpander) {
    String libraryType = library.getAttributeValue(LibraryImpl.LIBRARY_TYPE_ATTR);
    if (FlexLibraryType.FLEX_LIBRARY.getKindId().equals(libraryType)) {
        return true;
    }
    if (libraryType != null) {
        // ignore explicit non-Flex libraries
        return false;
    }
    final Element rootChild = library.getChild(OrderRootType.CLASSES.name());
    if (rootChild == null) {
        // corrupted element
        return false;
    }
    JarDirectories jarDirectories = new JarDirectories();
    try {
        jarDirectories.readExternal(library);
    } catch (InvalidDataException ignored) {
        jarDirectories.clear();
    }
    List<Element> classesRoots = rootChild.getChildren(LibraryImpl.ROOT_PATH_ELEMENT);
    if (classesRoots.isEmpty()) {
        // no classes root
        return false;
    }
    for (Element root : classesRoots) {
        final String url = root.getAttributeValue("url");
        if (url == null) {
            // corrupted element
            continue;
        }
        final String path = getPathFromUrl(url);
        if (path == null) {
            continue;
        }
        if (path.toLowerCase().endsWith(".swc")) {
            return true;
        } else {
            if (jarDirectories.contains(OrderRootType.CLASSES, url)) {
                String expanded = pathExpander.fun(path);
                File file = new File(expanded);
                if (!file.isDirectory()) {
                    return true;
                }
                String[] allChildren = file.list();
                if (allChildren == null || allChildren.length == 0) {
                    return true;
                }
                File[] swcs = file.listFiles(FileFilters.filesWithExtension("swc"));
                if (swcs != null && swcs.length > 0) {
                    return true;
                }
                File[] jars = file.listFiles(FileFilters.filesWithExtension("jar"));
                if (jars != null && jars.length > 0) {
                    continue;
                }
                return true;
            } else if (!path.toLowerCase().endsWith(".jar")) {
                return true;
            }
        }
    }
    return false;
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) JarDirectories(com.intellij.openapi.roots.impl.libraries.JarDirectories) File(java.io.File)

Example 18 with InvalidDataException

use of com.intellij.openapi.util.InvalidDataException in project azure-tools-for-java by Microsoft.

the class RemoteDebugRunConfiguration method readExternal.

@Override
public void readExternal(Element rootElement) throws InvalidDataException {
    super.readExternal(rootElement);
    SparkSubmitModel model = getSubmitModel();
    SparkSubmissionParameter parameter = Optional.ofNullable(model.getSubmissionParameter()).orElse(new SparkSubmissionParameter("", false, "", "", "", "", new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), Arrays.stream(SparkSubmissionParameter.defaultParameters).collect(Collectors.toMap(Pair::first, Pair::second))));
    Optional.ofNullable(rootElement.getChild(SUBMISSION_CONTENT_NAME)).ifPresent((element -> {
        Optional.ofNullable(element.getAttribute(SUBMISSION_ATTRIBUTE_CLUSTER_NAME)).ifPresent(attribute -> parameter.setClusterName(attribute.getValue()));
        Optional.ofNullable(element.getAttribute(SUBMISSION_ATTRIBUTE_IS_LOCAL_ARTIFACT)).ifPresent(attribute -> parameter.setLocalArtifact(attribute.getValue().toLowerCase().equals("true")));
        Optional.ofNullable(element.getAttribute(SUBMISSION_ATTRIBUTE_ARTIFACT_NAME)).ifPresent(attribute -> parameter.setArtifactName(attribute.getValue()));
        Optional.ofNullable(element.getAttribute(SUBMISSION_ATTRIBUTE_CLASSNAME)).ifPresent(attribute -> parameter.setClassName(attribute.getValue()));
        model.setSubmissionParameters(parameter);
    }));
}
Also used : SparkSubmissionParameter(com.microsoft.azure.hdinsight.spark.common.SparkSubmissionParameter) Arrays(java.util.Arrays) ExecutionException(com.intellij.execution.ExecutionException) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SparkSubmissionParameter(com.microsoft.azure.hdinsight.spark.common.SparkSubmissionParameter) Executor(com.intellij.execution.Executor) InvalidDataException(com.intellij.openapi.util.InvalidDataException) Collectors(java.util.stream.Collectors) com.intellij.execution.configurations(com.intellij.execution.configurations) ArrayList(java.util.ArrayList) Pair(com.microsoft.azuretools.utils.Pair) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) SparkSubmissionContentPanel(com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel) Project(com.intellij.openapi.project.Project) Optional(java.util.Optional) SparkSubmitModel(com.microsoft.azure.hdinsight.spark.common.SparkSubmitModel) Module(com.intellij.openapi.module.Module) WriteExternalException(com.intellij.openapi.util.WriteExternalException) SparkBatchJobSubmissionState(com.microsoft.azure.hdinsight.spark.run.SparkBatchJobSubmissionState) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) SettingsEditor(com.intellij.openapi.options.SettingsEditor) SparkSubmitModel(com.microsoft.azure.hdinsight.spark.common.SparkSubmitModel) ArrayList(java.util.ArrayList)

Example 19 with InvalidDataException

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

the class ModulesDetectionStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    final boolean validated = super.validate();
    if (!validated) {
        return false;
    }
    final List<ModuleDescriptor> modules = myModulesLayoutPanel.getChosenEntries();
    final Map<String, ModuleDescriptor> errors = new LinkedHashMap<>();
    for (ModuleDescriptor module : modules) {
        try {
            final String moduleFilePath = module.computeModuleFilePath();
            if (new File(moduleFilePath).exists()) {
                errors.put(IdeBundle.message("warning.message.the.module.file.0.already.exist.and.will.be.overwritten", moduleFilePath), module);
            }
        } catch (InvalidDataException e) {
            errors.put(e.getMessage(), module);
        }
    }
    if (!errors.isEmpty()) {
        final int answer = Messages.showYesNoCancelDialog(getComponent(), IdeBundle.message("warning.text.0.do.you.want.to.overwrite.these.files", StringUtil.join(errors.keySet(), "\n"), errors.size()), IdeBundle.message("title.file.already.exists"), "Overwrite", "Reuse", "Cancel", Messages.getQuestionIcon());
        if (answer == Messages.CANCEL) {
            return false;
        }
        if (answer != Messages.YES) {
            for (ModuleDescriptor moduleDescriptor : errors.values()) {
                moduleDescriptor.reuseExisting(true);
            }
        }
    }
    return true;
}
Also used : InvalidDataException(com.intellij.openapi.util.InvalidDataException) File(java.io.File)

Example 20 with InvalidDataException

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

the class ConfigureTasksActivationDialog method updateTree.

private void updateTree(@Nullable CachingSimpleNode nodeToUpdate) {
    Set<CachingSimpleNode> toUpdate = ContainerUtil.newIdentityTroveSet();
    if (nodeToUpdate == null) {
        for (DefaultMutableTreeNode node : myTree.getSelectedNodes(DefaultMutableTreeNode.class, null)) {
            final Object userObject = node.getUserObject();
            if (userObject instanceof SimpleNode && ((SimpleNode) userObject).getParent() instanceof CachingSimpleNode) {
                toUpdate.add((CachingSimpleNode) ((SimpleNode) userObject).getParent());
            }
        }
    } else {
        toUpdate.add(nodeToUpdate);
    }
    if (toUpdate.isEmpty()) {
        toUpdate.add(myRootNode);
    }
    Element treeStateElement = new Element("root");
    try {
        TreeState.createOn(myTree).writeExternal(treeStateElement);
    } catch (WriteExternalException ignore) {
    }
    for (CachingSimpleNode node : toUpdate) {
        cleanUpEmptyNodes(node);
    }
    TreeState treeState = new TreeState();
    try {
        treeState.readExternal(treeStateElement);
        treeState.applyTo(myTree);
    } catch (InvalidDataException ignore) {
    }
}
Also used : TreeState(com.intellij.ide.util.treeView.TreeState) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) 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