Search in sources :

Example 21 with StudioLoggerProgressIndicator

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

the class ChooseActivityTypeStep method initTemplateValues.

private static void initTemplateValues(@NotNull Map<String, Object> templateValues, @Nullable Project project) {
    templateValues.put(ATTR_GRADLE_PLUGIN_VERSION, determineGradlePluginVersion(project));
    templateValues.put(ATTR_GRADLE_VERSION, SdkConstants.GRADLE_LATEST_VERSION);
    templateValues.put(ATTR_IS_GRADLE, true);
    // TODO: Check if this is used at all by the templates
    templateValues.put("target.files", new HashSet<>());
    templateValues.put("files.to.open", new ArrayList<>());
    // TODO: Implement Instant App code
    String whSdkLocation = System.getenv(WH_SDK_ENV_VAR);
    templateValues.put(ATTR_WH_SDK, whSdkLocation + "/tools/resources/shared-libs");
    templateValues.put("whSdkEnabled", isNotEmpty(whSdkLocation));
    templateValues.put("alsoCreateIapk", false);
    templateValues.put("isInstantApp", false);
    // TODO: Check this one with Joe. It seems to be used by the old code on Import module, but can't find it on new code
    templateValues.put(ATTR_CREATE_ACTIVITY, false);
    templateValues.put(ATTR_PER_MODULE_REPOS, false);
    // TODO: This seems project stuff
    if (project != null) {
        templateValues.put(ATTR_TOP_OUT, project.getBasePath());
    }
    String mavenUrl = System.getProperty(TemplateWizard.MAVEN_URL_PROPERTY);
    if (mavenUrl != null) {
        templateValues.put(ATTR_MAVEN_URL, mavenUrl);
    }
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(ConfigureAndroidModuleStep.class), false);
    if (buildTool != null) {
        // If buildTool is null, the template will use buildApi instead, which might be good enough.
        templateValues.put(ATTR_BUILD_TOOLS_VERSION, buildTool.getRevision().toString());
    }
    File sdkLocation = sdkHandler.getLocation();
    if (sdkLocation != null) {
        // Gradle expects a platform-neutral path
        templateValues.put(ATTR_SDK_DIR, FileUtil.toSystemIndependentName(sdkLocation.getPath()));
        String espressoVersion = RepositoryUrlManager.get().getLibraryRevision(SupportLibrary.ESPRESSO_CORE.getGroupId(), SupportLibrary.ESPRESSO_CORE.getArtifactId(), null, false, sdkLocation, FileOpUtils.create());
        if (espressoVersion != null) {
            // TODO: Is this something that should be on the template (TemplateMetadata.ATTR_)?
            // Check with Jens, or at least send an email to verify template variables. We may also need to port some old dynamic step.
            templateValues.put("espressoVersion", espressoVersion);
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) ConfigureAndroidModuleStep(com.android.tools.idea.npw.module.ConfigureAndroidModuleStep) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 22 with StudioLoggerProgressIndicator

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

the class LicenseAgreementStep method createChangesList.

private List<Change> createChangesList() {
    ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = mySdkHandler.getSdkManager(progress);
    sdkManager.loadSynchronously(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, progress, new StudioDownloader(), StudioSettingsController.getInstance());
    Map<String, RemotePackage> remotePackages = sdkManager.getPackages().getRemotePackages();
    List<Change> toReturn = Lists.newArrayList();
    List<String> requestedPackages = myState.get(INSTALL_REQUESTS_KEY);
    if (requestedPackages != null) {
        for (String path : requestedPackages) {
            RemotePackage p = remotePackages.get(path);
            License license = p.getLicense();
            if (license == null) {
                license = AndroidSdkLicenseTemporaryData.getLicense(p.getTypeDetails() instanceof DetailsTypes.ApiDetailsType && ((DetailsTypes.ApiDetailsType) p.getTypeDetails()).getAndroidVersion().isPreview());
            }
            myLicenses.add(license);
            if (!license.checkAccepted(mySdkRoot, mySdkHandler.getFileOp())) {
                toReturn.add(new Change(ChangeType.INSTALL, p, license));
            }
        }
    }
    return toReturn;
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)

Example 23 with StudioLoggerProgressIndicator

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

the class StudioSdkUtil method reloadRemoteSdkWithModalProgress.

/**
   * Convenience method to reload the local and remote SDK, showing a modal, non-cancellable progress window.
   */
public static void reloadRemoteSdkWithModalProgress() {
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioProgressRunner runner = new StudioProgressRunner(true, false, "Refreshing SDK", false, null);
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(StudioSdkUtil.class);
    RepoManager sdkManager = sdkHandler.getSdkManager(progress);
    sdkManager.load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, null, null, null, runner, new StudioDownloader(null), StudioSettingsController.getInstance(), true);
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) RepoManager(com.android.repository.api.RepoManager) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler)

