Search in sources :

Example 36 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class InstantRunConfigurable method updateProjectToInstantRunTools.

/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
    String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
    // Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
    if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
        pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
    }
    // Update plugin version
    AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
    UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
    if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
        // Should be at least 23.0.2
        String buildToolsVersion = "23.0.2";
        AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
        BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
        if (latestBuildTool != null) {
            Revision revision = latestBuildTool.getRevision();
            if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
                buildToolsVersion = revision.toShortString();
            }
        }
        // Also update build files to set build tools version 23.0.2
        GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
        // Also update Gradle wrapper version
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
        }
        // Request a sync
        GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
        GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
        return true;
    } else {
        return false;
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper)

Example 37 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.

@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    boolean buildToolInstalled = false;
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
        RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
        LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
        buildToolInstalled = buildTool != null;
    }
    if (module != null) {
        VirtualFile buildFile = getGradleBuildFile(module);
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
        if (!buildToolInstalled) {
            if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
            } else {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
            }
        } else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
            hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
        }
        if (buildFile != null) {
            hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
        }
    }
    return hyperlinks;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalPackage(com.android.repository.api.LocalPackage) FixBuildToolsVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixBuildToolsVersionHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) InstallBuildToolsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallBuildToolsHyperlink) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class MissingPlatformErrorHandler method findAndAddQuickFixes.

private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
    String missingPlatform = getMissingPlatform(text);
    if (missingPlatform == null) {
        return;
    }
    String loadError = null;
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
        if (version != null) {
            // Is the platform installed?
            ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
            loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
            hyperlinks.add(new InstallPlatformHyperlink(version));
        }
    }
    if (hyperlinks.isEmpty()) {
        // We are unable to install platform automatically.
        List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
        if (!facets.isEmpty()) {
            // We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
            hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
        }
    }
    if (isNotEmpty(loadError)) {
        text += "\nPossible cause: " + loadError;
    }
    SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
Also used : OpenAndroidSdkManagerHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenAndroidSdkManagerHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidVersion(com.android.sdklib.AndroidVersion) InstallPlatformHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 39 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class SdkMergerTest method getSdkFingerprint.

private String getSdkFingerprint(File sdk) {
    StringBuilder s = new StringBuilder();
    RepoManager sdkManager = AndroidSdkHandler.getInstance(sdk).getSdkManager(new StudioLoggerProgressIndicator(getClass()));
    for (LocalPackage p : Sets.newTreeSet(sdkManager.getPackages().getLocalPackages().values())) {
        s.append(p.getPath());
        s.append(',');
        s.append(p.getVersion());
        s.append('\n');
    }
    return s.toString();
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) RepoManager(com.android.repository.api.RepoManager)

