/** * (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; }
/** Return a collection of features that are available to be installed. */ public Collection getAvailableFeatures() { IQuery query = QueryUtil.createIUPropertyQuery(PROP_TOAST_ROOT, Boolean.TRUE.toString()); IQueryResult result = metadataManager.query(query, new NullProgressMonitor()); return result.toSet(); }