Search in sources :

Example 1 with SourcePosition

use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.

the class ExternalNdkBuildIssuesReporterTest method testReportWithError.

public void testReportWithError() throws Exception {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String nativeToolOutput = "Failed to compile something";
    when(mySyncIssue.getData()).thenReturn(nativeToolOutput);
    VirtualFile buildFile = getGradleBuildFile(appModule);
    assertNotNull(buildFile);
    int line = 6;
    int column = 8;
    SourcePosition sourcePosition = new SourcePosition(line, column, 0);
    SourceFilePosition sourceFilePosition = new SourceFilePosition(virtualToIoFile(buildFile), sourcePosition);
    Message compilerMessage = new Message(ERROR, nativeToolOutput, sourceFilePosition);
    List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
    when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
    myReporter.report(mySyncIssue, appModule, buildFile);
    assertNull(mySyncMessagesStub.getFirstReportedMessage());
    NotificationData notification = mySyncMessagesStub.getNotification();
    assertNotNull(notification);
    assertTrue(myErrorHandler.isInvoked());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SyncMessageSubject.syncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) Module(com.intellij.openapi.module.Module) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 2 with SourcePosition

use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.

the class AndroidGradleJps method createCompilerMessages.

/**
   * Adapter method to create IDEA CompilerMessages from an Android build Message.
   *
   * If the Android build message has multiple source locations, this will create multiple CompilerMesssages with the same kind and
   * messageText, but different source positions.
   */
@NotNull
public static List<CompilerMessage> createCompilerMessages(@NotNull Message message) {
    final BuildMessage.Kind kind;
    switch(message.getKind()) {
        case INFO:
            kind = BuildMessage.Kind.INFO;
            break;
        case WARNING:
            kind = BuildMessage.Kind.WARNING;
            break;
        case ERROR:
            kind = BuildMessage.Kind.ERROR;
            break;
        default:
            kind = BuildMessage.Kind.PROGRESS;
    }
    List<CompilerMessage> compilerMessages = new ArrayList<CompilerMessage>();
    for (SourceFilePosition filePosition : message.getSourceFilePositions()) {
        File sourceFile = filePosition.getFile().getSourceFile();
        String sourceFilePath = sourceFile != null ? sourceFile.getAbsolutePath() : null;
        SourcePosition pos = filePosition.getPosition();
        compilerMessages.add(new CompilerMessage(COMPILER_NAME, kind, message.getText().trim(), sourceFilePath, pos.getStartOffset(), pos.getEndOffset(), pos.getEndOffset(), pos.getEndLine(), pos.getEndColumn()));
    }
    return Collections.unmodifiableList(compilerMessages);
}
Also used : BuildMessage(org.jetbrains.jps.incremental.messages.BuildMessage) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) SourcePosition(com.android.ide.common.blame.SourcePosition) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SourcePosition

use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.

the class ManifestPanel method goToDeclaration.