Example 40 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class SdkUpdaterConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    myPanel.saveSources();
    HtmlBuilder message = new HtmlBuilder();
    message.openHtmlBody();
    final List<LocalPackage> toDelete = Lists.newArrayList();
    final Map<RemotePackage, UpdatablePackage> requestedPackages = Maps.newHashMap();
    for (PackageNodeModel model : myPanel.getStates()) {
        if (model.getState() == PackageNodeModel.SelectedState.NOT_INSTALLED) {
            if (model.getPkg().hasLocal()) {
                toDelete.add(model.getPkg().getLocal());
            }
        } else if (model.getState() == PackageNodeModel.SelectedState.INSTALLED && (model.getPkg().isUpdate() || !model.getPkg().hasLocal())) {
            UpdatablePackage pkg = model.getPkg();
            requestedPackages.put(pkg.getRemote(), pkg);
        }
    }
    boolean found = false;
    if (!toDelete.isEmpty()) {
        found = true;
        message.add("The following components will be deleted: \n");
        message.beginList();
        for (LocalPackage item : toDelete) {
            message.listItem().add(item.getDisplayName()).add(", Revision: ").add(item.getVersion().toString());
        }
        message.endList();
    }
    if (!requestedPackages.isEmpty()) {
        found = true;
        message.add("The following components will be installed: \n");
        message.beginList();
        Multimap<RemotePackage, RemotePackage> dependencies = HashMultimap.create();
        ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
        RepositoryPackages packages = getRepoManager().getPackages();
        for (RemotePackage item : requestedPackages.keySet()) {
            List<RemotePackage> packageDependencies = InstallerUtil.computeRequiredPackages(ImmutableList.of(item), packages, progress);
            if (packageDependencies == null) {
                Messages.showErrorDialog((Project) null, "Unable to resolve dependencies for " + item.getDisplayName(), "Dependency Error");
                throw new ConfigurationException("Unable to resolve dependencies.");
            }
            for (RemotePackage dependency : packageDependencies) {
                dependencies.put(dependency, item);
            }
            message.listItem().add(String.format("%1$s %2$s %3$s", item.getDisplayName(), item.getTypeDetails() instanceof DetailsTypes.ApiDetailsType ? "revision" : "version", item.getVersion()));
        }
        for (RemotePackage dependency : dependencies.keySet()) {
            if (requestedPackages.containsKey(dependency)) {
                continue;
            }
            Set<RemotePackage> requests = Sets.newHashSet(dependencies.get(dependency));
            requests.remove(dependency);
            if (!requests.isEmpty()) {
                message.listItem().add(dependency.getDisplayName()).add(" (Required by ");
                Iterator<RemotePackage> requestIterator = requests.iterator();
                message.add(requestIterator.next().getDisplayName());
                while (requestIterator.hasNext()) {
                    message.add(", ").add(requestIterator.next().getDisplayName());
                }
                message.add(")");
            }
        }
        message.endList();
    }
    message.closeHtmlBody();
    if (found) {
        if (confirmChange(message)) {
            if (!requestedPackages.isEmpty() || !toDelete.isEmpty()) {
                ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPackages(myPanel.getComponent(), requestedPackages.values(), toDelete, true);
                if (dialog != null) {
                    dialog.show();
                    for (RemotePackage remotePackage : requestedPackages.keySet()) {
                        PackageOperation installer = getRepoManager().getInProgressInstallOperation(remotePackage);
                        if (installer != null) {
                            PackageOperation.StatusChangeListener listener = (installer1, progress) -> myPanel.getComponent().repaint();
                            myListeners.add(listener);
                            installer.registerStateChangeListener(listener);
                        }
                    }
                }
            }
            myPanel.refresh();
        } else {
            throw new ConfigurationException("Installation was canceled.");
        }
    } else {
        // We didn't have any changes, so just reload (maybe the channel changed).
        myChannelChangedCallback.run();
    }
}
Also used : Settings(com.intellij.openapi.options.ex.Settings) AllIcons(com.intellij.icons.AllIcons) DataContext(com.intellij.openapi.actionSystem.DataContext) com.android.repository.api(com.android.repository.api) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) Nls(org.jetbrains.annotations.Nls) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Objects(com.google.common.base.Objects) com.google.common.collect(com.google.common.collect) DataManager(com.intellij.ide.DataManager) AncestorEvent(javax.swing.event.AncestorEvent) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) Iterator(java.util.Iterator) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioHelpManagerImpl(com.android.tools.idea.help.StudioHelpManagerImpl) HtmlBuilder(com.android.utils.HtmlBuilder) Set(java.util.Set) Configurable(com.intellij.openapi.options.Configurable) InstallerUtil(com.android.repository.util.InstallerUtil) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) SdkQuickfixUtils(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) HtmlBuilder(com.android.utils.HtmlBuilder) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) ConfigurationException(com.intellij.openapi.options.ConfigurationException) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Aggregations

StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)40 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)22 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)9 RepoManager (com.android.repository.api.RepoManager)8 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)7 Revision (com.android.repository.Revision)6 LocalPackage (com.android.repository.api.LocalPackage)6 RemotePackage (com.android.repository.api.RemotePackage)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 NotNull (org.jetbrains.annotations.NotNull)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)4 VisibleForTesting (com.android.annotations.VisibleForTesting)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)3 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)3 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)3 ImmutableList (com.google.common.collect.ImmutableList)3