Example #1
0
  private void checkMirrors(final Change event) {
    if ((fRequireLoad & (REQUIRE_CRAN | REQUIRE_BIOC)) != 0) {
      return;
    }

    SelectedRepos selected = fSelectedRepos;
    fAllCRAN = ConstArrayList.concat(fCustomCRAN, fRCRAN);

    RRepo selectedCRAN = selected.getCRANMirror();
    if (selected.getCRANMirror() != null) {
      selectedCRAN = Util.findRepo(fAllCRAN, selectedCRAN);
    } else if (fFirstTime && fSelectedCRANInR != null) {
      selectedCRAN = Util.getRepoByURL(fAllCRAN, fSelectedCRANInR);
    }
    if (selectedCRAN == null) {
      fRequireConfirm |= REQUIRE_CRAN;
      selectedCRAN = PreferencesUtil.getInstancePrefs().getPreferenceValue(LAST_CRAN_PREF);
      if (selectedCRAN != null) {
        selectedCRAN = Util.findRepo(fAllCRAN, selectedCRAN);
      }
      if (!fCustomCRAN.isEmpty()
          && (selectedCRAN == null || !selectedCRAN.getId().startsWith(RRepo.CUSTOM_PREFIX))) {
        selectedCRAN = fCustomCRAN.get(0);
      }
      if (fFirstTime && selectedCRAN == null) {
        selectedCRAN = fRCRANByCountry;
      }
    }

    RRepo selectedBioC = selected.getBioCMirror();
    fAllBioC = ConstArrayList.concat(fCustomBioC, fRBioC);
    if (selectedBioC != null) {
      selectedBioC = Util.findRepo(fAllBioC, selectedBioC);
    } else if (fFirstTime && fSelectedBioCInR != null) {
      selectedBioC = RPkgUtil.getRepoByURL(fAllBioC, fSelectedBioCInR);
    }
    if (selectedBioC == null) {
      fRequireConfirm |= REQUIRE_BIOC;
      selectedBioC = PreferencesUtil.getInstancePrefs().getPreferenceValue(LAST_BIOC_PREF);
      if (!fCustomBioC.isEmpty()
          && (selectedBioC == null || !selectedBioC.getId().startsWith(RRepo.CUSTOM_PREFIX))) {
        selectedBioC = fCustomBioC.get(0);
      }
      if (fFirstTime && selectedBioC == null) {
        selectedBioC = Util.getRepoByURL(fAllBioC, "http://www.bioconductor.org"); // $NON-NLS-1$
      }
    }

    selected = new SelectedRepos(selected.getRepos(), selectedCRAN, fBioCVersion, selectedBioC);
    if ((fRequireLoad & (REQUIRE_REPOS)) == 0) {
      for (final RRepo repo : fAllRepos) {
        if (repo instanceof RVarRepo) {
          ((RVarRepo) repo).updateURL(selected);
        }
      }
    }
    fSelectedRepos = selected;

    event.fPkgs = 1;
  }
Example #2
0
  private void checkRepos(final Change event) {
    if ((fRequireLoad & (REQUIRE_CRAN | REQUIRE_BIOC | REQUIRE_REPOS)) != 0) {
      return;
    }

    SelectedRepos selected = fSelectedRepos;

    fAllRepos = new ArrayList<>(fCustomRepos.size() + fAddRepos.size() + fRRepos.size());
    fAllRepos.addAll(fCustomRepos);
    fAllRepos.addAll(fAddRepos);
    for (final RRepo repo : fAllRepos) {
      if (repo instanceof RVarRepo) {
        ((RVarRepo) repo).updateURL(selected);
      }
    }
    for (final RRepo repo : fRRepos) {
      if (repo instanceof RVarRepo) {
        ((RVarRepo) repo).updateURL(selected);
      }
    }
    for (final RRepo repo : fRRepos) {
      if (!repo.getId().isEmpty()) {
        if (RPkgUtil.getRepoById(fAllRepos, repo.getId()) == null) {
          fAllRepos.add(repo);
        }
      } else {
        if (Util.getRepoByURL(fAllRepos, repo) == null) {
          fAllRepos.add(
              RVarRepo.create(RRepo.R_PREFIX + repo.getURL(), repo.getName(), repo.getURL(), null));
        }
      }
    }

    {
      final Collection<RRepo> selectedRepos = selected.getRepos();
      final Collection<RRepo> previous =
          (fFirstTime && selectedRepos.isEmpty()) ? fSelectedReposInR : selectedRepos;
      final List<RRepo> repos = new ArrayList<>(previous.size());
      for (RRepo repo : previous) {
        repo = Util.findRepo(fAllRepos, repo);
        if (repo != null) {
          repos.add(repo);
        }
      }
      selected =
          new SelectedRepos(
              repos, selected.getCRANMirror(), selected.getBioCVersion(), selected.getBioCMirror());
      fSelectedRepos = selected;
    }

    fRequireLoad |= REQUIRE_REPO_PKGS;

    event.fRepos = 1;
  }
