use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class InstantRunConfigurable method updateProjectToInstantRunTools.
/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
// Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
}
// Update plugin version
AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
// Should be at least 23.0.2
String buildToolsVersion = "23.0.2";
AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
if (latestBuildTool != null) {
Revision revision = latestBuildTool.getRevision();
if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
buildToolsVersion = revision.toShortString();
}
}
// Also update build files to set build tools version 23.0.2
GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
// Also update Gradle wrapper version
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
}
// Request a sync
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
return true;
} else {
return false;
}
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.
@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
boolean buildToolInstalled = false;
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
buildToolInstalled = buildTool != null;
}
if (module != null) {
VirtualFile buildFile = getGradleBuildFile(module);
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
if (!buildToolInstalled) {
if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
} else {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
}
} else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
}
if (buildFile != null) {
hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
}
}
return hyperlinks;
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class MissingPlatformErrorHandler method findAndAddQuickFixes.
private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
String missingPlatform = getMissingPlatform(text);
if (missingPlatform == null) {
return;
}
String loadError = null;
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
if (version != null) {
// Is the platform installed?
ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
hyperlinks.add(new InstallPlatformHyperlink(version));
}
}
if (hyperlinks.isEmpty()) {
// We are unable to install platform automatically.
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (!facets.isEmpty()) {
// We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
}
}
if (isNotEmpty(loadError)) {
text += "\nPossible cause: " + loadError;
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SdkMergerTest method getSdkFingerprint.
private String getSdkFingerprint(File sdk) {
StringBuilder s = new StringBuilder();
RepoManager sdkManager = AndroidSdkHandler.getInstance(sdk).getSdkManager(new StudioLoggerProgressIndicator(getClass()));
for (LocalPackage p : Sets.newTreeSet(sdkManager.getPackages().getLocalPackages().values())) {
s.append(p.getPath());
s.append(',');
s.append(p.getVersion());
s.append('\n');
}
return s.toString();
}
use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.
the class SdkUpdaterConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
myPanel.saveSources();
HtmlBuilder message = new HtmlBuilder();
message.openHtmlBody();
final List<LocalPackage> toDelete = Lists.newArrayList();
final Map<RemotePackage, UpdatablePackage> requestedPackages = Maps.newHashMap();
for (PackageNodeModel model : myPanel.getStates()) {
if (model.getState() == PackageNodeModel.SelectedState.NOT_INSTALLED) {
if (model.getPkg().hasLocal()) {
toDelete.add(model.getPkg().getLocal());
}
} else if (model.getState() == PackageNodeModel.SelectedState.INSTALLED && (model.getPkg().isUpdate() || !model.getPkg().hasLocal())) {
UpdatablePackage pkg = model.getPkg();
requestedPackages.put(pkg.getRemote(), pkg);
}
}
boolean found = false;
if (!toDelete.isEmpty()) {
found = true;
message.add("The following components will be deleted: \n");
message.beginList();
for (LocalPackage item : toDelete) {
message.listItem().add(item.getDisplayName()).add(", Revision: ").add(item.getVersion().toString());
}
message.endList();
}
if (!requestedPackages.isEmpty()) {
found = true;
message.add("The following components will be installed: \n");
message.beginList();
Multimap<RemotePackage, RemotePackage> dependencies = HashMultimap.create();
ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
RepositoryPackages packages = getRepoManager().getPackages();
for (RemotePackage item : requestedPackages.keySet()) {
List<RemotePackage> packageDependencies = InstallerUtil.computeRequiredPackages(ImmutableList.of(item), packages, progress);
if (packageDependencies == null) {
Messages.showErrorDialog((Project) null, "Unable to resolve dependencies for " + item.getDisplayName(), "Dependency Error");
throw new ConfigurationException("Unable to resolve dependencies.");
}
for (RemotePackage dependency : packageDependencies) {
dependencies.put(dependency, item);
}
message.listItem().add(String.format("%1$s %2$s %3$s", item.getDisplayName(), item.getTypeDetails() instanceof DetailsTypes.ApiDetailsType ? "revision" : "version", item.getVersion()));
}
for (RemotePackage dependency : dependencies.keySet()) {
if (requestedPackages.containsKey(dependency)) {
continue;
}
Set<RemotePackage> requests = Sets.newHashSet(dependencies.get(dependency));
requests.remove(dependency);
if (!requests.isEmpty()) {
message.listItem().add(dependency.getDisplayName()).add(" (Required by ");
Iterator<RemotePackage> requestIterator = requests.iterator();
message.add(requestIterator.next().getDisplayName());
while (requestIterator.hasNext()) {
message.add(", ").add(requestIterator.next().getDisplayName());
}
message.add(")");
}
}
message.endList();
}
message.closeHtmlBody();
if (found) {
if (confirmChange(message)) {
if (!requestedPackages.isEmpty() || !toDelete.isEmpty()) {
ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPackages(myPanel.getComponent(), requestedPackages.values(), toDelete, true);
if (dialog != null) {
dialog.show();
for (RemotePackage remotePackage : requestedPackages.keySet()) {
PackageOperation installer = getRepoManager().getInProgressInstallOperation(remotePackage);
if (installer != null) {
PackageOperation.StatusChangeListener listener = (installer1, progress) -> myPanel.getComponent().repaint();
myListeners.add(listener);
installer.registerStateChangeListener(listener);
}
}
}
}
myPanel.refresh();
} else {
throw new ConfigurationException("Installation was canceled.");
}
} else {
// We didn't have any changes, so just reload (maybe the channel changed).
myChannelChangedCallback.run();
}
}
Aggregations