Search in sources :

Example 6 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class LintIdeClient method getSdk.

@Nullable
@Override
public AndroidSdkHandler getSdk() {
    if (sdk == null) {
        Module module = getModule();
        AndroidSdkHandler localSdk = getLocalSdk(module);
        if (localSdk != null) {
            sdk = localSdk;
        } else {
            for (Module m : ModuleManager.getInstance(myProject).getModules()) {
                localSdk = getLocalSdk(m);
                if (localSdk != null) {
                    sdk = localSdk;
                    break;
                }
            }
            if (localSdk == null) {
                sdk = super.getSdk();
            }
        }
    }
    return sdk;
}
Also used : AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AndroidVersionsInfo method loadRemoteTargets.

private void loadRemoteTargets(@NotNull FormFactor myFormFactor, int minSdkLevel, @NotNull List<VersionItem> versionItemList, ItemsLoaded completedCallback) {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    final Runnable runCallbacks = () -> {
        if (completedCallback != null) {
            completedCallback.onDataLoadedFinished(versionItemList);
        }
    };
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        addPackages(myFormFactor, versionItemList, packages.getNewPkgs(), minSdkLevel);
        addOfflineLevels(myFormFactor, versionItemList);
        runCallbacks.run();
    };
    // We need to pick up addons that don't have a target created due to the base platform not being installed.
    RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(myFormFactor, versionItemList, packages.getLocalPackages().values(), minSdkLevel);
    Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
        addOfflineLevels(myFormFactor, versionItemList);
        runCallbacks.run();
    }, ModalityState.any());
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
    sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : java.util(java.util) SdkConstants(com.android.SdkConstants) ModalityState(com.intellij.openapi.application.ModalityState) RemotePackage(com.android.repository.api.RemotePackage) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidTargetHash(com.android.sdklib.AndroidTargetHash) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) FormFactor(com.android.tools.idea.npw.FormFactor) RepoPackage(com.android.repository.api.RepoPackage) AndroidVersion(com.android.sdklib.AndroidVersion) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) AndroidSdkUtils(org.jetbrains.android.sdk.AndroidSdkUtils) TemplateUtils(com.android.tools.idea.templates.TemplateUtils) Collectors(java.util.stream.Collectors) IdDisplay(com.android.sdklib.repository.IdDisplay) Sets(com.google.common.collect.Sets) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable) SdkVersionInfo(com.android.sdklib.SdkVersionInfo) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) TypeDetails(com.android.repository.impl.meta.TypeDetails) ApplicationManager(com.intellij.openapi.application.ApplicationManager) RepoManager(com.android.repository.api.RepoManager) SystemImage(com.android.sdklib.repository.targets.SystemImage) NotNull(org.jetbrains.annotations.NotNull) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 8 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class ConfigureAndroidProjectPath method putSdkDependentParams.

/**
   * Populate the given state with a set of variables that depend on the user's installed SDK. This method should
   * be called early in the initialization of a wizard or path.
   * Variables:
   * Build Tools Version: Used to populate the project level build.gradle with the correct Gradle plugin version number
   * If the required build tools version is not installed, a request is added for installation
   * SDK Home: The location of the installed SDK
   *
   * @param state the state store to populate with the values stored in the SDK
   */
public static void putSdkDependentParams(@NotNull ScopedStateStore state) {
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(ConfigureAndroidProjectPath.class);
    BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(progress, false);
    Revision minimumRequiredBuildToolVersion = Revision.parseRevision(SdkConstants.MIN_BUILD_TOOLS_VERSION);
    if (buildTool != null && buildTool.getRevision().compareTo(minimumRequiredBuildToolVersion) >= 0) {
        state.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, buildTool.getRevision().toString());
    } else {
        // We need to install a new build tools version
        state.listPush(WizardConstants.INSTALL_REQUESTS_KEY, DetailsTypes.getBuildToolsPath(minimumRequiredBuildToolVersion));
        state.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, minimumRequiredBuildToolVersion.toString());
    }
    File location = sdkHandler.getLocation();
    if (location != null) {
        // Gradle expects a platform-neutral path
        state.put(WizardConstants.SDK_DIR_KEY, FileUtil.toSystemIndependentName(location.getPath()));
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) File(java.io.File)

Example 9 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class FirstRunWizard method init.

