Search in sources :

Example 1 with ConcurrentTaskManager

use of org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager in project epp.mpc by eclipse.

the class ProvisioningJobListener method done.

@Override
public void done(IJobChangeEvent event) {
    if (event.getResult().isOK()) {
        Job job = new Job(Messages.ProvisioningJobListener_notificationTaskName) {

            {
                setPriority(Job.LONG);
                setSystem(true);
                setUser(true);
            }

            @Override
            protected IStatus run(final IProgressMonitor monitor) {
                ConcurrentTaskManager taskManager = new ConcurrentTaskManager(installItems.size(), Messages.ProvisioningJobListener_notificationTaskName);
                for (CatalogItem item : installItems) {
                    if (item instanceof MarketplaceNodeCatalogItem) {
                        final MarketplaceNodeCatalogItem nodeItem = (MarketplaceNodeCatalogItem) item;
                        taskManager.submit(new Runnable() {

                            public void run() {
                                INode node = nodeItem.getData();
                                URL marketplaceUrl = nodeItem.getMarketplaceUrl();
                                IMarketplaceService marketplaceService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(marketplaceUrl.toString());
                                marketplaceService.reportInstallSuccess(node, new NullProgressMonitor() {

                                    @Override
                                    public boolean isCanceled() {
                                        return monitor.isCanceled();
                                    }
                                });
                            }
                        });
                    }
                }
                try {
                    taskManager.waitUntilFinished(monitor);
                } catch (CoreException e) {
                    return e.getStatus();
                }
                return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
            }
        };
        job.schedule();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentTaskManager(org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager) Job(org.eclipse.core.runtime.jobs.Job) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) URL(java.net.URL)

Example 2 with ConcurrentTaskManager

use of org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager 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();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IQuery(org.eclipse.equinox.p2.query.IQuery) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MultiStatus(org.eclipse.core.runtime.MultiStatus) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) Version(org.eclipse.equinox.p2.metadata.Version) ArrayList(java.util.ArrayList) List(java.util.List) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IQueryResult(org.eclipse.equinox.p2.query.IQueryResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentTaskManager(org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ConcurrentTaskManager (org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager)2 INode (org.eclipse.epp.mpc.core.model.INode)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Job (org.eclipse.core.runtime.jobs.Job)1 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)1 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)1 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)1 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1