Search in sources :

Example 1 with IMetadataRepositoryManager

use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project knime-core by knime.

the class InstallMissingNodesJob method findExtensions.

private IStatus findExtensions(final IProgressMonitor monitor, final List<NodeAndBundleInformation> missingNodes, final Set<IInstallableUnit> featuresToInstall) {
    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
    Bundle myself = FrameworkUtil.getBundle(getClass());
    try {
        IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
        for (URI uri : metadataManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)) {
            if (!missingNodes.isEmpty()) {
                IMetadataRepository repo = metadataManager.loadRepository(uri, monitor);
                for (Iterator<NodeAndBundleInformation> it = missingNodes.iterator(); it.hasNext(); ) {
                    NodeAndBundleInformation info = it.next();
                    if (searchInRepository(repo, info, metadataManager, monitor, featuresToInstall)) {
                        it.remove();
                    }
                }
            }
        }
        return Status.OK_STATUS;
    } catch (ProvisionException ex) {
        NodeLogger.getLogger(getClass()).error("Could not create provisioning agent: " + ex.getMessage(), ex);
        return new Status(IStatus.ERROR, myself.getSymbolicName(), "Could not query updates site for missing extensions", ex);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) NodeAndBundleInformation(org.knime.core.node.NodeAndBundleInformation) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) Bundle(org.osgi.framework.Bundle) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) URI(java.net.URI)

Example 2 with IMetadataRepositoryManager

use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project tycho by eclipse.

the class RemoteAgentMetadataRepositoryCacheTest method loadHttpRepository.

private IMetadataRepository loadHttpRepository(RemoteAgent agent) throws ProvisionException {
    IMetadataRepositoryManager metadataRepositoryManager = agent.getService(IMetadataRepositoryManager.class);
    IMetadataRepository repo = metadataRepositoryManager.loadRepository(localHttpRepo, null);
    return repo;
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 3 with IMetadataRepositoryManager

use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project tycho by eclipse.

the class TargetPlatformFilterEvaluatorTest method loadTestUnits.

private static Set<IInstallableUnit> loadTestUnits() throws Exception {
    IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) p2Context.getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    File testDataFile = ResourceUtil.resourceFile("targetfiltering/content.xml");
    IMetadataRepository testDataRepository = metadataManager.loadRepository(testDataFile.getParentFile().toURI(), null);
    return testDataRepository.query(QueryUtil.ALL_UNITS, null).toUnmodifiableSet();
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) File(java.io.File)

Example 4 with IMetadataRepositoryManager

use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager 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)

Example 5 with IMetadataRepositoryManager

use of org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager in project translationstudio8 by heartsome.

the class Activator method loadUpdateSite.

private void loadUpdateSite() throws InvocationTargetException {
    // get the agent
    final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(Activator.bundleContext, IProvisioningAgent.SERVICE_NAME);
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
        logger.error("When load repository,Metadata manager was null");
        return;
    }
    // Load artifact manager
    IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
    if (artifactManager == null) {
        logger.error("When load repository,Artifact manager was null");
        return;
    }
    // Load repository
    try {
        String url = getUrlString();
        if (url == null) {
            return;
        }
        URI repoLocation = new URI(url);
        URI[] ex = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
        for (URI e : ex) {
            manager.removeRepository(e);
            artifactManager.removeRepository(e);
        }
        manager.addRepository(repoLocation);
        artifactManager.addRepository(repoLocation);
    } catch (URISyntaxException e) {
        logger.error("Caught URI syntax exception " + e.getMessage(), e);
        throw new InvocationTargetException(e);
    }
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)16 URI (java.net.URI)10 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)10 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)6 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)5 ProvisioningSession (org.eclipse.equinox.p2.operations.ProvisioningSession)5 ArrayList (java.util.ArrayList)4 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)4 IArtifactRepositoryManager (org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager)4 CoreException (org.eclipse.core.runtime.CoreException)3 BundleContext (org.osgi.framework.BundleContext)3 File (java.io.File)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 IStatus (org.eclipse.core.runtime.IStatus)2 RepositoryTracker (org.eclipse.equinox.p2.operations.RepositoryTracker)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1