Search in sources :

Example 11 with JDOMException

use of org.jdom.JDOMException in project intellij-community by JetBrains.

the class CoreModuleManager method createAndLoadModule.

@NotNull
@Override
protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException {
    final ModuleEx module = createModule(filePath);
    try {
        ModuleRootManagerImpl.ModuleRootManagerState state = new ModuleRootManagerImpl.ModuleRootManagerState();
        state.readExternal(CoreProjectLoader.loadStorageFile(module, file).get("NewModuleRootManager"));
        ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state);
    } catch (JDOMException e) {
        throw new IOException(e);
    }
    return module;
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) ModuleEx(com.intellij.openapi.module.impl.ModuleEx) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with JDOMException

use of org.jdom.JDOMException in project intellij-community by JetBrains.

the class PathManagerEx method getCommunityModules.

private static synchronized Set<String> getCommunityModules() {
    if (ourCommunityModules != null) {
        return ourCommunityModules;
    }
    ourCommunityModules = new THashSet<>();
    File modulesXml = findFileUnderCommunityHome(Project.DIRECTORY_STORE_FOLDER + "/modules.xml");
    if (!modulesXml.exists()) {
        throw new IllegalStateException("Cannot obtain test data path: " + modulesXml.getAbsolutePath() + " not found");
    }
    try {
        Element element = JDomSerializationUtil.findComponent(JDOMUtil.load(modulesXml), ModuleManagerImpl.COMPONENT_NAME);
        assert element != null;
        for (ModulePath file : ModuleManagerImpl.getPathsToModuleFiles(element)) {
            ourCommunityModules.add(file.getModuleName());
        }
        return ourCommunityModules;
    } catch (JDOMException | IOException e) {
        throw new RuntimeException("Cannot read modules from " + modulesXml.getAbsolutePath(), e);
    }
}
Also used : ModulePath(com.intellij.openapi.module.impl.ModulePath) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 13 with JDOMException

use of org.jdom.JDOMException in project intellij-community by JetBrains.

the class Configuration method load.

@Nullable
public static Configuration load(final InputStream is) throws IOException, JDOMException {
    final List<Element> elements = new ArrayList<>();
    final Element rootElement = JDOMUtil.load(is);
    final Element state;
    if (rootElement.getName().equals(COMPONENT_NAME)) {
        state = rootElement;
    } else {
        elements.add(rootElement);
        //noinspection unchecked
        elements.addAll(rootElement.getChildren("component"));
        state = ContainerUtil.find(elements, element -> "component".equals(element.getName()) && COMPONENT_NAME.equals(element.getAttributeValue("name")));
    }
    if (state != null) {
        final Configuration cfg = new Configuration();
        cfg.loadState(state);
        return cfg;
    }
    return null;
}
Also used : Language(com.intellij.lang.Language) Storage(com.intellij.openapi.components.Storage) com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) com.intellij.util.containers(com.intellij.util.containers) URL(java.net.URL) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PairProcessor(com.intellij.util.PairProcessor) JDOMException(org.jdom.JDOMException) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) State(com.intellij.openapi.components.State) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) UndoConfirmationPolicy(com.intellij.openapi.command.UndoConfirmationPolicy) Logger(com.intellij.openapi.diagnostic.Logger) Extensions(com.intellij.openapi.extensions.Extensions) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) LanguageInjectionConfigBean(org.intellij.plugins.intelliLang.inject.LanguageInjectionConfigBean) CachedValueImpl(com.intellij.util.CachedValueImpl) GlobalUndoableAction(com.intellij.openapi.command.undo.GlobalUndoableAction) FileContentUtil(com.intellij.util.FileContentUtil) UndoableAction(com.intellij.openapi.command.undo.UndoableAction) IOException(java.io.IOException) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) Nullable(org.jetbrains.annotations.Nullable) ServiceManager(com.intellij.openapi.components.ServiceManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) CachedValue(com.intellij.psi.util.CachedValue) UndoManager(com.intellij.openapi.command.undo.UndoManager) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) InputStream(java.io.InputStream) PsiElement(com.intellij.psi.PsiElement) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) Element(org.jdom.Element) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with JDOMException

use of org.jdom.JDOMException in project intellij-community by JetBrains.

the class JpsPluginSyntheticArtifactProvider method createArtifact.

