static IArtifactRepository addArtifactRepository(IProvisioningAgent agent, URI location) { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); boolean createRepo = "file".equals(location.getScheme()); //$NON-NLS-1$ if (manager == null) throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$ try { return manager.loadRepository(location, null); } catch (ProvisionException e) { //fall through and create a new repository if (!createRepo) return null; } // could not load a repo at that location so create one as a convenience String repositoryName = location + " - artifacts"; //$NON-NLS-1$ try { return manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); } catch (ProvisionException e) { return null; } }
/** * Load an artifact repository from the given location. * @param location the URI location of the repository * @param modifiable whether to ask the manager for a modifiable repository * @param removeFromManager remove the loaded repository from the manager if it wasn't already loaded * @return the loaded repository * @throws ProvisionException */ public static IArtifactRepository loadArtifactRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { IArtifactRepositoryManager manager = getService(agent, IArtifactRepositoryManager.SERVICE_NAME); boolean existing = manager.contains(location); IArtifactRepository result = manager.loadRepository(location, modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); if (!existing && removeFromManager) manager.removeRepository(location); return result; }
/** * Helper method to load an extension location metadata repository from the given URL. * * @throws IllegalStateException * @throws ProvisionException */ public static IArtifactRepository loadArtifactRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME); if (manager == null) throw new IllegalStateException("ArtifactRepositoryManager not registered."); //$NON-NLS-1$ IArtifactRepository repository = manager.loadRepository(location, monitor); manager.setRepositoryProperty(location, IRepository.PROP_SYSTEM, String.valueOf(true)); return repository; }
/** * Returns the local bundle pool (repository) where bundles are stored * * @return local file artifact repository * @throws CoreException */ public static IFileArtifactRepository getBundlePool() throws CoreException { URI uri = BUNDLE_POOL.toFile().toURI(); IArtifactRepositoryManager manager = getArtifactRepositoryManager(); try { if (manager.contains(uri)) return (IFileArtifactRepository) manager.loadRepository(uri, null); } catch (CoreException e) { // could not load or there wasn't one, fall through to create } String repoName = "PDE Target Bundle Pool"; //$NON-NLS-1$ IArtifactRepository result = manager.createRepository(uri, repoName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); return (IFileArtifactRepository) result; }
private static void getRunnableRepositories(IArtifactRepositoryManager manager, List<IFileArtifactRepository> bundleRepositories) { URI[] localURLs = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL); for (int i = 0; i < localURLs.length; i++) { try { IArtifactRepository candidate = manager.loadRepository(localURLs[i], new NullProgressMonitor()); if (Boolean.parseBoolean(candidate.getProperty(IArtifactRepository.PROP_RUNNABLE))) { if (candidate != null && candidate instanceof IFileArtifactRepository && !bundleRepositories.contains(candidate)) bundleRepositories.add((IFileArtifactRepository) candidate); } } catch (ProvisionException e) { //skip repositories that could not be read } } }
private IArtifactRepository load(URI repoURI, IProgressMonitor monitor) throws ProvisionException { // make sure we are dealing with an absolute location repoURI = URIUtil.makeAbsolute(repoURI, getLocation()); boolean loaded = getManager().contains(repoURI); IArtifactRepository repo = getManager().loadRepository(repoURI, monitor); if (!loaded) { //set enabled to false so repositories do not get polled twice getManager().setEnabled(repoURI, false); //set repository to system to hide from users getManager().setRepositoryProperty(repoURI, IRepository.PROP_SYSTEM, String.valueOf(true)); } return repo; }
/** * Create a Composite repository in memory. * @return the repository or null if unable to create one */ public static CompositeArtifactRepository createMemoryComposite(IProvisioningAgent agent) { if (agent == null) return null; IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); if (manager == null) return null; try { //create a unique URI long time = System.currentTimeMillis(); URI repositoryURI = new URI("memory:" + String.valueOf(time)); //$NON-NLS-1$ while (manager.contains(repositoryURI)) repositoryURI = new URI("memory:" + String.valueOf(++time)); //$NON-NLS-1$ CompositeArtifactRepository result = (CompositeArtifactRepository) manager.createRepository(repositoryURI, repositoryURI.toString(), IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); manager.removeRepository(repositoryURI); return result; } catch (ProvisionException e) { LogHelper.log(e); // just return null } catch (URISyntaxException e) { // just return null } return null; }
IArtifactRepository result = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); if (result != null) { manager.removeRepository(result.getLocation()); if (reusePackedFiles) result.setProperty(PUBLISH_PACK_FILES_AS_SIBLINGS, "true"); //$NON-NLS-1$
@Override public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException { IArtifactRepository repository = delegate.loadRepository(location, monitor); disableMirrors(repository, mavenLogger); return repository; }
/** * Removes repositories from fragments locations as they might be obsolete and adds them back. */ private void setUpRepos() { //clean old junk IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); URI[] knownRepositories = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL); for (URI uri : knownRepositories) { if ("true".equals(metaManager.getRepositoryProperty(uri, EngineActivator.P2_FRAGMENT_PROPERTY))) { //$NON-NLS-1$ metaManager.removeRepository(uri); } } IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); knownRepositories = artifactManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL); for (URI uri : knownRepositories) { if ("true".equals(artifactManager.getRepositoryProperty(uri, EngineActivator.P2_FRAGMENT_PROPERTY))) { //$NON-NLS-1$ artifactManager.removeRepository(uri); } } File[] fragments = EngineActivator.getExtensionsDirectories(); for (File f : fragments) { metaManager.addRepository(f.toURI()); metaManager.setRepositoryProperty(f.toURI(), EngineActivator.P2_FRAGMENT_PROPERTY, Boolean.TRUE.toString()); artifactManager.addRepository(f.toURI()); artifactManager.setRepositoryProperty(f.toURI(), EngineActivator.P2_FRAGMENT_PROPERTY, Boolean.TRUE.toString()); } }
try targetRepository = repoManager.loadRepository( directory.toURI(), monitor ); repoManager.createRepository( directory.toURI(), directory.getName(), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, new HashMap<String, String>() ); IArtifactRequest request = repoManager.createMirrorRequest( key, targetRepository, null, null ); mgr.add( request );
private void removeFromRepoManager(List<URI> currentLoadedRepositories) { if (currentLoadedRepositories == null) return; for (URI loadedChild : currentLoadedRepositories) { manager.removeRepository(loadedChild); } }
try { IArtifactRepositoryManager manager = ProvUI.getArtifactRepositoryManager(getSession()); repo = manager.loadRepository(location, monitor); String name = manager.getRepositoryProperty(location, IRepository.PROP_NICKNAME); if (name == null) { name = manager.getRepositoryProperty(location, IRepository.PROP_NAME); if (name != null) manager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name);
artManager.addRepository(location); artManager.addRepository(location); setColocatedRepositoryEnablement(ui, location, false); if (name != null && name.length() > 0) { metaManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name); artManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name); if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyEnabled[i]))) { metaManager.removeRepository(currentlyEnabled[i]); artManager.removeRepository(currentlyEnabled[i]); if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyDisabled[i]))) { metaManager.removeRepository(currentlyDisabled[i]); artManager.removeRepository(currentlyDisabled[i]);
@Override public boolean contains(URI location) { return delegate.contains(location); }
@Override public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException { IArtifactRepository repository = delegate.createRepository(location, name, type, properties); disableMirrors(repository, mavenLogger); return repository; }
ProvUI.getArtifactRepositoryManager(ui.getSession()).addRepository(location); ProvUI.getArtifactRepositoryManager(ui.getSession()).refreshRepository(location, sub.newChild(100)); } catch (ProvisionException e) { ProvUI.getArtifactRepositoryManager(ui.getSession()).removeRepository(location);
@Override public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties) { return delegate.createMirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties); }
public void addRepository(URI repoLocation, String nickname, ProvisioningSession session) { ui.signalRepositoryOperationStart(); try { getMetadataRepositoryManager().addRepository(repoLocation); getArtifactRepositoryManager().addRepository(repoLocation); getMetadataRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_SYSTEM, Boolean.FALSE.toString()); getArtifactRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_SYSTEM, Boolean.FALSE.toString()); if (nickname != null) { getMetadataRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_NICKNAME, nickname); getArtifactRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_NICKNAME, nickname); } } finally { // We know that the UI only responds to metadata repo events so we cheat... ui.signalRepositoryOperationComplete(new RepositoryEvent(repoLocation, IRepository.TYPE_METADATA, RepositoryEvent.ADDED, true), true); } }
@Override public URI[] getKnownRepositories(int flags) { return delegate.getKnownRepositories(flags); }