Search in sources :

Example 41 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage 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)

Example 42 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class ConflictSet method showSelectionConflicts.

/**
   * Shows the "variant selection" conflicts in the "Build Variant" and "Messages" windows.
   */
public void showSelectionConflicts() {
    SyncMessages messages = SyncMessages.getInstance(myProject);
    String groupName = VARIANT_SELECTION_CONFLICTS;
    messages.removeMessages(groupName);
    for (Conflict conflict : mySelectionConflicts) {
        // Creates the "Select in 'Build Variants' window" hyperlink.
        Module source = conflict.getSource();
        String hyperlinkText = String.format("Select '%1$s' in \"Build Variants\" window", source.getName());
        NotificationHyperlink selectInBuildVariantsWindowHyperlink = new NotificationHyperlink("select.conflict.in.variants.window", hyperlinkText) {

            @Override
            protected void execute(@NotNull Project project) {
                BuildVariantView.getInstance(project).findAndSelect(source);
            }
        };
        // Creates the "Fix problem" hyperlink.
        NotificationHyperlink quickFixHyperlink = new NotificationHyperlink("fix.conflict", "Fix problem") {

            @Override
            protected void execute(@NotNull Project project) {
                boolean solved = solveSelectionConflict(conflict);
                if (solved) {
                    ConflictSet conflicts = findConflicts(project);
                    conflicts.showSelectionConflicts();
                }
            }
        };
        SyncMessage msg = new SyncMessage(groupName, MessageType.WARNING, conflict.toString());
        msg.add(selectInBuildVariantsWindowHyperlink);
        msg.add(quickFixHyperlink);
        messages.report(msg);
    }
    BuildVariantView.getInstance(myProject).updateContents(mySelectionConflicts);
}
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) ConflictResolution.solveSelectionConflict(com.android.tools.idea.gradle.variant.conflict.ConflictResolution.solveSelectionConflict) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 43 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class ExternalNdkBuildIssuesReporterTest method testReportWithWarning.

public void testReportWithWarning() throws Exception {
    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(WARNING, nativeToolOutput, sourceFilePosition);
    List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
    when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
    myReporter.report(mySyncIssue, appModule, buildFile);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    assertAbout(syncMessage()).that(message).hasMessageLine(nativeToolOutput, 0);
    PositionInFile position = message.getPosition();
    assertNotNull(position);
    assertEquals(buildFile, position.file);
    assertEquals(line, position.line);
    assertEquals(column, position.column);
    assertThat(message.getQuickFixes()).isEmpty();
    assertFalse(myErrorHandler.isInvoked());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) 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) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Example 44 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class SyncIssuesReporterTest method testReportUsingDefaultStrategy.

public void testReportUsingDefaultStrategy() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    when(mySyncIssue.getType()).thenReturn(TYPE_GRADLE_TOO_OLD);
    when(mySyncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
    when(myStrategy2.getSupportedIssueType()).thenReturn(TYPE_UNRESOLVED_DEPENDENCY);
    SyncIssuesReporter reporter = new SyncIssuesReporter(myStrategy1, myStrategy2);
    Module appModule = myModules.getAppModule();
    VirtualFile buildFile = getGradleBuildFile(appModule);
    reporter.report(Lists.newArrayList(mySyncIssue), appModule);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    verify(myStrategy1, never()).report(mySyncIssue, appModule, buildFile);
    verify(myStrategy2, never()).report(mySyncIssue, appModule, buildFile);
    assertTrue(GradleSyncState.getInstance(getProject()).getSummary().hasSyncErrors());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Module(com.intellij.openapi.module.Module)

Example 45 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class UnresolvedDependenciesReporterTest method testReportWithAppCompat.

public void testReportWithAppCompat() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    when(mySyncIssue.getData()).thenReturn("com.android.support:appcompat-v7:24.1.1");
    myReporter.report(mySyncIssue, appModule, null);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Unresolved Android dependencies").hasMessageLine("Failed to resolve: com.android.support:appcompat-v7:24.1.1", 0);
    // @formatter:on
    List<NotificationHyperlink> quickFixes = message.getQuickFixes();
    int expectedSize = IdeInfo.getInstance().isAndroidStudio() ? 2 : 1;
    assertThat(quickFixes).hasSize(expectedSize);
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(InstallRepositoryHyperlink.class);
    InstallRepositoryHyperlink hyperlink = (InstallRepositoryHyperlink) quickFix;
    assertSame(ANDROID, hyperlink.getRepository());
    if (IdeInfo.getInstance().isAndroidStudio()) {
        quickFix = quickFixes.get(1);
        assertThat(quickFix).isInstanceOf(ShowDependencyInProjectStructureHyperlink.class);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) InstallRepositoryHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallRepositoryHyperlink) Module(com.intellij.openapi.module.Module) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Aggregations

SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)55 Module (com.intellij.openapi.module.Module)18 Project (com.intellij.openapi.project.Project)14 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)12 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)11 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 AndroidProject (com.android.builder.model.AndroidProject)5 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)5 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 GradleVersion (com.android.ide.common.repository.GradleVersion)3 ProjectSubset (com.android.tools.idea.gradle.project.subset.ProjectSubset)3 ComponentVersionReader (com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Message (com.android.ide.common.blame.Message)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2