Search in sources :

Example 1 with CompilerMessageCategory

use of com.intellij.openapi.compiler.CompilerMessageCategory in project intellij-elixir by KronicDeth.

the class ElixirCompilerError method create.

@Nullable
public static ElixirCompilerError create(String rootPath, String elixircMessage) {
    Matcher matcher = COMPILER_MESSAGE_PATTERN.matcher(StringUtil.trimTrailing(elixircMessage));
    if (!matcher.matches())
        return null;
    String relativeFilePath = FileUtil.toSystemIndependentName(matcher.group(1));
    String line = matcher.group(2);
    String warning = matcher.group(3);
    String details = matcher.group(4);
    String path = StringUtil.isEmpty(rootPath) ? relativeFilePath : new File(FileUtil.toSystemIndependentName(rootPath), relativeFilePath).getPath();
    int lineNumber = StringUtil.parseInt(line, UNKNOWN_LINE_NUMBER);
    CompilerMessageCategory category = warning != null ? CompilerMessageCategory.WARNING : CompilerMessageCategory.ERROR;
    assert path != null;
    return new ElixirCompilerError(details, VfsUtilCore.pathToUrl(path), lineNumber, category);
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) Matcher(java.util.regex.Matcher) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CompilerMessageCategory

use of com.intellij.openapi.compiler.CompilerMessageCategory in project intellij-community by JetBrains.

the class CompilerTask method doAddMessage.

