Search in sources :

Example 6 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class UnresolvedDependenciesReporterTest method testReportWithRegularJavaLibrary.

public void testReportWithRegularJavaLibrary() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    when(mySyncIssue.getData()).thenReturn("com.google.guava:guava:19.0");
    Module appModule = myModules.getAppModule();
    VirtualFile buildFile = getGradleBuildFile(appModule);
    myReporter.report(mySyncIssue, appModule, buildFile);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Unresolved dependencies").hasMessageLine("Failed to resolve: com.google.guava:guava:19.0", 0);
    // @formatter:on
    assertThat(message.getNavigatable()).isInstanceOf(OpenFileDescriptor.class);
    OpenFileDescriptor navigatable = (OpenFileDescriptor) message.getNavigatable();
    assertEquals(buildFile, navigatable.getFile());
    PositionInFile position = message.getPosition();
    assertNotNull(position);
    assertSame(buildFile, position.file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Module(com.intellij.openapi.module.Module)

Example 7 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class UnhandledIssueMessageReporterTest method testReportWithBuildFile.

public void testReportWithBuildFile() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String expectedText = "Hello World!";
    when(mySyncIssue.getMessage()).thenReturn(expectedText);
    when(mySyncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
    VirtualFile buildFile = getGradleBuildFile(appModule);
    myReporter.report(mySyncIssue, appModule, buildFile);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasType(ERROR).hasMessageLine(expectedText, 0);
    // @formatter:on
    PositionInFile position = message.getPosition();
    assertNotNull(position);
    assertSame(buildFile, position.file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Example 8 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class ExternalNdkBuildIssuesReporter method createPosition.

@Nullable
private static PositionInFile createPosition(@NotNull List<SourceFilePosition> sourceFilePositions) {
    assert !sourceFilePositions.isEmpty();
    VirtualFile sourceFile = null;
    SourceFile source = sourceFilePositions.get(0).getFile();
    if (source.getSourceFile() != null) {
        sourceFile = findFileByIoFile(source.getSourceFile(), true);
    }
    if (sourceFile != null) {
        SourcePosition sourcePosition = sourceFilePositions.get(0).getPosition();
        return new PositionInFile(sourceFile, sourcePosition.getStartLine(), sourcePosition.getStartColumn());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourcePosition(com.android.ide.common.blame.SourcePosition) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) SourceFile(com.android.ide.common.blame.SourceFile) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class ExternalNdkBuildIssuesReporter method report.

@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String group = "External Native Build Issues";
    String nativeToolOutput = syncIssue.getData();
    if (nativeToolOutput != null) {
        SyncMessages messages = getSyncMessages(module);
        // Parse the native build tool output with the list of existing parsers.
        List<Message> compilerMessages = myBuildOutputParser.parseGradleOutput(nativeToolOutput);
        for (Message compilerMessage : compilerMessages) {
            MessageType type = MessageType.findMatching(compilerMessage.getKind());
            PositionInFile position = createPosition(compilerMessage.getSourceFilePositions());
            String text = compilerMessage.getText();
            Project project = module.getProject();
            if (type == ERROR) {
                // TODO make error handlers work with SyncMessage, instead of NotificationData.
                NotificationCategory category = type.convertToCategory();
                NotificationData notification = messages.createNotification(group, text, category, position);
                // Try to parse the error messages using the list of existing error handlers to find any potential quick-fixes.
                for (SyncErrorHandler handler : myErrorHandlers) {
                    if (handler.handleError(new ExternalSystemException(text), notification, project)) {
                        break;
                    }
                }
                messages.report(notification);
                continue;
            }
            SyncMessage message;
            if (position != null) {
                message = new SyncMessage(project, group, type, position, text);
            } else {
                message = new SyncMessage(group, type, text);
            }
            messages.report(message);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SyncMessages(com.android.tools.idea.gradle.project.sync.messages.SyncMessages) Project(com.intellij.openapi.project.Project) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) SyncErrorHandler(com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 10 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class UnhandledIssuesReporter method report.

@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String group = DEFAULT_GROUP;
    String text = syncIssue.getMessage();
    MessageType type = getMessageType(syncIssue);
    SyncMessage message;
    if (buildFile != null) {
        PositionInFile position = new PositionInFile(buildFile);
        message = new SyncMessage(module.getProject(), group, type, position, text);
    } else {
        message = new SyncMessage(group, type, NonNavigatable.INSTANCE, text);
    }
    getSyncMessages(module).report(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Aggregations

PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)12 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)9 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)3 Message (com.android.ide.common.blame.Message)2 SourcePosition (com.android.ide.common.blame.SourcePosition)2 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)2 Document (com.intellij.openapi.editor.Document)2 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)2 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 SourceFile (com.android.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoPackage (com.android.repository.api.RepoPackage)1