use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class UnresolvedDependenciesReporter method report.
private void report(@NotNull String dependency, @NotNull Module module, @Nullable VirtualFile buildFile) {
String group = "Unresolved Android dependencies";
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(dependency);
RepoPackage constraintPackage = null;
if (coordinate != null) {
ProgressIndicator indicator = new StudioLoggerProgressIndicator(getClass());
reloadRemoteSdkWithModalProgress();
Collection<RemotePackage> remotePackages = getRemotePackages(indicator);
constraintPackage = findBestPackageMatching(coordinate, remotePackages);
}
List<NotificationHyperlink> quickFixes = new ArrayList<>();
if (dependency.startsWith("com.android.support.constraint:constraint-layout:") && !canGetConstraintLayoutFromSdkManager(module)) {
quickFixes.add(new FixAndroidGradlePluginVersionHyperlink());
} else if (constraintPackage != null) {
quickFixes.add(new InstallArtifactHyperlink(constraintPackage.getPath()));
} else if (dependency.startsWith("com.android.support")) {
quickFixes.add(new InstallRepositoryHyperlink(ANDROID));
} else if (dependency.startsWith("com.google.android")) {
quickFixes.add(new InstallRepositoryHyperlink(GOOGLE));
} else {
group = "Unresolved dependencies";
Project project = module.getProject();
if (isOfflineBuildModeEnabled(project)) {
quickFixes.add(new DisableOfflineModeHyperlink());
}
}
String text = "Failed to resolve: " + dependency;
SyncMessage message;
if (buildFile != null) {
PositionInFile position = findDependencyPosition(dependency, buildFile);
message = new SyncMessage(module.getProject(), group, ERROR, position, text);
String hyperlinkText = position.line > -1 ? "Show in File" : "Open File";
quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), hyperlinkText, position.line, position.column));
} else {
message = new SyncMessage(group, ERROR, NonNavigatable.INSTANCE, text);
}
if (IdeInfo.getInstance().isAndroidStudio()) {
if (coordinate != null) {
quickFixes.add(new ShowDependencyInProjectStructureHyperlink(module, coordinate));
}
}
message.add(quickFixes);
getSyncMessages(module).report(message);
}
use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class SyncMessages method report.
public void report(@NotNull SyncMessage message) {
String title = message.getGroup();
String text = join(message.getText(), "\n");
NotificationCategory category = message.getType().convertToCategory();
PositionInFile position = message.getPosition();
NotificationData notification = createNotification(title, text, category, position);
Navigatable navigatable = message.getNavigatable();
notification.setNavigatable(navigatable);
List<NotificationHyperlink> quickFixes = message.getQuickFixes();
if (!quickFixes.isEmpty()) {
updateNotification(notification, text, quickFixes);
}
report(notification);
}
use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class JdkModuleSetupStep method reportWrongJdkError.
@NotNull
private SyncMessage reportWrongJdkError(@NotNull Project project, @NotNull String text, @NotNull VirtualFile buildFile) {
int line = -1;
int column = -1;
Document document = FileDocumentManager.getInstance().getDocument(buildFile);
if (document != null) {
int offset = myCompileSdkVersionFinder.findOffsetIn(document.getText());
if (offset > -1) {
line = document.getLineNumber(offset);
if (line > -1) {
int lineStartOffset = document.getLineStartOffset(line);
column = offset - lineStartOffset;
}
}
}
PositionInFile position = new PositionInFile(buildFile, line, column);
SyncMessage msg = new SyncMessage(project, PROJECT_CONFIGURATION_SYNC_MESSAGE_GROUP, ERROR, position, text);
List<NotificationHyperlink> quickFixes = Lists.newArrayList(myJdks.getWrongJdkQuickFixes(project));
quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), "Open build.gradle File", line, column));
msg.add(quickFixes);
return msg;
}
use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class VersionIncompatibility method reportMessages.
void reportMessages(@NotNull Project project) {
ComponentVersionReader reader = myReaderAndVersion.getFirst();
String componentName = reader.getComponentName();
String version = myReaderAndVersion.getSecond();
String requirementComponentName = myRequirementVersionReader.getComponentName();
StringBuilder msg = new StringBuilder();
msg.append(componentName).append(" ").append(version);
PositionInFile position = reader.getVersionSource(myModule);
if (!reader.isProjectLevel() && position == null) {
msg.append(", in module '").append(myModule.getName()).append(",'");
}
msg.append(" requires ").append(requirementComponentName).append(" ");
VersionRange requirementVersionRange = myRequirement.getVersionRange();
msg.append(requirementVersionRange.getDescription());
int messageCount = myMessages.size();
if (messageCount == 1) {
msg.append(" ").append(myMessages.get(0));
} else if (messageCount > 1) {
msg.append("<ul>");
for (String message : myMessages) {
msg.append("<li>").append(message).append("</li>");
}
msg.append("</ul>");
}
MessageType messageType = myCompatibilityCheck.getType();
SyncMessage message;
List<String> textLines = new ArrayList<>();
textLines.add(msg.toString());
String failureMsg = myRequirement.getFailureMessage();
if (failureMsg != null) {
List<String> lines = Splitter.on("\\n").omitEmptyStrings().splitToList(failureMsg);
textLines.addAll(lines);
}
String[] text = toStringArray(textLines);
if (position != null) {
message = new SyncMessage(project, DEFAULT_GROUP, messageType, position, text);
} else {
message = new SyncMessage(DEFAULT_GROUP, messageType, text);
}
message.add(myRequirementVersionReader.getQuickFixes(myModule, requirementVersionRange, position));
SyncMessages.getInstance(project).report(message);
}
use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.
the class UnhandledIssueMessageReporterTest method testReportWithoutBuildFile.
public void testReportWithoutBuildFile() throws Exception {
loadSimpleApplication();
mySyncMessagesStub.clearReportedMessages();
Module appModule = myModules.getAppModule();
String expectedText = "Hello World!";
when(mySyncIssue.getMessage()).thenReturn(expectedText);
when(mySyncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
myReporter.report(mySyncIssue, appModule, null);
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();
assertNull(position);
}
Aggregations