@Override
public void init() {
    File initialSdkLocation = FirstRunWizardDefaults.getInitialSdkLocation(myMode);
    ConsolidatedProgressStep progressStep = new FirstRunProgressStep();
    myComponentsPath = new InstallComponentsPath(myMode, initialSdkLocation, progressStep, true);
    if (myMode == FirstRunWizardMode.NEW_INSTALL) {
        boolean sdkExists = false;
        if (initialSdkLocation.isDirectory()) {
            AndroidSdkHandler sdkHandler = AndroidSdkHandler.getInstance(initialSdkLocation);
            ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
            sdkExists = ((AndroidSdkHandler) sdkHandler).getLocalPackage(SdkConstants.FD_TOOLS, progress) != null;
        }
        addPath(new SingleStepPath(new FirstRunWelcomeStep(sdkExists)));
    }
    if (myMode == FirstRunWizardMode.NEW_INSTALL) {
        if (initialSdkLocation.getPath().isEmpty()) {
            // We don't have a default path specified, have to do custom install.
            myState.put(KEY_CUSTOM_INSTALL, true);
        } else {
            addPath(new SingleStepPath(new InstallationTypeWizardStep(KEY_CUSTOM_INSTALL)));
        }
        addPath(new SingleStepPath(new SelectThemeStep(KEY_CUSTOM_INSTALL)));
    }
    if (myMode == FirstRunWizardMode.MISSING_SDK) {
        addPath(new SingleStepPath(new MissingSdkAlertStep()));
    }
    addPath(myComponentsPath);
    if (SystemInfo.isLinux && myMode == FirstRunWizardMode.NEW_INSTALL) {
        addPath(new SingleStepPath(new LinuxHaxmInfoStep()));
    }
    if (myMode != FirstRunWizardMode.INSTALL_HANDOFF) {
        addPath(new SingleStepPath(new LicenseAgreementStep(getDisposable())));
    }
    addPath(new SingleStepPath(progressStep));
    super.init();
}
Also used : SingleStepPath(com.android.tools.idea.wizard.dynamic.SingleStepPath) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) LicenseAgreementStep(com.android.tools.idea.sdk.wizard.legacy.LicenseAgreementStep) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) File(java.io.File)

Example 10 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class InstallCMakeHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    // We need to statically fetch the SDK handler each time because the location might change.
    // TODO: remove the need for doing this each time.
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progressIndicator = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = sdkHandler.getSdkManager(progressIndicator);
    StudioProgressRunner progressRunner = new StudioProgressRunner(false, /* backgroundable */
    false, /* cancellable */
    "Loading Remote SDK", true, /* in UI thread */
    project);
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        Collection<RemotePackage> cmakePackages = packages.getRemotePackagesForPrefix(FD_CMAKE);
        if (!cmakePackages.isEmpty()) {
            RemotePackage cmakePackage;
            if (cmakePackages.size() == 1) {
                cmakePackage = getFirstItem(cmakePackages);
            } else {
                cmakePackage = sdkHandler.getLatestRemotePackageForPrefix(FD_CMAKE, false, progressIndicator);
            }
            if (cmakePackage != null) {
                ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(cmakePackage.getPath()));
                if (dialog != null && dialog.showAndGet()) {
                    GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
                }
                return;
            }
            notifyCMakePackageNotFound(project);
        }
    };
    Runnable onError = () -> notifyCMakePackageNotFound(project);
    sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) ContainerUtil.getFirstItem(com.intellij.util.containers.ContainerUtil.getFirstItem) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Collection(java.util.Collection) DEFAULT_EXPIRATION_PERIOD_MS(com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS) RemotePackage(com.android.repository.api.RemotePackage) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) FD_CMAKE(com.android.SdkConstants.FD_CMAKE) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) RepoManager(com.android.repository.api.RepoManager) NotNull(org.jetbrains.annotations.NotNull) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) SdkQuickfixUtils.createDialogForPaths(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Collection(java.util.Collection) RemotePackage(com.android.repository.api.RemotePackage) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Aggregations

AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)38 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)23 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)11 RepoManager (com.android.repository.api.RepoManager)10 NotNull (org.jetbrains.annotations.NotNull)9 RemotePackage (com.android.repository.api.RemotePackage)8 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)6 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)6 ImmutableList (com.google.common.collect.ImmutableList)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 Revision (com.android.repository.Revision)3 LocalPackage (com.android.repository.api.LocalPackage)3 RepoPackage (com.android.repository.api.RepoPackage)3 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)3 MockFileOp (com.android.repository.testframework.MockFileOp)3