Search in sources :

Example 16 with Operation

use of org.eclipse.epp.mpc.ui.Operation 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 17 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class ProfileChangeOperationComputer method checkForUnavailable.

/**
 * Verifies that we found what we were looking for: it's possible that we have connector descriptors that are no
 * longer available on their respective sites. In that case we must inform the user. Unfortunately this is the
 * earliest point at which we can know.
 */
private void checkForUnavailable(final List<IInstallableUnit> installableUnits) throws CoreException {
    // at least one selected connector could not be found in a repository
    Set<String> foundIds = new HashSet<String>();
    for (IInstallableUnit unit : installableUnits) {
        foundIds.add(unit.getId());
    }
    Set<String> installFeatureIds = new HashSet<String>();
    for (FeatureEntry entry : featureEntries) {
        Operation operation = entry.computeChangeOperation();
        if (operation == Operation.INSTALL || operation == Operation.UPDATE) {
            installFeatureIds.add(entry.getFeatureDescriptor().getId());
        }
    }
    // $NON-NLS-1$
    String message = "";
    // $NON-NLS-1$
    String detailedMessage = "";
    for (CatalogItem descriptor : items) {
        StringBuilder unavailableIds = null;
        for (String id : getFeatureIds(descriptor)) {
            if (!foundIds.contains(id) && installFeatureIds.contains(id)) {
                if (unavailableIds == null) {
                    unavailableIds = new StringBuilder();
                } else {
                    unavailableIds.append(Messages.ProvisioningOperation_commaSeparator);
                }
                unavailableIds.append(id);
            }
        }
        if (unavailableIds != null) {
            if (message.length() > 0) {
                message += Messages.ProvisioningOperation_commaSeparator;
            }
            message += descriptor.getName();
            if (detailedMessage.length() > 0) {
                detailedMessage += Messages.ProvisioningOperation_commaSeparator;
            }
            detailedMessage += NLS.bind(Messages.ProvisioningOperation_unavailableFeatures, new Object[] { descriptor.getName(), unavailableIds.toString(), descriptor.getSiteUrl() });
        }
    }
    if (message.length() > 0) {
        // instead of aborting here we ask the user if they wish to proceed anyways
        final boolean[] okayToProceed = new boolean[1];
        final String finalMessage = message;
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                okayToProceed[0] = MessageDialog.openQuestion(WorkbenchUtil.getShell(), Messages.ProvisioningOperation_proceedQuestion, NLS.bind(Messages.ProvisioningOperation_unavailableSolutions_proceedQuestion, new Object[] { finalMessage }));
            }
        });
        if (!okayToProceed[0]) {
            throw new CoreException(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.ProvisioningOperation_unavailableSolutions, detailedMessage), null));
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) 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) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) CoreException(org.eclipse.core.runtime.CoreException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 18 with Operation

use of org.eclipse.epp.mpc.ui.Operation in project epp.mpc by eclipse.

the class SelectionModelStateSerializerTest method testSerialize.

// (expected=AssertionError.class)//FIXME bug 487157: disabled until entries declare Neon compatibility
@Test
@Category(RemoteTests.class)
public void testSerialize() {
    catalog.performDiscovery(new NullProgressMonitor());
    assertFalse(catalog.getItems().isEmpty());
    assertTrue(catalog.getItems().size() > 4);
    // first two are promoted downloads, which might not be installable in current target
    CatalogItem firstItem = catalog.getItems().get(2);
    CatalogItem secondItem = catalog.getItems().get(3);
    assertThat(firstItem.getDescription(), not(startsWith(PROMOTED_MARKER)));
    assertThat(secondItem.getDescription(), not(startsWith(PROMOTED_MARKER)));
    assertThat(firstItem.getInstallableUnits(), not(empty()));
    assertThat(secondItem.getInstallableUnits(), not(empty()));
    selectionModel.select(firstItem, Operation.INSTALL);
    selectionModel.select(secondItem, Operation.INSTALL);
    SelectionModelStateSerializer serializer = new SelectionModelStateSerializer(catalog, selectionModel);
    String state = serializer.serialize();
    assertNotNull(state);
    assertFalse(state.trim().length() == 0);
    assertTrue(selectionModel.computeProvisioningOperationViable());
    selectionModel.clear();
    assertTrue(selectionModel.getItemToSelectedOperation().isEmpty());
    assertFalse(selectionModel.computeProvisioningOperationViable());
    serializer.deserialize(state, new NullProgressMonitor());
    assertEquals(2, selectionModel.getItemToSelectedOperation().size());
    assertTrue(selectionModel.computeProvisioningOperationViable());
    Map<CatalogItem, Operation> itemToOperation = selectionModel.getItemToSelectedOperation();
    assertEquals(Operation.INSTALL, itemToOperation.get(firstItem));
    assertEquals(Operation.INSTALL, itemToOperation.get(secondItem));
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SelectionModelStateSerializer(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModelStateSerializer) Operation(org.eclipse.epp.mpc.ui.Operation) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Operation (org.eclipse.epp.mpc.ui.Operation)18 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)9 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)8 HashMap (java.util.HashMap)6 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)6 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)6 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)6 IStatus (org.eclipse.core.runtime.IStatus)5 CoreException (org.eclipse.core.runtime.CoreException)4 Status (org.eclipse.core.runtime.Status)4 AbstractProvisioningOperation (org.eclipse.epp.internal.mpc.ui.operations.AbstractProvisioningOperation)4 FeatureEntry (org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Entry (java.util.Map.Entry)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 InstallOperation (org.eclipse.equinox.p2.operations.InstallOperation)2