Search in sources :

Example 1 with ProfileChangeOperation

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

the class MarketplaceWizard method performFinish.

@Override
public boolean performFinish() {
    if (profileChangeOperation != null && profileChangeOperation.getResolutionResult().getSeverity() != IStatus.ERROR) {
        if (computeMustCheckLicenseAcceptance()) {
            if (acceptLicensesPage != null && acceptLicensesPage.isPageComplete()) {
                acceptLicensesPage.performFinish();
            }
        }
        ProvisioningJob provisioningJob = profileChangeOperation.getProvisioningJob(null);
        if (provisioningJob != null) {
            if (!operationNewInstallItems.isEmpty()) {
                provisioningJob.addJobChangeListener(new ProvisioningJobListener(operationNewInstallItems));
            }
            ProvisioningUI.getDefaultUI().schedule(provisioningJob, StatusManager.SHOW | StatusManager.LOG);
            addedRepositoryLocations = null;
            return true;
        }
    }
    return false;
}
Also used : ProvisioningJob(org.eclipse.equinox.p2.operations.ProvisioningJob)

Example 2 with ProfileChangeOperation

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

the class ProfileChangeOperationComputer method resolve.

private ProfileChangeOperation resolve(IProgressMonitor monitor, ProfileChangeOperationFactory operationFactory, IInstallableUnit[] ius, URI[] repositories) throws CoreException {
    List<IInstallableUnit> installableUnits = Arrays.asList(ius);
    List<ResolutionStrategy> strategies = new ArrayList<ProfileChangeOperationComputer.ResolutionStrategy>(2);
    switch(resolutionStrategy) {
        case FALLBACK_STRATEGY:
            strategies.add(ResolutionStrategy.SELECTED_REPOSITORIES);
            strategies.add(ResolutionStrategy.ALL_REPOSITORIES);
            break;
        default:
            strategies.add(resolutionStrategy);
    }
    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
    RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
    URI[] knownRepositories = repositoryTracker.getKnownRepositories(session);
    ProfileChangeOperation operation = null;
    final int workPerStrategy = 1000;
    SubMonitor subMonitor = SubMonitor.convert(monitor, strategies.size() * workPerStrategy + workPerStrategy);
    Set<URI> previousRepositoryLocations = null;
    for (ResolutionStrategy strategy : strategies) {
        Set<URI> repositoryLocations = new HashSet<URI>(Arrays.asList(repositories));
        if (strategy == ResolutionStrategy.SELECTED_REPOSITORIES) {
            repositoryLocations.addAll(Arrays.asList(repositories));
        }
        if (dependenciesRepository != null) {
            repositoryLocations.add(dependenciesRepository);
        }
        if (strategy == ResolutionStrategy.ALL_REPOSITORIES && !repositoryLocations.isEmpty()) {
            repositoryLocations.addAll(Arrays.asList(knownRepositories));
        }
        if (repositoryLocations.equals(previousRepositoryLocations)) {
            continue;
        }
        operation = operationFactory.create(installableUnits);
        if (!repositoryLocations.isEmpty()) {
            URI[] locations = repositoryLocations.toArray(new URI[repositoryLocations.size()]);
            operation.getProvisioningContext().setMetadataRepositories(locations);
            operation.getProvisioningContext().setArtifactRepositories(locations);
        }
        resolveModal(subMonitor.newChild(workPerStrategy), operation);
        if (operation.getResolutionResult() != null && operation.getResolutionResult().getSeverity() != IStatus.ERROR) {
            break;
        }
        previousRepositoryLocations = repositoryLocations;
    }
    return operation;
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(java.net.URI) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker) HashSet(java.util.HashSet)

Example 3 with ProfileChangeOperation

use of org.eclipse.equinox.p2.operations.ProfileChangeOperation 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 4 with ProfileChangeOperation

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

the class MarketplaceWizard method getNextPage.

