Search in sources :

Example 6 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 7 with CompilerMessageCategory

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

the class ProblemsView method addMessage.

public final void addMessage(CompilerMessage message, @NotNull UUID sessionId) {
    final VirtualFile file = message.getVirtualFile();
    Navigatable navigatable = message.getNavigatable();
    if (navigatable == null && file != null) {
        navigatable = new OpenFileDescriptor(myProject, file, -1, -1);
    }
    final CompilerMessageCategory category = message.getCategory();
    final int type = CompilerTask.translateCategory(category);
    final String[] text = convertMessage(message);
    final String groupName = file != null ? file.getPresentableUrl() : category.getPresentableText();
    addMessage(type, text, groupName, navigatable, message.getExportTextPrefix(), message.getRenderTextPrefix(), sessionId);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable)

Example 8 with CompilerMessageCategory

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

the class JavacOutputParser method processMessageLine.

public boolean processMessageLine(Callback callback) {
    if (super.processMessageLine(callback)) {
        return true;
    }
    final String line = callback.getCurrentLine();
    if (line == null) {
        return false;
    }
    if (JavacResourcesReader.MSG_PATTERNS_START.equals(line)) {
        myParserActions.clear();
        while (true) {
            final String patternLine = callback.getNextLine();
            if (JavacResourcesReader.MSG_PATTERNS_END.equals(patternLine)) {
                break;
            }
            addJavacPattern(patternLine);
        }
        return true;
    }
    int colonIndex1 = line.indexOf(':');
    if (colonIndex1 == 1) {
        // drive letter
        colonIndex1 = line.indexOf(':', colonIndex1 + 1);
    }
    if (colonIndex1 >= 0) {
        // looks like found something like file path
        @NonNls String part1 = line.substring(0, colonIndex1).trim();
        if (part1.equalsIgnoreCase("error") || /*jikes*/
        part1.equalsIgnoreCase("Caused by")) {
            addMessage(callback, CompilerMessageCategory.ERROR, line.substring(colonIndex1));
            return true;
        }
        if (part1.equalsIgnoreCase("warning")) {
            addMessage(callback, CompilerMessageCategory.WARNING, line.substring(colonIndex1));
            return true;
        }
        if (part1.equals("javac")) {
            addMessage(callback, CompilerMessageCategory.ERROR, line);
            return true;
        }
        final int colonIndex2 = line.indexOf(':', colonIndex1 + 1);
        if (colonIndex2 >= 0) {
            final String filePath = part1.replace(File.separatorChar, '/');
            final Boolean fileExists = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                public Boolean compute() {
                    return LocalFileSystem.getInstance().findFileByPath(filePath) != null;
                }
            });
            if (!fileExists.booleanValue()) {
                // the part one turned out to be something else than a file path
                return true;
            }
            try {
                final int lineNum = Integer.parseInt(line.substring(colonIndex1 + 1, colonIndex2).trim());
                String message = line.substring(colonIndex2 + 1).trim();
                CompilerMessageCategory category = CompilerMessageCategory.ERROR;
                if (message.startsWith(WARNING_PREFIX)) {
                    message = message.substring(WARNING_PREFIX.length()).trim();
                    category = CompilerMessageCategory.WARNING;
                }
                List<String> messages = new ArrayList<>();
                messages.add(message);
                int colNum;
                String prevLine = null;
                do {
                    final String nextLine = callback.getNextLine();
                    if (nextLine == null) {
                        return false;
                    }
                    if (nextLine.trim().equals("^")) {
                        final CharSequence chars = prevLine == null ? line : prevLine;
                        final int offset = Math.max(0, Math.min(chars.length(), nextLine.indexOf('^')));
                        colNum = EditorUtil.calcColumnNumber(null, chars, 0, offset, myTabSize);
                        String messageEnd = callback.getNextLine();
                        while (isMessageEnd(messageEnd)) {
                            messages.add(messageEnd.trim());
                            messageEnd = callback.getNextLine();
                        }
                        if (messageEnd != null) {
                            callback.pushBack(messageEnd);
                        }
                        break;
                    }
                    if (prevLine != null) {
                        messages.add(prevLine);
                    }
                    prevLine = nextLine;
                } while (true);
                if (colNum >= 0) {
                    messages = convertMessages(messages);
                    final StringBuilder buf = StringBuilderSpinAllocator.alloc();
                    try {
                        for (final String m : messages) {
                            if (buf.length() > 0) {
                                buf.append("\n");
                            }
                            buf.append(m);
                        }
                        addMessage(callback, category, buf.toString(), VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath), lineNum, colNum + 1);
                    } finally {
                        StringBuilderSpinAllocator.dispose(buf);
                    }
                    return true;
                }
            } catch (NumberFormatException ignored) {
            }
        }
    }
    if (line.endsWith("java.lang.OutOfMemoryError")) {
        addMessage(callback, CompilerMessageCategory.ERROR, CompilerBundle.message("error.javac.out.of.memory"));
        return true;
    }
    addMessage(callback, CompilerMessageCategory.INFORMATION, line);
    return true;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) NonNls(org.jetbrains.annotations.NonNls) ArrayList(java.util.ArrayList)