Example #3
0
  private void savePrefs(final SelectedRepos repos) {
    if (fREnv.getConfig() == null) {
      return;
    }
    final IScopeContext prefs = InstanceScope.INSTANCE;

    final IEclipsePreferences node = prefs.getNode(fSelectedReposPref.getQualifier());

    PreferencesUtil.setPrefValue(node, fSelectedReposPref, repos.getRepos());
    PreferencesUtil.setPrefValue(node, fSelectedCRANPref, repos.getCRANMirror());
    PreferencesUtil.setPrefValue(node, fBioCVersionPref, repos.getBioCVersion());
    PreferencesUtil.setPrefValue(node, fSelectedBioCPref, repos.getBioCMirror());

    if (repos.getCRANMirror() != null) {
      PreferencesUtil.setPrefValue(prefs, LAST_CRAN_PREF, repos.getCRANMirror());
    }
    if (repos.getBioCMirror() != null) {
      PreferencesUtil.setPrefValue(prefs, LAST_BIOC_PREF, repos.getBioCMirror());
    }

    try {
      node.flush();
    } catch (final BackingStoreException e) {
      RCorePlugin.log(
          new Status(
              IStatus.ERROR,
              RCore.PLUGIN_ID,
              "An error occurred when saving the R package manager preferences.",
              e));
    }
  }
Example #4
0
  @Override
  public void setSelectedRepos(final ISelectedRepos repos) {
    List<RRepo> selectedRepos;
    {
      final Collection<RRepo> selected = repos.getRepos();
      selectedRepos = new ArrayList<>(selected.size());
      for (final RRepo repo : fAllRepos) {
        if (selected.contains(repo)) {
          selectedRepos.add(repo);
        }
      }
    }
    RRepo selectedCRAN;
    {
      final RRepo repo = repos.getCRANMirror();
      selectedCRAN = (repo != null) ? Util.findRepo(fAllCRAN, repo) : null;
      fRequireConfirm &= ~REQUIRE_CRAN;
    }
    RRepo selectedBioC;
    {
      final RRepo repo = repos.getBioCMirror();
      selectedBioC = (repo != null) ? Util.findRepo(fAllBioC, repo) : null;
      fRequireConfirm &= ~REQUIRE_BIOC;
    }

    final SelectedRepos previousSettings = fSelectedRepos;
    final SelectedRepos newSettings =
        new SelectedRepos(
            selectedRepos, selectedCRAN, previousSettings.getBioCVersion(), selectedBioC);
    for (final RRepo repo : fAllRepos) {
      if (repo instanceof RVarRepo) {
        ((RVarRepo) repo).updateURL(newSettings);
      }
    }
    fSelectedRepos = newSettings;
    savePrefs(newSettings);

    if (!newSettings.equals(previousSettings)) {
      fRequireLoad |= (REQUIRE_REPO_PKGS);

      final Change event = new Change(fREnv);
      event.fRepos = 1;
      fireUpdate(event);
    }
  }
Example #5
0
 @Override
 public RRepo getRepo(final String repoId) {
   if (repoId.isEmpty()) {
     return null;
   }
   RRepo repo = fSelectedRepos.getRepo(repoId);
   if (repo == null) {
     repo = RPkgUtil.getRepoById(fAllRepos, repoId);
   }
   return repo;
 }