Search in sources :

Example 1 with InstallableUnit

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

the class MarketplaceCatalogTest method setupCatalog.

protected void setupCatalog() throws MalformedURLException {
    final SearchResult discoveryResult = new SearchResult();
    discoveryResult.setNodes(discoveryNodes);
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
    catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
    MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        final MarketplaceCategory category = new MarketplaceCategory();

        {
            category.setId("<root>");
        }

        @Override
        public void performDiscovery(IProgressMonitor monitor) throws CoreException {
            if (!categories.contains(category)) {
                categories.add(category);
            }
            handleSearchResult(category, discoveryResult, new NullProgressMonitor());
        }

        @Override
        protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
            Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
            for (INode node : installedNodes) {
                IIus ius = node.getIus();
                if (ius != null) {
                    for (IIu iu : ius.getIuElements()) {
                        String featureId = iu.getId() + ".feature.group";
                        InstallableUnit installableUnit = new InstallableUnit();
                        installableUnit.setId(featureId);
                        installedIus.put(featureId, installableUnit);
                    }
                }
            }
            return installedIus;
        }

        @Override
        protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
            return category;
        }
    };
    catalog = new MarketplaceCatalog() {

        @Override
        protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
            for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
                checkedForUpdate.add(item.getData());
                List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                boolean hasUpdate = updateAvailable.contains(item.getData());
                for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                    iuItem.setUpdateAvailable(hasUpdate);
                }
            }
            return Status.OK_STATUS;
        }
    };
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IIu(org.eclipse.epp.mpc.core.model.IIu) MarketplaceNodeInstallableUnitItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IIus(org.eclipse.epp.mpc.core.model.IIus) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 2 with InstallableUnit

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

the class ExtensionUpdateSite method getExtensions.

public List<IServerExtension> getExtensions(IProgressMonitor monitor) throws CoreException, ProvisionException {
    URI url2 = null;
    IMetadataRepositoryManager manager = null;
    IProvisioningAgent agent = null;
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    URI[] existingSites = null;
    try {
        /*
			 * To discovery the server adapter, there are three methods:
			 * 1. Looking at the site.xml (if it exists). This is the legacy method
			 * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2
			 *    update site (that may not have a site.xml). The property is necessary to identify
			 *    the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show
			 *    up regardless of whether it is a server or not
			 * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml
			 *    to use category.xml)
			 */
        BundleContext bd = org.eclipse.wst.server.discovery.internal.Activator.getDefault().getBundle().getBundleContext();
        agent = ExtensionUtility.getAgent(bd);
        url2 = new URI(url);
        // Method 1: Looking at the site.xml
        UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory();
        mrf.setAgent(ExtensionUtility.getAgent(bd));
        manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        // Sites already existing for both enabled and disabled
        URI[] existingSitesAll = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
        URI[] existingSitesDisabled = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED);
        int existingSitesAllLen = existingSitesAll == null ? 0 : existingSitesAll.length;
        int existingSitesDisabledLen = existingSitesDisabled == null ? 0 : existingSitesDisabled.length;
        existingSites = new URI[existingSitesAllLen + existingSitesDisabledLen];
        if (existingSitesAllLen > 0) {
            System.arraycopy(existingSitesAll, 0, existingSites, 0, existingSitesAllLen);
        }
        if (existingSitesDisabledLen > 0) {
            System.arraycopy(existingSitesDisabled, 0, existingSites, existingSitesAllLen, existingSitesDisabledLen);
        }
        // If the site.xml does not exist, the load will throw a org.eclipse.equinox.p2.core.ProvisionException
        try {
            IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            list = getInstallableUnits(repo, query, url2, monitor);
        } catch (ProvisionException pe) {
            // $NON-NLS-1$
            Trace.trace(Trace.WARNING, "Error getting update site information", pe);
        }
        // specifying any server adapters there or no site.xml exists)
        if (list.isEmpty()) {
            manager.addRepository(url2);
            // Need to query for all IUs
            IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor);
            int size = list2.size();
            for (int i = 0; i < size; i++) {
                Extension e = (Extension) list2.get(i);
                IInstallableUnit[] iuArr = e.getIUs();
                if (iuArr != null && iuArr.length > 0) {
                    if (iuArr[0] != null) {
                        if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) {
                            list.add(e);
                        }
                    }
                }
            }
        }
        // a provider property with org.eclipse.wst.server.core.serverAdapter
        if (list.isEmpty()) {
            manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
            manager.addRepository(url2);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            list = getInstallableUnits(repo, query, url2, monitor);
        }
        return list;
    } catch (ProvisionException e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        throw e;
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        return new ArrayList<IServerExtension>(0);
    } finally {
        if (url2 != null && url2.getPath().length() != 0 && manager != null) {
            if (existingSites != null && existingSites.length > 0) {
                boolean urlExists = false;
                for (URI uri : existingSites) {
                    if (uri.getPath().equals(url2.getPath())) {
                        urlExists = true;
                        break;
                    }
                }
                // If site did not exist before, remove it as it was added with load
                if (!urlExists) {
                    manager.removeRepository(url2);
                }
            }
        }
    }
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) UpdateSiteMetadataRepositoryFactory(org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) BundleContext(org.osgi.framework.BundleContext)

Example 3 with InstallableUnit

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

the class MarketplaceInfoTest method computeInstalledCatalogNodeIdsNoMarketplaceInfo.

@Test
public void computeInstalledCatalogNodeIdsNoMarketplaceInfo() {
    assertTrue(item.getInstallableUnits().size() > 1);
    assertEquals(0, catalogRegistry.getNodeKeyToIU().size());
    Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
    InstallableUnit mainIu = addIU(installedIus, item.getInstallableUnits().get(0));
    Set<? extends INode> installedCatalogNodeIds = catalogRegistry.computeInstalledNodes(item.getMarketplaceUrl(), installedIus);
    assertNotNull(installedCatalogNodeIds);
    assertEquals(0, installedCatalogNodeIds.size());
    for (String iu : item.getInstallableUnits()) {
        addIU(installedIus, iu);
    }
    mainIu.setProperty(MarketplaceInfo.MPC_NODE_IU_PROPERTY, item.getData().getUrl());
    installedCatalogNodeIds = catalogRegistry.computeInstalledNodes(item.getMarketplaceUrl(), installedIus);
    assertNotNull(installedCatalogNodeIds);
    assertEquals(1, installedCatalogNodeIds.size());
    assertEquals(item.getData().getUrl(), installedCatalogNodeIds.iterator().next().getUrl());
}
Also used : HashMap(java.util.HashMap) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) Test(org.junit.Test)

Example 4 with InstallableUnit

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

the class MarketplaceInfoTest method addIU.

private InstallableUnit addIU(Map<String, IInstallableUnit> installedIus, String id) {
    InstallableUnit installableUnit = (InstallableUnit) installedIus.get(id);
    if (installableUnit == null) {
        installableUnit = new InstallableUnit();
        installableUnit.setId(id);
        IInstallableUnit iu = installableUnit;
        installedIus.put(iu.getId(), iu);
    }
    return installableUnit;
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 InstallableUnit (org.eclipse.equinox.internal.p2.metadata.InstallableUnit)3 HashMap (java.util.HashMap)2 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)1 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)1 MarketplaceCategory (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)1 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)1 MarketplaceNodeCatalogItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem)1 MarketplaceNodeInstallableUnitItem (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem)1 IIu (org.eclipse.epp.mpc.core.model.IIu)1 IIus (org.eclipse.epp.mpc.core.model.IIus)1 INode (org.eclipse.epp.mpc.core.model.INode)1