Search in sources :

Example 71 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit 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;
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(java.net.URI) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker) HashSet(java.util.HashSet)

Example 72 with IInstallableUnit

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

the class MarketplaceCatalog method checkForUpdates.

public IStatus checkForUpdates(final IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceCatalog_checkingForUpdates, 10000000);
    try {
        Map<String, IInstallableUnit> installedIUs = calculateInstalledIUs(progress.newChild(100000));
        List<MarketplaceNodeCatalogItem> updateCheckNeeded = new ArrayList<MarketplaceNodeCatalogItem>();
        for (CatalogItem item : getItems()) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            if (!(item instanceof MarketplaceNodeCatalogItem)) {
                continue;
            }
            MarketplaceNodeCatalogItem catalogItem = (MarketplaceNodeCatalogItem) item;
            if (catalogItem.isInstalled()) {
                if (setUpdatesAvailable(installedIUs, catalogItem)) {
                    updateCheckNeeded.add(catalogItem);
                }
            }
        }
        if (!updateCheckNeeded.isEmpty()) {
            checkForUpdates(updateCheckNeeded, installedIUs, progress.newChild(10000000 - 100000));
        }
        return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
    } finally {
        monitor.done();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 73 with IInstallableUnit

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

the class ExtensionUpdateSite method getInstallableUnits.

// Get the list of InstallableUnits and all its requirements
protected List<IServerExtension> getInstallableUnits(IMetadataRepository repo, IQuery<IInstallableUnit> query, URI url, IProgressMonitor monitor) {
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    IQueryResult<IInstallableUnit> collector = repo.query(query, monitor);
    for (IInstallableUnit iu : collector.toUnmodifiableSet()) {
        Collection<IRequirement> req = iu.getRequirements();
        if (req != null) {
            for (IRequirement requirement : req) {
                IMatchExpression<IInstallableUnit> matches = requirement.getMatches();
                query = new ExpressionMatchQuery<IInstallableUnit>(IInstallableUnit.class, matches);
                IQueryResult<IInstallableUnit> collector2 = repo.query(query, monitor);
                Iterator<IInstallableUnit> iter2 = collector2.iterator();
                while (iter2.hasNext()) {
                    IInstallableUnit iu2 = iter2.next();
                    if (!list.contains(iu2)) {
                        Extension ext = new Extension(iu2, url);
                        list.add(ext);
                    }
                }
            }
        }
    }
    return list;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 74 with IInstallableUnit

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

the class ExtensionWizardPage method handleSelection.

protected void handleSelection(Extension sel) {
    extension = sel;
    if (extension == null)
        licensePage.updateForPlan(new IInstallableUnit[0], null);
    else {
        try {
            getContainer().run(true, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    final IProvisioningPlan plan = extension.getProvisioningPlan(true, monitor);
                    if (plan != null && plan.getStatus().isOK()) {
                        getShell().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                licensePage.updateForPlan(extension.getIUs(), plan);
                                nextPage = licensePage;
                                ((ExtensionWizard) getWizard()).setSecondPage(nextPage);
                            }
                        });
                    } else {
                        getShell().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                errorPage.setStatus(plan.getStatus());
                            }
                        });
                        nextPage = errorPage;
                        ((ExtensionWizard) getWizard()).setSecondPage(nextPage);
                    }
                    monitor.done();
                }
            });
        } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Error verifying license", e);
        }
    }
    setPageComplete(extension != null);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExtensionWizard(org.eclipse.wst.server.discovery.ExtensionWizard) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProvisioningPlan(org.eclipse.equinox.p2.engine.IProvisioningPlan) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 75 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project azure-tools-for-java by Microsoft.

the class PluginUtil method forceInstallPluginUsingP2.

private static void forceInstallPluginUsingP2(String pluginGroupID) {
    URI repoURI = getEclipseP2Repository();
    ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
    if (provisioningUI != null && repoURI != null) {
        ProvisioningSession provisioningSession = provisioningUI.getSession();
        IProvisioningAgent provisioningAgent = null;
        if (provisioningSession != null && (provisioningAgent = provisioningSession.getProvisioningAgent()) != null) {
            IMetadataRepositoryManager manager = (IMetadataRepositoryManager) provisioningAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
            if (manager != null) {
                try {
                    IMetadataRepository repository = manager.loadRepository(repoURI, null);
                    if (repository != null) {
                        IQueryResult<IInstallableUnit> iqr = repository.query(QueryUtil.createIUQuery(pluginGroupID), null);
                        if (iqr != null) {
                            Collection<IInstallableUnit> iuList = StreamSupport.stream(iqr.spliterator(), false).collect(Collectors.toList());
                            if (iuList.size() > 0) {
                                InstallOperation io = new InstallOperation(provisioningSession, iuList);
                                provisioningUI.openInstallWizard(iuList, io, null);
                                return;
                            }
                        }
                    }
                } catch (Exception e) {
                    String errorMsg = "Error installing " + pluginGroupID + "! Please manually install using Eclipse P2 repository from: Help -> Install New Software.... Click OK to continue.";
                    PluginUtil.displayErrorDialogAndLog(getParentShell(), "Fail to install", errorMsg, e);
                }
            }
        }
    }
    String errorMsg = "Error installing " + pluginGroupID + "! In the following installation wizard, please select the right repository and then filter by " + pluginGroupID + "! Click OK to continue.";
    PluginUtil.displayErrorDialogAndLog(getParentShell(), "Fail to install", errorMsg, null);
    provisioningUI.openInstallWizard(null, null, null);
}
Also used : ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

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