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