Exemplo n.º 1
0
  /**
   * Finds available WSO2 features in current profile and search for updates to them in WSO2 p2
   * repository for updates.
   *
   * @param monitor
   * @throws Exception
   */
  public void checkForAvailableUpdates(IProgressMonitor monitor) throws Exception {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_18, 6);

    // get all available IUs in update repository
    IMetadataRepository metadataRepo =
        metadataRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1));
    IQuery<IInstallableUnit> allIUQuery = QueryUtil.createIUAnyQuery();
    IQueryResult<IInstallableUnit> allIUQueryResult =
        metadataRepo.query(allIUQuery, progress.newChild(1));

    // read artifact repository for updates
    IArtifactRepository artifactRepo =
        artifactRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1));

    // read meta-data of all available features
    Map<String, EnhancedFeature> allFeaturesInUpdateRepo =
        loadWSO2FeaturesInRepo(artifactRepo, allIUQueryResult, progress.newChild(1));

    // get all installed wso2 features
    Collection<IInstallableUnit> installedWSO2Features =
        getInstalledWSO2Features(progress.newChild(1));

    installedWSO2FeaturesMap = new HashMap<String, IInstallableUnit>();
    for (IInstallableUnit iInstallableUnit : installedWSO2Features) {
      installedWSO2FeaturesMap.put(iInstallableUnit.getId(), iInstallableUnit);
    }

    if (progress.isCanceled()) {
      throw new OperationCanceledException();
    }

    URI[] repos = new URI[] {getDevStudioUpdateSite()};
    updateOperation = new UpdateOperation(session, installedWSO2Features);
    updateOperation.getProvisioningContext().setArtifactRepositories(repos);
    updateOperation.getProvisioningContext().setMetadataRepositories(repos);

    // resolve update operation
    IStatus status = updateOperation.resolveModal(progress.newChild(1));
    // user cancelled the job while resolving
    if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) {
      throw new OperationCanceledException();
    }
    // there is nothing to update
    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
      featuresWithPossibleUpdates = new HashMap<String, EnhancedFeature>();
      log.info(Messages.UpdateManager_19);
    } else if (status.getSeverity() == IStatus.ERROR) { // resolution errors
      // something wrong with the updates
      log.info(Messages.UpdateManager_20);
    } else {
      // good to proceed installing updates
      setPossibleUpdates(updateOperation.getPossibleUpdates(), allFeaturesInUpdateRepo);
    }
  }
Exemplo n.º 2
0
 protected void doExecute(LoadMetadataRepositoryJob job) {
   if (hasNoRepos) {
     return;
   }
   UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
   // check for updates
   operation.resolveModal(null);
   if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
     if (UpdateSingleIUWizard.validFor(operation)) {
       // Special case for only updating a single root
       UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
       WizardDialog dialog = new WizardDialog(getShell(), wizard);
       dialog.create();
       dialog.open();
     } else {
       // Open the normal version of the update wizard
       getProvisioningUI().openUpdateWizard(false, operation, job);
     }
   }
 }
Exemplo n.º 3
0
  public IStatus service(Command command, IProcess context)
      throws InterruptedException, CoreException {
    UpdateFeature updateFeature = (UpdateFeature) command;
    String featureId = updateFeature.getId();

    ProvisioningSession session = PlatformPlugin.createProvisioningSession();

    IProfile profile = PlatformPlugin.getProfileRegistry().getProfile(IProfileRegistry.SELF);
    IQuery<IInstallableUnit> query =
        QueryUtil.createLatestQuery(QueryUtil.createIUQuery(featureId));
    IQueryResult<IInstallableUnit> result = profile.query(query, new NullProgressMonitor());

    if (result.isEmpty()) {
      return Status.OK_STATUS;
    }

    UpdateOperation op = new UpdateOperation(session, result.toSet());
    IStatus status = op.resolveModal(new NullProgressMonitor());

    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
      return Status.OK_STATUS;
    }
    if (status.getSeverity() == IStatus.CANCEL) {
      // should not happen,
      throw new CoreException(status);
    }

    if (status.getSeverity() == IStatus.ERROR) {
      throw new CoreException(status);
    }

    ProvisioningJob job = op.getProvisioningJob(null);
    if (job == null) {
      return Status.OK_STATUS;
    }

    status = job.runModal(new NullProgressMonitor());
    if (status.getSeverity() == IStatus.CANCEL) throw new CoreException(status);

    return Status.OK_STATUS;
  }
Exemplo n.º 4
0
  /**
   * Install selected updates in to developer studio. Note: call {@link #setSelectedUpdates(List)
   * setSelectedUpdates} first.
   *
   * @param monitor
   */
  public void installSelectedUpdates(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_26, 2);
    URI[] repos = new URI[] {getDevStudioUpdateSite()};
    session = new ProvisioningSession(p2Agent);
    updateOperation = new UpdateOperation(session);
    updateOperation.getProvisioningContext().setArtifactRepositories(repos);
    updateOperation.getProvisioningContext().setMetadataRepositories(repos);

    updateOperation.setSelectedUpdates(selectedUpdates);
    IStatus status = updateOperation.resolveModal(progress.newChild(1));
    if (status.getSeverity() == IStatus.CANCEL) {
      throw new OperationCanceledException();
    } else if (status.getSeverity() == IStatus.ERROR) {
      String message = status.getChildren()[0].getMessage();
      log.error(Messages.UpdateManager_27 + message);
    } else {
      final ProvisioningJob provisioningJob =
          updateOperation.getProvisioningJob(progress.newChild(1));
      if (provisioningJob != null) {
        provisioningJob.addJobChangeListener(
            new JobChangeAdapter() {
              @Override
              public void done(IJobChangeEvent arg0) {
                Display.getDefault()
                    .syncExec(
                        new Runnable() {
                          @Override
                          public void run() {
                            boolean restart =
                                MessageDialog.openQuestion(
                                    Display.getDefault().getActiveShell(),
                                    Messages.UpdateManager_28,
                                    Messages.UpdateManager_29 + Messages.UpdateManager_30);
                            if (restart) {
                              PlatformUI.getWorkbench().restart();
                            }
                          }
                        });
              }
            });
        provisioningJob.schedule();
        Display.getDefault()
            .syncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      PlatformUI.getWorkbench()
                          .getActiveWorkbenchWindow()
                          .getActivePage()
                          .showView(IProgressConstants.PROGRESS_VIEW_ID);
                    } catch (PartInitException e) {
                      log.error(e);
                    }
                  }
                });
      } else {
        log.error(Messages.UpdateManager_31);
      }
    }
  }