Search in sources :

Example 31 with CatalogDescriptor

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

the class MarketplaceViewerSorter method compare.

@Override
public int compare(Viewer viewer, Object o1, Object o2) {
    if (o1 == o2) {
        return 0;
    }
    CatalogCategory cat1 = getCategory(o1);
    CatalogCategory cat2 = getCategory(o2);
    // FIXME filter uncategorized items?
    if (cat1 == null) {
        return (cat2 != null) ? 1 : 0;
    } else if (cat2 == null) {
        return 1;
    }
    int i = categoryComparator.compare(cat1, cat2);
    if (i == 0) {
        if (o1 instanceof CatalogCategory) {
            return -1;
        }
        if (o2 instanceof CatalogCategory) {
            return 1;
        }
        CatalogItem i1 = (CatalogItem) o1;
        CatalogItem i2 = (CatalogItem) o2;
        // catalog descriptor comes last
        if (i1.getData() instanceof CatalogDescriptor) {
            i = 1;
        } else if (i2.getData() instanceof CatalogDescriptor) {
            i = -1;
        } else {
            // otherwise we sort by name
            String n1 = i1.getName();
            String n2 = i2.getName();
            if (n1 == null) {
                // $NON-NLS-1$
                n1 = "";
            }
            if (n2 == null) {
                // $NON-NLS-1$
                n2 = "";
            }
            i = n1.compareToIgnoreCase(n2);
            if (i == 0) {
                i = n1.compareTo(n2);
                if (i == 0) {
                    // same name, so we sort by id.
                    String id1 = i1.getId();
                    String id2 = i2.getId();
                    if (id1 == null) {
                        // $NON-NLS-1$
                        id1 = "";
                    }
                    if (id2 == null) {
                        // $NON-NLS-1$
                        id2 = "";
                    }
                    i = id1.compareTo(id2);
                }
            }
        }
    }
    return i;
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 32 with CatalogDescriptor

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

the class MarketplaceDiscoveryStrategy method performNodeQuery.

private ISearchResult performNodeQuery(String nodeUrl, IProgressMonitor progress) throws CoreException {
    final INode[] queryNode = new INode[1];
    MarketplaceUrlHandler urlHandler = new MarketplaceUrlHandler() {

        @Override
        protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
            queryNode[0] = node;
            return true;
        }
    };
    if (urlHandler.handleUri(nodeUrl) && queryNode[0] != null) {
        INode node = marketplaceService.getNode(queryNode[0], progress);
        SearchResult result = new SearchResult();
        result.setMatchCount(1);
        result.setNodes(Collections.singletonList((Node) node));
        return result;
    }
    return null;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceUrlHandler(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 33 with CatalogDescriptor

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

the class MarketplaceUrlHandlerTest method testHttpsVariants.

@Test
public void testHttpsVariants() {
    MarketplaceUrlHandler handler = new MarketplaceUrlHandler() {

        @Override
        protected boolean handleFeatured(CatalogDescriptor descriptor, String url, String category, String market) {
            assertEquals(eclipseMarketplace, descriptor);
            assertEquals("featured", url);
            return true;
        }
    };
    String url = "http://marketplace.eclipse.org/featured";
    assertTrue(handler.handleUri(url));
    url = "https://marketplace.eclipse.org/featured";
    assertTrue(handler.handleUri(url));
}
Also used : MarketplaceUrlHandler(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Test(org.junit.Test)

Example 34 with CatalogDescriptor

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

the class MarketplaceUrlHandlerTest method testNodeUrls.

@Test
public void testNodeUrls() throws Exception {
    final INode[] testNode = new INode[1];
    MarketplaceUrlHandler handler = new MarketplaceUrlHandler() {

        @Override
        protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
            testNode[0] = node;
            return true;
        }
    };
    testNode[0] = null;
    String url = "http://marketplace.eclipse.org/content/test";
    assertTrue(handler.handleUri(url));
    assertNotNull(testNode[0]);
    assertEquals(url, testNode[0].getUrl());
    testNode[0] = null;
    String nodeId = "12345";
    url = "http://marketplace.eclipse.org/node/" + nodeId;
    assertTrue(handler.handleUri(url));
    assertNotNull(testNode[0]);
    assertEquals(nodeId, testNode[0].getId());
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) MarketplaceUrlHandler(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Test(org.junit.Test)

Example 35 with CatalogDescriptor

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

the class CatalogRegistry method findCatalogDescriptor.

public CatalogDescriptor findCatalogDescriptor(String url) {
    if (url == null || url.length() == 0) {
        return null;
    }
    CatalogDescriptor matchingDescriptor = doFindCatalogDescriptor(url);
    url = URLUtil.toggleHttps(url);
    CatalogDescriptor matchingToggledDescriptor = doFindCatalogDescriptor(url);
    if (matchingDescriptor == null) {
        matchingDescriptor = matchingToggledDescriptor;
    } else if (matchingToggledDescriptor != null) {
        String matchingUrl = matchingDescriptor.getUrl().toExternalForm();
        String matchingToggledUrl = matchingToggledDescriptor.getUrl().toExternalForm();
        // $NON-NLS-1$
        int protocolDelta = matchingToggledUrl.startsWith("https") ? 1 : -1;
        if (matchingToggledUrl.length() - protocolDelta > matchingUrl.length()) {
            matchingDescriptor = matchingToggledDescriptor;
        }
    }
    return matchingDescriptor;
}
Also used : CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Aggregations

CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)37 URL (java.net.URL)18 Test (org.junit.Test)10 IStatus (org.eclipse.core.runtime.IStatus)7 CatalogRegistry (org.eclipse.epp.internal.mpc.ui.CatalogRegistry)7 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)4 MarketplaceUrlHandler (org.eclipse.epp.mpc.ui.MarketplaceUrlHandler)4 Before (org.junit.Before)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Status (org.eclipse.core.runtime.Status)3 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)3 INode (org.eclipse.epp.mpc.core.model.INode)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2