Search in sources :

Example 11 with Update

use of org.eclipse.equinox.p2.operations.Update in project epp.mpc by eclipse.

the class MarketplaceWizard method updateProfileChangeOperation.

public void updateProfileChangeOperation() {
    removeAddedRepositoryLocations();
    addedRepositoryLocations = null;
    profileChangeOperation = null;
    operationIUs = null;
    IWizardContainer wizardContainer = getContainer();
    if (getSelectionModel().computeProvisioningOperationViable()) {
        ProfileChangeOperationComputer provisioningOperation = null;
        try {
            final Map<CatalogItem, Operation> itemToOperation = getSelectionModel().getItemToSelectedOperation();
            final Set<CatalogItem> selectedItems = getSelectionModel().getSelectedCatalogItems();
            OperationType operationType = null;
            for (Map.Entry<CatalogItem, Operation> entry : itemToOperation.entrySet()) {
                if (!selectedItems.contains(entry.getKey())) {
                    continue;
                }
                OperationType entryOperationType = OperationType.map(entry.getValue());
                if (entryOperationType != null) {
                    if (operationType == null || operationType == OperationType.UPDATE || entryOperationType == OperationType.CHANGE) {
                        operationType = entryOperationType;
                    }
                }
            }
            Map<FeatureEntry, Operation> featureEntries = getSelectionModel().getFeatureEntryToOperation(false, false);
            if (operationType == OperationType.CHANGE || operationType == OperationType.UPDATE) {
                Set<OperationType> featureOperations = EnumSet.noneOf(OperationType.class);
                for (Entry<FeatureEntry, Operation> entry : featureEntries.entrySet()) {
                    OperationType operation = OperationType.map(entry.getValue());
                    if (operation != null) {
                        featureOperations.add(operation);
                    }
                }
                if (featureOperations.contains(OperationType.INSTALL) && featureOperations.contains(OperationType.UPDATE)) {
                    // just perform install instead, which covers update
                    featureOperations.remove(OperationType.UPDATE);
                }
                if (featureOperations.size() == 1) {
                    operationType = featureOperations.iterator().next();
                }
            }
            URI dependenciesRepository = null;
            if (getConfiguration().getCatalogDescriptor().getDependenciesRepository() != null) {
                try {
                    dependenciesRepository = getConfiguration().getCatalogDescriptor().getDependenciesRepository().toURI();
                } catch (URISyntaxException e) {
                    throw new InvocationTargetException(e);
                }
            }
            provisioningOperation = new ProfileChangeOperationComputer(operationType, selectedItems, featureEntries.keySet(), dependenciesRepository, getConfiguration().getCatalogDescriptor().isInstallFromAllRepositories() ? ProfileChangeOperationComputer.ResolutionStrategy.FALLBACK_STRATEGY : ProfileChangeOperationComputer.ResolutionStrategy.SELECTED_REPOSITORIES, withRemediation);
            wizardContainer.run(true, true, provisioningOperation);
            profileChangeOperation = provisioningOperation.getOperation();
            operationIUs = provisioningOperation.getIus();
            addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
            operationNewInstallItems = computeNewInstallCatalogItems();
            errorMessage = provisioningOperation.getErrorMessage();
            final IStatus result = profileChangeOperation.getResolutionResult();
            if (result != null && operationIUs != null && operationIUs.length > 0 && operationType == OperationType.INSTALL) {
                switch(result.getSeverity()) {
                    case IStatus.ERROR:
                        Job job = new Job(Messages.MarketplaceWizard_errorNotificationJob) {

                            IStatus r = result;

                            Set<CatalogItem> items = new HashSet<CatalogItem>(itemToOperation.keySet());

                            IInstallableUnit[] ius = operationIUs;

                            String details = profileChangeOperation.getResolutionDetails();

                            {
                                setSystem(false);
                                setUser(false);
                                setPriority(LONG);
                            }

                            @Override
                            protected IStatus run(IProgressMonitor monitor) {
                                getCatalog().installErrorReport(monitor, r, items, ius, details);
                                return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                }
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            IStatus status;
            if (cause instanceof CoreException) {
                status = ((CoreException) cause).getStatus();
            } else {
                status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.MarketplaceWizard_problemsPerformingProvisioningOperation, new Object[] { cause.getMessage() }), cause);
            }
            MarketplaceClientUi.handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
        } catch (InterruptedException e) {
            // canceled
            MarketplaceClientUi.log(IStatus.CANCEL, MarketplaceClientUi.BUNDLE_ID, Messages.MarketplaceWizard_ProvisioningOperationCancelled, e);
        } finally {
            if (provisioningOperation != null) {
                addedRepositoryLocations = provisioningOperation.getAddedRepositoryLocations();
            }
        }
    }
    // re-get the container - in case the wizard was closed in the meantime, this will be null...
    wizardContainer = getContainer();
    if (wizardContainer != null && wizardContainer.getCurrentPage() == featureSelectionWizardPage) {
        featureSelectionWizardPage.updateMessage();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) AbstractProvisioningOperation(org.eclipse.epp.internal.mpc.ui.operations.AbstractProvisioningOperation) RemediationOperation(org.eclipse.equinox.p2.operations.RemediationOperation) ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) UninstallOperation(org.eclipse.equinox.p2.operations.UninstallOperation) Operation(org.eclipse.epp.mpc.ui.Operation) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) Job(org.eclipse.core.runtime.jobs.Job) ProvisioningJob(org.eclipse.equinox.p2.operations.ProvisioningJob) ProfileChangeOperationComputer(org.eclipse.epp.internal.mpc.ui.operations.ProfileChangeOperationComputer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationType(org.eclipse.epp.internal.mpc.ui.operations.ProfileChangeOperationComputer.OperationType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Update

use of org.eclipse.equinox.p2.operations.Update in project epp.mpc by eclipse.

the class ProfileChangeOperationComputer method run.

public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
    try {
        boolean hasInstall = hasInstall();
        boolean hasUninstall = hasUninstall();
        SubMonitor monitor = SubMonitor.convert(progressMonitor, Messages.ProvisioningOperation_configuringProvisioningOperation, 1000 + (hasInstall ? 500 : 0) + (hasUninstall ? 100 : 0));
        try {
            IInstallableUnit[] uninstallIUs = null;
            if (hasInstall) {
                ius = computeInstallableUnits(monitor.newChild(500));
            } else {
                ius = new IInstallableUnit[0];
            }
            if (hasUninstall) {
                uninstallIUs = computeUninstallUnits(monitor.newChild(100));
            }
            checkCancelled(monitor);
            URI[] repositories = repositoryLocations == null ? new URI[0] : repositoryLocations.toArray(new URI[0]);
            switch(operationType) {
                case INSTALL:
                    operation = resolveInstall(monitor.newChild(500), ius, repositories);
                    break;
                case UPDATE:
                    operation = resolveUpdate(monitor.newChild(500), computeInstalledIus(ius), repositories);
                    break;
                case UNINSTALL:
                    operation = resolveUninstall(monitor.newChild(500), uninstallIUs, repositories);
                    break;
                case CHANGE:
                    operation = resolveChange(monitor.newChild(500), ius, uninstallIUs, repositories);
                    break;
                default:
                    throw new UnsupportedOperationException(operationType.name());
            }
            if (withRemediation && operation != null && operation.getResolutionResult().getSeverity() == IStatus.ERROR) {
                RemediationOperation remediationOperation = new RemediationOperation(ProvisioningUI.getDefaultUI().getSession(), operation.getProfileChangeRequest());
                remediationOperation.resolveModal(monitor.newChild(500));
                if (remediationOperation.getResolutionResult() == Status.OK_STATUS) {
                    errorMessage = operation.getResolutionDetails();
                    operation = remediationOperation;
                }
            }
            checkCancelled(monitor);
        } finally {
            monitor.done();
        }
    } catch (OperationCanceledException e) {
        throw new InterruptedException();
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    }
}
Also used : RemediationOperation(org.eclipse.equinox.p2.operations.RemediationOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with Update

use of org.eclipse.equinox.p2.operations.Update in project archi by archimatetool.

the class P2Handler method update.

public IStatus update(URI uri, IProgressMonitor monitor) throws ProvisionException {
    loadRepository(uri, monitor);
    UpdateOperation operation = new UpdateOperation(getProvisioningSession());
    return performOperation(operation, monitor);
}
Also used : UpdateOperation(org.eclipse.equinox.p2.operations.UpdateOperation)

Example 14 with Update

use of org.eclipse.equinox.p2.operations.Update in project tycho by eclipse.

the class RemoteMetadataRepositoryManager method failIfRepositoryContainsPartialIUs.

private void failIfRepositoryContainsPartialIUs(IMetadataRepository repository, URI effectiveLocation) throws ProvisionException {
    IQueryResult<IInstallableUnit> allUnits = repository.query(QueryUtil.ALL_UNITS, null);
    boolean hasPartialIUs = false;
    for (IInstallableUnit unit : allUnits.toUnmodifiableSet()) {
        if (Boolean.valueOf(unit.getProperty(IInstallableUnit.PROP_PARTIAL_IU))) {
            hasPartialIUs = true;
            logger.error("Partial IU: " + unit.getId());
        }
    }
    if (hasPartialIUs) {
        String message = "The p2 repository at " + effectiveLocation + " contains partial IUs (see above) from an old style update site which cannot be used for dependency resolution";
        throw new ProvisionException(message);
    }
}
Also used : ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

UpdateOperation (org.eclipse.equinox.p2.operations.UpdateOperation)5 URI (java.net.URI)4 CoreException (org.eclipse.core.runtime.CoreException)4 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 IStatus (org.eclipse.core.runtime.IStatus)3 UpdateSingleIUWizard (org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard)3 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)3 Update (org.eclipse.equinox.p2.operations.Update)3 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 BundleContext (org.osgi.framework.BundleContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URISyntaxException (java.net.URISyntaxException)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 AvailableUpdateElement (org.eclipse.equinox.internal.p2.ui.model.AvailableUpdateElement)2 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)2 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1