Search in sources :

Example 16 with SyncMessage

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

the class DependencySetupErrors method reportModulesNotFoundIssues.

private void reportModulesNotFoundIssues(@NotNull List<MissingModule> missingModules) {
    if (!missingModules.isEmpty()) {
        MessageType type = ERROR;
        for (MissingModule missingModule : missingModules) {
            List<String> messageLines = new ArrayList<>();
            StringBuilder text = new StringBuilder();
            text.append(String.format("Unable to find module with Gradle path '%1$s' (needed by module", missingModule.dependencyPath));
            addDependentsToText(text, missingModule.dependentNames);
            text.append(".)");
            messageLines.add(text.toString());
            String backupLibraryName = missingModule.backupLibraryName;
            if (isNotEmpty(backupLibraryName)) {
                type = WARNING;
                String msg = String.format("Linking to library '%1$s' instead.", backupLibraryName);
                messageLines.add(msg);
            }
            mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, type, toStringArray(messageLines)));
        }
        // If the project is really a subset of the project, attempt to find and include missing modules.
        ProjectSubset projectSubset = ProjectSubset.getInstance(myProject);
        String[] selection = projectSubset.getSelection();
        boolean hasSelection = selection != null && selection.length > 0;
        if (type == ERROR && hasSelection && projectSubset.hasCachedModules()) {
            String text = "The missing modules may have been excluded from the project subset.";
            SyncMessage message = new SyncMessage(MISSING_DEPENDENCIES, MessageType.INFO, text);
            message.add(new IncludeMissingModulesHyperlink(missingModules));
            mySyncMessages.report(message);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Example 17 with SyncMessage

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

the class DependencySetupErrorsTest method testReportErrors.

public void testReportErrors() {
    myErrors.addMissingModule(":lib1", "app1", null);
    myErrors.addMissingModule(":lib2", "app2", "library2.jar");
    myErrors.addMissingModule(":lib2", "app1", "library2.jar");
    myErrors.addMissingModule(":lib3", "app1", "library3.jar");
    myErrors.addMissingName("app2");
    myErrors.addMissingName("app1");
    myErrors.addMissingBinaryPath("app2");
    myErrors.addMissingBinaryPath("app1");
    myErrors.reportErrors();
    List<SyncMessage> messages = mySyncMessages.getReportedMessages();
    assertThat(messages).hasSize(7);
    SyncMessage message = messages.get(0);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Unable to find module with Gradle path ':lib1' (needed by module 'app1'.)", 0);
    // @formatter:on
    message = messages.get(1);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app1' depends on modules that do not have a name.", 0);
    // @formatter:on
    message = messages.get(2);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app2' depends on modules that do not have a name.", 0);
    // @formatter:on
    message = messages.get(3);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app1' depends on libraries that do not have a 'binary' path.", 0);
    // @formatter:on
    message = messages.get(4);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app2' depends on libraries that do not have a 'binary' path.", 0);
    // @formatter:on
    message = messages.get(5);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(WARNING).hasMessageLine("Unable to find module with Gradle path ':lib2' (needed by modules: 'app1', 'app2'.)", 0).hasMessageLine("Linking to library 'library2.jar' instead.", 1);
    // @formatter:on
    message = messages.get(6);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(WARNING).hasMessageLine("Unable to find module with Gradle path ':lib3' (needed by module 'app1'.)", 0).hasMessageLine("Linking to library 'library3.jar' instead.", 1);
// @formatter:on
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage)

Example 18 with SyncMessage

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

the class BuildToolsTooLowReporterTest method testReport.

public void testReport() {
    String text = "Upgrade Build Tools!";
    when(mySyncIssue.getMessage()).thenReturn(text);
    String minVersion = "25";
    when(mySyncIssue.getData()).thenReturn(minVersion);
    Module module = getModule();
    List<NotificationHyperlink> quickFixes = new ArrayList<>();
    quickFixes.add(mock(NotificationHyperlink.class));
    when(myErrorHandler.getQuickFixHyperlinks(minVersion, getProject(), module)).thenReturn(quickFixes);
    myIssueReporter.report(mySyncIssue, module, null);
    List<SyncMessage> messages = mySyncMessages.getReportedMessages();
    assertThat(messages).hasSize(1);
    SyncMessage message = messages.get(0);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasType(ERROR).hasMessageLine(text, 0);
    // @formatter:on
    assertEquals(quickFixes, message.getQuickFixes());
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) ArrayList(java.util.ArrayList) Module(com.intellij.openapi.module.Module) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 19 with SyncMessage

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

the class UnresolvedDependenciesReporterTest method testReportWithPlayServices.

public void testReportWithPlayServices() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    when(mySyncIssue.getData()).thenReturn("com.google.android.gms:play-services:9.4.0");
    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.google.android.gms:play-services:9.4.0", 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(GOOGLE, 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)

Example 20 with SyncMessage

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

the class UnsupportedGradleReporterTest method testReport.

public void testReport() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String expectedText = "Hello World!";
    when(mySyncIssue.getMessage()).thenReturn(expectedText);
    when(mySyncIssue.getData()).thenReturn("2.14.1");
    myReporter.report(mySyncIssue, appModule, null);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasGroup("Gradle Sync Issues").hasMessageLine(expectedText, 0);
    // @formatter:on
    List<NotificationHyperlink> quickFixes = message.getQuickFixes();
    assertThat(quickFixes).hasSize(2);
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(FixGradleVersionInWrapperHyperlink.class);
    FixGradleVersionInWrapperHyperlink hyperlink = (FixGradleVersionInWrapperHyperlink) quickFix;
    assertEquals("2.14.1", hyperlink.getGradleVersion());
    quickFix = quickFixes.get(1);
    assertThat(quickFix).isInstanceOf(OpenGradleSettingsHyperlink.class);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) FixGradleVersionInWrapperHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixGradleVersionInWrapperHyperlink) 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