Search in sources :

Example 26 with StudioLoggerProgressIndicator

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

the class InstallTask method run.

@Override
public void run(@NotNull ProgressIndicator indicator) {
    final List<RepoPackage> failures = Lists.newArrayList();
    LinkedHashMap<RepoPackage, PackageOperation> operations = new LinkedHashMap<>();
    for (UpdatablePackage install : myInstallRequests) {
        operations.put(install.getRemote(), getOrCreateInstaller(install.getRemote(), indicator));
    }
    for (LocalPackage uninstall : myUninstallRequests) {
        operations.put(uninstall, getOrCreateUninstaller(uninstall));
    }
    try {
        while (!operations.isEmpty()) {
            preparePackages(operations, failures);
            if (myPrepareCompleteCallback != null) {
                myPrepareCompleteCallback.run();
            }
            if (!myBackgrounded) {
                completePackages(operations, failures);
            } else {
                // Otherwise show a notification that we're ready to complete.
                showPrepareCompleteNotification(operations.keySet());
                return;
            }
        }
    } finally {
        if (!failures.isEmpty()) {
            myLogger.logInfo("Failed packages:");
            for (RepoPackage p : failures) {
                myLogger.logInfo(String.format("- %1$s (%2$s)", p.getDisplayName(), p.getPath()));
            }
        }
    }
    // Use a simple progress indicator here so we don't pick up the log messages from the reload.
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
    myRepoManager.loadSynchronously(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, progress, null, mySettingsController);
    if (myCompleteCallback != null) {
        myCompleteCallback.apply(failures);
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with StudioLoggerProgressIndicator

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

the class PatchInstallingRestarter method restartAndInstallIfNecessary.

/**
   * Find any pending patches under the given sdk root that require studio to be restarted, and if there are any, restart and install them.
   * If they have already been installed (as indicated by the patch itself being missing, and the revision mentioned in source.properties
   * matching that in the pending XML, do the install complete actions (write package.xml and fire listeners) and clean up.
   */
public void restartAndInstallIfNecessary() {
    File patchesDir = new File(mySdkHandler.getLocation(), PatchInstallerUtil.PATCHES_DIR_NAME);
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(PatchInstallerFactory.class);
    if (patchesDir.exists()) {
        File[] subDirs = patchesDir.listFiles(file -> file.isDirectory() && file.getName().startsWith(PatchInstallerUtil.PATCH_DIR_PREFIX));
        for (File patchDir : subDirs) {
            processPatch(mySdkHandler.getLocation(), progress, patchDir);
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) File(java.io.File)

Example 28 with StudioLoggerProgressIndicator

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

the class AaptInvoker method getPathToAapt.

/**
   * @return the path to aapt from the latest version of build tools that is installed, null if there are no build tools
   */
@Nullable
private static Path getPathToAapt() {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    BuildToolInfo latestBuildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(AaptInvoker.class), true);
    if (latestBuildTool == null) {
        return null;
    }
    return latestBuildTool.getLocation().toPath().resolve(SdkConstants.FN_AAPT);
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with StudioLoggerProgressIndicator

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

the class SdksCleanupStep method cleanUpSdk.

public void cleanUpSdk(@NotNull Module module, @NotNull Collection<Sdk> invalidAndroidSdks) {
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet == null || androidFacet.getAndroidModel() == null) {
        return;
    }
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk != null && !invalidAndroidSdks.contains(sdk) && (isMissingAndroidLibrary(sdk) || shouldRemoveAnnotationsJar(sdk))) {
        // First try to recreate SDK; workaround for issue 78072
        AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
        AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
        if (additionalData != null && sdkData != null) {
            IAndroidTarget target = additionalData.getBuildTarget(sdkData);
            if (target == null) {
                AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
                StudioLoggerProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
                sdkHandler.getSdkManager(logger).loadSynchronously(0, logger, null, null);
                target = sdkHandler.getAndroidTargetManager(logger).getTargetFromHashString(additionalData.getBuildTargetHashString(), logger);
            }
            if (target != null) {
                SdkModificator sdkModificator = sdk.getSdkModificator();
                sdkModificator.removeAllRoots();
                for (OrderRoot orderRoot : myAndroidSdks.getLibraryRootsForTarget(target, sdk, true)) {
                    sdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
                }
                attachJdkAnnotations(sdkModificator);
                sdkModificator.commitChanges();
            }
        }
        // above workaround deals with)
        if (isMissingAndroidLibrary(sdk)) {
            invalidAndroidSdks.add(sdk);
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 30 with StudioLoggerProgressIndicator

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

the class UpgradeConstraintLayoutFix method apply.

public static void apply(@Nullable Module module) {
    if (module != null) {
        StudioSdkUtil.reloadRemoteSdkWithModalProgress();
        AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
        StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(AndroidLintMissingConstraintsInspection.class);
        RepoPackage p = SdkMavenRepository.findLatestVersion(LATEST_KNOWN_VERSION, sdkHandler, progress);
        if (p != null) {
            GradleCoordinate gc = SdkMavenRepository.getCoordinateFromSdkPath(p.getPath());
            if (gc != null) {
                // should always be the case unless the version suffix is somehow wrong
                // Update version dependency in the module. Note that this will trigger a sync too.
                GradleDependencyManager manager = GradleDependencyManager.getInstance(module.getProject());
                manager.updateLibrariesToVersion(module, Collections.singletonList(gc), null);
            }
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager) RepoPackage(com.android.repository.api.RepoPackage)

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