use of com.android.tools.idea.sdk.StudioDownloader 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);
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class InstallNdkHyperlink method execute.
@Override
protected void execute(@NotNull Project project) {
File path = getNdkPath(project);
if (path != null) {
// Try to install SDK in local.properties.
SelectNdkDialog dialog = new SelectNdkDialog(path.getPath(), false, true);
dialog.setModal(true);
if (dialog.showAndGet() && setNdkPath(project, dialog.getAndroidNdkPath())) {
// Saving NDK path is successful.
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
return;
}
// There is no path. Try installing from SDK.
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 -> {
Map<String, RemotePackage> remotePackages = packages.getRemotePackages();
RemotePackage ndkPackage = remotePackages.get(FD_NDK);
if (ndkPackage != null) {
ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(ndkPackage.getPath()));
if (dialog != null && dialog.showAndGet()) {
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
return;
}
notifyNdkPackageNotFound(project);
};
Runnable onError = () -> notifyNdkPackageNotFound(project);
sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class SdkQuickfixUtils method createDialog.
@VisibleForTesting
@Nullable
static ModelWizardDialog createDialog(@Nullable Project project, @Nullable Component parent, @Nullable Collection<String> requestedPaths, @Nullable Collection<UpdatablePackage> requestedPackages, @Nullable Collection<LocalPackage> requestedUninstalls, @Nullable AndroidSdkHandler sdkHandler, boolean backgroundable) {
if (sdkHandler == null) {
return null;
}
RepoManager mgr = sdkHandler.getSdkManager(REPO_LOGGER);
if (mgr.getLocalPath() == null) {
String title = "SDK Problem";
String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
Messages.showErrorDialog(msg, title);
return null;
}
List<String> unknownPaths = new ArrayList<>();
List<UpdatablePackage> resolvedPackages;
mgr.loadSynchronously(0, new StudioLoggerProgressIndicator(SdkQuickfixUtils.class), new StudioDownloader(), StudioSettingsController.getInstance());
RepositoryPackages packages = mgr.getPackages();
if (requestedPackages == null) {
requestedPackages = new ArrayList<>();
}
requestedPackages.addAll(lookupPaths(requestedPaths, packages, unknownPaths));
try {
resolvedPackages = resolve(requestedPackages, packages);
} catch (PackageResolutionException e) {
Messages.showErrorDialog(e.getMessage(), "Error Resolving Packages");
return null;
}
Set<LocalPackage> resolvedUninstalls = new HashSet<>();
if (requestedUninstalls != null) {
resolvedUninstalls.addAll(requestedUninstalls);
// We don't want to uninstall something required by a package we're installing
resolvedPackages.forEach(updatable -> resolvedUninstalls.remove(updatable.getLocal()));
}
List<UpdatablePackage> unavailableDownloads = Lists.newArrayList();
verifyAvailability(resolvedPackages, unavailableDownloads);
// If there were requests we didn't understand or can't download, show an error.
if (!unknownPaths.isEmpty() || !unavailableDownloads.isEmpty()) {
String title = "Packages Unavailable";
HtmlBuilder builder = new HtmlBuilder();
builder.openHtmlBody().add(String.format("%1$s packages are not available for download!", resolvedPackages.isEmpty() ? "All" : "Some")).newline().newline().add("The following packages are not available:").beginList();
for (UpdatablePackage p : unavailableDownloads) {
builder.listItem().add(p.getRepresentative().getDisplayName());
}
for (String p : unknownPaths) {
builder.listItem().add("Package id " + p);
}
builder.endList().closeHtmlBody();
Messages.showErrorDialog(builder.getHtml(), title);
}
// If everything was removed, don't continue.
if (resolvedPackages.isEmpty() && resolvedUninstalls.isEmpty()) {
return null;
}
List<RemotePackage> installRequests = resolvedPackages.stream().map(UpdatablePackage::getRemote).collect(Collectors.toList());
ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
wizardBuilder.addStep(new LicenseAgreementStep(new LicenseAgreementModel(mgr.getLocalPath()), installRequests));
InstallSelectedPackagesStep installStep = new InstallSelectedPackagesStep(resolvedPackages, resolvedUninstalls, sdkHandler, backgroundable);
wizardBuilder.addStep(installStep);
ModelWizard wizard = wizardBuilder.build();
String title = "SDK Quickfix Installation";
return new StudioWizardDialogBuilder(wizard, title, parent).setProject(project).setModalityType(DialogWrapper.IdeModalityType.IDE).setCancellationPolicy(ModelWizardDialog.CancellationPolicy.CAN_CANCEL_UNTIL_CAN_FINISH).build();
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class SystemImageListModel method refreshImages.
public void refreshImages(final boolean forceRefresh) {
synchronized (myLock) {
myCompletedCalls = 0;
}
myIndicator.onRefreshStart("Refreshing...");
final List<SystemImageDescription> items = Lists.newArrayList();
RepoManager.RepoLoadedCallback localComplete = new RepoManager.RepoLoadedCallback() {
@Override
public void doRun(@NotNull RepositoryPackages packages) {
// getLocalImages() doesn't use SdkPackages, so it's ok that we're not using what's passed in.
items.addAll(getLocalImages());
// Update list in the UI immediately with the locally available system images
setItems(items);
// Assume the remote has not completed yet
completedDownload("");
}
};
RepoManager.RepoLoadedCallback remoteComplete = new RepoManager.RepoLoadedCallback() {
@Override
public void doRun(@NotNull RepositoryPackages packages) {
List<SystemImageDescription> remotes = getRemoteImages(packages);
if (remotes != null) {
items.addAll(remotes);
setItems(items);
}
completedDownload("");
}
};
Runnable error = new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
completedDownload("Error loading remote images");
}
});
}
};
StudioProgressRunner runner = new StudioProgressRunner(false, false, "Loading Images", true, myProject);
mySdkHandler.getSdkManager(LOGGER).load(forceRefresh ? 0 : RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(localComplete), ImmutableList.of(remoteComplete), ImmutableList.of(error), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.tools.idea.sdk.StudioDownloader 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;
}
Aggregations