Search in sources :

Example 1 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class UnresolvedDependenciesReporter method report.

private void report(@NotNull String dependency, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String group = "Unresolved Android dependencies";
    GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(dependency);
    RepoPackage constraintPackage = null;
    if (coordinate != null) {
        ProgressIndicator indicator = new StudioLoggerProgressIndicator(getClass());
        reloadRemoteSdkWithModalProgress();
        Collection<RemotePackage> remotePackages = getRemotePackages(indicator);
        constraintPackage = findBestPackageMatching(coordinate, remotePackages);
    }
    List<NotificationHyperlink> quickFixes = new ArrayList<>();
    if (dependency.startsWith("com.android.support.constraint:constraint-layout:") && !canGetConstraintLayoutFromSdkManager(module)) {
        quickFixes.add(new FixAndroidGradlePluginVersionHyperlink());
    } else if (constraintPackage != null) {
        quickFixes.add(new InstallArtifactHyperlink(constraintPackage.getPath()));
    } else if (dependency.startsWith("com.android.support")) {
        quickFixes.add(new InstallRepositoryHyperlink(ANDROID));
    } else if (dependency.startsWith("com.google.android")) {
        quickFixes.add(new InstallRepositoryHyperlink(GOOGLE));
    } else {
        group = "Unresolved dependencies";
        Project project = module.getProject();
        if (isOfflineBuildModeEnabled(project)) {
            quickFixes.add(new DisableOfflineModeHyperlink());
        }
    }
    String text = "Failed to resolve: " + dependency;
    SyncMessage message;
    if (buildFile != null) {
        PositionInFile position = findDependencyPosition(dependency, buildFile);
        message = new SyncMessage(module.getProject(), group, ERROR, position, text);
        String hyperlinkText = position.line > -1 ? "Show in File" : "Open File";
        quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), hyperlinkText, position.line, position.column));
    } else {
        message = new SyncMessage(group, ERROR, NonNavigatable.INSTANCE, text);
    }
    if (IdeInfo.getInstance().isAndroidStudio()) {
        if (coordinate != null) {
            quickFixes.add(new ShowDependencyInProjectStructureHyperlink(module, coordinate));
        }
    }
    message.add(quickFixes);
    getSyncMessages(module).report(message);
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) ArrayList(java.util.ArrayList) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) StringUtil.unquoteString(com.intellij.openapi.util.text.StringUtil.unquoteString) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Project(com.intellij.openapi.project.Project) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) RemotePackage(com.android.repository.api.RemotePackage) RepoPackage(com.android.repository.api.RepoPackage)

Example 2 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class SyncMessages method report.

public void report(@NotNull SyncMessage message) {
    String title = message.getGroup();
    String text = join(message.getText(), "\n");
    NotificationCategory category = message.getType().convertToCategory();
    PositionInFile position = message.getPosition();
    NotificationData notification = createNotification(title, text, category, position);
    Navigatable navigatable = message.getNavigatable();
    notification.setNavigatable(navigatable);
    List<NotificationHyperlink> quickFixes = message.getQuickFixes();
    if (!quickFixes.isEmpty()) {
        updateNotification(notification, text, quickFixes);
    }
    report(notification);
}
Also used : PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) Navigatable(com.intellij.pom.Navigatable) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 3 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class JdkModuleSetupStep method reportWrongJdkError.

@NotNull
private SyncMessage reportWrongJdkError(@NotNull Project project, @NotNull String text, @NotNull VirtualFile buildFile) {
    int line = -1;
    int column = -1;
    Document document = FileDocumentManager.getInstance().getDocument(buildFile);
    if (document != null) {
        int offset = myCompileSdkVersionFinder.findOffsetIn(document.getText());
        if (offset > -1) {
            line = document.getLineNumber(offset);
            if (line > -1) {
                int lineStartOffset = document.getLineStartOffset(line);
                column = offset - lineStartOffset;
            }
        }
    }
    PositionInFile position = new PositionInFile(buildFile, line, column);
    SyncMessage msg = new SyncMessage(project, PROJECT_CONFIGURATION_SYNC_MESSAGE_GROUP, ERROR, position, text);
    List<NotificationHyperlink> quickFixes = Lists.newArrayList(myJdks.getWrongJdkQuickFixes(project));
    quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), "Open build.gradle File", line, column));
    msg.add(quickFixes);
    return msg;
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) Document(com.intellij.openapi.editor.Document) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile 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 5 with PositionInFile

use of com.android.tools.idea.gradle.util.PositionInFile in project android by JetBrains.

the class UnhandledIssueMessageReporterTest method testReportWithoutBuildFile.

public void testReportWithoutBuildFile() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String expectedText = "Hello World!";
    when(mySyncIssue.getMessage()).thenReturn(expectedText);
    when(mySyncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
    myReporter.report(mySyncIssue, appModule, null);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    // @formatter:off
    assertAbout(syncMessage()).that(message).hasType(ERROR).hasMessageLine(expectedText, 0);
    // @formatter:on
    PositionInFile position = message.getPosition();
    assertNull(position);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Aggregations

PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)12 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)9 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)3 Message (com.android.ide.common.blame.Message)2 SourcePosition (com.android.ide.common.blame.SourcePosition)2 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)2 Document (com.intellij.openapi.editor.Document)2 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)2 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)2 Project (com.intellij.openapi.project.Project)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 SourceFile (com.android.ide.common.blame.SourceFile)1 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)1 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoPackage (com.android.repository.api.RepoPackage)1