Search in sources :

Example 1 with Dependency

use of org.rstudio.studio.client.common.dependencies.model.Dependency in project rstudio by rstudio.

the class DependencyManager method withUnsatisfiedDependencies.

public void withUnsatisfiedDependencies(final Dependency dependency, final ServerRequestCallback<JsArray<Dependency>> requestCallback) {
    // determine if already satisfied
    for (Dependency d : satisfied_) {
        if (d.isEqualTo(dependency)) {
            JsArray<Dependency> empty = JsArray.createArray().cast();
            requestCallback.onResponseReceived(empty);
            return;
        }
    }
    List<Dependency> dependencies = new ArrayList<Dependency>();
    dependencies.add(dependency);
    withUnsatisfiedDependencies(dependencies, requestCallback);
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.rstudio.studio.client.common.dependencies.model.Dependency)

Example 2 with Dependency

use of org.rstudio.studio.client.common.dependencies.model.Dependency in project rstudio by rstudio.

the class DependencyManager method processDependencyRequest.

private void processDependencyRequest(final DependencyRequest req) {
    // convert dependencies to JsArray, excluding satisfied dependencies
    final JsArray<Dependency> deps = JsArray.createArray().cast();
    for (int i = 0; i < req.dependencies.length; i++) {
        boolean satisfied = false;
        for (Dependency d : satisfied_) {
            if (req.dependencies[i].isEqualTo(d)) {
                satisfied = true;
                break;
            }
        }
        if (!satisfied)
            deps.push(req.dependencies[i]);
    }
    // if no unsatisfied dependencies were found, we're done already
    if (deps.length() == 0) {
        req.onComplete.execute(true);
        return;
    }
    // create progress indicator
    final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, req.progressCaption + "...").getIndicator();
    // query for unsatisfied dependencies
    server_.unsatisfiedDependencies(deps, req.silentEmbeddedUpdate, new ServerRequestCallback<JsArray<Dependency>>() {

        @Override
        public void onResponseReceived(final JsArray<Dependency> unsatisfiedDeps) {
            progress.onCompleted();
            updateSatisfied(deps, unsatisfiedDeps);
            // if we've satisfied all dependencies then execute the command
            if (unsatisfiedDeps.length() == 0) {
                req.onComplete.execute(true);
                return;
            }
            // check to see if we can satisfy the version requirement for all
            // dependencies
            String unsatisfiedVersions = "";
            for (int i = 0; i < unsatisfiedDeps.length(); i++) {
                if (!unsatisfiedDeps.get(i).getVersionSatisfied()) {
                    unsatisfiedVersions += unsatisfiedDeps.get(i).getName() + " " + unsatisfiedDeps.get(i).getVersion();
                    String version = unsatisfiedDeps.get(i).getAvailableVersion();
                    if (version.isEmpty())
                        unsatisfiedVersions += " is not available\n";
                    else
                        unsatisfiedVersions += " is required but " + version + " is available\n";
                }
            }
            if (!unsatisfiedVersions.isEmpty()) {
                // error if we can't satisfy requirements
                globalDisplay_.showErrorMessage(StringUtil.isNullOrEmpty(req.userAction) ? "Packages Not Found" : req.userAction, "Required package versions could not be found:\n\n" + unsatisfiedVersions + "\n" + "Check that getOption(\"repos\") refers to a CRAN " + "repository that contains the needed package versions.");
                req.onComplete.execute(false);
            } else {
                // otherwise ask the user if they want to install the 
                // unsatisifed dependencies
                final CommandWithArg<Boolean> installCommand = new CommandWithArg<Boolean>() {

                    @Override
                    public void execute(Boolean confirmed) {
                        // bail if user didn't confirm
                        if (!confirmed) {
                            req.onComplete.execute(false);
                            return;
                        }
                        // the incoming JsArray from the server may not serialize
                        // as expected when this code is executed from a satellite
                        // (see RemoteServer.sendRequestViaMainWorkbench), so we
                        // clone it before passing to the dependency installer
                        JsArray<Dependency> newArray = JsArray.createArray().cast();
                        newArray.setLength(unsatisfiedDeps.length());
                        for (int i = 0; i < unsatisfiedDeps.length(); i++) {
                            newArray.set(i, unsatisfiedDeps.get(i));
                        }
                        installDependencies(newArray, req.silentEmbeddedUpdate, req.onComplete);
                    }
                };
                if (req.userPrompt != null) {
                    req.userPrompt.execute(describeDepPkgs(unsatisfiedDeps), new Command() {

                        @Override
                        public void execute() {
                            installCommand.execute(true);
                        }
                    });
                } else {
                    confirmPackageInstallation(req.userAction, unsatisfiedDeps, installCommand);
                }
            }
        }

        @Override
        public void onError(ServerError error) {
            progress.onError(error.getUserMessage());
            req.onComplete.execute(false);
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) Dependency(org.rstudio.studio.client.common.dependencies.model.Dependency) CommandWithArg(org.rstudio.core.client.CommandWithArg) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator)

Aggregations

Dependency (org.rstudio.studio.client.common.dependencies.model.Dependency)2 JsArray (com.google.gwt.core.client.JsArray)1 Command (com.google.gwt.user.client.Command)1 ArrayList (java.util.ArrayList)1 CommandWithArg (org.rstudio.core.client.CommandWithArg)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)1 ServerError (org.rstudio.studio.client.server.ServerError)1