Example 9 with CompilerMessageCategory

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

the class AndroidAutogenerator method runRenderscript.

private static void runRenderscript(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AndroidRenderscriptFileType.INSTANCE, true);
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.RENDERSCRIPT);
    for (final VirtualFile file : files) {
        final RenderscriptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<RenderscriptAutogenerationItem>() {

            @Nullable
            @Override
            public RenderscriptAutogenerationItem compute() {
                final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
                if (platform == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final IAndroidTarget target = platform.getTarget();
                final String sdkLocation = platform.getSdkData().getPath();
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String resourceDirPath = AndroidRootUtil.getResourceDirPath(facet);
                assert resourceDirPath != null;
                final String sourceRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
                if (sourceRootPath == null) {
                    return null;
                }
                final String rawDirPath = resourceDirPath + '/' + SdkConstants.FD_RES_RAW;
                return new RenderscriptAutogenerationItem(sdkLocation, target, sourceRootPath, rawDirPath);
            }
        });
        if (item == null) {
            continue;
        }
        File tempOutDir = null;
        try {
            tempOutDir = FileUtil.createTempDirectory("android_renderscript_autogeneration", "tmp");
            final VirtualFile vTempOutDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempOutDir);
            final String depFolderPath = vTempOutDir != null ? getDependencyFolder(context.getProject(), file, vTempOutDir) : null;
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidRenderscript.execute(item.mySdkLocation, item.myTarget, file.getPath(), tempOutDir.getPath(), depFolderPath, item.myRawDirPath));
            if (messages.get(CompilerMessageCategory.ERROR).size() == 0) {
                final List<File> newFiles = new ArrayList<File>();
                AndroidCommonUtils.moveAllFiles(tempOutDir, new File(item.myGenDirPath), newFiles);
                for (File newFile : newFiles) {
                    final VirtualFile newVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(newFile);
                    if (newVFile != null) {
                        patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.RENDERSCRIPT, newVFile);
                    }
                }
                final File bcFile = new File(item.myRawDirPath, FileUtil.getNameWithoutExtension(file.getName()) + ".bc");
                final VirtualFile vBcFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(bcFile);
                if (vBcFile != null) {
                    facet.markFileAutogenerated(AndroidAutogeneratorMode.RENDERSCRIPT, vBcFile);
                }
            }
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed()) {
                        return;
                    }
                    for (final CompilerMessageCategory category : messages.keySet()) {
                        final List<String> messageList = messages.get(category);
                        for (final String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myGenDirPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
        } catch (final IOException e) {
            LOG.info(e);
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        } finally {
            if (tempOutDir != null) {
                FileUtil.delete(tempOutDir);
            }
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with CompilerMessageCategory

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

the class AndroidAutogenerator method runAidl.

private static void runAidl(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AidlFileType.INSTANCE, true);
    final List<IdlAutogenerationItem> items = new ArrayList<IdlAutogenerationItem>();
    for (final VirtualFile file : files) {
        final IdlAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<IdlAutogenerationItem>() {

            @Nullable
            @Override
            public IdlAutogenerationItem compute() {
                if (module.isDisposed() || module.getProject().isDisposed()) {
                    return null;
                }
                final IAndroidTarget target = facet.getConfiguration().getAndroidTarget();
                if (target == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String sourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
                if (sourceRootPath == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.apt.gen.not.specified", module.getName()), null, -1, -1);
                    return null;
                }
                final VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module, false);
                final String[] sourceRootOsPaths = AndroidCompileUtil.toOsPaths(sourceRoots);
                final String outFileOsPath = FileUtil.toSystemDependentName(sourceRootPath + '/' + packageName.replace('.', '/') + '/' + file.getNameWithoutExtension() + ".java");
                return new IdlAutogenerationItem(file, target, outFileOsPath, sourceRootOsPaths, sourceRootPath, packageName);
            }
        });
        if (item != null) {
            items.add(item);
        }
    }
    final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
    for (IdlAutogenerationItem item : items) {
        if (new File(FileUtil.toSystemDependentName(item.myFile.getPath())).exists()) {
            filesToCheck.add(item.myFile);
        }
    }
    if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
        return;
    }
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AIDL);
    for (IdlAutogenerationItem item : items) {
        final VirtualFile file = item.myFile;
        final String fileOsPath = FileUtil.toSystemDependentName(file.getPath());
        try {
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidIdl.execute(item.myTarget, fileOsPath, item.myOutFileOsPath, item.mySourceRootOsPaths));
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    for (CompilerMessageCategory category : messages.keySet()) {
                        List<String> messageList = messages.get(category);
                        for (String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            removeDuplicateClasses(module, item.myPackage, new File(item.myOutFileOsPath), item.myOutDirOsPath);
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myOutDirOsPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
            final VirtualFile outFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(item.myOutFileOsPath);
            if (outFile != null && outFile.exists()) {
                patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.AIDL, outFile);
            }
        } catch (final IOException e) {
            LOG.info(e);
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) HashSet(com.intellij.util.containers.HashSet)

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