use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class PatchInstallingRestarter method processPatch.
/**
* Either restart and install the given patch or delete it (if it's already installed).
*/
private void processPatch(File androidSdkPath, StudioLoggerProgressIndicator progress, File patchDir) {
RepoPackage pendingPackage = null;
File installDir = null;
try {
RepoManager mgr = mySdkHandler.getSdkManager(progress);
Repository repo = InstallerUtil.readPendingPackageXml(patchDir, mgr, myFileOp, progress);
if (repo != null) {
File patch = new File(patchDir, PatchInstallerUtil.PATCH_JAR_FN);
pendingPackage = repo.getLocalPackage();
boolean remote = false;
if (pendingPackage != null) {
// If the pending package was local, use the corresponding installed local package.
installDir = mgr.getPackages().getLocalPackages().get(pendingPackage.getPath()).getLocation();
} else {
// Otherwise it's remote.
pendingPackage = repo.getRemotePackage().get(0);
installDir = ((RemotePackage) pendingPackage).getInstallDir(mgr, progress);
remote = true;
}
File existingPackageXml = new File(installDir, LocalRepoLoaderImpl.PACKAGE_XML_FN);
File oldPackageXml = new File(patchDir, OLD_PACKAGE_XML_FN);
if (patch.exists() && existingPackageXml.renameTo(oldPackageXml)) {
// This will exit the app.
// Main.installPatch("sdk", PatchInstallerUtil.PATCH_JAR_FN, FileUtil.getTempDirectory(), patch, installDir.getAbsolutePath());
} else {
// The patch is already installed, or was cancelled.
String relativePath = FileOpUtils.makeRelative(androidSdkPath, installDir, myFileOp);
// Use the old mechanism to get the version, since it's actually part of the package itself. Thus we can tell if the patch
// has already been applied.
Revision rev = AndroidCommonUtils.parsePackageRevision(androidSdkPath.getPath(), relativePath);
if (rev != null && rev.equals(pendingPackage.getVersion())) {
// We need to make sure the listeners are fired, so create an installer that does nothing and invoke it.
InstallerFactory dummyFactory = new DummyInstallerFactory();
dummyFactory.setListenerFactory(new StudioSdkInstallListenerFactory(mySdkHandler));
if (remote) {
Installer installer = dummyFactory.createInstaller((RemotePackage) pendingPackage, mgr, new StudioDownloader(), myFileOp);
installer.complete(progress);
} else {
Uninstaller uninstaller = dummyFactory.createUninstaller((LocalPackage) pendingPackage, mgr, myFileOp);
uninstaller.complete(progress);
}
} else {
// something went wrong. Move the old package.xml back into place.
progress.logWarning("Failed to find version information in " + new File(androidSdkPath, SdkConstants.FN_SOURCE_PROP));
oldPackageXml.renameTo(existingPackageXml);
}
}
}
} catch (Exception e) {
StringBuilder message = new StringBuilder("A problem occurred while installing ");
message.append(pendingPackage != null ? pendingPackage.getDisplayName() : "an SDK package");
if (installDir != null) {
message.append(" in ").append(installDir);
}
message.append(". Please try again.");
Messages.showErrorDialog(message.toString(), "Error Launching SDK Component Installer");
progress.logWarning("Failed to install SDK package", e);
}
// If we get here we either got an error or the patch was already installed. Delete the patch dir.
try {
myFileOp.deleteFileOrFolder(patchDir);
} catch (Exception e) {
progress.logWarning("Problem during patch cleanup", e);
}
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class ComponentInstaller method installPackages.
public void installPackages(@NotNull List<RemotePackage> packages, ProgressIndicator progress) throws WizardException {
RepoManager sdkManager = mySdkHandler.getSdkManager(progress);
for (RemotePackage request : packages) {
// Intentionally don't register any listeners on the installer, so we don't recurse on haxm
// TODO: This is a hack. Any future rewrite of this shouldn't require this behavior.
InstallerFactory factory = new BasicInstallerFactory();
Installer installer = factory.createInstaller(request, sdkManager, new StudioDownloader(), mySdkHandler.getFileOp());
if (installer.prepare(progress)) {
installer.complete(progress);
}
}
sdkManager.loadSynchronously(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, progress, null, null);
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class FormFactorApiComboBox method loadRemoteTargets.
private void loadRemoteTargets(final int minSdkLevel, final Runnable completedCallback, final Runnable foundItemsCallback, final Runnable noItemsCallback) {
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
final Runnable runCallbacks = () -> {
if (completedCallback != null) {
completedCallback.run();
}
if (getItemCount() > 0) {
if (foundItemsCallback != null) {
foundItemsCallback.run();
}
} else {
if (noItemsCallback != null) {
noItemsCallback.run();
}
}
};
RepoManager.RepoLoadedCallback onComplete = packages -> {
addPackages(packages.getNewPkgs(), minSdkLevel);
addOfflineLevels();
loadSavedApi();
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(packages.getLocalPackages().values(), minSdkLevel);
Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
addOfflineLevels();
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);
}
use of com.android.tools.idea.sdk.StudioDownloader in project android by JetBrains.
the class SourcesTableModel method reset.
/**
* Reset the sources to the state they were before the user made any changes.
*/
public void reset() {
if (!isSourcesModified()) {
// We don't have any changes, but if we haven't initialized at all, do it now.
if (myInitialItems == null) {
refreshUi();
}
return;
}
// Force refresh so the file is reloaded.
myConfigurable.getRepoManager().getSources(new StudioDownloader(), myLogger, true);
myInitialItems = null;
refreshUi();
}
Aggregations