private static JpsArtifact createArtifact(JpsModule module, JpsPluginModuleProperties properties) {
    JpsPackagingElementFactory factory = JpsPackagingElementFactory.getInstance();
    JpsCompositePackagingElement root = factory.createArtifactRoot();
    String pluginXmlUrl = properties.getPluginXmlUrl();
    if (pluginXmlUrl != null) {
        String pluginXmlPath = JpsPathUtil.urlToPath(pluginXmlUrl);
        JpsCompositePackagingElement metaInfDir = factory.getOrCreateDirectory(root, "META-INF");
        metaInfDir.addChild(factory.createFileCopy(pluginXmlPath, null));
        File pluginXmlFile = JpsPathUtil.urlToFile(pluginXmlUrl);
        if (pluginXmlFile.exists()) {
            try {
                Element rootElement = JDOMUtil.load(pluginXmlFile);
                for (Element dependsElement : JDOMUtil.getChildren(rootElement, "depends")) {
                    String relativePath = dependsElement.getAttributeValue("config-file");
                    if (relativePath != null) {
                        File dependencyFile = new File(pluginXmlFile.getParent(), FileUtil.toSystemDependentName(relativePath));
                        String dependencyPath = FileUtil.toSystemIndependentName(dependencyFile.getAbsolutePath());
                        metaInfDir.addChild(factory.createFileCopy(dependencyPath, null));
                    }
                }
            } catch (JDOMException | IOException e) {
                LOG.info(e);
            }
        }
    }
    JpsJavaDependenciesEnumerator enumerator = JpsJavaExtensionService.dependencies(module).recursively().includedIn(JpsJavaClasspathKind.PRODUCTION_RUNTIME);
    JpsCompositePackagingElement classesDir = factory.getOrCreateDirectory(root, "classes");
    for (JpsModule depModule : enumerator.getModules()) {
        if (depModule.getModuleType().equals(JpsJavaModuleType.INSTANCE)) {
            classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(depModule.createReference()));
        }
    }
    classesDir.addChild(JpsJavaExtensionService.getInstance().createProductionModuleOutput(module.createReference()));
    for (JpsLibrary library : enumerator.getLibraries()) {
        JpsCompositePackagingElement parent;
        if (hasDirsOnly(library)) {
            parent = classesDir;
        } else {
            parent = factory.getOrCreateDirectory(root, "lib");
        }
        parent.addChild(factory.createLibraryElement(library.createReference()));
    }
    String name = module.getName() + ":plugin";
    JpsArtifact artifact = JpsArtifactService.getInstance().createArtifact(name, root, DirectoryArtifactType.INSTANCE, JpsElementFactory.getInstance().createDummyElement());
    JpsSdk<JpsSimpleElement<JpsIdeaSdkProperties>> sdk = module.getSdk(JpsIdeaSdkType.INSTANCE);
    if (sdk != null) {
        String sandboxHome = sdk.getSdkProperties().getData().getSandboxHome();
        if (sandboxHome != null) {
            artifact.setOutputPath(sandboxHome + "/plugins/" + module.getName());
        }
    }
    return artifact;
}
Also used : JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) Element(org.jdom.Element) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsPackagingElementFactory(org.jetbrains.jps.model.artifact.elements.JpsPackagingElementFactory) File(java.io.File) JpsJavaDependenciesEnumerator(org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsCompositePackagingElement(org.jetbrains.jps.model.artifact.elements.JpsCompositePackagingElement)

Example 15 with JDOMException

use of org.jdom.JDOMException in project intellij-community by JetBrains.

the class EclipseImportBuilder method validate.

@Override
public boolean validate(final Project currentProject, final Project dstProject) {
    final Ref<Exception> refEx = new Ref<>();
    final Set<String> variables = new THashSet<>();
    final Map<String, String> naturesNames = new THashMap<>();
    final List<String> projectsToConvert = getParameters().projectsToConvert;
    final boolean oneProjectToConvert = projectsToConvert.size() == 1;
    final String separator = oneProjectToConvert ? "<br>" : ", ";
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        try {
            for (String path : projectsToConvert) {
                File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
                if (classPathFile.exists()) {
                    EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
                }
                collectUnknownNatures(path, naturesNames, separator);
            }
        } catch (IOException | JDOMException e) {
            refEx.set(e);
        }
    }, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
    if (!refEx.isNull()) {
        Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
        return false;
    }
    if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
        return false;
    }
    if (!naturesNames.isEmpty()) {
        final String title = "Unknown Natures Detected";
        final String naturesByProject;
        if (oneProjectToConvert) {
            naturesByProject = naturesNames.values().iterator().next();
        } else {
            naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
        }
        Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
    }
    return true;
}
Also used : ClassPathStorageUtil(com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) IdeaXml(org.jetbrains.idea.eclipse.IdeaXml) ClasspathStorage(com.intellij.openapi.roots.impl.storage.ClasspathStorage) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) EclipseIcons(icons.EclipseIcons) Library(com.intellij.openapi.roots.libraries.Library) ProjectImportBuilder(com.intellij.projectImport.ProjectImportBuilder) Task(com.intellij.openapi.progress.Task) JDOMException(org.jdom.JDOMException) EclipseUserLibrariesHelper(org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) ModuleManagerImpl(com.intellij.openapi.module.impl.ModuleManagerImpl) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryTablesRegistrar(com.intellij.openapi.roots.libraries.LibraryTablesRegistrar) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) Comparing(com.intellij.openapi.util.Comparing) StartupManager(com.intellij.openapi.startup.StartupManager) JDOMUtil(com.intellij.openapi.util.JDOMUtil) EclipseXml(org.jetbrains.idea.eclipse.EclipseXml) Project(com.intellij.openapi.project.Project) JpsEclipseClasspathSerializer(org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) File(java.io.File) EclipseProjectFinder(org.jetbrains.idea.eclipse.EclipseProjectFinder) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectMacrosUtil(com.intellij.openapi.project.impl.ProjectMacrosUtil) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) EclipseBundle(org.jetbrains.idea.eclipse.EclipseBundle) javax.swing(javax.swing) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) Notification(com.intellij.notification.Notification) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

JDOMException (org.jdom.JDOMException)67 IOException (java.io.IOException)55 Element (org.jdom.Element)44 Document (org.jdom.Document)22 File (java.io.File)17 SAXBuilder (org.jdom.input.SAXBuilder)15 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 StringReader (java.io.StringReader)8 THashMap (gnu.trove.THashMap)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 InvalidDataException (com.intellij.openapi.util.InvalidDataException)5 Path (java.nio.file.Path)4 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 StringWriter (java.io.StringWriter)3 Format (org.jdom.output.Format)3 XMLOutputter (org.jdom.output.XMLOutputter)3