Search in sources :

Example 16 with CatalogDescriptor

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

the class AbstractMarketplaceWizardCommand method installRemoteCatalogs.

public IStatus installRemoteCatalogs() {
    try {
        final AtomicReference<List<? extends ICatalog>> result = new AtomicReference<List<? extends ICatalog>>();
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    ICatalogService catalogService = ServiceHelper.getMarketplaceServiceLocator().getCatalogService();
                    final List<? extends ICatalog> catalogs = catalogService.listCatalogs(monitor);
                    result.set(catalogs);
                } catch (CoreException e) {
                    if (e.getStatus().getSeverity() == IStatus.CANCEL) {
                        throw new InterruptedException();
                    }
                    throw new InvocationTargetException(e);
                }
            }
        });
        List<? extends ICatalog> catalogs = result.get();
        for (ICatalog catalog : catalogs) {
            ResourceProvider resourceProvider = MarketplaceClientUiPlugin.getInstance().getResourceProvider();
            String catalogName = catalog.getName();
            String requestSource = NLS.bind(Messages.MarketplaceWizardCommand_requestCatalog, catalogName, catalog.getId());
            String catalogImageUrl = catalog.getImageUrl();
            if (catalogImageUrl != null) {
                try {
                    resourceProvider.retrieveResource(requestSource, catalogImageUrl);
                } catch (Exception e) {
                    MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogImage, catalogName, catalogImageUrl, e);
                }
            }
            if (catalog.getBranding() != null && catalog.getBranding().getWizardIcon() != null) {
                String wizardIconUrl = catalog.getBranding().getWizardIcon();
                try {
                    resourceProvider.retrieveResource(requestSource, wizardIconUrl);
                } catch (Exception e) {
                    MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogWizardIcon, catalogName, wizardIconUrl, e);
                }
            }
            CatalogDescriptor descriptor = new CatalogDescriptor(catalog);
            registerOrOverrideCatalog(descriptor);
        }
    } catch (InterruptedException ie) {
        if (ie.getMessage() == null || "".equals(ie.getMessage())) {
            InterruptedException ie1 = new InterruptedException("Operation cancelled");
            ie1.setStackTrace(ie.getStackTrace());
            if (ie.getCause() != null) {
                ie1.initCause(ie.getCause());
            }
            ie = ie1;
        }
        IStatus errorStatus = MarketplaceClientCore.computeStatus(ie, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
        return new Status(IStatus.CANCEL, MarketplaceClientCore.BUNDLE_ID, errorStatus.getMessage(), ie);
    } catch (Exception e) {
        IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
        return status;
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) List(java.util.List) ICatalog(org.eclipse.epp.mpc.core.model.ICatalog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 17 with CatalogDescriptor

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

the class NewsViewer method computeNewsPreferenceKey.

private String computeNewsPreferenceKey() {
    CatalogDescriptor catalogDescriptor = wizard.getConfiguration().getCatalogDescriptor();
    URL catalogUrl = catalogDescriptor.getUrl();
    URI catalogUri;
    try {
        catalogUri = catalogUrl.toURI();
    } catch (URISyntaxException e) {
        // should never happen
        throw new IllegalStateException(e);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    String marketplaceId = catalogUri.toString().replaceAll("[^a-zA-Z0-9_-]", "_");
    // $NON-NLS-1$
    return News.class.getSimpleName() + "/" + marketplaceId;
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 18 with CatalogDescriptor

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

the class MarketplaceDiscoveryStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    catalogUrl = new URL("http://marketplace.eclipse.org");
    catalogDescriptor = new CatalogDescriptor(catalogUrl, "Eclipse.org Marketplace");
    CatalogRegistry.getInstance().register(catalogDescriptor);
    catalog = new MarketplaceCatalog();
}
Also used : MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Before(org.junit.Before)

Example 19 with CatalogDescriptor

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

the class CatalogDescriptorTest method testFindCatalogDescriptorWithCommonPrefixDifferentProtocol2.

/**
 * @throws Exception
 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=488436">bug 488436</a>
 */
@Test
public void testFindCatalogDescriptorWithCommonPrefixDifferentProtocol2() throws Exception {
    CatalogRegistry registry = CatalogRegistry.getInstance();
    String marketplace = "https://marketplace.eclipse.org";
    String marketplaceHttp = URLUtil.toggleHttps(marketplace);
    String hostedMarketplace = "http://marketplace.eclipse.org/hosted_catalog/test";
    String hostedMarketplaceHttps = URLUtil.toggleHttps(hostedMarketplace);
    CatalogDescriptor marketplaceDescriptor = new CatalogDescriptor(new URL(marketplace), null);
    CatalogDescriptor hostedMarketplaceDescriptor = new CatalogDescriptor(new URL(hostedMarketplace), null);
    registry.register(marketplaceDescriptor);
    registry.register(hostedMarketplaceDescriptor);
    CatalogDescriptor found = registry.findCatalogDescriptor(marketplaceHttp);
    assertThat(found, is(marketplaceDescriptor));
    found = registry.findCatalogDescriptor(hostedMarketplaceHttps);
    assertThat(found, is(hostedMarketplaceDescriptor));
}
Also used : CatalogRegistry(org.eclipse.epp.internal.mpc.ui.CatalogRegistry) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Test(org.junit.Test)

Example 20 with CatalogDescriptor

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

the class CatalogDescriptorTest method testCatalogDescriptorURLString.

@Test
public void testCatalogDescriptorURLString() throws Exception {
    String label = "some label";
    URL url = new URL("http://marketplace.eclipse.org");
    CatalogDescriptor descriptor = new CatalogDescriptor(url, label);
    assertEquals(label, descriptor.getLabel());
    assertEquals(url.toString(), descriptor.getUrl().toString());
}
Also used : URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Test(org.junit.Test)

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