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);
}
}
}
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
}
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());
}
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);
}
}
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);
}
Aggregations