use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class ExternalNdkBuildIssuesReporterTest method testReportWithError.
public void testReportWithError() throws Exception {
if (SystemInfo.isWindows) {
// Do not run tests on Windows (see http://b.android.com/222904)
return;
}
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(ERROR, nativeToolOutput, sourceFilePosition);
List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
myReporter.report(mySyncIssue, appModule, buildFile);
assertNull(mySyncMessagesStub.getFirstReportedMessage());
NotificationData notification = mySyncMessagesStub.getNotification();
assertNotNull(notification);
assertTrue(myErrorHandler.isInvoked());
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class BuildOutputParserTest method toString.
@NotNull
private static String toString(@NotNull List<Message> messages) {
StringBuilder sb = new StringBuilder();
for (int i = 0, n = messages.size(); i < n; i++) {
Message message = messages.get(i);
sb.append(Integer.toString(i)).append(':').append(' ');
// INFO => Info
sb.append(StringUtil.capitalize(message.getKind().toString().toLowerCase(Locale.US))).append(':');
sb.append(message.getText());
if (message.getSourcePath() != null) {
for (SourceFilePosition position : message.getSourceFilePositions()) {
sb.append('\n');
sb.append('\t');
// Fudge for windows tests. As messages use a file object, which is filesystem aware, Windows paths come out prefaced with the
// unix CWD.
String path = position.getFile().toString();
if (path.startsWith(WINDOWS_PATH_UNDER_UNIX)) {
path = path.substring(WINDOWS_PATH_UNIX_PREFIX_LENGTH);
}
sb.append(path);
int line = position.getPosition().getStartLine();
sb.append(':').append(Integer.toString(line == -1 ? -1 : line + 1));
int col = position.getPosition().getStartColumn();
sb.append(':').append(Integer.toString(col == -1 ? -1 : col + 1));
}
} else {
String gradlePath = message.getSourceFilePositions().get(0).getFile().getDescription();
if (gradlePath != null) {
sb.append('\n');
sb.append(gradlePath);
}
}
sb.append('\n');
}
return sb.toString();
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class AndroidGradleJps method createCompilerMessages.
/**
* Adapter method to create IDEA CompilerMessages from an Android build Message.
*
* If the Android build message has multiple source locations, this will create multiple CompilerMesssages with the same kind and
* messageText, but different source positions.
*/
@NotNull
public static List<CompilerMessage> createCompilerMessages(@NotNull Message message) {
final BuildMessage.Kind kind;
switch(message.getKind()) {
case INFO:
kind = BuildMessage.Kind.INFO;
break;
case WARNING:
kind = BuildMessage.Kind.WARNING;
break;
case ERROR:
kind = BuildMessage.Kind.ERROR;
break;
default:
kind = BuildMessage.Kind.PROGRESS;
}
List<CompilerMessage> compilerMessages = new ArrayList<CompilerMessage>();
for (SourceFilePosition filePosition : message.getSourceFilePositions()) {
File sourceFile = filePosition.getFile().getSourceFile();
String sourceFilePath = sourceFile != null ? sourceFile.getAbsolutePath() : null;
SourcePosition pos = filePosition.getPosition();
compilerMessages.add(new CompilerMessage(COMPILER_NAME, kind, message.getText().trim(), sourceFilePath, pos.getStartOffset(), pos.getEndOffset(), pos.getEndOffset(), pos.getEndLine(), pos.getEndColumn()));
}
return Collections.unmodifiableList(compilerMessages);
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class ManifestPanel method goToDeclaration.
private void goToDeclaration(Node element) {
List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, element);
for (Actions.Record record : records) {
SourceFilePosition sourceFilePosition = ManifestUtils.getActionLocation(myFacet.getModule(), record);
SourceFile sourceFile = sourceFilePosition.getFile();
if (!SourceFile.UNKNOWN.equals(sourceFile)) {
File ioFile = sourceFile.getSourceFile();
if (ioFile != null) {
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
assert file != null;
int line = -1;
int column = 0;
SourcePosition sourcePosition = sourceFilePosition.getPosition();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
line = sourcePosition.getStartLine();
column = sourcePosition.getStartColumn();
}
Project project = myFacet.getModule().getProject();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
break;
}
}
}
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class AndroidPluginOutputParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
if (line.contains("[DEBUG] ") || line.contains("[INFO] ")) {
// Ignore 'debug' and 'info' messages.
return false;
}
if (IGNORED_MESSAGE_PATTERN.matcher(line).matches()) {
return false;
}
// pattern is type|path|message
String[] segments = line.split("\\|", SEGMENT_COUNT);
if (segments.length == SEGMENT_COUNT) {
Message.Kind kind = Message.Kind.findIgnoringCase(segments[0], Message.Kind.ERROR);
String path = segments[1];
if (StringUtil.isEmpty(path)) {
return false;
}
String msg = StringUtil.notNullize(segments[2]);
// The SourceFile description is the Gradle path of the project.
messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new SourceFile(path.trim()), SourcePosition.UNKNOWN)));
return true;
}
return false;
}
Aggregations