use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class DexExceptionParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
Matcher m1 = ERROR.matcher(line);
if (!m1.matches()) {
return false;
}
String stackTrace = ParserUtil.digestStackTrace(reader);
if (stackTrace == null) {
return false;
}
Matcher m2 = ALREADY_ADDED_EXCEPTION.matcher(stackTrace);
if (!m2.matches()) {
return false;
}
String message = String.format("Class %1s has already been added to output. Please remove duplicate copies.", m2.group(1).replace('/', '.').replace('$', '.'));
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(SourceFile.UNKNOWN, SourcePosition.UNKNOWN)));
return true;
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class ManifestMergeFailureParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
Matcher m = ERROR1.matcher(line);
if (m.matches()) {
String sourcePath = m.group(1);
int lineNumber;
try {
lineNumber = Integer.parseInt(m.group(2));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
String message = m.group(3);
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, -1, -1))));
return true;
}
m = ERROR2.matcher(line);
if (m.matches()) {
String sourcePath = removeLeadingTab(m.group(1)).trim();
int lineNumber;
try {
lineNumber = Integer.parseInt(m.group(2));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
int column;
try {
column = Integer.parseInt(m.group(3));
} catch (NumberFormatException e) {
throw new ParsingFailedException(e);
}
if (lineNumber == 0 && column == 0) {
// When both line number and column is zero, it is just a message saying "Validation failed, exiting". No need to display it.
String next = reader.peek(0);
if (next != null && next.contains("Validation failed, exiting")) {
reader.readLine();
return true;
}
} else {
String msg = reader.readLine();
if (msg != null) {
msg = removeLeadingTab(msg).trim();
Message.Kind kind = Message.Kind.findIgnoringCase(m.group(4), Message.Kind.ERROR);
messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new File(sourcePath), new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
}
}
return false;
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class ManifestUtils method getActionLocation.
@NotNull
static SourceFilePosition getActionLocation(@NotNull Module module, @NotNull Actions.Record record) {
SourceFilePosition sourceFilePosition = record.getActionLocation();
SourceFile sourceFile = sourceFilePosition.getFile();
File file = sourceFile.getSourceFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
if (file != null && !SourcePosition.UNKNOWN.equals(sourcePosition)) {
VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
assert vFile != null;
Module fileModule = ModuleUtilCore.findModuleForFile(vFile, module.getProject());
if (fileModule != null && !fileModule.equals(module)) {
MergedManifest manifest = MergedManifest.get(fileModule);
Document document = manifest.getDocument();
assert document != null;
Element root = document.getDocumentElement();
assert root != null;
int startLine = sourcePosition.getStartLine();
int startColumn = sourcePosition.getStartColumn();
Node node = PositionXmlParser.findNodeAtLineAndCol(document, startLine, startColumn);
if (node == null) {
Logger.getInstance(ManifestPanel.class).warn("Can not find node in " + fileModule + " for " + sourceFilePosition);
} else {
List<? extends Actions.Record> records = getRecords(manifest, node);
if (!records.isEmpty()) {
return getActionLocation(fileModule, records.get(0));
}
}
}
}
return sourceFilePosition;
}
use of com.android.ide.common.blame.SourceFilePosition in project android by JetBrains.
the class ManifestPanel method updateDetails.
public void updateDetails(@Nullable ManifestTreeNode node) {
HtmlBuilder sb = new HtmlBuilder();
Font font = UIUtil.getLabelFont();
sb.addHtml("<html><body style=\"font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt;\">");
sb.beginUnderline().beginBold();
sb.add("Manifest Sources");
sb.endBold().endUnderline().newline();
sb.addHtml("<table border=\"0\">");
String borderColor = ColorUtil.toHex(JBColor.GRAY);
for (File file : myFiles) {
Color color = getFileColor(file);
sb.addHtml("<tr><td width=\"24\" height=\"24\" style=\"background-color:#");
sb.addHtml(ColorUtil.toHex(color));
sb.addHtml("; border: 1px solid #");
sb.addHtml(borderColor);
sb.addHtml(";\">");
sb.addHtml("</td><td>");
describePosition(sb, myFacet, new SourceFilePosition(file, SourcePosition.UNKNOWN));
sb.addHtml("</td></tr>");
}
sb.addHtml("</table>");
sb.newline();
if (!myOtherFiles.isEmpty()) {
sb.beginUnderline().beginBold();
sb.add("Other Manifest Files");
sb.endBold().endUnderline().newline();
sb.add("(Included in merge, but did not contribute any elements)").newline();
boolean first = true;
for (File file : myOtherFiles) {
if (first) {
first = false;
} else {
sb.add(", ");
}
describePosition(sb, myFacet, new SourceFilePosition(file, SourcePosition.UNKNOWN));
}
sb.newline().newline();
}
// See if there are errors; if so, show the merging report instead of node selection report
if (!myManifest.getLoggingRecords().isEmpty()) {
for (MergingReport.Record record : myManifest.getLoggingRecords()) {
if (record.getSeverity() == MergingReport.Record.Severity.ERROR) {
node = null;
break;
}
}
}
if (node != null) {
List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, node.getUserObject());
sb.beginUnderline().beginBold();
sb.add("Merging Log");
sb.endBold().endUnderline().newline();
if (records.isEmpty()) {
sb.add("No records found. (This is a bug in the manifest merger.)");
}
SourceFilePosition prev = null;
boolean prevInjected = false;
for (Actions.Record record : records) {
// There are currently some duplicated entries; filter these out
SourceFilePosition location = ManifestUtils.getActionLocation(myFacet.getModule(), record);
if (location.equals(prev)) {
continue;
}
prev = location;
Actions.ActionType actionType = record.getActionType();
boolean injected = actionType == Actions.ActionType.INJECTED;
if (injected && prevInjected) {
continue;
}
prevInjected = injected;
if (injected) {
// TODO: include module source? Are we certain it's correct?
sb.add("Value provided by Gradle");
sb.newline();
continue;
}
sb.add(StringUtil.capitalize(String.valueOf(actionType).toLowerCase(Locale.US)));
sb.add(" from the ");
sb.addHtml(getHtml(myFacet, location));
String reason = record.getReason();
if (reason != null) {
sb.add("; reason: ");
sb.add(reason);
}
sb.newline();
}
} else if (!myManifest.getLoggingRecords().isEmpty()) {
sb.add("Merging Errors:").newline();
for (MergingReport.Record record : myManifest.getLoggingRecords()) {
sb.addHtml(getHtml(record.getSeverity()));
sb.add(" ");
try {
sb.addHtml(getErrorHtml(myFacet, record.getMessage(), record.getSourceLocation(), myHtmlLinkManager, LocalFileSystem.getInstance().findFileByIoFile(myFiles.get(0))));
} catch (Exception ex) {
Logger.getInstance(ManifestPanel.class).error("error getting error html", ex);
sb.add(record.getMessage());
}
sb.add(" ");
sb.addHtml(getHtml(myFacet, record.getSourceLocation()));
sb.newline();
}
}
sb.closeHtmlBody();
myDetails.setText(sb.getHtml());
myDetails.setCaretPosition(0);
}
use of com.android.ide.common.blame.SourceFilePosition 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());
}
Aggregations