Search in sources :

Example 16 with ExternalSystemException

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);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SyncMessages(com.android.tools.idea.gradle.project.sync.messages.SyncMessages) Project(com.intellij.openapi.project.Project) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) SyncErrorHandler(com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 17 with ExternalSystemException

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;
}
Also used : StringWriter(java.io.StringWriter) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) PrintWriter(java.io.PrintWriter) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with ExternalSystemException

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;
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ExternalSystemException

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());
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties)

Example 20 with ExternalSystemException

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;
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)20 File (java.io.File)6 IOException (java.io.IOException)5 NotNull (org.jetbrains.annotations.NotNull)5 LocationAwareExternalSystemException (com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException)4 Nullable (org.jetbrains.annotations.Nullable)3 Application (com.intellij.openapi.application.Application)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Test (org.junit.Test)2 Message (com.android.ide.common.blame.Message)1 SyncErrorHandler (com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler)1 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)1 ValidationResult (com.android.tools.idea.sdk.SdkPaths.ValidationResult)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AndroidStudioEvent (com.google.wireless.android.sdk.stats.AndroidStudioEvent)1