Search in sources :

Example 16 with JDOMException

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

the class EclipseClasspathConverter method readClasspath.

@Override
public void readClasspath(@NotNull ModifiableRootModel model) throws IOException {
    try {
        CachedXmlDocumentSet fileSet = getFileSet();
        String path = fileSet.getParent(EclipseXml.PROJECT_FILE);
        Element classpath = null;
        if (!fileSet.exists(EclipseXml.PROJECT_FILE)) {
            classpath = fileSet.load(EclipseXml.CLASSPATH_FILE, false);
            if (classpath == null) {
                return;
            }
            path = fileSet.getParent(EclipseXml.CLASSPATH_FILE);
        }
        EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, module.getProject(), null);
        classpathReader.init(model);
        if (classpath == null) {
            classpath = fileSet.load(EclipseXml.CLASSPATH_FILE, false);
        }
        if (classpath == null) {
            EclipseClasspathReader.setOutputUrl(model, path + "/bin");
        } else {
            classpathReader.readClasspath(model, classpath);
        }
        Element eml = fileSet.load(model.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX, false);
        if (eml == null) {
            model.getModuleExtension(CompilerModuleExtension.class).setExcludeOutput(false);
        } else {
            new IdeaSpecificSettings().readIdeaSpecific(eml, model, null, null);
        }
    } catch (JDOMException e) {
        throw new IOException(e);
    }
}
Also used : Element(org.jdom.Element) IdeaSpecificSettings(org.jetbrains.idea.eclipse.conversion.IdeaSpecificSettings) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Example 17 with JDOMException

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

the class EclipseProjectFinder method findProjectName.

@Nullable
public static String findProjectName(String rootPath) {
    String name = null;
    final File file = new File(rootPath, DOT_PROJECT_EXT);
    if (file.isFile()) {
        try {
            name = JDOMUtil.load(file).getChildText(NAME_TAG);
            if (StringUtil.isEmptyOrSpaces(name)) {
                return null;
            }
            name = name.replace("\n", " ").trim();
        } catch (JDOMException | IOException e) {
            return null;
        }
    }
    return name;
}
Also used : IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with JDOMException

use of org.jdom.JDOMException in project android by JetBrains.

the class CompatibilityChecksMetadataUpdater method fetchMetadata.

@NotNull
private static ActionCallback fetchMetadata() {
    ActionCallback callback = new ActionCallback();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        String url = "https://dl.google.com/android/studio/metadata/android-component-compatibility.xml";
        try {
            Document metadata = HttpRequests.request(url).connect(request -> {
                try {
                    return loadDocument(request.getInputStream());
                } catch (JDOMException e) {
                    LOG.info("Failed to parse XML metadata", e);
                    return null;
                } catch (Throwable e) {
                    LOG.info("Failed to parse XML metadata", e);
                    return null;
                }
            });
            if (metadata != null) {
                VersionCompatibilityChecker.getInstance().updateMetadata(metadata);
                callback.setDone();
            }
        } catch (IOException e) {
            LOG.info(String.format("Failed to connect to '%1$s'", url), e);
        }
        callback.setRejected();
    });
    return callback;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) IOException(java.io.IOException) Document(org.jdom.Document) JDOMUtil.loadDocument(com.intellij.openapi.util.JDOMUtil.loadDocument) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with JDOMException

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

the class ConversionTestBaseEx method doTest.

@Override
protected boolean doTest(String testName, boolean conversionShouldHappen) throws IOException, JDOMException {
    String path = getHomePath() + getBasePath() + testName;
    final File globalBefore = new File(path, "global_before");
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            if (checkJdk()) {
                Element d = JDOMUtil.load(new File(globalBefore, JDK_TABLE_XML));
                ConversionHelper.expandPaths(d);
                ((ProjectJdkTableImpl) ProjectJdkTable.getInstance()).loadState(d);
            }
            {
                Element d = JDOMUtil.load(new File(globalBefore, GLOBAL_LIBS_XML));
                ConversionHelper.expandPaths(d);
                ApplicationLibraryTable.getApplicationTable().loadState(d);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    if (!super.doTest(testName, conversionShouldHappen)) {
        return false;
    }
    Path globalAfter = Paths.get(path, "global_after");
    if (checkJdk()) {
        Element sdkState = ((ProjectJdkTableImpl) ProjectJdkTable.getInstance()).getState();
        ConversionHelper.collapsePaths(sdkState);
        assertThat(sdkState).isEqualTo(globalAfter.resolve(JDK_TABLE_XML));
    }
    {
        Element globalLibState = ApplicationLibraryTable.getApplicationTable().getState();
        ConversionHelper.collapsePaths(globalLibState);
        assertThat(globalLibState).isEqualTo(globalAfter.resolve(GLOBAL_LIBS_XML));
    }
    return true;
}
Also used : Path(java.nio.file.Path) Element(org.jdom.Element) ProjectJdkTableImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkTableImpl) File(java.io.File) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 20 with JDOMException

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

the class FlexBuilderUtils method copyAndFixCustomAirDescriptor.

private static void copyAndFixCustomAirDescriptor(final CompileContext context, final BuildOutputConsumer outputConsumer, final JpsFlexBuildConfiguration bc, final JpsAirPackagingOptions packagingOptions) {
    final String customDescriptorPath = packagingOptions.getCustomDescriptorPath();
    final File descriptorTemplateFile = new File(customDescriptorPath);
    if (!descriptorTemplateFile.isFile()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("air.descriptor.not.found", customDescriptorPath)));
        return;
    }
    final String outputFilePath = bc.getActualOutputFilePath();
    final String outputFolderPath = PathUtilRt.getParentPath(outputFilePath);
    final File outputFolder = new File(outputFolderPath);
    if (!outputFolder.isDirectory()) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("output.folder.does.not.exist", outputFolder.getPath())));
        return;
    }
    final String content;
    try {
        content = fixInitialContent(descriptorTemplateFile, PathUtilRt.getFileName(outputFilePath));
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.open.air.descriptor", descriptorTemplateFile.getPath(), e.getMessage())));
        return;
    } catch (JDOMException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("incorrect.air.descriptor.content", descriptorTemplateFile.getPath(), e.getMessage())));
        return;
    }
    try {
        final String descriptorFileName = bc.isTempBCForCompilation() ? FlexCommonUtils.getGeneratedAirDescriptorName(bc, packagingOptions) : descriptorTemplateFile.getName();
        final File outputFile = new File(outputFolder, descriptorFileName);
        FileUtil.writeToFile(outputFile, content.getBytes("UTF-8"));
        outputConsumer.registerOutputFile(outputFile, Collections.singletonList(descriptorTemplateFile.getPath()));
    } catch (IOException e) {
        context.processMessage(new CompilerMessage(getCompilerName(bc), BuildMessage.Kind.ERROR, FlexCommonBundle.message("failed.to.copy.air.descriptor", e.getMessage())));
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ZipFile(java.util.zip.ZipFile) 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