use of org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate in project rstudio by rstudio.
the class Packages method doUpdatePackages.
private void doUpdatePackages(final PackageInstallContext installContext) {
new CheckForUpdatesDialog(globalDisplay_, new ServerDataSource<JsArray<PackageUpdate>>() {
public void requestData(ServerRequestCallback<JsArray<PackageUpdate>> requestCallback) {
server_.checkForPackageUpdates(requestCallback);
}
}, new OperationWithInput<ArrayList<PackageUpdate>>() {
@Override
public void execute(ArrayList<PackageUpdate> updates) {
InstallCommand cmd = buildUpdatePackagesCommand(updates, installContext);
executeWithLoadedPackageCheck(cmd);
}
}, new Operation() {
@Override
public void execute() {
// cancel emits an empty console input line to clear
// the busy indicator
events_.fireEvent(new SendToConsoleEvent("", true));
}
}).showModal();
}
use of org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate in project rstudio by rstudio.
the class Packages method buildUpdatePackagesCommand.
private InstallCommand buildUpdatePackagesCommand(ArrayList<PackageUpdate> updates, final PackageInstallContext installContext) {
// split the updates into their respective target libraries
List<String> packages = new ArrayList<String>();
LinkedHashMap<String, ArrayList<PackageUpdate>> updatesByLibPath = new LinkedHashMap<String, ArrayList<PackageUpdate>>();
for (PackageUpdate update : updates) {
// auto-create target list if necessary
String libPath = update.getLibPath();
if (!updatesByLibPath.containsKey(libPath))
updatesByLibPath.put(libPath, new ArrayList<PackageUpdate>());
// insert into list
updatesByLibPath.get(libPath).add(update);
// track global list of packages
packages.add(update.getPackageName());
}
// generate an install packages command for each targeted library
StringBuilder command = new StringBuilder();
for (String libPath : updatesByLibPath.keySet()) {
if (command.length() > 0)
command.append("\n");
ArrayList<PackageUpdate> libPathUpdates = updatesByLibPath.get(libPath);
command.append("install.packages(");
if (libPathUpdates.size() > 1)
command.append("c(");
for (int i = 0; i < libPathUpdates.size(); i++) {
PackageUpdate update = libPathUpdates.get(i);
if (i > 0)
command.append(", ");
command.append("\"");
command.append(update.getPackageName());
command.append("\"");
}
if (libPathUpdates.size() > 1)
command.append(")");
if (!libPath.equals(installContext.getDefaultLibraryPath())) {
command.append(", lib=\"");
command.append(libPath);
command.append("\"");
}
command.append(")");
}
return new InstallCommand(packages, command.toString());
}
Aggregations