Ejemplo n.º 1
0
  /**
   * (inheritDoc)
   *
   * @see org.goko.featuremanager.service.IFeatureManager#getInstallableUnits()
   */
  @Override
  public List<GkInstallableUnit> getInstallableUnits(IProgressMonitor monitor) throws GkException {
    List<GkInstallableUnit> lstUnits = new ArrayList<GkInstallableUnit>();
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager =
        (IMetadataRepositoryManager)
            getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);

    try {
      manager.addRepository(new URI("http://update.goko.fr/"));
      manager.loadRepository(new URI("http://update.goko.fr/"), monitor);
    } catch (ProvisionException | OperationCanceledException | URISyntaxException e) {
      throw new GkTechnicalException(e);
    }
    // Query installed units
    IProfileRegistry registry =
        (IProfileRegistry) getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
    IProfile profile = registry.getProfile(IProfileRegistry.SELF);
    Collection<IInstallableUnit> lstInstalledUnits =
        profile.query(new UserVisibleRootQuery(), monitor).toUnmodifiableSet();

    // Query "groups"
    IQuery<IInstallableUnit> query =
        QueryUtil.createLatestQuery(
            QueryUtil.createMatchQuery(
                "properties[$0] == $1 && properties[$2] != null",
                "org.eclipse.equinox.p2.type.group",
                "true",
                "org.eclipse.equinox.p2.type.category"));
    Collection<IInstallableUnit> lstInstallableUnit =
        manager.query(query, monitor).toUnmodifiableSet();

    if (CollectionUtils.isNotEmpty(lstInstallableUnit)) {
      for (IInstallableUnit iInstallableUnit : lstInstallableUnit) {
        GkInstallableUnit gkUnit = new GkInstallableUnit(iInstallableUnit);
        // Same ID already installed ?
        for (IInstallableUnit installedUnit : lstInstalledUnits) {
          if (StringUtils.equals(gkUnit.getId(), installedUnit.getId())) {
            gkUnit.setInstalled(true);
            break;
          }
        }

        lstUnits.add(gkUnit);
      }
    }

    return lstUnits;
  }
Ejemplo n.º 2
0
  /**
   * (inheritDoc)
   *
   * @param listener
   * @see org.goko.featuremanager.service.IFeatureManager#install(java.util.List)
   */
  @Override
  public IStatus install(
      List<GkInstallableUnit> units, IProgressMonitor monitor, IJobChangeListener listener)
      throws GkException {
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager =
        (IMetadataRepositoryManager)
            getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);

    List<IInstallableUnit> p2Units = new ArrayList<IInstallableUnit>();
    for (GkInstallableUnit gkInstallableUnit : units) {
      if (!gkInstallableUnit.isInstalled()) {
        p2Units.add(gkInstallableUnit.getBaseUnit());
      }
    }
    final InstallOperation installOperation =
        new InstallOperation(new ProvisioningSession(getProvisioningAgent()), p2Units);
    LOG.info("installOperation created " + String.valueOf(installOperation));

    IStatus operationStatus = installOperation.resolveModal(monitor);
    LOG.info("operationStatus " + String.valueOf(operationStatus));

    if (operationStatus.getSeverity() > IStatus.WARNING) {
      LOG.error("installOperation detail :" + installOperation.getResolutionDetails());

      LOG.error("Install operation failed :" + operationStatus.toString());
      if (operationStatus.isMultiStatus()) {
        for (IStatus status : operationStatus.getChildren()) {
          LOG.error("   + " + status.getMessage());
        }
      }
      LOG.error(new CoreException(operationStatus));
      return operationStatus;
    }

    final ProvisioningJob provisioningJob = installOperation.getProvisioningJob(monitor);
    LOG.info("ProvisioningJob created " + String.valueOf(provisioningJob));

    provisioningJob.schedule();

    provisioningJob.addJobChangeListener(listener);

    LOG.info("Installation of feature done");

    return operationStatus;
  }