Search in sources :

Example 1 with SourceFilePosition

use of com.android.ide.common.blame.SourceFilePosition 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 SourceFilePosition

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

the class BuildOutputParserTest method toString.

@NotNull
private static String toString(@NotNull List<Message> messages) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0, n = messages.size(); i < n; i++) {
        Message message = messages.get(i);
        sb.append(Integer.toString(i)).append(':').append(' ');
        // INFO => Info
        sb.append(StringUtil.capitalize(message.getKind().toString().toLowerCase(Locale.US))).append(':');
        sb.append(message.getText());
        if (message.getSourcePath() != null) {
            for (SourceFilePosition position : message.getSourceFilePositions()) {
                sb.append('\n');
                sb.append('\t');
                // Fudge for windows tests. As messages use a file object, which is filesystem aware, Windows paths come out prefaced with the
                // unix CWD.
                String path = position.getFile().toString();
                if (path.startsWith(WINDOWS_PATH_UNDER_UNIX)) {
                    path = path.substring(WINDOWS_PATH_UNIX_PREFIX_LENGTH);
                }
                sb.append(path);
                int line = position.getPosition().getStartLine();
                sb.append(':').append(Integer.toString(line == -1 ? -1 : line + 1));
                int col = position.getPosition().getStartColumn();
                sb.append(':').append(Integer.toString(col == -1 ? -1 : col + 1));
            }
        } else {
            String gradlePath = message.getSourceFilePositions().get(0).getFile().getDescription();
            if (gradlePath != null) {
                sb.append('\n');
                sb.append(gradlePath);
            }
        }
        sb.append('\n');
    }
    return sb.toString();
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SourceFilePosition

use of com.android.ide.common.blame.SourceFilePosition 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 4 with SourceFilePosition

use of com.android.ide.common.blame.SourceFilePosition 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 5 with SourceFilePosition

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

the class AndroidPluginOutputParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    if (line.contains("[DEBUG] ") || line.contains("[INFO] ")) {
        // Ignore 'debug' and 'info' messages.
        return false;
    }
    if (IGNORED_MESSAGE_PATTERN.matcher(line).matches()) {
        return false;
    }
    // pattern is type|path|message
    String[] segments = line.split("\\|", SEGMENT_COUNT);
    if (segments.length == SEGMENT_COUNT) {
        Message.Kind kind = Message.Kind.findIgnoringCase(segments[0], Message.Kind.ERROR);
        String path = segments[1];
        if (StringUtil.isEmpty(path)) {
            return false;
        }
        String msg = StringUtil.notNullize(segments[2]);
        // The SourceFile description is the Gradle path of the project.
        messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new SourceFile(path.trim()), SourcePosition.UNKNOWN)));
        return true;
    }
    return false;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) SourceFile(com.android.ide.common.blame.SourceFile)

Aggregations

SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)16 SourcePosition (com.android.ide.common.blame.SourcePosition)12 Message (com.android.ide.common.blame.Message)11 File (java.io.File)11 SourceFile (com.android.ide.common.blame.SourceFile)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Matcher (java.util.regex.Matcher)4 Actions (com.android.manifmerger.Actions)3 Module (com.intellij.openapi.module.Module)3 XmlFile (com.intellij.psi.xml.XmlFile)3 NotNull (org.jetbrains.annotations.NotNull)3 MergingReport (com.android.manifmerger.MergingReport)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 IdeActions (com.intellij.openapi.actionSystem.IdeActions)2 ArrayList (java.util.ArrayList)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 ParsingFailedException (com.android.ide.common.blame.parser.ParsingFailedException)1 ManifestMerger2 (com.android.manifmerger.ManifestMerger2)1