Search in sources :

Example 1 with InstallableComponent

use of org.eclipse.amalgam.discovery.InstallableComponent in project gemoc-studio by eclipse.

the class PrepareInstallProfileJob 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) {
        String id = unit.getId();
        if (id.endsWith(P2_FEATURE_GROUP_SUFFIX)) {
            id = id.substring(0, id.indexOf(P2_FEATURE_GROUP_SUFFIX));
        }
        foundIds.add(id);
    }
    // $NON-NLS-1$
    String message = "";
    // $NON-NLS-1$
    String detailedMessage = "";
    for (InstallableComponent descriptor : installableConnectors) {
        StringBuilder unavailableIds = null;
        for (String id : descriptor.getId()) {
            if (!foundIds.contains(id)) {
                if (unavailableIds == null) {
                    unavailableIds = new StringBuilder();
                } else {
                    unavailableIds.append(Messages.InstallConnectorsJob_commaSeparator);
                }
                unavailableIds.append(id);
            }
        }
        if (unavailableIds != null) {
            if (message.length() > 0) {
                message += Messages.InstallConnectorsJob_commaSeparator;
            }
            message += descriptor.getName();
            if (detailedMessage.length() > 0) {
                detailedMessage += Messages.InstallConnectorsJob_commaSeparator;
            }
            detailedMessage += NLS.bind(Messages.PrepareInstallProfileJob_notFoundDescriptorDetail, new Object[] { descriptor.getName(), unavailableIds.toString(), descriptor.getSitesURLS() });
        }
    }
    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;
        if (headless) {
            throw new RuntimeException(detailedMessage);
        } else {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    okayToProceed[0] = MessageDialog.openQuestion(DiscoveryUiUtil.getShell(), Messages.InstallConnectorsJob_questionProceed, NLS.bind(Messages.InstallConnectorsJob_questionProceed_long, new Object[] { finalMessage }));
                }
            });
            if (!okayToProceed[0]) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(Messages.InstallConnectorsJob_connectorsNotAvailable, detailedMessage), null));
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) InstallableComponent(org.eclipse.amalgam.discovery.InstallableComponent) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 2 with InstallableComponent

use of org.eclipse.amalgam.discovery.InstallableComponent in project gemoc-studio by eclipse.

the class PrepareInstallProfileJob method addRepositories.

private List<IMetadataRepository> addRepositories(SubMonitor monitor) throws MalformedURLException, URISyntaxException, ProvisionException {
    // tell p2 that it's okay to use these repositories
    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
    RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
    repositoryLocations = new HashSet<URI>();
    monitor.setWorkRemaining(installableConnectors.size() * 5);
    for (InstallableComponent descriptor : installableConnectors) {
        for (String url : descriptor.getSitesURLS()) {
            addASiteURL(monitor, session, repositoryTracker, url);
        }
    }
    // fetch meta-data for these repositories
    ArrayList<IMetadataRepository> repositories = new ArrayList<IMetadataRepository>();
    monitor.setWorkRemaining(repositories.size());
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    for (URI uri : repositoryLocations) {
        checkCancelled(monitor);
        IMetadataRepository repository = manager.loadRepository(uri, monitor.newChild(1));
        repositories.add(repository);
    }
    return repositories;
}
Also used : ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) ArrayList(java.util.ArrayList) InstallableComponent(org.eclipse.amalgam.discovery.InstallableComponent) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) URI(java.net.URI) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Aggregations

InstallableComponent (org.eclipse.amalgam.discovery.InstallableComponent)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)1 RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)1 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)1 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)1