Search in sources :

Example 1 with IArtifactRepositoryManager

use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager in project knime-core by knime.

the class RepositoryUpdater method updateArtifactRepositoryURLs.

/**
 * Updates the URLs of all enabled artifact repository by adding the KNIME ID to them.
 */
public void updateArtifactRepositoryURLs() {
    BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
    ServiceReference<IProvisioningAgent> ref = context.getServiceReference(IProvisioningAgent.class);
    if (ref != null) {
        IProvisioningAgent agent = context.getService(ref);
        try {
            IArtifactRepositoryManager repoManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
            if (repoManager != null) {
                // is null if started from the SDK
                for (URI uri : repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_LOCAL)) {
                    updateArtifactRepositoryURL(repoManager, uri, true);
                }
            }
        } finally {
            context.ungetService(ref);
        }
    }
}
Also used : IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URI(java.net.URI) BundleContext(org.osgi.framework.BundleContext)

Example 2 with IArtifactRepositoryManager

use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager in project knime-core by knime.

the class RepositoryUpdater method removeOutdatedArtifactRepository.

private void removeOutdatedArtifactRepository(final RepositoryEvent event) {
    BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
    ServiceReference<IProvisioningAgent> ref = context.getServiceReference(IProvisioningAgent.class);
    if (ref != null) {
        IProvisioningAgent agent = context.getService(ref);
        try {
            IArtifactRepositoryManager repoManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
            if (repoManager != null) {
                URI removedMetadatalocation = event.getRepositoryLocation();
                String correspondingArtifactRepoPrefix = removedMetadatalocation.toString();
                if (!correspondingArtifactRepoPrefix.endsWith("/")) {
                    correspondingArtifactRepoPrefix += "/";
                }
                correspondingArtifactRepoPrefix += "knid=";
                for (URI uri : repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_NON_LOCAL)) {
                    if (urlContainsID(uri) && uri.toString().startsWith(correspondingArtifactRepoPrefix)) {
                        repoManager.removeRepository(uri);
                    }
                }
                for (URI uri : repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED)) {
                    if (urlContainsID(uri) && uri.toString().startsWith(correspondingArtifactRepoPrefix)) {
                        repoManager.removeRepository(uri);
                    }
                }
            }
        } finally {
            context.ungetService(ref);
        }
    }
}
Also used : IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URI(java.net.URI) BundleContext(org.osgi.framework.BundleContext)

Example 3 with IArtifactRepositoryManager

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

Example 4 with IArtifactRepositoryManager

use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager in project knime-core by knime.

the class RepositoryUpdater method updateArtifactRepository.

private void updateArtifactRepository(final RepositoryEvent event) {
    BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
    ServiceReference<IProvisioningAgent> ref = context.getServiceReference(IProvisioningAgent.class);
    if (ref != null) {
        IProvisioningAgent agent = context.getService(ref);
        try {
            IArtifactRepositoryManager repoManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
            if (repoManager != null) {
                updateArtifactRepositoryURL(repoManager, event.getRepositoryLocation(), event.isRepositoryEnabled());
            }
        } finally {
            context.ungetService(ref);
        }
    }
}
Also used : IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) BundleContext(org.osgi.framework.BundleContext)

Example 5 with IArtifactRepositoryManager

use of org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager in project tycho by eclipse.

the class RemoteAgentMavenMirrorsTest method loadRepositories.

private Repositories loadRepositories(String id, URI specifiedUrl) throws Exception {
    IRepositoryIdManager idManager = (IRepositoryIdManager) subject.getService(IRepositoryIdManager.SERVICE_NAME);
    idManager.addMapping(id, specifiedUrl);
    IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) subject.getService(IMetadataRepositoryManager.SERVICE_NAME);
    IMetadataRepository metadataRepo = metadataManager.loadRepository(specifiedUrl, null);
    IArtifactRepositoryManager artifactsManager = (IArtifactRepositoryManager) subject.getService(IArtifactRepositoryManager.SERVICE_NAME);
    IArtifactRepository artifactsRepo = artifactsManager.loadRepository(specifiedUrl, null);
    return new Repositories(metadataRepo, artifactsRepo);
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) IArtifactRepository(org.eclipse.equinox.p2.repository.artifact.IArtifactRepository) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Aggregations

IArtifactRepositoryManager (org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager)10 URI (java.net.URI)5 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)5 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)4 IArtifactRepository (org.eclipse.equinox.p2.repository.artifact.IArtifactRepository)3 BundleContext (org.osgi.framework.BundleContext)3 File (java.io.File)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 CompositeArtifactRepository (org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository)1 CompositeMetadataRepository (org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository)1