Search in sources :

Example 1 with SyncMessage

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

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

the class JdkPreSyncCheck method doCheckCanSync.

@Override
@NotNull
PreSyncCheckResult doCheckCanSync(@NotNull Project project) {
    Sdk jdk = IdeSdks.getInstance().getJdk();
    if (!isValidJdk(jdk)) {
        String msg = "Please use JDK 8 or newer.";
        SyncMessage message = new SyncMessage("Project sync error", MessageType.ERROR, msg);
        List<NotificationHyperlink> quickFixes = Jdks.getInstance().getWrongJdkQuickFixes(project);
        message.add(quickFixes);
        SyncMessages.getInstance(project).report(message);
        return failure(msg);
    }
    return SUCCESS;
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Sdk(com.intellij.openapi.projectRoots.Sdk) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SyncMessage

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

the class JavaModuleSetup method setUpModule.

public void setUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels models, @Nullable ProgressIndicator indicator) {
    if (javaModuleModel.isAndroidModuleWithoutVariants()) {
        // See https://code.google.com/p/android/issues/detail?id=170722
        SyncMessages messages = SyncMessages.getInstance(module.getProject());
        String[] text = { String.format("The module '%1$s' is an Android project without build variants, and cannot be built.", module.getName()), "Please fix the module's configuration in the build.gradle file and sync the project again." };
        messages.report(new SyncMessage(PROJECT_STRUCTURE_ISSUES, ERROR, text));
        cleanUpAndroidModuleWithoutVariants(module, ideModelsProvider);
        // happen due to a project configuration error and there is a lot of module configuration missing, there is no point on even trying.
        return;
    }
    for (JavaModuleSetupStep step : mySetupSteps) {
        if (indicator != null) {
            step.displayDescription(module, indicator);
        }
        step.setUpModule(module, ideModelsProvider, javaModuleModel, models, indicator);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SyncMessages(com.android.tools.idea.gradle.project.sync.messages.SyncMessages)

Example 4 with SyncMessage

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

the class BuildToolsTooLowReporter method report.

@Override
void report(@NotNull SyncIssue syncIssue, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String minimumVersion = syncIssue.getData();
    assert minimumVersion != null;
    SyncMessage message = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, syncIssue.getMessage());
    List<NotificationHyperlink> quickFixes = myErrorHandler.getQuickFixHyperlinks(minimumVersion, module.getProject(), module);
    message.add(quickFixes);
    getSyncMessages(module).report(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 5 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage 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)

Aggregations

SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)55 Module (com.intellij.openapi.module.Module)18 Project (com.intellij.openapi.project.Project)14 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)12 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)11 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 AndroidProject (com.android.builder.model.AndroidProject)5 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)5 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 GradleVersion (com.android.ide.common.repository.GradleVersion)3 ProjectSubset (com.android.tools.idea.gradle.project.subset.ProjectSubset)3 ComponentVersionReader (com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Message (com.android.ide.common.blame.Message)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2