IWizardPage getNextPage(IWizardPage page, boolean nextpressed) {
    boolean skipFeatureSelection = false;
    MarketplacePage catalogPage = getCatalogPage();
    if (page == catalogPage && nextpressed) {
        profileChangeOperation = null;
        featureSelectionWizardPage.updateMessage();
        if (catalogPage.canSkipFeatureSelection()) {
            skipFeatureSelection = true;
        }
    }
    if (page == featureSelectionWizardPage || (page == catalogPage && skipFeatureSelection)) {
        IWizardContainer container = getContainer();
        if (nextpressed && profileChangeOperation != null && profileChangeOperation instanceof RemediationOperation) {
            try {
                container.run(true, false, new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor) {
                        ((RemediationOperation) profileChangeOperation).setCurrentRemedy(featureSelectionWizardPage.getRemediationGroup().getCurrentRemedy());
                        profileChangeOperation.resolveModal(monitor);
                    }
                });
            } catch (InterruptedException e) {
            // Nothing to report if thread was interrupted
            } catch (InvocationTargetException e) {
                ProvUI.handleException(e.getCause(), null, StatusManager.SHOW | StatusManager.LOG);
            }
        }
        IWizardPage nextPage = null;
        boolean operationUpdated = false;
        if (profileChangeOperation == null) {
            if (nextpressed) {
                updateProfileChangeOperation();
                operationUpdated = true;
            }
            if (profileChangeOperation == null || !profileChangeOperation.getResolutionResult().isOK()) {
                // can't compute a change operation, so there must be some kind of error
                // we show these on the the feature selection wizard page
                nextPage = featureSelectionWizardPage;
            } else if (profileChangeOperation instanceof UninstallOperation) {
                // next button was used to resolve errors on an uninstall.
                // by returning the same page the finish button will be enabled, allowing the user to finish.
                nextPage = featureSelectionWizardPage;
            } else if (profileChangeOperation instanceof RemediationOperation) {
                nextPage = featureSelectionWizardPage;
            }
        }
        if (nextPage == null && nextpressed && profileChangeOperation instanceof RemediationOperation && !featureSelectionWizardPage.isInRemediationMode()) {
            featureSelectionWizardPage.flipToRemediationComposite();
            nextPage = featureSelectionWizardPage;
        }
        if (nextPage == null && computeMustCheckLicenseAcceptance()) {
            if (acceptLicensesPage == null) {
                acceptLicensesPage = new AcceptLicensesWizardPage(ProvisioningUI.getDefaultUI().getLicenseManager(), operationIUs, profileChangeOperation);
                addPage(acceptLicensesPage);
            } else {
                acceptLicensesPage.update(operationIUs, profileChangeOperation);
            }
            if (nextpressed || acceptLicensesPage.hasLicensesToAccept() || profileChangeOperation instanceof RemediationOperation) {
                nextPage = acceptLicensesPage;
            }
        }
        if (nextPage == null && page == catalogPage) {
            nextPage = featureSelectionWizardPage;
        }
        if (operationUpdated && nextPage == container.getCurrentPage()) {
            container.updateButtons();
        }
        return nextPage;
    }
    if (page instanceof ImportFavoritesPage) {
        return catalogPage;
    }
    return getNextPageInList(page);
}
Also used : IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AcceptLicensesWizardPage(org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage) RemediationOperation(org.eclipse.equinox.p2.operations.RemediationOperation) UninstallOperation(org.eclipse.equinox.p2.operations.UninstallOperation) IWizardPage(org.eclipse.jface.wizard.IWizardPage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 5 with ProfileChangeOperation

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

the class FeatureSelectionWizardPage method updateMessage.

void updateMessage() {
    ProfileChangeOperation profileChangeOperation = getWizard().getProfileChangeOperation();
    if (profileChangeOperation != null) {
        if (profileChangeOperation instanceof RemediationOperation && ((RemediationOperation) profileChangeOperation).getResolutionResult() == Status.OK_STATUS) {
            if (remediationGroup == null) {
                remediationGroup = new RemediationGroup(this);
                remediationGroup.createRemediationControl(container);
            }
            setMessage(remediationGroup.getMessage(), IStatus.WARNING);
            remediationGroup.getDetailsGroup().setDetailText(getWizard().getErrorMessage());
            remediationGroup.update((RemediationOperation) profileChangeOperation);
            flipToRemediationComposite();
        } else {
            IStatus resolutionResult = profileChangeOperation.getResolutionResult();
            if (!resolutionResult.isOK()) {
                String message = resolutionResult.getMessage();
                if (resolutionResult.getSeverity() == IStatus.ERROR) {
                    message = Messages.FeatureSelectionWizardPage_provisioningErrorAdvisory;
                } else if (resolutionResult.getSeverity() == IStatus.WARNING) {
                    message = Messages.FeatureSelectionWizardPage_provisioningWarningAdvisory;
                }
                setMessage(message, Util.computeMessageType(resolutionResult));
                // avoid gratuitous scrolling
                String originalText = detailStatusText.getText();
                String newText;
                try {
                    newText = profileChangeOperation.getResolutionDetails();
                } catch (Exception e) {
                    // sometimes p2 might throw an exception
                    MarketplaceClientUi.error(e);
                    newText = Messages.FeatureSelectionWizardPage_detailsUnavailable;
                }
                if (newText != originalText || (newText != null && !newText.equals(originalText))) {
                    detailStatusText.setText(newText);
                }
                ((GridData) detailsControl.getLayoutData()).exclude = false;
            } else {
                setMessage(null, IMessageProvider.NONE);
                ((GridData) detailsControl.getLayoutData()).exclude = true;
            }
        }
    } else {
        setMessage(null, IMessageProvider.NONE);
        ((GridData) detailsControl.getLayoutData()).exclude = true;
    }
    ((Composite) getControl()).layout(true);
    defaultComposite.layout(true);
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) RemediationOperation(org.eclipse.equinox.p2.operations.RemediationOperation) StyledString(org.eclipse.jface.viewers.StyledString) RemediationGroup(org.eclipse.equinox.internal.p2.ui.dialogs.RemediationGroup) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)4 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 ProfileChangeRequest (org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 ProvisioningJob (org.eclipse.equinox.p2.operations.ProvisioningJob)2 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)2 IProfileChangeRequest (org.eclipse.equinox.p2.planner.IProfileChangeRequest)2 IWizardContainer (org.eclipse.jface.wizard.IWizardContainer)2 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1