use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class ExternalNdkBuildIssuesReporter method report.
@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
String group = "External Native Build Issues";
String nativeToolOutput = syncIssue.getData();
if (nativeToolOutput != null) {
SyncMessages messages = getSyncMessages(module);
// Parse the native build tool output with the list of existing parsers.
List<Message> compilerMessages = myBuildOutputParser.parseGradleOutput(nativeToolOutput);
for (Message compilerMessage : compilerMessages) {
MessageType type = MessageType.findMatching(compilerMessage.getKind());
PositionInFile position = createPosition(compilerMessage.getSourceFilePositions());
String text = compilerMessage.getText();
Project project = module.getProject();
if (type == ERROR) {
// TODO make error handlers work with SyncMessage, instead of NotificationData.
NotificationCategory category = type.convertToCategory();
NotificationData notification = messages.createNotification(group, text, category, position);
// Try to parse the error messages using the list of existing error handlers to find any potential quick-fixes.
for (SyncErrorHandler handler : myErrorHandlers) {
if (handler.handleError(new ExternalSystemException(text), notification, project)) {
break;
}
}
messages.report(notification);
continue;
}
SyncMessage message;
if (position != null) {
message = new SyncMessage(project, group, type, position, text);
} else {
message = new SyncMessage(group, type, text);
}
messages.report(message);
}
}
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class ProjectImportErrorHandler method getUserFriendlyError.
@Override
@Nullable
public ExternalSystemException getUserFriendlyError(@NotNull Throwable error, @NotNull String projectPath, @Nullable String buildFilePath) {
if (error instanceof ExternalSystemException) {
// This is already a user-friendly error.
logSyncFailure();
return (ExternalSystemException) error;
}
Pair<Throwable, String> rootCauseAndLocation = getRootCauseAndLocation(error);
Throwable rootCause = rootCauseAndLocation.getFirst();
// Create ExternalSystemException or LocationAwareExternalSystemException, so that it goes to SyncErrorHandlers directly.
String location = rootCauseAndLocation.getSecond();
String errMessage;
if (rootCause.getMessage() == null) {
StringWriter writer = new StringWriter();
rootCause.printStackTrace(new PrintWriter(writer));
errMessage = writer.toString();
} else {
errMessage = rootCause.getMessage();
}
if (!errMessage.isEmpty() && Character.isLowerCase(errMessage.charAt(0))) {
// Message starts with lower case letter. Sentences should start with uppercase.
errMessage = "Cause: " + errMessage;
}
ExternalSystemException exception = null;
if (isNotEmpty(location)) {
Pair<String, Integer> pair = getErrorLocation(location);
if (pair != null) {
exception = new LocationAwareExternalSystemException(errMessage, pair.first, pair.getSecond());
}
}
if (exception == null) {
exception = new ExternalSystemException(errMessage);
}
exception.initCause(rootCause);
return exception;
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class AndroidGradleProjectResolver method getUserFriendlyError.
@NotNull
@Override
public ExternalSystemException getUserFriendlyError(@NotNull Throwable error, @NotNull String projectPath, @Nullable String buildFilePath) {
String msg = error.getMessage();
if (msg != null && !msg.contains(UNSUPPORTED_MODEL_VERSION_ERROR_PREFIX)) {
//noinspection ThrowableResultOfMethodCallIgnored
Throwable rootCause = getRootCause(error);
if (rootCause instanceof ClassNotFoundException) {
msg = rootCause.getMessage();
// Project is using an old version of Gradle (and most likely an old version of the plug-in.)
if (isUsingUnsupportedGradleVersion(msg)) {
AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder();
// @formatter:off
event.setCategory(GRADLE_SYNC).setKind(GRADLE_SYNC_FAILURE).setGradleSyncFailure(GradleSyncFailure.UNSUPPORTED_GRADLE_VERSION);
// @formatter:on;
UsageTracker.getInstance().log(event);
return new ExternalSystemException("The project is using an unsupported version of Gradle.");
}
}
}
ExternalSystemException userFriendlyError = myErrorHandler.getUserFriendlyError(error, projectPath, buildFilePath);
assert userFriendlyError != null;
return userFriendlyError;
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class SdkSyncTest method testSyncIdeAndProjectAndroidHomesWhenUserDoesNotSelectValidSdkPath.
public void testSyncIdeAndProjectAndroidHomesWhenUserDoesNotSelectValidSdkPath() throws Exception {
SdkSync.FindValidSdkPathTask task = new SdkSync.FindValidSdkPathTask(myIdeSdks) {
@Nullable
@Override
File selectValidSdkPath() {
return null;
}
};
try {
mySdkSync.syncIdeAndProjectAndroidSdk(myLocalProperties, task, myProject);
fail("Expecting ExternalSystemException");
} catch (ExternalSystemException e) {
// expected
}
assertNull(myIdeSdks.getAndroidSdkPath());
myLocalProperties = new LocalProperties(myProject);
assertNull(myLocalProperties.getAndroidSdkPath());
}
use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.
the class IdeFrameFixture method invokeProjectMakeAndSimulateFailure.
@NotNull
public IdeFrameFixture invokeProjectMakeAndSimulateFailure(@NotNull String failure) {
Runnable failTask = () -> {
throw new ExternalSystemException(failure);
};
ApplicationManager.getApplication().putUserData(EXECUTE_BEFORE_PROJECT_BUILD_IN_GUI_TEST_KEY, failTask);
selectProjectMakeAction();
return this;
}
Aggregations