Example 24 with StudioLoggerProgressIndicator

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

the class PatchInstallerFactory method canHandlePackage.

/**
   * Check whether we can create an installer for this package.
   */
@Override
protected boolean canHandlePackage(@NotNull RepoPackage p, @NotNull RepoManager manager, @NotNull FileOp fop) {
    ProgressIndicator progress = new StudioLoggerProgressIndicator(PatchInstallerFactory.class);
    if (p instanceof LocalPackage) {
        // Uninstall case. Only useful on windows, since it locks in-use files.
        if (fop.isWindows()) {
            // Any patcher will do: just see if we have any patcher available.
            LocalPackage latestPatcher = PatchInstallerUtil.getLatestPatcher(manager);
            // don't try to use the patcher to uninstall itself
            return latestPatcher != null && !latestPatcher.equals(p);
        } else {
            // Don't use patcher on non-windows.
            return false;
        }
    }
    LocalPackage local = manager.getPackages().getLocalPackages().get(p.getPath());
    RemotePackage remote = (RemotePackage) p;
    if (local == null || (!fop.isWindows() && !hasPatch(local, remote))) {
        // If this isn't an update, or if we're not on windows and there's no patch, there's no reason to use the patcher.
        return false;
    }
    if (hasPatch(local, remote)) {
        // If a patch is available, make sure we can get the patcher itself
        LocalPackage patcher = PatchInstallerUtil.getDependantPatcher((RemotePackage) p, manager);
        if (patcher != null && PatchRunner.getPatchRunner(patcher, progress, fop) != null) {
            return true;
        }
        // Maybe it's not installed yet, but is being installed right now as part of the same operation.
        if (PatchInstallerUtil.getInProgressDependantPatcherInstall((RemotePackage) p, manager) != null) {
            return true;
        }
    }
    // At this point we must be on Windows.
    // There's no patch available, but if a patch installer is installed and better than KNOWN_GOOD_VERSION we can still use it.
    LocalPackage patcher = PatchInstallerUtil.getLatestPatcher(manager);
    return patcher != null && PatchInstallerUtil.comparePatcherPaths(patcher.getPath(), KNOWN_GOOD_VERSION) >= 0;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)

Example 25 with StudioLoggerProgressIndicator

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

the class HaxmWizard method doCancelAction.

@Override
public void doCancelAction() {
    if (myHaxmPath.canPerformFinishingActions()) {
        doFinishAction();
        return;
    }
    // Have to ensure the SDK package is removed
    if (!myInvokedToUninstall) {
        try {
            AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
            ComponentInstaller componentInstaller = new ComponentInstaller(sdkHandler);
            ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
            sdkHandler.getSdkManager(progress).reloadLocalIfNeeded(progress);
            componentInstaller.ensureSdkPackagesUninstalled(myHaxmPath.myHaxm.getRequiredSdkPackages(), progress);
        } catch (Exception e) {
            Messages.showErrorDialog(SDK_PACKAGE_CLEANUP_FAILED, "Cleanup Error");
            LOG.warn("Failed to make sure HAXM SDK package is uninstalled after HAXM wizard was cancelled", e);
        }
    }
    super.doCancelAction();
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IOException(java.io.IOException)

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