Search in sources :

Example 1 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class EclipseCodeStyleSchemeImporter method readFromStream.

private static void readFromStream(@NotNull final VirtualFile file, @NotNull final ThrowableConsumer<InputStream, SchemeImportException> consumer) throws SchemeImportException {
    InputStream inputStream = null;
    try {
        inputStream = file.getInputStream();
        consumer.consume(inputStream);
    } catch (IOException e) {
        throw new SchemeImportException(e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            //
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) SchemeImportException(com.intellij.openapi.options.SchemeImportException) IOException(java.io.IOException)

Example 2 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class EclipseXmlProfileReader method readSettings.

/**
   * Reads either basic profile info (name) or all the settings depending on whether <code>settings</code> parameter is null.
   * 
   * @param input The input stream to read from.
   * @throws SchemeImportException
   */
protected void readSettings(InputStream input) throws SchemeImportException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser parser;
    try {
        parser = spf.newSAXParser();
        parser.parse(input, this);
    } catch (Exception e) {
        if (e.getCause() instanceof NonEclipseXmlFileException) {
            throw new SchemeImportException("The input file is not a valid Eclipse XML profile.");
        } else {
            throw new SchemeImportException(e);
        }
    }
}
Also used : SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXParser(javax.xml.parsers.SAXParser) SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 3 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class EclipseThemeReader method readSettings.

protected void readSettings(InputStream input) throws SchemeImportException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(false);
    SAXParser parser;
    try {
        parser = spf.newSAXParser();
        parser.parse(input, this);
    } catch (Exception e) {
        if (e.getCause() instanceof NotAnEclipseThemeException) {
            throw new SchemeImportException("The input file is not a valid Eclipse theme.");
        } else {
            throw new SchemeImportException(e);
        }
    }
}
Also used : SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXParser(javax.xml.parsers.SAXParser) SchemeImportException(com.intellij.openapi.options.SchemeImportException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 4 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class FormatterStarter method readSettings.

private static CodeStyleSettings readSettings(@NotNull String settingsPath) throws SchemeImportException {
    VirtualFile vFile = VfsUtil.findFileByIoFile(new File(settingsPath), true);
    CodeStyleSettingsLoader loader = new CodeStyleSettingsLoader();
    if (vFile == null) {
        throw new SchemeImportException("Cannot find file " + settingsPath);
    }
    return loader.loadSettings(vFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleSettingsLoader(com.intellij.psi.impl.source.codeStyle.CodeStyleSettingsLoader) SchemeImportException(com.intellij.openapi.options.SchemeImportException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class FormatterStarter method main.

@Override
public void main(String[] args) {
    @SuppressWarnings("UseOfSystemOutOrSystemErr") MessageOutput messageOutput = new MessageOutput(new PrintWriter(System.out), new PrintWriter(System.err));
    messageOutput.info(getAppInfo() + " Formatter\n");
    FileSetFormatter fileSetFormatter = new FileSetFormatter(messageOutput);
    logArgs(args);
    if (args.length < 2) {
        showUsageInfo(messageOutput);
    }
    for (int i = 1; i < args.length; i++) {
        if (args[i].startsWith("-")) {
            if (checkOption(args[i], "-h", "-help")) {
                showUsageInfo(messageOutput);
            }
            if (checkOption(args[i], "-s", "-settings")) {
                //noinspection AssignmentToForLoopParameter
                i++;
                if (i >= args.length) {
                    fatalError(messageOutput, "Missing settings file path.");
                }
                try {
                    CodeStyleSettings settings = readSettings(args[i]);
                    fileSetFormatter.setCodeStyleSettings(settings);
                } catch (SchemeImportException e) {
                    fatalError(messageOutput, e.getLocalizedMessage() + "\n");
                }
            } else if (checkOption(args[i], "-r", "-R")) {
                fileSetFormatter.setRecursive();
            } else if (checkOption(args[i], "-m", "-mask")) {
                //noinspection AssignmentToForLoopParameter
                i++;
                if (i >= args.length) {
                    fatalError(messageOutput, "Missing file mask(s).");
                }
                for (String mask : args[i].split(",")) {
                    if (!mask.isEmpty()) {
                        fileSetFormatter.addFileMask(mask);
                    }
                }
            } else {
                fatalError(messageOutput, "Unknown option " + args[i]);
            }
        } else {
            try {
                fileSetFormatter.addEntry(args[i]);
            } catch (IOException e) {
                fatalError(messageOutput, e.getLocalizedMessage());
            }
        }
    }
    try {
        fileSetFormatter.processFiles();
        messageOutput.info("\n" + fileSetFormatter.getProcessedFiles() + " file(s) formatted.\n");
    } catch (IOException e) {
        fatalError(messageOutput, e.getLocalizedMessage());
    }
    ((ApplicationEx) ApplicationManager.getApplication()).exit(true, true);
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) SchemeImportException(com.intellij.openapi.options.SchemeImportException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

SchemeImportException (com.intellij.openapi.options.SchemeImportException)8 IOException (java.io.IOException)3 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)2 InputStream (java.io.InputStream)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXException (org.xml.sax.SAXException)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 CodeStyleSettingsLoader (com.intellij.psi.impl.source.codeStyle.CodeStyleSettingsLoader)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Attribute (org.jdom.Attribute)1 NotNull (org.jetbrains.annotations.NotNull)1