use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class GradleNotificationExtensionTest method testCustomizeWithExternalSystemException.
public void testCustomizeWithExternalSystemException() throws Exception {
ExternalSystemException error = new ExternalSystemException("Testing");
// myHandler1 returns 'true', myHandler2 should not be invoked.
when(myHandler1.handleError(error, myNotification, myProject)).thenReturn(true);
myNotificationExtension.customize(myNotification, myProject, error);
verify(mySyncMessages, times(1)).removeProjectMessages();
verify(myHandler1, times(1)).handleError(error, myNotification, myProject);
verify(myHandler2, never()).handleError(error, myNotification, myProject);
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class ProjectImportErrorHandlerTest method getUserFriendlyError.
// https://code.google.com/p/android/issues/detail?id=226506
@Test
public void getUserFriendlyError() {
ProjectImportErrorHandler errorHandler = new ProjectImportErrorHandler();
IllegalStateException cause = new IllegalStateException("Failed to find Build Tools revision 24.0.3");
BuildException error = new BuildException("Could not run build action.", cause);
ExternalSystemException userFriendlyError = errorHandler.getUserFriendlyError(error, "fakeProjectPath", null);
assertNotNull(userFriendlyError);
assertEquals("Failed to find Build Tools revision 24.0.3", userFriendlyError.getMessage());
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class ProjectImportErrorHandlerTest method getUserFriendlyErrorWithLowerCase.
// https://code.google.com/p/android/issues/detail?id=226870
@Test
public void getUserFriendlyErrorWithLowerCase() {
ProjectImportErrorHandler errorHandler = new ProjectImportErrorHandler();
Throwable error = new Throwable("some random sync error");
ExternalSystemException userFriendlyError = errorHandler.getUserFriendlyError(error, "fakeProjectPath", null);
assertNotNull(userFriendlyError);
assertEquals("Cause: some random sync error", userFriendlyError.getMessage());
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SdkSync method setProjectNdk.
private static void setProjectNdk(@NotNull LocalProperties localProperties, @Nullable File ndkPath) {
File currentNdkPath = localProperties.getAndroidNdkPath();
if (filesEqual(currentNdkPath, ndkPath)) {
return;
}
localProperties.setAndroidNdkPath(ndkPath);
try {
localProperties.save();
} catch (IOException e) {
String msg = String.format("Unable to save '%1$s'", localProperties.getPropertiesFilePath().getPath());
throw new ExternalSystemException(msg, e);
}
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SdkSync method syncIdeAndProjectAndroidSdk.
@VisibleForTesting
void syncIdeAndProjectAndroidSdk(@NotNull LocalProperties localProperties, @NotNull FindValidSdkPathTask findSdkPathTask, @Nullable Project project) {
if (localProperties.hasAndroidDirProperty()) {
// if android.dir is specified, we don't sync SDKs. User is working with SDK sources.
return;
}
File ideAndroidSdkPath = myIdeSdks.getAndroidSdkPath();
File projectAndroidSdkPath = localProperties.getAndroidSdkPath();
if (ideAndroidSdkPath != null) {
if (projectAndroidSdkPath == null) {
// If we have the IDE default SDK and we don't have a project SDK, update local.properties with default SDK path and exit.
setProjectSdk(localProperties, ideAndroidSdkPath);
return;
}
ValidationResult validationResult = validateAndroidSdk(projectAndroidSdkPath, true);
if (!validationResult.success) {
// If we have the IDE default SDK and we don't have a valid project SDK, update local.properties with default SDK path and exit.
invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
String error = validationResult.message;
if (isEmpty(error)) {
error = String.format("The path \n'%1$s'\n" + "does not refer to a valid Android SDK.", projectAndroidSdkPath.getPath());
}
String format = "%1$s\n\nAndroid Studio will use this Android SDK instead:\n'%2$s'\nand will modify the project's local.properties file.";
Messages.showErrorDialog(String.format(format, error, ideAndroidSdkPath.getPath()), ERROR_DIALOG_TITLE);
}
setProjectSdk(localProperties, ideAndroidSdkPath);
}
});
return;
}
} else {
if (projectAndroidSdkPath == null || !myIdeSdks.isValidAndroidSdkPath(projectAndroidSdkPath)) {
// We don't have any SDK (IDE or project.)
File selectedPath = findSdkPathTask.selectValidSdkPath();
if (selectedPath == null) {
throw new ExternalSystemException("Unable to continue until an Android SDK is specified");
}
setIdeSdk(localProperties, selectedPath);
return;
}
// If we have a valid project SDK but we don't have IDE default SDK, update IDE with project SDK path and exit.
setIdeSdk(localProperties, projectAndroidSdkPath);
return;
}
if (!filesEqual(ideAndroidSdkPath, projectAndroidSdkPath)) {
String msg = String.format("The project and Android Studio point to different Android SDKs.\n\n" + "Android Studio's default SDK is in:\n" + "%1$s\n\n" + "The project's SDK (specified in local.properties) is in:\n" + "%2$s\n\n" + "To keep results consistent between IDE and command line builds, only one path can be used. " + "Do you want to:\n\n" + "[1] Use Android Studio's default SDK (modifies the project's local.properties file.)\n\n" + "[2] Use the project's SDK (modifies Android Studio's default.)\n\n" + "Note that switching SDKs could cause compile errors if the selected SDK doesn't have the " + "necessary Android platforms or build tools.", ideAndroidSdkPath.getPath(), projectAndroidSdkPath.getPath());
invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
// We need to pass the project, so on Mac, the "Mac sheet" showing this message shows inside the IDE during UI tests, otherwise
// it will show outside and the UI testing infrastructure cannot see it. It is overall a good practice to pass the project when
// showing a message, to ensure that the message shows in the IDE instance containing the project.
int result = MessageDialogBuilder.yesNo("Android SDK Manager", msg).yesText("Use Android Studio's SDK").noText("Use Project's SDK").project(project).show();
if (result == Messages.YES) {
// Use Android Studio's SDK
setProjectSdk(localProperties, ideAndroidSdkPath);
} else {
// Use project's SDK
setIdeSdk(localProperties, projectAndroidSdkPath);
}
if (isGuiTestingMode() && !getGuiTestSuiteState().isSkipSdkMerge()) {
mergeIfNeeded(projectAndroidSdkPath, ideAndroidSdkPath);
}
}
});
}
}
Aggregations