use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
use of com.android.ide.common.blame.SourcePosition 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.ide.common.blame.SourcePosition 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.ide.common.blame.SourcePosition in project android by JetBrains.
the class MergingExceptionParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
boolean hasError = false;
int messageIndex;
Message.Kind kind = null;
//noinspection SpellCheckingInspection
if (line.contains("rror: ")) {
messageIndex = line.indexOf(": Error: ");
if (messageIndex == -1) {
messageIndex = line.indexOf(": error: ");
if (messageIndex == -1) {
return false;
}
}
kind = Message.Kind.ERROR;
} else {
//noinspection SpellCheckingInspection
if (line.contains("arning: ")) {
messageIndex = line.indexOf(": Warning: ");
if (messageIndex == -1) {
messageIndex = line.indexOf(": warning: ");
if (messageIndex == -1) {
return false;
}
}
kind = Message.Kind.WARNING;
} else {
return false;
}
}
// TODO: This doesn't handle ambiguous scenarios where the error message itself contains ": " or the path contains " : ".
// I could disambiguate this by checking file existence on the path component containing a ":" !
// See if it's preceded by a line number and/or a column
String path;
int lineNumber = -1;
int column = -1;
int colon = line.lastIndexOf(':', messageIndex - 1);
if (colon != -1) {
// Is there a column?
int colon2 = line.lastIndexOf(':', colon - 1);
if (colon2 != -1) {
// Both line number and column
//lineNumber =
String columnString = line.substring(colon + 1, messageIndex);
String lineString = line.substring(colon2 + 1, colon);
try {
column = Integer.parseInt(columnString);
lineNumber = Integer.parseInt(lineString);
} catch (NumberFormatException e) {
// Could it be a Windows path with drive letters (and no line number) ?
if (colon2 == 1) {
String p = line.substring(0, colon);
if (new File(p).exists()) {
colon2 = colon;
} else {
return false;
}
} else {
return false;
}
}
path = line.substring(0, colon2);
} else {
// Just one number: it's the line
try {
lineNumber = Integer.parseInt(line.substring(colon + 1, messageIndex));
} catch (NumberFormatException e) {
// Could it be a Windows path with drive letters (and no line number) ?
if (colon == 1) {
String p = line.substring(0, messageIndex);
if (new File(p).exists()) {
colon = messageIndex;
} else {
return false;
}
} else {
return false;
}
}
path = line.substring(0, colon);
}
} else {
path = line.substring(0, messageIndex);
}
String message = line.substring(messageIndex + 2);
messages.add(new Message(kind, message, new SourceFilePosition(new File(path), new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
use of com.android.ide.common.blame.SourcePosition in project android by JetBrains.
the class XmlValidationErrorParser method parse.
@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
Matcher m1 = FATAL_ERROR.matcher(line);
if (!m1.matches()) {
// Sometimes the parse failure message appears by itself (for example with duplicate resources);
// in this case also recognize the line by itself even though it's separated from the next message
Matcher m2 = FILE_REFERENCE.matcher(line);
if (m2.matches()) {
File sourceFile = new File(m2.group(1));
if (sourceFile.exists()) {
String message = line;
// Eat the entire stacktrace
String exceptionMessage = ParserUtil.digestStackTrace(reader);
if (exceptionMessage != null) {
message = exceptionMessage + ": " + message;
}
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(sourceFile, SourcePosition.UNKNOWN)));
return true;
}
}
return false;
}
String message = m1.group(3);
int lineNumber = Integer.parseInt(m1.group(1));
int column = Integer.parseInt(m1.group(2));
SourceFile sourceFile = SourceFile.UNKNOWN;
String nextLine = reader.peek(0);
if (nextLine == null) {
return false;
}
Matcher m2 = FILE_REFERENCE.matcher(nextLine);
if (m2.matches()) {
// digest peeked line
reader.readLine();
File possibleSourceFile = new File(m2.group(1));
if (possibleSourceFile.exists()) {
sourceFile = new SourceFile(possibleSourceFile);
}
}
messages.add(new Message(Message.Kind.ERROR, message, new SourceFilePosition(sourceFile, new SourcePosition(lineNumber - 1, column - 1, -1))));
return true;
}
Aggregations