use of com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink in project android by JetBrains.
the class ClassLoadingErrorHandler method handleError.
@Override
public boolean handleError(@NotNull ExternalSystemException error, @NotNull NotificationData notification, @NotNull Project project) {
String text = findErrorMessage(getRootCause(error));
if (text == null) {
return false;
}
String firstLine = getFirstLineMessage(text);
boolean classNotFound = firstLine.startsWith("Unable to load class");
NotificationHyperlink openJdkSettingsHyperlink = null;
NotificationHyperlink syncProjectHyperlink = syncProjectRefreshingDependencies();
NotificationHyperlink stopDaemonsHyperlink = createStopGradleDaemonsHyperlink();
boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode();
boolean isJdk7 = false;
String jdkVersion = null;
if (unitTestMode) {
isJdk7 = true;
} else if (classNotFound) {
Sdk jdk = IdeSdks.getInstance().getJdk();
if (jdk != null) {
String jdkHomePath = jdk.getHomePath();
if (jdkHomePath != null) {
jdkVersion = SdkVersionUtil.detectJdkVersion(jdkHomePath);
}
JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
isJdk7 = version == JDK_1_7;
}
}
String jdk7Hint = "";
if (isJdk7) {
jdk7Hint = "<li>";
if (jdkVersion != null) {
jdk7Hint += String.format("You are using JDK version '%1$s'. ", jdkVersion);
}
jdk7Hint += "Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.\n" + "Please update to a newer version (e.g. 1.7.0_67).";
if (!unitTestMode) {
openJdkSettingsHyperlink = openJdkSettings(project);
if (openJdkSettingsHyperlink != null) {
jdk7Hint = jdk7Hint + "\n" + openJdkSettingsHyperlink.toHtml();
}
}
jdk7Hint += "</li>";
}
String newMsg = firstLine + "\nPossible causes for this unexpected error include:<ul>" + jdk7Hint + "<li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)\n" + syncProjectHyperlink.toHtml() + "</li>" + "<li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.\n" + stopDaemonsHyperlink.toHtml() + "</li>" + "<li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project " + "or the version of Gradle requested by the project.</li></ul>" + "In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.";
notification.setTitle(SyncMessage.DEFAULT_GROUP);
notification.setMessage(newMsg);
notification.setNotificationCategory(NotificationCategory.convert(DEFAULT_NOTIFICATION_TYPE));
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
if (openJdkSettingsHyperlink != null) {
hyperlinks.add(openJdkSettingsHyperlink);
}
hyperlinks.add(syncProjectHyperlink);
hyperlinks.add(stopDaemonsHyperlink);
SyncMessages.getInstance(project).addNotificationListener(notification, hyperlinks);
return true;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink in project android by JetBrains.
the class ConnectionPermissionDeniedErrorHandler method getQuickFixHyperlinks.
@Override
@NotNull
protected List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
NotificationHyperlink quickFix = new OpenUrlHyperlink("https://developer.android.com/studio/troubleshoot.html#project-sync", "More details (and potential fix)");
hyperlinks.add(quickFix);
return hyperlinks;
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink 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.NotificationHyperlink in project android by JetBrains.
the class MissingPlatformErrorHandler method findAndAddQuickFixes.
private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
String missingPlatform = getMissingPlatform(text);
if (missingPlatform == null) {
return;
}
String loadError = null;
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
if (version != null) {
// Is the platform installed?
ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
hyperlinks.add(new InstallPlatformHyperlink(version));
}
}
if (hyperlinks.isEmpty()) {
// We are unable to install platform automatically.
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (!facets.isEmpty()) {
// We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
}
}
if (isNotEmpty(loadError)) {
text += "\nPossible cause: " + loadError;
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink 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