Search in sources :

Example 1 with PackageUpdate

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();
}
Also used : ServerDataSource(org.rstudio.studio.client.server.ServerDataSource) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) ArrayList(java.util.ArrayList) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) PackageUpdate(org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) CheckForUpdatesDialog(org.rstudio.studio.client.workbench.views.packages.ui.CheckForUpdatesDialog) Operation(org.rstudio.core.client.widget.Operation)

Example 2 with PackageUpdate

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());
}
Also used : ArrayList(java.util.ArrayList) PackageUpdate(org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)2 PackageUpdate (org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate)2 LinkedHashMap (java.util.LinkedHashMap)1 Operation (org.rstudio.core.client.widget.Operation)1 OperationWithInput (org.rstudio.core.client.widget.OperationWithInput)1 ProgressOperationWithInput (org.rstudio.core.client.widget.ProgressOperationWithInput)1 ServerDataSource (org.rstudio.studio.client.server.ServerDataSource)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1 SendToConsoleEvent (org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent)1 CheckForUpdatesDialog (org.rstudio.studio.client.workbench.views.packages.ui.CheckForUpdatesDialog)1