Search in sources :

Example 1 with FeatureEntry

use of org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry in project epp.mpc by eclipse.

the class MarketplaceWizard method computeNewInstallCatalogItems.

private Set<CatalogItem> computeNewInstallCatalogItems() {
    Set<CatalogItem> items = new HashSet<CatalogItem>();
    Map<CatalogItem, Collection<String>> iusByCatalogItem = new HashMap<CatalogItem, Collection<String>>();
    for (CatalogItemEntry entry : getSelectionModel().getCatalogItemEntries()) {
        List<FeatureEntry> features = entry.getChildren();
        Collection<String> featureIds = new ArrayList<String>(features.size());
        for (FeatureEntry feature : features) {
            if (feature.computeChangeOperation() == Operation.INSTALL) {
                featureIds.add(feature.getFeatureDescriptor().getId());
            }
        }
        if (!featureIds.isEmpty()) {
            iusByCatalogItem.put(entry.getItem(), featureIds);
        }
    }
    for (IInstallableUnit unit : operationIUs) {
        for (Entry<CatalogItem, Collection<String>> entry : iusByCatalogItem.entrySet()) {
            if (entry.getValue().contains(unit.getId())) {
                items.add(entry.getKey());
            }
        }
    }
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) Collection(java.util.Collection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 2 with FeatureEntry

use of org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry in project tycho by eclipse.

the class FeatureDependenciesAction method getVersionRange.

/**
 * Copy&Paste from 3.7
 * org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction.getVersionRange(FeatureEntry)
 */
private VersionRange getVersionRange(FeatureEntry entry) {
    String versionSpec = entry.getVersion();
    if (versionSpec == null)
        return VersionRange.emptyRange;
    String match = entry.getMatch();
    if (// $NON-NLS-1$
    "versionRange".equals(match))
        return new VersionRange(versionSpec);
    Version version = Version.parseVersion(versionSpec);
    if (version.equals(Version.emptyVersion))
        return VersionRange.emptyRange;
    if (!entry.isRequires())
        return new VersionRange(version, true, version, true);
    if (match == null)
        // TODO should really be returning VersionRange.emptyRange here...
        return null;
    if (// $NON-NLS-1$
    match.equals("perfect"))
        return new VersionRange(version, true, version, true);
    org.osgi.framework.Version osgiVersion = PublisherHelper.toOSGiVersion(version);
    if (match.equals("equivalent")) {
        // $NON-NLS-1$
        Version upper = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor() + 1, 0);
        return new VersionRange(version, true, upper, false);
    }
    if (match.equals("compatible")) {
        // $NON-NLS-1$
        Version upper = Version.createOSGi(osgiVersion.getMajor() + 1, 0, 0);
        return new VersionRange(version, true, upper, false);
    }
    if (// $NON-NLS-1$
    match.equals("greaterOrEqual"))
        return new VersionRange(version, true, new VersionRange(null).getMaximum(), true);
    return null;
}
Also used : Version(org.eclipse.equinox.p2.metadata.Version) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange)

Example 3 with FeatureEntry

use of org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry in project tycho by eclipse.

the class ProductDependenciesAction method getRequiredCapabilities.

@Override
protected Set<IRequirement> getRequiredCapabilities() {
    Set<IRequirement> required = new LinkedHashSet<>();
    if (product.useFeatures()) {
        for (IVersionedId feature : product.getFeatures()) {
            // $NON-NLS-1$
            String id = feature.getId() + FEATURE_GROUP_IU_SUFFIX;
            Version version = feature.getVersion();
            addRequiredCapability(required, id, version, null, false);
        }
    } else {
        for (FeatureEntry plugin : ((ProductFile) product).getProductEntries()) {
            addRequiredCapability(required, plugin.getId(), Version.parseVersion(plugin.getVersion()), null, true);
        }
    }
    if (product.includeLaunchers()) {
        addRequiredCapability(required, "org.eclipse.equinox.executable.feature.group", null, null, false);
    }
    return required;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) LinkedHashSet(java.util.LinkedHashSet) FeatureEntry(org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry) ProductFile(org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile) IVersionedId(org.eclipse.equinox.p2.metadata.IVersionedId) Version(org.eclipse.equinox.p2.metadata.Version)

Example 4 with FeatureEntry

use of org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry in project tycho by eclipse.

the class ProductFile2 method processPlugin.

@Override
protected void processPlugin(Attributes attributes) {
    String fragment = attributes.getValue(ATTRIBUTE_FRAGMENT);
    String pluginId = attributes.getValue(ATTRIBUTE_ID);
    String pluginVersion = attributes.getValue(ATTRIBUTE_VERSION);
    boolean isFragment = Boolean.valueOf(fragment);
    FeatureEntry entry = new FeatureEntry(pluginId, pluginVersion != null ? pluginVersion : GENERIC_VERSION_NUMBER, true);
    entry.setFragment(isFragment);
    String os = attributes.getValue(ATTRIBUTE_OS);
    String ws = attributes.getValue(ATTRIBUTE_WS);
    String arch = attributes.getValue(ATTRIBUTE_ARCH);
    if (os != null || ws != null || arch != null) {
        entry.setEnvironment(os, ws, arch, null);
    }
    if (isFragment) {
        fragments.add(entry);
    } else {
        plugins.add(entry);
    }
}
Also used : FeatureEntry(org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry)

Example 5 with FeatureEntry

use of org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry 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)

Aggregations

HashSet (java.util.HashSet)5 FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 FeatureEntry (org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry)4 Operation (org.eclipse.epp.mpc.ui.Operation)3 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)3 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)3 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)3 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)2 Version (org.eclipse.equinox.p2.metadata.Version)2 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)2 InstallOperation (org.eclipse.equinox.p2.operations.InstallOperation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1