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