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;
}
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;
}
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();
}
}
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);
}
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);
}
Aggregations