private static IQuery<IInstallableUnit> createQuery(IUDescription iu) {
   String id = iu.getId();
   String version = iu.getVersion();
   if (iu.getQueryMatchExpression() != null) {
     return QueryUtil.createMatchQuery(
         iu.getQueryMatchExpression(), (Object[]) iu.getQueryParameters());
   } else {
     if (version == null || version.length() == 0) {
       return QueryUtil.createLatestQuery(QueryUtil.createIUQuery(id));
     } else {
       return QueryUtil.createIUQuery(id, Version.parseVersion(version));
     }
   }
 }
Ejemplo n.º 2
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.º 3
0
  public List<IServerExtension> getExtensions(IProgressMonitor monitor)
      throws CoreException, ProvisionException {
    try {
      /*
       * To discovery the server adapter, there are three methods:
       * 1. Looking at the site.xml (if it exists). This is the legacy method
       * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2
       *    update site (that may not have a site.xml). The property is necessary to identify
       *    the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show
       *    up regardless of whether it is a server or not
       * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml
       *    to use category.xml)
       */
      BundleContext bd =
          org.eclipse.wst.server.discovery.internal.Activator.getDefault()
              .getBundle()
              .getBundleContext();
      IProvisioningAgent agent = ExtensionUtility.getAgent(bd);

      URI url2 = new URI(url);

      // Method 1: Looking at the site.xml
      UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory();
      mrf.setAgent(ExtensionUtility.getAgent(bd));
      // If the site.xml does not exist, the load will throw a
      // org.eclipse.equinox.p2.core.ProvisionException
      List<IServerExtension> list = new ArrayList<IServerExtension>();
      try {
        IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
        IQuery<IInstallableUnit> query =
            QueryUtil.createMatchQuery(
                "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$

        list = getInstallableUnits(repo, query, url2, monitor);
      } catch (ProvisionException pe) {
        Trace.trace(Trace.WARNING, "Error getting update site information", pe); // $NON-NLS-1$
      }

      // Call Method 2 if there are no results from Method 1 (e.g. if the site.xml exists without
      // specifying any server adapters there or no site.xml exists)
      if (list.isEmpty()) {
        IMetadataRepositoryManager manager =
            (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        manager.addRepository(url2);
        // Need to query for all IUs
        IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();

        IMetadataRepository repo = manager.loadRepository(url2, monitor);
        List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor);

        int size = list2.size();
        for (int i = 0; i < size; i++) {
          Extension e = (Extension) list2.get(i);
          IInstallableUnit[] iuArr = e.getIUs();
          if (iuArr != null && iuArr.length > 0) {
            if (iuArr[0] != null) {
              if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) {
                list.add(e);
              }
            }
          }
        }
      }

      // Call Method 3 if no results from Method 2. Creating the p2 update site using the
      // category.xml will generate
      // a provider property with org.eclipse.wst.server.core.serverAdapter
      if (list.isEmpty()) {
        IMetadataRepositoryManager manager =
            (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        manager.addRepository(url2);
        IQuery<IInstallableUnit> query =
            QueryUtil.createMatchQuery(
                "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$

        IMetadataRepository repo = manager.loadRepository(url2, monitor);
        list = getInstallableUnits(repo, query, url2, monitor);
      }

      return list;
    } catch (ProvisionException e) {
      Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$
      throw e;
    } catch (Exception e) {
      Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$

      return new ArrayList<IServerExtension>(0);
    }
  }