use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.
the class ProfileChangeOperationComputer method checkForUnavailable.
/**
* Verifies that we found what we were looking for: it's possible that we have connector descriptors that are no
* longer available on their respective sites. In that case we must inform the user. Unfortunately this is the
* earliest point at which we can know.
*/
private void checkForUnavailable(final List<IInstallableUnit> installableUnits) throws CoreException {
// at least one selected connector could not be found in a repository
Set<String> foundIds = new HashSet<String>();
for (IInstallableUnit unit : installableUnits) {
foundIds.add(unit.getId());
}
Set<String> installFeatureIds = new HashSet<String>();
for (FeatureEntry entry : featureEntries) {
Operation operation = entry.computeChangeOperation();
if (operation == Operation.INSTALL || operation == Operation.UPDATE) {
installFeatureIds.add(entry.getFeatureDescriptor().getId());
}
}
// $NON-NLS-1$
String message = "";
// $NON-NLS-1$
String detailedMessage = "";
for (CatalogItem descriptor : items) {
StringBuilder unavailableIds = null;
for (String id : getFeatureIds(descriptor)) {
if (!foundIds.contains(id) && installFeatureIds.contains(id)) {
if (unavailableIds == null) {
unavailableIds = new StringBuilder();
} else {
unavailableIds.append(Messages.ProvisioningOperation_commaSeparator);
}
unavailableIds.append(id);
}
}
if (unavailableIds != null) {
if (message.length() > 0) {
message += Messages.ProvisioningOperation_commaSeparator;
}
message += descriptor.getName();
if (detailedMessage.length() > 0) {
detailedMessage += Messages.ProvisioningOperation_commaSeparator;
}
detailedMessage += NLS.bind(Messages.ProvisioningOperation_unavailableFeatures, new Object[] { descriptor.getName(), unavailableIds.toString(), descriptor.getSiteUrl() });
}
}
if (message.length() > 0) {
// instead of aborting here we ask the user if they wish to proceed anyways
final boolean[] okayToProceed = new boolean[1];
final String finalMessage = message;
Display.getDefault().syncExec(new Runnable() {
public void run() {
okayToProceed[0] = MessageDialog.openQuestion(WorkbenchUtil.getShell(), Messages.ProvisioningOperation_proceedQuestion, NLS.bind(Messages.ProvisioningOperation_unavailableSolutions_proceedQuestion, new Object[] { finalMessage }));
}
});
if (!okayToProceed[0]) {
throw new CoreException(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.ProvisioningOperation_unavailableSolutions, detailedMessage), null));
}
}
}
use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.
the class MarketplaceClientUi method computeInstalledFeatures.
public static Set<String> computeInstalledFeatures(IProgressMonitor monitor) {
Map<String, IInstallableUnit> iusById = computeInstalledIUsById(monitor);
Set<String> features = new HashSet<String>(iusById.keySet());
if (features.isEmpty()) {
// probably a self-hosted environment
IBundleGroupProvider[] bundleGroupProviders = Platform.getBundleGroupProviders();
for (IBundleGroupProvider provider : bundleGroupProviders) {
if (monitor.isCanceled()) {
break;
}
IBundleGroup[] bundleGroups = provider.getBundleGroups();
for (IBundleGroup group : bundleGroups) {
String identifier = group.getIdentifier();
if (!identifier.endsWith(DOT_FEATURE_DOT_GROUP)) {
identifier += DOT_FEATURE_DOT_GROUP;
}
features.add(identifier);
}
}
}
return features;
}
use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.
the class MarketplaceClientUi method computeInstalledIUsById.
public static Map<String, IInstallableUnit> computeInstalledIUsById(IProgressMonitor monitor) {
Map<String, IInstallableUnit> iUs = new HashMap<String, IInstallableUnit>();
BundleContext bundleContext = MarketplaceClientUi.getBundleContext();
ServiceReference<IProvisioningAgent> serviceReference = bundleContext.getServiceReference(IProvisioningAgent.class);
if (serviceReference != null) {
IProvisioningAgent agent = bundleContext.getService(serviceReference);
try {
IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
if (profileRegistry != null) {
IProfile profile = profileRegistry.getProfile(ProvisioningUI.getDefaultUI().getProfileId());
if (profile != null) {
IQueryResult<IInstallableUnit> result = profile.available(QueryUtil.createIUGroupQuery(), monitor);
for (IInstallableUnit unit : result) {
iUs.put(unit.getId(), unit);
}
}
}
} finally {
bundleContext.ungetService(serviceReference);
}
}
return iUs;
}
use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.
the class MarketplaceCatalog method checkForUpdates.
protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
Map<URI, List<MarketplaceNodeCatalogItem>> installedCatalogItemsByUpdateUri = new HashMap<URI, List<MarketplaceNodeCatalogItem>>();
for (MarketplaceNodeCatalogItem catalogItem : updateCheckNeeded) {
INode node = catalogItem.getData();
String updateurl = node.getUpdateurl();
try {
if (updateurl == null) {
catalogItem.setAvailable(false);
continue;
}
URI uri = new URI(updateurl);
List<MarketplaceNodeCatalogItem> catalogItemsThisSite = installedCatalogItemsByUpdateUri.get(uri);
if (catalogItemsThisSite == null) {
catalogItemsThisSite = new ArrayList<MarketplaceNodeCatalogItem>();
installedCatalogItemsByUpdateUri.put(uri, catalogItemsThisSite);
}
catalogItemsThisSite.add(catalogItem);
} catch (URISyntaxException e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceCatalog_InvalidRepositoryUrl, node.getName(), updateurl);
catalogItem.setAvailable(false);
}
}
if (installedCatalogItemsByUpdateUri.isEmpty()) {
return Status.OK_STATUS;
}
ConcurrentTaskManager executor = new ConcurrentTaskManager(installedCatalogItemsByUpdateUri.size(), Messages.MarketplaceCatalog_checkingForUpdates);
try {
final IProgressMonitor pm = new NullProgressMonitor() {
@Override
public boolean isCanceled() {
return super.isCanceled() || monitor.isCanceled();
}
};
for (Map.Entry<URI, List<MarketplaceNodeCatalogItem>> entry : installedCatalogItemsByUpdateUri.entrySet()) {
final URI uri = entry.getKey();
final List<MarketplaceNodeCatalogItem> catalogItemsThisSite = entry.getValue();
executor.submit(new Runnable() {
public void run() {
ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
try {
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
if (Boolean.TRUE.equals(item.getAvailable())) {
item.setAvailable(null);
}
}
IMetadataRepository repository = manager.loadRepository(uri, pm);
IQuery<IInstallableUnit> query = //
QueryUtil.createMatchQuery(// $NON-NLS-1$
"id ~= /*.feature.group/ && " + // $NON-NLS-1$
"properties['org.eclipse.equinox.p2.type.group'] == true ");
IQueryResult<IInstallableUnit> result = repository.query(query, pm);
// compute highest version for all available IUs.
Map<String, Version> repositoryIuVersionById = new HashMap<String, Version>();
for (IInstallableUnit iu : result) {
String key = createRepositoryIuKey(uri.toString(), iu.getId());
Version version = iu.getVersion();
Version priorVersion = repositoryIuVersionById.put(key, version);
if (priorVersion != null && priorVersion.compareTo(version) > 0) {
repositoryIuVersionById.put(key, priorVersion);
}
}
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
String key = createRepositoryIuKey(uri.toString(), iuItem.getId());
Version availableVersion = repositoryIuVersionById.get(key);
MarketplaceCatalog.this.repositoryIuVersionById.put(key, availableVersion);
if (availableVersion != null) {
item.setAvailable(true);
}
}
}
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
setUpdatesAvailable(installedIUs, item);
}
} catch (ProvisionException e) {
MultiStatus errorStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, IStatus.WARNING, NLS.bind(Messages.MarketplaceCatalog_ErrorReadingRepository, uri), e);
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
item.setAvailable(false);
errorStatus.add(MarketplaceClientUi.newStatus(IStatus.INFO, item.getName()));
}
MarketplaceClientUi.getLog().log(errorStatus);
} catch (OperationCanceledException e) {
// nothing to do
}
}
});
}
try {
executor.waitUntilFinished(monitor);
} catch (CoreException e) {
MarketplaceClientUi.error(e);
return e.getStatus();
}
return Status.OK_STATUS;
} finally {
executor.shutdownNow();
}
}
use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.
the class MarketplaceCatalog method calculateInstalledIUs.
private Map<String, IInstallableUnit> calculateInstalledIUs(IProgressMonitor monitor) {
Map<String, IInstallableUnit> installedIUs = new HashMap<String, IInstallableUnit>();
List<AbstractDiscoveryStrategy> discoveryStrategies = getDiscoveryStrategies();
SubMonitor progress = SubMonitor.convert(monitor, discoveryStrategies.size() * 1000);
for (AbstractDiscoveryStrategy discoveryStrategy : discoveryStrategies) {
if (monitor.isCanceled()) {
break;
}
SubMonitor childProgress = progress.newChild(1000);
if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
MarketplaceDiscoveryStrategy marketplaceDiscoveryStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
Map<String, IInstallableUnit> ius = marketplaceDiscoveryStrategy.computeInstalledIUs(childProgress);
installedIUs.putAll(ius);
}
childProgress.setWorkRemaining(0);
}
return installedIUs;
}
Aggregations