Search in sources :

Example 1 with MessageType

use of com.android.tools.idea.gradle.project.sync.messages.MessageType in project android by JetBrains.

the class VersionIncompatibility method reportMessages.

void reportMessages(@NotNull Project project) {
    ComponentVersionReader reader = myReaderAndVersion.getFirst();
    String componentName = reader.getComponentName();
    String version = myReaderAndVersion.getSecond();
    String requirementComponentName = myRequirementVersionReader.getComponentName();
    StringBuilder msg = new StringBuilder();
    msg.append(componentName).append(" ").append(version);
    PositionInFile position = reader.getVersionSource(myModule);
    if (!reader.isProjectLevel() && position == null) {
        msg.append(", in module '").append(myModule.getName()).append(",'");
    }
    msg.append(" requires ").append(requirementComponentName).append(" ");
    VersionRange requirementVersionRange = myRequirement.getVersionRange();
    msg.append(requirementVersionRange.getDescription());
    int messageCount = myMessages.size();
    if (messageCount == 1) {
        msg.append(" ").append(myMessages.get(0));
    } else if (messageCount > 1) {
        msg.append("<ul>");
        for (String message : myMessages) {
            msg.append("<li>").append(message).append("</li>");
        }
        msg.append("</ul>");
    }
    MessageType messageType = myCompatibilityCheck.getType();
    SyncMessage message;
    List<String> textLines = new ArrayList<>();
    textLines.add(msg.toString());
    String failureMsg = myRequirement.getFailureMessage();
    if (failureMsg != null) {
        List<String> lines = Splitter.on("\\n").omitEmptyStrings().splitToList(failureMsg);
        textLines.addAll(lines);
    }
    String[] text = toStringArray(textLines);
    if (position != null) {
        message = new SyncMessage(project, DEFAULT_GROUP, messageType, position, text);
    } else {
        message = new SyncMessage(DEFAULT_GROUP, messageType, text);
    }
    message.add(myRequirementVersionReader.getQuickFixes(myModule, requirementVersionRange, position));
    SyncMessages.getInstance(project).report(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) ArrayList(java.util.ArrayList) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) VersionRange(com.android.tools.idea.gradle.project.sync.compatibility.version.VersionRange) ComponentVersionReader(com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Example 2 with MessageType

use of com.android.tools.idea.gradle.project.sync.messages.MessageType in project android by JetBrains.

the class DependencySetupErrors method reportModulesNotFoundIssues.

private void reportModulesNotFoundIssues(@NotNull List<MissingModule> missingModules) {
    if (!missingModules.isEmpty()) {
        MessageType type = ERROR;
        for (MissingModule missingModule : missingModules) {
            List<String> messageLines = new ArrayList<>();
            StringBuilder text = new StringBuilder();
            text.append(String.format("Unable to find module with Gradle path '%1$s' (needed by module", missingModule.dependencyPath));
            addDependentsToText(text, missingModule.dependentNames);
            text.append(".)");
            messageLines.add(text.toString());
            String backupLibraryName = missingModule.backupLibraryName;
            if (isNotEmpty(backupLibraryName)) {
                type = WARNING;
                String msg = String.format("Linking to library '%1$s' instead.", backupLibraryName);
                messageLines.add(msg);
            }
            mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, type, toStringArray(messageLines)));
        }
        // If the project is really a subset of the project, attempt to find and include missing modules.
        ProjectSubset projectSubset = ProjectSubset.getInstance(myProject);
        String[] selection = projectSubset.getSelection();
        boolean hasSelection = selection != null && selection.length > 0;
        if (type == ERROR && hasSelection && projectSubset.hasCachedModules()) {
            String text = "The missing modules may have been excluded from the project subset.";
            SyncMessage message = new SyncMessage(MISSING_DEPENDENCIES, MessageType.INFO, text);
            message.add(new IncludeMissingModulesHyperlink(missingModules));
            mySyncMessages.report(message);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Example 3 with MessageType

use of com.android.tools.idea.gradle.project.sync.messages.MessageType 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 4 with MessageType

use of com.android.tools.idea.gradle.project.sync.messages.MessageType in project android by JetBrains.

the class UnsupportedGradleReporter method report.

@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String text = syncIssue.getMessage();
    MessageType type = getMessageType(syncIssue);
    SyncMessage message = new SyncMessage(DEFAULT_GROUP, type, NonNavigatable.INSTANCE, text);
    String gradleVersion = syncIssue.getData();
    List<NotificationHyperlink> quickFixes = getQuickFixHyperlinks(module.getProject(), gradleVersion);
    message.add(quickFixes);
    getSyncMessages(module).report(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 5 with MessageType

use of com.android.tools.idea.gradle.project.sync.messages.MessageType in project android by JetBrains.

the class UnhandledIssuesReporter method report.

@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String group = DEFAULT_GROUP;
    String text = syncIssue.getMessage();
    MessageType type = getMessageType(syncIssue);
    SyncMessage message;
    if (buildFile != null) {
        PositionInFile position = new PositionInFile(buildFile);
        message = new SyncMessage(module.getProject(), group, type, position, text);
    } else {
        message = new SyncMessage(group, type, NonNavigatable.INSTANCE, text);
    }
    getSyncMessages(module).report(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Aggregations

MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)5 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)5 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)3 Message (com.android.ide.common.blame.Message)1 ProjectSubset (com.android.tools.idea.gradle.project.subset.ProjectSubset)1 ComponentVersionReader (com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader)1 VersionRange (com.android.tools.idea.gradle.project.sync.compatibility.version.VersionRange)1 SyncErrorHandler (com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)1 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)1 Project (com.intellij.openapi.project.Project)1 ArrayList (java.util.ArrayList)1