Search in sources :

Example 81 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit 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 82 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project webtools.servertools by eclipse.

the class ExtensionWizard method addPages.

public void addPages() {
    super.addPages();
    ProvisioningUI ui = ProvisioningUI.getDefaultUI();
    licensePage = new AcceptLicensesWizardPage(ui.getLicenseManager(), new IInstallableUnit[0], null);
    licensePage.setWizard(this);
    errorPage = new ErrorWizardPage();
    errorPage.setWizard(this);
    extensionPage = new ExtensionWizardPage(licensePage, errorPage);
    extensionPage.setWizard(this);
}
Also used : ExtensionWizardPage(org.eclipse.wst.server.discovery.internal.wizard.ExtensionWizardPage) ErrorWizardPage(org.eclipse.wst.server.discovery.internal.wizard.ErrorWizardPage) AcceptLicensesWizardPage(org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 83 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method installErrorReport.

public void installErrorReport(IProgressMonitor monitor, IStatus result, Set<CatalogItem> items, IInstallableUnit[] operationIUs, String resolutionDetails) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_sendingErrorNotification, 100);
    try {
        Set<Node> nodes = new HashSet<Node>();
        for (CatalogItem item : items) {
            Object data = item.getData();
            if (data instanceof INode) {
                nodes.add((Node) data);
            }
        }
        Set<String> iuIdsAndVersions = new HashSet<String>();
        for (IInstallableUnit iu : operationIUs) {
            String id = iu.getId();
            String version = iu.getVersion() == null ? null : iu.getVersion().toString();
            // $NON-NLS-1$
            iuIdsAndVersions.add(id + "," + version);
        }
        marketplaceService.reportInstallError(result, nodes, iuIdsAndVersions, resolutionDetails, progress);
    } finally {
        progress.done();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 84 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.

the class MarketplaceInfo method computeInstalledNodes.

/**
 * Calculate the known catalog nodes that might be installed. Since no remote query should happen, this only checks
 * if any one of the IUs for a node are installed.
 *
 * @param repositoryUrl
 *            the catalog url for which installed nodes should be computed
 * @param installedIus
 *            all of the currently installed IUs
 * @return a set of node ids, or an empty set if there are no known installed nodes
 */
public synchronized Set<INode> computeInstalledNodes(URL repositoryUrl, Map<String, IInstallableUnit> installedIus) {
    Set<INode> nodes = new HashSet<INode>();
    String keyPrefix = computeUrlKey(repositoryUrl) + '#';
    for (Map.Entry<String, List<String>> entry : nodeKeyToIU.entrySet()) {
        if (entry.getKey().startsWith(keyPrefix)) {
            List<String> ius = nodeKeyToIU.get(entry.getKey());
            if (computeInstalled(installedIus.keySet(), ius, false)) {
                String nodeId = entry.getKey().substring(keyPrefix.length());
                INode node = QueryHelper.nodeById(nodeId);
                nodes.add(node);
            }
        }
    }
    for (IInstallableUnit iu : installedIus.values()) {
        String nodeUrl = iu.getProperty(MPC_NODE_IU_PROPERTY);
        if (nodeUrl != null && nodeUrl.startsWith(repositoryUrl.toString())) {
            INode node = QueryHelper.nodeByUrl(nodeUrl);
            nodes.add(node);
        }
    }
    return nodes;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ArrayList(java.util.ArrayList) List(java.util.List) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 85 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.

the class AbstractProvisioningOperation method queryInstallableUnits.

/**
 * Perform a query to get the installable units. This causes p2 to determine what features are available in each
 * repository. We select installable units by matching both the feature id and the repository; it is possible though
 * unlikely that the same feature id is available from more than one of the selected repositories, and we must
 * ensure that the user gets the one that they asked for.
 */
protected List<IInstallableUnit> queryInstallableUnits(SubMonitor monitor, List<IMetadataRepository> repositories) throws URISyntaxException {
    final List<IInstallableUnit> installableUnits = new ArrayList<IInstallableUnit>();
    monitor.setWorkRemaining(repositories.size());
    for (final IMetadataRepository repository : repositories) {
        checkCancelled(monitor);
        final Set<String> installableUnitIdsThisRepository = getDescriptorIds(repository);
        IQuery<IInstallableUnit> query = QueryUtil.createLatestQuery(QueryUtil.createIUGroupQuery());
        IQueryResult<IInstallableUnit> result = repository.query(query, monitor.newChild(1));
        for (IInstallableUnit iu : result) {
            String id = iu.getId();
            if (installableUnitIdsThisRepository.contains(id)) {
                installableUnits.add(iu);
            }
        }
    }
    return installableUnits;
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)153 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)44 File (java.io.File)38 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)25 HashSet (java.util.HashSet)18 IStatus (org.eclipse.core.runtime.IStatus)18 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)16 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)11 CoreException (org.eclipse.core.runtime.CoreException)11 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)11 ResourceUtil.resourceFile (org.eclipse.tycho.p2.tools.test.util.ResourceUtil.resourceFile)11 URI (java.net.URI)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)9 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)9 Status (org.eclipse.core.runtime.Status)8 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8