Search in sources :

Example 86 with IInstallableUnit

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

the class ProfileChangeOperationComputer method computeInstalledIus.

private IInstallableUnit[] computeInstalledIus(IInstallableUnit[] ius) {
    List<IInstallableUnit> installedIus = new ArrayList<IInstallableUnit>(ius.length);
    Map<String, IInstallableUnit> iUsById = MarketplaceClientUi.computeInstalledIUsById(new NullProgressMonitor());
    for (IInstallableUnit iu : ius) {
        IInstallableUnit installedIu = iUsById.get(iu.getId());
        installedIus.add(installedIu);
    }
    return installedIus.toArray(new IInstallableUnit[installedIus.size()]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 87 with IInstallableUnit

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

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

the class ProfileChangeOperationComputer method pruneNonInstall.

private void pruneNonInstall(List<IInstallableUnit> installableUnits) {
    Set<String> installableFeatureIds = new HashSet<String>();
    for (FeatureEntry featureEntry : featureEntries) {
        Operation operation = featureEntry.computeChangeOperation();
        if (operation == Operation.INSTALL || operation == Operation.UPDATE) {
            installableFeatureIds.add(featureEntry.getFeatureDescriptor().getId());
        }
    }
    Iterator<IInstallableUnit> it = installableUnits.iterator();
    while (it.hasNext()) {
        IInstallableUnit iu = it.next();
        if (!installableFeatureIds.contains(iu.getId())) {
            it.remove();
        }
    }
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) 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) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) HashSet(java.util.HashSet)

Example 89 with IInstallableUnit

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

the class ProfileChangeOperationComputer method computeInstallableUnits.

public IInstallableUnit[] computeInstallableUnits(IProgressMonitor monitor) throws CoreException {
    try {
        SubMonitor progress = SubMonitor.convert(monitor, 100);
        // add repository urls and load meta data
        List<IMetadataRepository> repositories = addRepositories(progress.newChild(50));
        List<IInstallableUnit> installableUnits = queryInstallableUnits(progress.newChild(50), repositories);
        checkForUnavailable(installableUnits);
        pruneNonInstall(installableUnits);
        // bug 306446 we never want to downgrade the installed version
        pruneOlderVersions(installableUnits);
        return installableUnits.toArray(new IInstallableUnit[installableUnits.size()]);
    } catch (URISyntaxException e) {
        // should never happen, since we already validated URLs.
        throw new CoreException(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.ProvisioningOperation_unexpectedErrorUrl, e));
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) URISyntaxException(java.net.URISyntaxException) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 90 with IInstallableUnit

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

the class ProfileChangeOperationComputer method pruneNonUninstall.

private void pruneNonUninstall(List<IInstallableUnit> installableUnits) {
    Set<String> installableFeatureIds = new HashSet<String>();
    for (FeatureEntry featureEntry : featureEntries) {
        if (featureEntry.computeChangeOperation() == Operation.UNINSTALL) {
            installableFeatureIds.add(featureEntry.getFeatureDescriptor().getId());
        }
    }
    Iterator<IInstallableUnit> it = installableUnits.iterator();
    while (it.hasNext()) {
        IInstallableUnit iu = it.next();
        if (!installableFeatureIds.contains(iu.getId())) {
            it.remove();
        }
    }
}
Also used : FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

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