use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class GradleDslMethodNotFoundErrorHandler method getQuickFixHyperlinks.
private static void getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
String filePath = notification.getFilePath();
VirtualFile file = filePath != null ? LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath) : null;
if (file != null && FN_BUILD_GRADLE.equals(file.getName())) {
updateNotificationWithBuildFile(project, file, notification, text);
return;
}
if (file != null && notification.getLine() > 0 && notification.getNavigatable() == null) {
OpenFileHyperlink hyperlink = new OpenFileHyperlink(filePath, notification.getLine() - 1);
hyperlinks.add(hyperlink);
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class MissingDependencyErrorHandler method handleError.
@Override
public boolean handleError(@NotNull ExternalSystemException error, @NotNull NotificationData notification, @NotNull Project project) {
//noinspection ThrowableResultOfMethodCallIgnored
Throwable rootCause = getRootCause(error);
String text = rootCause.getMessage();
List<String> message = Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text);
String firstLine = message.get(0);
Matcher matcher = MISSING_MATCHING_DEPENDENCY_PATTERN.matcher(firstLine);
if (matcher.matches()) {
String dependency = matcher.group(1);
handleMissingDependency(notification, project, firstLine, dependency, Collections.emptyList());
return true;
}
String lastLine = message.get(message.size() - 1);
matcher = MISSING_DEPENDENCY_PATTERN.matcher(firstLine);
if (matcher.matches() && message.size() > 1 && message.get(1).startsWith("Required by:")) {
String dependency = matcher.group(1);
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
if (isNotEmpty(dependency)) {
if (lastLine != null) {
Pair<String, Integer> errorLocation = getErrorLocation(lastLine);
if (errorLocation != null) {
// We have a location in file, show the "Open File" hyperlink.
String filePath = errorLocation.getFirst();
int line = errorLocation.getSecond();
hyperlinks.add(new OpenFileHyperlink(filePath, line - 1));
}
}
handleMissingDependency(notification, project, error.getMessage(), dependency, hyperlinks);
return true;
}
}
for (String line : message) {
// This happens when Gradle cannot find the Android Gradle plug-in in Maven Central or jcenter.
if (line == null) {
continue;
}
matcher = MISSING_MATCHING_DEPENDENCY_PATTERN.matcher(line);
if (matcher.matches()) {
String dependency = matcher.group(1);
handleMissingDependency(notification, project, line, dependency, Collections.emptyList());
return true;
}
}
return false;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink in project android by JetBrains.
the class MissingAndroidSdkErrorHandler method getQuickFixHyperlinks.
@Override
@NotNull
protected List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
// If we got this far, local.properties exists.
// Confirmed in findErrorMessage().
File file = new File(getBaseDirPath(project), FN_LOCAL_PROPERTIES);
int lineNumber = 0;
BufferedReader reader = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
reader = new BufferedReader(new FileReader(file));
int counter = 0;
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith(SDK_DIR_PROPERTY)) {
lineNumber = counter;
break;
}
counter++;
}
} catch (IOException e) {
Logger.getInstance(getClass()).info("Unable to read file: " + file.getPath(), e);
} finally {
try {
close(reader, true);
} catch (IOException ignored) {
// Cannot happen
}
}
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
hyperlinks.add(new OpenFileHyperlink(file.getPath(), lineNumber));
return hyperlinks;
}
Aggregations