private void goToDeclaration(Node element) {
    List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, element);
    for (Actions.Record record : records) {
        SourceFilePosition sourceFilePosition = ManifestUtils.getActionLocation(myFacet.getModule(), record);
        SourceFile sourceFile = sourceFilePosition.getFile();
        if (!SourceFile.UNKNOWN.equals(sourceFile)) {
            File ioFile = sourceFile.getSourceFile();
            if (ioFile != null) {
                VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
                assert file != null;
                int line = -1;
                int column = 0;
                SourcePosition sourcePosition = sourceFilePosition.getPosition();
                if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
                    line = sourcePosition.getStartLine();
                    column = sourcePosition.getStartColumn();
                }
                Project project = myFacet.getModule().getProject();
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
                FileEditorManager.getInstance(project).openEditor(descriptor, true);
                break;
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) IdeActions(com.intellij.openapi.actionSystem.IdeActions) Actions(com.android.manifmerger.Actions) SourcePosition(com.android.ide.common.blame.SourcePosition) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) SourceFile(com.android.ide.common.blame.SourceFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFile(com.android.ide.common.blame.SourceFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File)

Example 4 with SourcePosition

use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.

the class ManifestMergeFailureParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    Matcher m = ERROR1.matcher(line);
    if (m.matches()) {
        String sourcePath = m.group(1);
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(m.group(2));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        String message = m.group(3);
        messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, -1, -1))));
        return true;
    }
    m = ERROR2.matcher(line);
    if (m.matches()) {
        String sourcePath = removeLeadingTab(m.group(1)).trim();
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(m.group(2));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        int column;
        try {
            column = Integer.parseInt(m.group(3));
        } catch (NumberFormatException e) {
            throw new ParsingFailedException(e);
        }
        if (lineNumber == 0 && column == 0) {
            // When both line number and column is zero, it is just a message saying "Validation failed, exiting". No need to display it.
            String next = reader.peek(0);
            if (next != null && next.contains("Validation failed, exiting")) {
                reader.readLine();
                return true;
            }
        } else {
            String msg = reader.readLine();
            if (msg != null) {
                msg = removeLeadingTab(msg).trim();
                Message.Kind kind = Message.Kind.findIgnoringCase(m.group(4), Message.Kind.ERROR);
                messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, column - 1, -1))));
                return true;
            }
        }
    }
    return false;
}
Also used : ParsingFailedException(com.android.ide.common.blame.parser.ParsingFailedException) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) Matcher(java.util.regex.Matcher) SourcePosition(com.android.ide.common.blame.SourcePosition) SourceFile(com.android.ide.common.blame.SourceFile) File(java.io.File)

Example 5 with SourcePosition

use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.

the class ManifestUtils method getActionLocation.

@NotNull
static SourceFilePosition getActionLocation(@NotNull Module module, @NotNull Actions.Record record) {
    SourceFilePosition sourceFilePosition = record.getActionLocation();
    SourceFile sourceFile = sourceFilePosition.getFile();
    File file = sourceFile.getSourceFile();
    SourcePosition sourcePosition = sourceFilePosition.getPosition();
    if (file != null && !SourcePosition.UNKNOWN.equals(sourcePosition)) {
        VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
        assert vFile != null;
        Module fileModule = ModuleUtilCore.findModuleForFile(vFile, module.getProject());
        if (fileModule != null && !fileModule.equals(module)) {
            MergedManifest manifest = MergedManifest.get(fileModule);
            Document document = manifest.getDocument();
            assert document != null;
            Element root = document.getDocumentElement();
            assert root != null;
            int startLine = sourcePosition.getStartLine();
            int startColumn = sourcePosition.getStartColumn();
            Node node = PositionXmlParser.findNodeAtLineAndCol(document, startLine, startColumn);
            if (node == null) {
                Logger.getInstance(ManifestPanel.class).warn("Can not find node in " + fileModule + " for " + sourceFilePosition);
            } else {
                List<? extends Actions.Record> records = getRecords(manifest, node);
                if (!records.isEmpty()) {
                    return getActionLocation(fileModule, records.get(0));
                }
            }
        }
    }
    return sourceFilePosition;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MergedManifest(com.android.tools.idea.model.MergedManifest) Actions(com.android.manifmerger.Actions) XmlNode(com.android.manifmerger.XmlNode) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SourcePosition(com.android.ide.common.blame.SourcePosition) SourceFile(com.android.ide.common.blame.SourceFile) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) SourceFile(com.android.ide.common.blame.SourceFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SourcePosition (com.android.ide.common.blame.SourcePosition)15 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)12 File (java.io.File)11 Message (com.android.ide.common.blame.Message)9 SourceFile (com.android.ide.common.blame.SourceFile)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Module (com.intellij.openapi.module.Module)4 XmlFile (com.intellij.psi.xml.XmlFile)3 Matcher (java.util.regex.Matcher)3 Actions (com.android.manifmerger.Actions)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)2 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)2 SyncMessageSubject.syncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage)2 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 ParsingFailedException (com.android.ide.common.blame.parser.ParsingFailedException)1