private void doAddMessage(final CompilerMessage message) {
    synchronized (myMessageViewLock) {
        if (myErrorTreeView != null) {
            final Navigatable navigatable = message.getNavigatable();
            final VirtualFile file = message.getVirtualFile();
            final CompilerMessageCategory category = message.getCategory();
            final int type = translateCategory(category);
            final String[] text = convertMessage(message);
            if (navigatable != null) {
                final String groupName = file != null ? file.getPresentableUrl() : category.getPresentableText();
                myErrorTreeView.addMessage(type, text, groupName, navigatable, message.getExportTextPrefix(), message.getRenderTextPrefix(), message.getVirtualFile());
            } else {
                myErrorTreeView.addMessage(type, text, file, -1, -1, message.getVirtualFile());
            }
            final boolean shouldAutoActivate = !myMessagesAutoActivated && (CompilerMessageCategory.ERROR.equals(category) || (CompilerMessageCategory.WARNING.equals(category) && !ErrorTreeViewConfiguration.getInstance(myProject).isHideWarnings()));
            if (shouldAutoActivate) {
                myMessagesAutoActivated = true;
                activateMessageView();
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) Navigatable(com.intellij.pom.Navigatable)

Example 3 with CompilerMessageCategory

use of com.intellij.openapi.compiler.CompilerMessageCategory in project intellij-community by JetBrains.

the class CompilerTask method addMessage.

public void addMessage(final CompilerMessage message) {
    prepareMessageView();
    final CompilerMessageCategory messageCategory = message.getCategory();
    if (CompilerMessageCategory.WARNING.equals(messageCategory)) {
        myWarningCount += 1;
    } else if (CompilerMessageCategory.ERROR.equals(messageCategory)) {
        myErrorCount += 1;
        informWolf(message);
    }
    if (ApplicationManager.getApplication().isDispatchThread()) {
        openMessageView();
        doAddMessage(message);
    } else {
        final Window window = getWindow();
        final ModalityState modalityState = window != null ? ModalityState.stateForComponent(window) : ModalityState.NON_MODAL;
        ApplicationManager.getApplication().invokeLater(() -> {
            if (myProject != null && !myProject.isDisposed()) {
                openMessageView();
                doAddMessage(message);
            }
        }, modalityState);
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) ToolWindow(com.intellij.openapi.wm.ToolWindow) ModalityState(com.intellij.openapi.application.ModalityState)

Example 4 with CompilerMessageCategory

use of com.intellij.openapi.compiler.CompilerMessageCategory in project intellij-community by JetBrains.

the class OutputParser method processJavacMessages.

private static void processJavacMessages(final List<String> javacMessages, final AntBuildMessageView messageView, final Project project) {
    if (javacMessages == null) {
        return;
    }
    final com.intellij.compiler.OutputParser outputParser = new JavacOutputParser(project);
    com.intellij.compiler.OutputParser.Callback callback = new com.intellij.compiler.OutputParser.Callback() {

        private int myIndex = -1;

        @Nullable
        public String getCurrentLine() {
            if (myIndex >= javacMessages.size()) {
                return null;
            }
            return javacMessages.get(myIndex);
        }

        public String getNextLine() {
            final int size = javacMessages.size();
            final int next = Math.min(myIndex + 1, javacMessages.size());
            myIndex = next;
            if (next >= size) {
                return null;
            }
            return javacMessages.get(next);
        }

        @Override
        public void pushBack(String line) {
            myIndex--;
        }

        public void message(final CompilerMessageCategory category, final String message, final String url, final int lineNum, final int columnNum) {
            StringTokenizer tokenizer = new StringTokenizer(message, "\n", false);
            final String[] strings = new String[tokenizer.countTokens()];
            //noinspection ForLoopThatDoesntUseLoopVariable
            for (int idx = 0; tokenizer.hasMoreTokens(); idx++) {
                strings[idx] = tokenizer.nextToken();
            }
            ApplicationManager.getApplication().runReadAction(() -> {
                VirtualFile file = url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url);
                messageView.outputJavacMessage(convertCategory(category), strings, file, url, lineNum, columnNum);
                if (file != null && category == CompilerMessageCategory.ERROR) {
                    final WolfTheProblemSolver wolf = WolfTheProblemSolver.getInstance(project);
                    final Problem problem = wolf.convertToProblem(file, lineNum, columnNum, strings);
                    wolf.weHaveGotNonIgnorableProblems(file, Collections.singletonList(problem));
                }
            });
        }

        public void setProgressText(String text) {
        }

        public void fileProcessed(String path) {
        }

        public void fileGenerated(String path) {
        }
    };
    try {
        while (true) {
            if (!outputParser.processMessageLine(callback)) {
                break;
            }
        }
    } catch (Exception e) {
    //ignore
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WolfTheProblemSolver(com.intellij.problems.WolfTheProblemSolver) JavacOutputParser(com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser) StringTokenizer(com.intellij.util.text.StringTokenizer) Problem(com.intellij.problems.Problem) JavacOutputParser(com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser)

Example 5 with CompilerMessageCategory

use of com.intellij.openapi.compiler.CompilerMessageCategory in project android by JetBrains.

the class AndroidMavenExecutor method generateResources.

public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
    final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
    result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
    try {
        JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {

            @Nullable
            @Override
            public JavaParameters compute() {
                try {
                    return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
                } catch (ExecutionException e) {
                    LOG.info(e);
                    result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
                    return null;
                }
            }
        });
        if (javaParams == null) {
            return result;
        }
        GeneralCommandLine commandLine = javaParams.toCommandLine();
        final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
        boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
        String message = processor.getMessage();
        if (!success) {
            LOG.info(message);
            String lcmessage = message.toLowerCase();
            int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
            if (buildErrorIndex >= 0) {
                result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
            }
        }
    } catch (ExecutionException e) {
        LOG.info(e);
        result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
    }
    return result;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) HashMap(com.intellij.util.containers.HashMap) StringBuildingOutputProcessor(org.jetbrains.android.util.StringBuildingOutputProcessor) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Aggregations

CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)12 Nullable (org.jetbrains.annotations.Nullable)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 Matcher (java.util.regex.Matcher)3 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)2 Module (com.intellij.openapi.module.Module)2 Navigatable (com.intellij.pom.Navigatable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JavacOutputParser (com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 ModalityState (com.intellij.openapi.application.ModalityState)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ToolWindow (com.intellij.openapi.wm.ToolWindow)1 Problem (com.intellij.problems.Problem)1 WolfTheProblemSolver (com.intellij.problems.WolfTheProblemSolver)1