diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java index c2ec67e7ad..084c35e6c5 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java @@ -16,7 +16,6 @@ import java.io.*; import java.net.URI; -import java.net.URISyntaxException; import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -24,6 +23,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; +import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IArtifactKey; @@ -58,28 +58,8 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl * @return the repository or null if unable to create one */ public static CompositeArtifactRepository createMemoryComposite(IProvisioningAgent agent) { - if (agent == null) - return null; - IArtifactRepositoryManager manager = agent.getService(IArtifactRepositoryManager.class); - 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; + return (CompositeArtifactRepository) RepositoryHelper.createMemoryComposite(agent, + IArtifactRepositoryManager.class, IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY); } private IArtifactRepositoryManager getManager() { diff --git a/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF index 8b7703bc82..43e6543310 100644 --- a/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.console;singleton:=true -Bundle-Version: 1.3.100.qualifier +Bundle-Version: 1.3.200.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.console.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java index d7fd978ca6..8cd900cba8 100644 --- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java +++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java @@ -305,11 +305,9 @@ public void _provlr(CommandInterpreter interpreter) { String id = processArgument(interpreter.nextArgument()); String version = processArgument(interpreter.nextArgument()); if (urlString == null) { - URI[] repositories = ProvisioningHelper.getMetadataRepositories(agent); - if (repositories != null) - for (URI repository : repositories) { - interpreter.println(repository); - } + for (URI repository : ProvisioningHelper.getMetadataRepositories(agent)) { + interpreter.println(repository); + } return; } URI repoLocation = toURI(interpreter, urlString); @@ -358,10 +356,7 @@ public void _provlg(CommandInterpreter interpreter) { public void _provlar(CommandInterpreter interpreter) { String urlString = processArgument(interpreter.nextArgument()); if (urlString == null) { - URI[] repositories = ProvisioningHelper.getArtifactRepositories(agent); - if (repositories == null) - return; - for (URI repository : repositories) { + for (URI repository : ProvisioningHelper.getArtifactRepositories(agent)) { interpreter.println(repository); } return; diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java index 4074db2fec..47634470ef 100644 --- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java +++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java @@ -16,97 +16,46 @@ package org.eclipse.equinox.internal.p2.console; import java.net.URI; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.provisional.p2.director.PlanExecutionHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.engine.*; -import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.planner.IPlanner; import org.eclipse.equinox.p2.planner.IProfileChangeRequest; import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; -import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.service.environment.EnvironmentInfo; public class ProvisioningHelper { - static IMetadataRepository addMetadataRepository(IProvisioningAgent agent, URI location) { - IMetadataRepositoryManager manager = agent.getService(IMetadataRepositoryManager.class); - 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) { - if (!createRepo) - return null; - } - - // for convenience create and add a repository here - String repositoryName = location + " - metadata"; //$NON-NLS-1$ - try { - return manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); - } catch (ProvisionException e) { - return null; - } + static IRepository addMetadataRepository(IProvisioningAgent agent, URI location) { + return addRepository(IMetadataRepositoryManager.class, agent, location, "metadata", //$NON-NLS-1$ + IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY); } - static IMetadataRepository getMetadataRepository(IProvisioningAgent agent, URI location) { - IMetadataRepositoryManager manager = agent.getService(IMetadataRepositoryManager.class); - if (manager == null) - throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$ - try { - return manager.loadRepository(location, null); - } catch (ProvisionException e) { - return null; - } + static IRepository getMetadataRepository(IProvisioningAgent agent, URI location) { + return getRepository(IMetadataRepositoryManager.class, agent, location); } static void removeMetadataRepository(IProvisioningAgent agent, URI location) { - IMetadataRepositoryManager manager = agent.getService(IMetadataRepositoryManager.class); - if (manager == null) - throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$ - manager.removeRepository(location); + removeRepository(IMetadataRepositoryManager.class, agent, location); } - static IArtifactRepository addArtifactRepository(IProvisioningAgent agent, URI location) { - IArtifactRepositoryManager manager = agent.getService(IArtifactRepositoryManager.class); - 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; - } + static IRepository addArtifactRepository(IProvisioningAgent agent, URI location) { + return addRepository(IArtifactRepositoryManager.class, agent, location, "artifacts", //$NON-NLS-1$ + IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY); } static void removeArtifactRepository(IProvisioningAgent agent, URI location) { - IArtifactRepositoryManager manager = agent.getService(IArtifactRepositoryManager.class); - if (manager == null) - // TODO log here - return; - manager.removeRepository(location); + removeRepository(IArtifactRepositoryManager.class, agent, location); } static IProfile addProfile(IProvisioningAgent agent, String profileId, Map properties) throws ProvisionException { @@ -172,15 +121,8 @@ static IQueryResult getInstallableUnits(IProvisioningAgent age return Collector.emptyCollector(); } - static URI[] getMetadataRepositories(IProvisioningAgent agent) { - IMetadataRepositoryManager manager = agent.getService(IMetadataRepositoryManager.class); - if (manager == null) - // TODO log here - return null; - URI[] repos = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); - if (repos.length > 0) - return repos; - return null; + static List getMetadataRepositories(IProvisioningAgent agent) { + return getRepositories(IArtifactRepositoryManager.class, agent); } /** @@ -194,11 +136,8 @@ static IStatus install(IProvisioningAgent agent, String unitId, String version, StringBuilder error = new StringBuilder(); error.append("Installable unit not found: " + unitId + ' ' + version + '\n'); //$NON-NLS-1$ error.append("Repositories searched:\n");//$NON-NLS-1$ - URI[] repos = getMetadataRepositories(agent); - if (repos != null) { - for (URI repo : repos) - error.append(repo + "\n");//$NON-NLS-1$ - } + for (URI repo : getMetadataRepositories(agent)) + error.append(repo + "\n");//$NON-NLS-1$ throw new ProvisionException(error.toString()); } @@ -216,25 +155,12 @@ static IStatus install(IProvisioningAgent agent, String unitId, String version, return PlanExecutionHelper.executePlan(result, engine, context, progress); } - static URI[] getArtifactRepositories(IProvisioningAgent agent) { - IArtifactRepositoryManager manager = agent.getService(IArtifactRepositoryManager.class); - if (manager == null) - throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$ - URI[] repos = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); - if (repos.length > 0) - return repos; - return null; + static List getArtifactRepositories(IProvisioningAgent agent) { + return getRepositories(IArtifactRepositoryManager.class, agent); } static IArtifactRepository getArtifactRepository(IProvisioningAgent agent, URI repoURL) { - IArtifactRepositoryManager manager = agent.getService(IArtifactRepositoryManager.class); - try { - if (manager != null) - return manager.loadRepository(repoURL, null); - } catch (ProvisionException e) { - //for console, just ignore repositories that can't be read - } - return null; + return (IArtifactRepository) getRepository(IArtifactRepositoryManager.class, agent, repoURL); } static long[] getProfileTimestamps(IProvisioningAgent agent, String profileId) { @@ -273,8 +199,8 @@ static IStatus revertToPreviousState(IProvisioningAgent agent, IProfile profile, } if (targetProfile == null) throw new ProvisionException("target profile with timestamp=" + revertToPreviousState + " not found"); //$NON-NLS-1$//$NON-NLS-2$ - URI[] artifactRepos = getArtifactRepositories(agent); - URI[] metadataRepos = getMetadataRepositories(agent); + URI[] artifactRepos = getArtifactRepositories(agent).toArray(URI[]::new); + URI[] metadataRepos = getMetadataRepositories(agent).toArray(URI[]::new); IProvisioningPlan plan = planner.getDiffPlan(profile, targetProfile, new NullProgressMonitor()); ProvisioningContext context = new ProvisioningContext(agent); context.setMetadataRepositories(metadataRepos); @@ -293,10 +219,8 @@ static IStatus uninstall(IProvisioningAgent agent, String unitId, String version StringBuilder error = new StringBuilder(); error.append("Installable unit not found: " + unitId + ' ' + version + '\n'); //$NON-NLS-1$ error.append("Repositories searched:\n"); //$NON-NLS-1$ - URI[] repos = getMetadataRepositories(agent); - if (repos != null) { - for (URI repo : repos) - error.append(repo + "\n"); //$NON-NLS-1$ + for (URI repo : getMetadataRepositories(agent)) { + error.append(repo + "\n"); //$NON-NLS-1$ } throw new ProvisionException(error.toString()); } @@ -315,4 +239,57 @@ static IStatus uninstall(IProvisioningAgent agent, String unitId, String version return PlanExecutionHelper.executePlan(result, engine, context, progress); } + private static IRepository addRepository(Class> repositoryManager, + IProvisioningAgent agent, URI location, String nameSuffix, String repoType) { + IRepositoryManager manager = getRepositoryManager(agent, repositoryManager); + try { + return manager.loadRepository(location, null); + } catch (ProvisionException e) { + // fall through and create a new repository + boolean createRepo = "file".equals(location.getScheme()); //$NON-NLS-1$ + if (!createRepo) { + return null; + } + } + // could not load a repo at that location so create one as a convenience + String repositoryName = location + " - " + nameSuffix; //$NON-NLS-1$ + try { + return manager.createRepository(location, repositoryName, repoType, null); + } catch (ProvisionException e) { + return null; + } + } + + private static void removeRepository(Class> repositoryManager, + IProvisioningAgent agent, URI location) { + IRepositoryManager manager = getRepositoryManager(agent, repositoryManager); + manager.removeRepository(location); + } + + private static IRepository getRepository(Class> repositoryManager, + IProvisioningAgent agent, URI location) { + IRepositoryManager manager = getRepositoryManager(agent, repositoryManager); + try { + return manager.loadRepository(location, null); + } catch (ProvisionException e) { + // for console, just ignore repositories that can't be read + return null; + } + } + + private static List getRepositories(Class> repositoryManager, + IProvisioningAgent agent) { + IRepositoryManager manager = getRepositoryManager(agent, repositoryManager); + URI[] repos = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL); + return Arrays.asList(repos); + } + + private static IRepositoryManager getRepositoryManager(IProvisioningAgent agent, + Class> repositoryManager) { + IRepositoryManager manager = agent.getService(repositoryManager); + if (manager == null) { + throw new IllegalStateException("No repository manager found for type " + repositoryManager); //$NON-NLS-1$ + } + return manager; + } } diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Messages.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Messages.java index 99539fb9d9..e5c3f2b6b6 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Messages.java +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Messages.java @@ -17,13 +17,11 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.provisional.p2.directorywatcher.messages"; //$NON-NLS-1$ - public static String artifact_repo_manager_not_registered; public static String error_main_loop; public static String error_processing; - public static String failed_create_artifact_repo; - public static String failed_create_metadata_repo; + public static String failed_create_repo; public static String filename_missing; - public static String metadata_repo_manager_not_registered; + public static String repo_manager_not_registered; public static String null_folder; public static String thread_not_started; public static String thread_started; diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java index c369fb8b04..7c7e0d4ce2 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java @@ -28,6 +28,8 @@ import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction; import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction; import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.equinox.p2.repository.artifact.*; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; @@ -79,42 +81,17 @@ private void initializePublisher() { info.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_NO_MD5); } - protected CachingArtifactRepository initializeArtifactRepository(String name, URI repositoryLocation, Map properties) { - IArtifactRepositoryManager manager = getArtifactRepositoryManager(); - if (manager == null) - throw new IllegalStateException(Messages.artifact_repo_manager_not_registered); - - try { - IArtifactRepository result = manager.loadRepository(repositoryLocation, null); - return result == null ? null : new CachingArtifactRepository(result); - } catch (ProvisionException e) { - //fall through and create a new repository - } - try { - IArtifactRepository result = manager.createRepository(repositoryLocation, name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); - return result == null ? null : new CachingArtifactRepository(result); - } catch (ProvisionException e) { - LogHelper.log(e); - throw new IllegalStateException(NLS.bind(Messages.failed_create_artifact_repo, repositoryLocation)); - } + protected CachingArtifactRepository initializeArtifactRepository(String name, URI repositoryLocation, + Map properties) { + IArtifactRepository repository = (IArtifactRepository) initializeRepository(IArtifactRepositoryManager.class, + name, repositoryLocation, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); + return repository == null ? null : new CachingArtifactRepository(repository); } - protected IMetadataRepository initializeMetadataRepository(String name, URI repositoryLocation, Map properties) { - IMetadataRepositoryManager manager = getMetadataRepositoryManager(); - if (manager == null) - throw new IllegalStateException(Messages.metadata_repo_manager_not_registered); - - try { - return manager.loadRepository(repositoryLocation, null); - } catch (ProvisionException e) { - //fall through and create new repository - } - try { - return manager.createRepository(repositoryLocation, name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); - } catch (ProvisionException e) { - LogHelper.log(e); - throw new IllegalStateException(NLS.bind(Messages.failed_create_metadata_repo, repositoryLocation)); - } + protected IMetadataRepository initializeMetadataRepository(String name, URI repositoryLocation, + Map properties) { + return (IMetadataRepository) initializeRepository(IMetadataRepositoryManager.class, name, repositoryLocation, + IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties); } @Override @@ -136,7 +113,8 @@ public boolean removed(File file) { private boolean process(File file, boolean isAddition) { boolean isDirectory = file.isDirectory(); // is it a feature ? - if (isDirectory && file.getParentFile() != null && file.getParentFile().getName().equals("features") && new File(file, "feature.xml").exists()) //$NON-NLS-1$ //$NON-NLS-2$) + if (isDirectory && file.getParentFile() != null && file.getParentFile().getName().equals("features") //$NON-NLS-1$ + && new File(file, "feature.xml").exists()) //$NON-NLS-1$ ) return processFeature(file, isAddition); // could it be a bundle ? if (isDirectory || file.getName().endsWith(".jar")) //$NON-NLS-1$ @@ -150,7 +128,7 @@ private boolean processBundle(File file, boolean isDirectory, boolean isAddition return false; advice.setProperties(file, file.lastModified(), file.toURI()); - return publish(new BundlesAction(new BundleDescription[] {bundleDescription}), isAddition); + return publish(new BundlesAction(new BundleDescription[] { bundleDescription }), isAddition); // TODO see bug 222370 // we only want to return the bundle IU so must exclude all fragment IUs // not sure if this is still relevant but we should investigate. @@ -159,7 +137,7 @@ private boolean processBundle(File file, boolean isDirectory, boolean isAddition private boolean processFeature(File file, boolean isAddition) { String link = metadataRepository.getProperties().get(Site.PROP_LINK_FILE); advice.setProperties(file, file.lastModified(), file.toURI(), link); - return publish(new FeaturesAction(new File[] {file}), isAddition); + return publish(new FeaturesAction(new File[] { file }), isAddition); } private boolean publish(IPublisherAction action, boolean isAddition) { @@ -238,7 +216,8 @@ private void synchronizeArtifactRepository(final Collection removedFiles) if (artifactRepository == null) return; if (!removedFiles.isEmpty()) { - IArtifactDescriptor[] descriptors = artifactRepository.descriptorQueryable().query(ArtifactDescriptorQuery.ALL_DESCRIPTORS, null).toArray(IArtifactDescriptor.class); + IArtifactDescriptor[] descriptors = artifactRepository.descriptorQueryable() + .query(ArtifactDescriptorQuery.ALL_DESCRIPTORS, null).toArray(IArtifactDescriptor.class); for (IArtifactDescriptor d : descriptors) { SimpleArtifactDescriptor descriptor = (SimpleArtifactDescriptor) d; String filename = descriptor.getRepositoryProperty(FILE_NAME); @@ -305,14 +284,28 @@ public IArtifactRepository getArtifactRepository() { return artifactRepository; } - private static IMetadataRepositoryManager getMetadataRepositoryManager() { - BundleContext bundleContext = FrameworkUtil.getBundle(RepositoryListener.class).getBundleContext(); - return ServiceHelper.getService(bundleContext, IProvisioningAgent.class).getService(IMetadataRepositoryManager.class); - } + private static IRepository initializeRepository(Class> repositoryManager, + String name, URI repositoryLocation, String type, Map properties) { - private static IArtifactRepositoryManager getArtifactRepositoryManager() { BundleContext bundleContext = FrameworkUtil.getBundle(RepositoryListener.class).getBundleContext(); - return ServiceHelper.getService(bundleContext, IProvisioningAgent.class).getService(IArtifactRepositoryManager.class); + IProvisioningAgent agent = ServiceHelper.getService(bundleContext, IProvisioningAgent.class); + IRepositoryManager manager = agent.getService(repositoryManager); + if (manager == null) { + throw new IllegalStateException( + NLS.bind(Messages.repo_manager_not_registered, repositoryManager.getSimpleName())); + } + try { + return manager.loadRepository(repositoryLocation, null); + } catch (ProvisionException e) { + // fall through and create a new repository + } + try { + return manager.createRepository(repositoryLocation, name, type, properties); + } catch (ProvisionException e) { + LogHelper.log(e); + throw new IllegalStateException( + NLS.bind(Messages.failed_create_repo, repositoryManager.getSimpleName(), repositoryLocation)); + } } private static URI getDefaultRepositoryLocation(Object object, String repositoryName) { diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/messages.properties b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/messages.properties index 698be83bc0..86de4fad7f 100644 --- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/messages.properties +++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/messages.properties @@ -11,13 +11,11 @@ # Contributors: # IBM Corporation - initial API and implementation ############################################################################### -artifact_repo_manager_not_registered=ArtifactRepositoryManager not registered. error_main_loop=Error in watcher thread main loop. error_processing=Error Processing: {0} -failed_create_artifact_repo=Could not create artifact repository for: {0} -failed_create_metadata_repo=Could not create metadata repository for: {0} +failed_create_repo=Could not create repository of type {0} for: {1} filename_missing=The {0} {1} is missing the filename property. -metadata_repo_manager_not_registered=MetadataRepositoryManager not registered. +repo_manager_not_registered=No RepositoryManager registered for type: {0} null_folder=Folder must not be null thread_not_started=Watcher thread not Started thread_started=Watcher thread already Started diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java index 247cf06ca0..60b212f948 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java @@ -224,9 +224,7 @@ private Set getLoadedMetadataRepositories(IProgressMonitor for (URI repositorie : repositories) { loadMetadataRepository(repoManager, repositorie, repos, shouldFollowReferences(), sub.split(1)); } - Set set = new HashSet<>(); - set.addAll(repos.values()); - return set; + return new HashSet<>(repos.values()); } private void loadMetadataRepository(IMetadataRepositoryManager manager, URI location, @@ -346,16 +344,12 @@ private URI getSecureLocation(URI uri, Transport transport) { } } - private interface Manager { - T loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; - } - private Collection getAllLoadedMetadataRepositories(IProgressMonitor monitor) { if (allLoadedMetadataRepositories == null) { SubMonitor subMonitor = SubMonitor.convert(monitor, 2); var repoManager = agent.getService(IMetadataRepositoryManager.class); getLoadedMetadataRepositories(subMonitor.split(1)); - allLoadedMetadataRepositories = getAllLoadedRepositories(repoManager::loadRepository, + allLoadedMetadataRepositories = getAllLoadedRepositories(repoManager, loadedMetadataRepositories, failedMetadataRepositories, subMonitor.split(1)); } return allLoadedMetadataRepositories.values(); @@ -366,14 +360,14 @@ private Collection getAllLoadedArtifactRepositories(IProgre SubMonitor subMonitor = SubMonitor.convert(monitor, 2); var repoManager = agent.getService(IArtifactRepositoryManager.class); getLoadedArtifactRepositories(subMonitor.split(1)); - allLoadedArtifactRepositories = getAllLoadedRepositories(repoManager::loadRepository, + allLoadedArtifactRepositories = getAllLoadedRepositories(repoManager, loadedArtifactRepositories, failedArtifactRepositories, subMonitor.split(1)); } return allLoadedArtifactRepositories.values(); } - private Map getAllLoadedRepositories(Manager manager, Map loadedRepositories, - Set failedRepositories, IProgressMonitor monitor) { + private > Map getAllLoadedRepositories(IRepositoryManager manager, + Map loadedRepositories, Set failedRepositories, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, loadedRepositories.size()); var allLoadedRepositories = new HashMap<>(loadedRepositories); for (var repository : loadedRepositories.values()) { @@ -382,8 +376,8 @@ private Map getAllLoadedRepositories(Manager manager, Map return allLoadedRepositories; } - private void loadComposites(Manager manager, T repository, Map repos, Set failedRepositories, - IProgressMonitor monitor) { + private > void loadComposites(IRepositoryManager manager, R repository, + Map repos, Set failedRepositories, IProgressMonitor monitor) { if (repository instanceof ICompositeRepository composite) { List children = composite.getChildren(); SubMonitor subMonitor = SubMonitor.convert(monitor, children.size()); @@ -393,18 +387,18 @@ private void loadComposites(Manager manager, T repository, Map re } } - private void loadRepository(Manager manager, URI location, Map repos, Set failedRepositories, + private > void loadRepository(IRepositoryManager manager, URI location, + Map repos, Set failedRepositories, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, 2); - if (repos.containsKey(location) || failedMetadataRepositories.contains(location)) { + if (failedMetadataRepositories.contains(location)) { return; } - - var repository = repos.get(location); - if (repository == null) { + if (!repos.containsKey(location)) { // A previous attempt may have failed try { - repository = manager.loadRepository(location, subMonitor.split(1)); + @SuppressWarnings("unchecked") + R repository = (R) manager.loadRepository(location, subMonitor.split(1)); repos.put(location, repository); loadComposites(manager, repository, repos, failedRepositories, subMonitor.split(1)); } catch (ProvisionException e) { diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java index d9a2514f29..4c584af1f2 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java @@ -16,7 +16,6 @@ import java.io.*; import java.net.URI; -import java.net.URISyntaxException; import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -24,6 +23,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; +import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; import org.eclipse.equinox.p2.core.*; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.index.IIndex; @@ -63,28 +63,8 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl * @return the repository or null if unable to create one */ public static CompositeMetadataRepository createMemoryComposite(IProvisioningAgent agent) { - if (agent == null) - return null; - IMetadataRepositoryManager repoManager = agent.getService(IMetadataRepositoryManager.class); - if (repoManager == null) - return null; - try { - //create a unique opaque URI - long time = System.currentTimeMillis(); - URI repositoryURI = new URI("memory:" + String.valueOf(time)); //$NON-NLS-1$ - while (repoManager.contains(repositoryURI)) - repositoryURI = new URI("memory:" + String.valueOf(++time)); //$NON-NLS-1$ - - CompositeMetadataRepository result = (CompositeMetadataRepository) repoManager.createRepository(repositoryURI, repositoryURI.toString(), IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); - repoManager.removeRepository(repositoryURI); - return result; - } catch (ProvisionException e) { - // just return null - LogHelper.log(e); - } catch (URISyntaxException e) { - // just return null - } - return null; + return (CompositeMetadataRepository) RepositoryHelper.createMemoryComposite(agent, + IMetadataRepositoryManager.class, IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY); } private IMetadataRepositoryManager getManager() { diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java index 8f79df8bb9..f0835d11bb 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java @@ -17,21 +17,13 @@ import java.net.URI; import java.util.Collection; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; import org.eclipse.equinox.internal.p2.publisher.Activator; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.repository.IRepository; -import org.eclipse.equinox.p2.repository.IRepositoryManager; -import org.eclipse.equinox.p2.repository.IRunnableWithProgress; +import org.eclipse.equinox.p2.repository.*; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; @@ -103,17 +95,9 @@ public static IMetadataRepository createMetadataRepository(IProvisioningAgent ag */ public static IMetadataRepository loadMetadataRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { - IMetadataRepositoryManager manager = getService(agent, IMetadataRepositoryManager.SERVICE_NAME); - boolean existing = manager.contains(location); - - IMetadataRepository result = manager.loadRepository(location, - modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); - if (!existing && removeFromManager) - manager.removeRepository(location); - return result; + return loadRepository(agent, IMetadataRepositoryManager.SERVICE_NAME, location, modifiable, removeFromManager); } - /** * Returns an artifact repository that corresponds to the given settings. If a * repository at the given location already exists, it is updated with the @@ -169,13 +153,19 @@ public static IArtifactRepository createArtifactRepository(IProvisioningAgent ag */ 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); + return loadRepository(agent, IArtifactRepositoryManager.SERVICE_NAME, location, modifiable, removeFromManager); + } - IArtifactRepository result = manager.loadRepository(location, - modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); - if (!existing && removeFromManager) + private static > R loadRepository(IProvisioningAgent agent, String serviceName, + URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { + IRepositoryManager manager = getService(agent, serviceName); + boolean existing = manager.contains(location); + int flags = modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0; + @SuppressWarnings("unchecked") + R result = (R) manager.loadRepository(location, flags, null); + if (!existing && removeFromManager) { manager.removeRepository(location); + } return result; } diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF index 5e4bccb72e..83fc1fe961 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.reconciler.dropins;singleton:=true -Bundle-Version: 1.5.100.qualifier +Bundle-Version: 1.5.200.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.reconciler.dropins.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java index ed2e411ae2..30fed3557a 100644 --- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java +++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java @@ -32,6 +32,7 @@ import org.eclipse.equinox.p2.engine.IProfile; import org.eclipse.equinox.p2.engine.IProfileRegistry; import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; @@ -98,12 +99,7 @@ private static IProvisioningAgent getAgent() { * @throws ProvisionException */ public static IMetadataRepository loadMetadataRepository(URI location, IProgressMonitor monitor) throws ProvisionException { - IMetadataRepositoryManager manager = getAgent().getService(IMetadataRepositoryManager.class); - if (manager == null) - throw new IllegalStateException("MetadataRepositoryManager not registered."); //$NON-NLS-1$ - IMetadataRepository repository = manager.loadRepository(location, monitor); - manager.setRepositoryProperty(location, IRepository.PROP_SYSTEM, String.valueOf(true)); - return repository; + return (IMetadataRepository) loadRepository(IMetadataRepositoryManager.class, location, monitor); } /** @@ -141,10 +137,16 @@ public static IArtifactRepository createExtensionLocationArtifactRepository(URI * @throws ProvisionException */ public static IArtifactRepository loadArtifactRepository(URI location, IProgressMonitor monitor) throws ProvisionException { - IArtifactRepositoryManager manager = getAgent().getService(IArtifactRepositoryManager.class); - if (manager == null) - throw new IllegalStateException("ArtifactRepositoryManager not registered."); //$NON-NLS-1$ - IArtifactRepository repository = manager.loadRepository(location, monitor); + return (IArtifactRepository) loadRepository(IArtifactRepositoryManager.class, location, monitor); + } + + private static IRepository loadRepository(Class> repositoryManager, + URI location, IProgressMonitor monitor) throws ProvisionException { + IRepositoryManager manager = getAgent().getService(repositoryManager); + if (manager == null) { + throw new IllegalStateException(repositoryManager.getSimpleName() + " not registered."); //$NON-NLS-1$ + } + IRepository repository = manager.loadRepository(location, monitor); manager.setRepositoryProperty(location, IRepository.PROP_SYSTEM, String.valueOf(true)); return repository; } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF index db69def4d4..05a701dd98 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.p2.repository.tools;singleton:=true -Bundle-Version: 2.4.100.qualifier +Bundle-Version: 2.4.200.qualifier Bundle-Activator: org.eclipse.equinox.p2.internal.repository.tools.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java index fe82a23e67..ea2ffdc338 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java @@ -16,6 +16,7 @@ import java.net.MalformedURLException; import java.net.URI; import java.util.*; +import java.util.function.Predicate; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; @@ -97,11 +98,13 @@ public void setSourceIUs(List ius) { protected void finalizeRepositories() { if (removeAddedRepositories) { IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager(); - for (URI uri : artifactReposToRemove) + for (URI uri : artifactReposToRemove) { artifactRepositoryManager.removeRepository(uri); + } IMetadataRepositoryManager metadataRepositoryManager = getMetadataRepositoryManager(); - for (URI uri : metadataReposToRemove) + for (URI uri : metadataReposToRemove) { metadataRepositoryManager.removeRepository(uri); + } } metadataReposToRemove = null; artifactReposToRemove = null; @@ -127,14 +130,15 @@ public void initializeRepos(IProgressMonitor progress) throws ProvisionException try { curLocation = repo.getRepoLocation(); if (repo.isBoth()) { - addRepository(artifactRepositoryManager, curLocation, 0, progress); - addRepository(metadataRepositoryManager, curLocation, 0, progress); - } else if (repo.isArtifact()) - addRepository(artifactRepositoryManager, curLocation, 0, progress); - else if (repo.isMetadata()) - addRepository(metadataRepositoryManager, curLocation, 0, progress); - else + addRepository(artifactRepositoryManager, curLocation, 0, artifactReposToRemove, progress); + addRepository(metadataRepositoryManager, curLocation, 0, metadataReposToRemove, progress); + } else if (repo.isArtifact()) { + addRepository(artifactRepositoryManager, curLocation, 0, artifactReposToRemove, progress); + } else if (repo.isMetadata()) { + addRepository(metadataRepositoryManager, curLocation, 0, metadataReposToRemove, progress); + } else { throw new ProvisionException(NLS.bind(Messages.unknown_repository_type, repo.getRepoLocation())); + } } catch (ProvisionException e) { if (e.getCause() instanceof MalformedURLException) { throw new ProvisionException(NLS.bind(Messages.exception_invalidSource, curLocation), e); @@ -149,43 +153,33 @@ else if (repo.isMetadata()) // Helper to add a repository. It takes care of adding the repos to the deletion // list and loading it - protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, - IProgressMonitor monitor) throws ProvisionException { - if (!manager.contains(location)) - metadataReposToRemove.add(location); - return manager.loadRepository(location, flags, monitor); - } - - // Helper to add a repository. It takes care of adding the repos to the deletion - // list and loading it - protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, - IProgressMonitor monitor) throws ProvisionException { - if (!manager.contains(location)) - artifactReposToRemove.add(location); + protected IRepository addRepository(IRepositoryManager manager, URI location, int flags, + List repoList, IProgressMonitor monitor) throws ProvisionException { + if (!manager.contains(location)) { + repoList.add(location); + } return manager.loadRepository(location, flags, monitor); } private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { - RepositoryDescriptor artifactRepoDescriptor = null; - RepositoryDescriptor metadataRepoDescriptor = null; - Iterator iter = destinationRepos.iterator(); - while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) { - RepositoryDescriptor repo = iter.next(); - if (repo.isArtifact() && artifactRepoDescriptor == null) - artifactRepoDescriptor = repo; - if (repo.isMetadata() && metadataRepoDescriptor == null) - metadataRepoDescriptor = repo; + destinationArtifactRepository = (IArtifactRepository) initializeDestinationRepo(artifactRepositoryManager, + RepositoryDescriptor::isArtifact); + destinationMetadataRepository = (IMetadataRepository) initializeDestinationRepo(metadataRepositoryManager, + RepositoryDescriptor::isMetadata); + if (destinationMetadataRepository == null && destinationArtifactRepository == null) { + throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations); } + } - if (artifactRepoDescriptor != null) - destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); - if (metadataRepoDescriptor != null) - destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); - - if (destinationMetadataRepository == null && destinationArtifactRepository == null) - throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations); + private IRepository initializeDestinationRepo(IRepositoryManager repositoryManager, + Predicate typeFilter) throws ProvisionException { + Optional descriptor = destinationRepos.stream().filter(typeFilter).findFirst(); + if (descriptor.isPresent()) { + return initializeDestination(descriptor.get(), repositoryManager); + } + return null; } public IMetadataRepository getDestinationMetadataRepository() { @@ -196,55 +190,34 @@ public IArtifactRepository getDestinationArtifactRepository() { return destinationArtifactRepository; } - protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) + protected IRepository initializeDestination(RepositoryDescriptor toInit, IRepositoryManager mgr) throws ProvisionException { - try { - IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), - IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); - if (initDestinationRepository(repository, toInit)) - return repository; - } catch (ProvisionException e) { - // fall through and create a new repository below - } - IMetadataRepository source = null; - try { - if (toInit.getFormat() != null) - source = mgr.loadRepository(toInit.getFormat(), 0, null); - } catch (ProvisionException e) { - // Ignore. + String repositoryType; + List repoList; + if (mgr instanceof IMetadataRepositoryManager) { + repositoryType = IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY; + repoList = metadataReposToRemove; + } else if (mgr instanceof IArtifactRepositoryManager) { + repositoryType = IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY; + repoList = artifactReposToRemove; + } else { + throw new AssertionError("Unsupported repository type: " + mgr.getClass()); //$NON-NLS-1$ } - // This code assumes source has been successfully loaded before this point - // No existing repository; create a new repository at destinationLocation but - // with source's attributes. try { - IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), - toInit.getName() != null ? toInit.getName() - : (source != null ? source.getName() : toInit.getRepoLocation().toString()), - IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); - if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) - result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ - return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result); - } catch (UnsupportedOperationException e) { - throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), - e.getCause()); - } - } - - protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) - throws ProvisionException { - try { - IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), - IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); - if (initDestinationRepository(repository, toInit)) + IRepository repository = addRepository(mgr, toInit.getRepoLocation(), + IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, repoList, null); + if (initDestinationRepository(repository, toInit)) { return repository; + } } catch (ProvisionException e) { // fall through and create a new repository below } - IArtifactRepository source = null; + IRepository source = null; try { - if (toInit.getFormat() != null) + if (toInit.getFormat() != null) { source = mgr.loadRepository(toInit.getFormat(), 0, null); + } } catch (ProvisionException e) { // Ignore. } @@ -253,13 +226,13 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, // with source's attributes. // TODO for now create a Simple repo by default. try { - IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), + IRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), - IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); + repositoryType, source != null ? source.getProperties() : null); if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ - return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); + return RepositoryHelper.validDestinationRepository(result); } catch (UnsupportedOperationException e) { throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); @@ -268,14 +241,16 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) { if (repository != null && repository.isModifiable()) { - if (descriptor.getName() != null) + if (descriptor.getName() != null) { repository.setProperty(IRepository.PROP_NAME, descriptor.getName()); - if (repository instanceof ICompositeRepository && !descriptor.isAppend()) + } + if (repository instanceof ICompositeRepository && !descriptor.isAppend()) { ((ICompositeRepository) repository).removeAllChildren(); - else if (repository instanceof IMetadataRepository && !descriptor.isAppend()) - ((IMetadataRepository) repository).removeAll(); - else if (repository instanceof IArtifactRepository && !descriptor.isAppend()) - ((IArtifactRepository) repository).removeAll(); + } else if (repository instanceof IMetadataRepository metadataRepository && !descriptor.isAppend()) { + metadataRepository.removeAll(); + } else if (repository instanceof IArtifactRepository artifactRepository && !descriptor.isAppend()) { + artifactRepository.removeAll(); + } return true; } return false; @@ -308,11 +283,11 @@ public IArtifactRepository getCompositeArtifactRepository() { } public boolean hasArtifactSources() { - return ((ICompositeRepository) getCompositeArtifactRepository()).getChildren().size() > 0; + return !((ICompositeRepository) getCompositeArtifactRepository()).getChildren().isEmpty(); } public boolean hasMetadataSources() { - return ((ICompositeRepository) getCompositeMetadataRepository()).getChildren().size() > 0; + return !((ICompositeRepository) getCompositeMetadataRepository()).getChildren().isEmpty(); } public abstract IStatus run(IProgressMonitor monitor) throws ProvisionException; diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java index 3c71954668..0fc5eeae47 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java @@ -14,8 +14,7 @@ package org.eclipse.equinox.p2.internal.repository.tools; import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; @@ -23,11 +22,8 @@ import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.repository.ICompositeRepository; -import org.eclipse.equinox.p2.repository.IRepository; -import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.*; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; -import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; @@ -38,7 +34,7 @@ public class CompositeRepositoryApplication extends AbstractApplication { private boolean removeAllChildren = false; private boolean failOnExists = false; private String comparatorID = null; - + public CompositeRepositoryApplication() { super(); } @@ -106,75 +102,57 @@ public void setFailOnExists(boolean value) { } @Override - protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException { - // remove the repo first. - mgr.removeRepository(toInit.getRepoLocation()); - - // first try and load to see if one already exists at that location. - try { - IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null); - if (validRepositoryLocation(repository) && initDestinationRepository(repository, toInit)) - return repository; - throw new ProvisionException(new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation()))); - } catch (ProvisionException e) { - // re-throw the exception if we got anything other than "repo not found" - if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) { - if (e.getCause() instanceof MalformedURLException) - throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); - throw e; - } - } - - IArtifactRepository source = null; - try { - if (toInit.getFormat() != null) - source = mgr.loadRepository(toInit.getFormat(), 0, null); - } catch (ProvisionException e) { - //Ignore. + protected IRepository initializeDestination(RepositoryDescriptor toInit, IRepositoryManager mgr) + throws ProvisionException { + + String repositoryType; + String defaultName; + if (mgr instanceof IArtifactRepositoryManager) { + repositoryType = IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY; + defaultName = Messages.CompositeRepository_default_artifactRepo_name; + } else if (mgr instanceof IMetadataRepositoryManager) { + repositoryType = IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY; + defaultName = Messages.CompositeRepository_default_metadataRepo_name; + } else { + throw new AssertionError("Unsupported repository type: " + mgr.getClass()); //$NON-NLS-1$ } - //This code assumes source has been successfully loaded before this point - try { - //No existing repository; create a new repository at destinationLocation but with source's attributes. - IArtifactRepository repo = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : Messages.CompositeRepository_default_artifactRepo_name), IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null); - initRepository(repo, toInit); - return repo; - } catch (IllegalStateException e) { - mgr.removeRepository(toInit.getRepoLocation()); - throw e; - } - } - - @Override - protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { // remove the repo first. mgr.removeRepository(toInit.getRepoLocation()); // first try and load to see if one already exists at that location. try { - IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null); - if (!validRepositoryLocation(repository) && initDestinationRepository(repository, toInit)) - throw new ProvisionException(new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation()))); + IRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null); + validRepositoryLocation(repository); + if (!initDestinationRepository(repository, toInit)) { + throw new ProvisionException(Status.info( + NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation()))); + } return repository; } catch (ProvisionException e) { // re-throw the exception if we got anything other than "repo not found" if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) { if (e.getCause() instanceof MalformedURLException) - throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); + throw new ProvisionException( + NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); throw e; } } - IMetadataRepository source = null; + IRepository source = null; try { - if (toInit.getFormat() != null) + if (toInit.getFormat() != null) { source = mgr.loadRepository(toInit.getFormat(), 0, null); + } } catch (ProvisionException e) { - //Ignore + // Ignore } - //This code assumes source has been successfully loaded before this point + // This code assumes source has been successfully loaded before this point try { - //No existing repository; create a new repository at destinationLocation but with source's attributes. - IMetadataRepository repo = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : Messages.CompositeRepository_default_metadataRepo_name), IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null); + // No existing repository; create a new repository at destinationLocation but + // with source's attributes. + String name = Optional.ofNullable(toInit.getName()).orElse(source != null ? source.getName() : defaultName); + IRepository repo = mgr.createRepository(toInit.getRepoLocation(), name, repositoryType, + source != null ? source.getProperties() : null); initRepository(repo, toInit); return repo; } catch (IllegalStateException e) { @@ -186,17 +164,16 @@ protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, /* * Determine if the repository is valid for this operation */ - private boolean validRepositoryLocation(IRepository repository) throws ProvisionException { + private void validRepositoryLocation(IRepository repository) throws ProvisionException { if (repository instanceof ICompositeRepository) { // if we have an already existing repository at that location, then throw an error // if the user told us to - if (failOnExists) + if (failOnExists) { throw new ProvisionException(NLS.bind(Messages.CompositeRepository_composite_repository_exists, repository.getLocation())); + } RepositoryHelper.validDestinationRepository(repository); - return true; } // we have a non-composite repo at this location. that is ok because we can co-exist. - return true; } /* diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java index 738ebe1a9c..72ccc01c06 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java @@ -16,19 +16,8 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.URIUtil; +import java.util.*; +import org.eclipse.core.runtime.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -38,24 +27,13 @@ import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; -import org.eclipse.equinox.p2.engine.IProfile; -import org.eclipse.equinox.p2.engine.IProfileRegistry; -import org.eclipse.equinox.p2.engine.IProvisioningPlan; +import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.internal.repository.comparator.ArtifactChecksumComparator; -import org.eclipse.equinox.p2.internal.repository.mirroring.FileMirrorLog; -import org.eclipse.equinox.p2.internal.repository.mirroring.IArtifactMirrorLog; -import org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring; -import org.eclipse.equinox.p2.internal.repository.mirroring.XMLMirrorLog; -import org.eclipse.equinox.p2.metadata.IArtifactKey; -import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.metadata.VersionRange; +import org.eclipse.equinox.p2.internal.repository.mirroring.*; +import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.planner.IPlanner; import org.eclipse.equinox.p2.planner.IProfileChangeRequest; -import org.eclipse.equinox.p2.query.CompoundQueryable; -import org.eclipse.equinox.p2.query.IQuery; -import org.eclipse.equinox.p2.query.IQueryResult; -import org.eclipse.equinox.p2.query.IQueryable; -import org.eclipse.equinox.p2.query.QueryUtil; +import org.eclipse.equinox.p2.query.*; import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; @@ -292,7 +270,8 @@ private IArtifactRepository initializeBaseline() { if (baseline == null) return null; try { - return addRepository(getArtifactRepositoryManager(), baseline, 0, null); + return (IArtifactRepository) addRepository(getArtifactRepositoryManager(), baseline, 0, + artifactReposToRemove, null); } catch (ProvisionException e) { if (mirrorLog != null && e.getStatus() != null) mirrorLog.log(e.getStatus()); diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java index 9b71118eb8..92945f953c 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java @@ -17,18 +17,23 @@ import java.io.File; import java.net.*; import java.util.Objects; +import java.util.stream.LongStream; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.repository.Activator; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.osgi.util.NLS; public class RepositoryHelper { protected static final String FILE_SCHEME = "file"; //$NON-NLS-1$ /** - * If the provided URI can be interpreted as representing a local address (no schema, or one letter schema) - * but is missing the file schema, a new URI is created which represents the local file. - * + * If the provided URI can be interpreted as representing a local address (no schema, or one letter schema) + * but is missing the file schema, a new URI is created which represents the local file. + * * @param location the URI to convert * @return the converted URI, or the original */ @@ -98,4 +103,39 @@ public static IStatus checkRepositoryLocationSyntax(URI location) { } return Status.OK_STATUS; } + + /** + * Create a Composite repository in memory. + * + * @return the repository or null if unable to create one + */ + public static IRepository createMemoryComposite(IProvisioningAgent agent, + Class> repoManagerClass, String repositoryType) { + if (agent == null) { + return null; + } + IRepositoryManager manager = agent.getService(repoManagerClass); + if (manager == null) { + return null; + } + try { + // create a unique URI + URI repositoryURI = LongStream.iterate(System.currentTimeMillis(), t -> t + 1) + .mapToObj(t -> URI.create("memory:" + t)) //$NON-NLS-1$ + .dropWhile(manager::contains).findFirst().orElseThrow(); + IRepository result = manager.createRepository(repositoryURI, repositoryURI.toString(), repositoryType, + null); + manager.removeRepository(repositoryURI); + return result; + } catch (ProvisionException e) { + LogHelper.log(e); + // just return null + } catch (IllegalArgumentException e) { + if (!(e.getCause() instanceof URISyntaxException)) { + throw e; // not thrown by the URI creation above + } // else just return null + } + return null; + } + } \ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java index 5b532c1c8e..d7d3b047c1 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 IBM Corporation and others. + * Copyright (c) 2008, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -7,26 +7,31 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation + * Hannes Wellmann - Generalize create/load/refereshRepository() into IRepositoryManager *******************************************************************************/ package org.eclipse.equinox.p2.repository; import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.query.IQueryable; /** * The common base class for metadata and artifact repository managers. *

- * A repository manager keeps track of a set of known repositories, and provides - * caching of these known repositories to avoid unnecessary loading of repositories - * from the disk or network. + * A repository manager keeps track of a set of known repositories, and provides + * caching of these known repositories to avoid unnecessary loading of + * repositories from the disk or network. *

*

* All {@link URI} instances provided to a repository manager must be absolute. *

+ * * @param the type of contents in the repositories controlled by this manager * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. @@ -36,55 +41,61 @@ public interface IRepositoryManager extends IQueryable { /** * Constant used to indicate that all enabled repositories are of interest. */ - public static final int REPOSITORIES_ALL = 0; + int REPOSITORIES_ALL = 0; /** * Constant used to indicate that only system repositories are of interest. + * * @see IRepository#PROP_SYSTEM * @see #getKnownRepositories(int) */ - public static final int REPOSITORIES_SYSTEM = 1 << 0; + int REPOSITORIES_SYSTEM = 1 << 0; /** * Constant used to indicate that only non-system repositories are of interest. + * * @see IRepository#PROP_SYSTEM * @see #getKnownRepositories(int) */ - public static final int REPOSITORIES_NON_SYSTEM = 1 << 1; + int REPOSITORIES_NON_SYSTEM = 1 << 1; /** * Constant used to indicate that only local repositories are of interest. Any * repository that requires network communication will be omitted when * this flag is used. + * * @see #getKnownRepositories(int) */ - public static final int REPOSITORIES_LOCAL = 1 << 2; + int REPOSITORIES_LOCAL = 1 << 2; /** * Constant used to indicate that only remote repositories are of interest. Any * repository that doesn't require network communication will be omitted when * this flag is used. + * * @see #getKnownRepositories(int) */ - public static final int REPOSITORIES_NON_LOCAL = 1 << 4; + int REPOSITORIES_NON_LOCAL = 1 << 4; /** * Constant used to indicate that only disabled repositories are of interest. * When this flag is used, all enabled repositories will be ignored and * all disabled repositories that match the remaining filters will be returned. + * * @see #getKnownRepositories(int) */ - public static final int REPOSITORIES_DISABLED = 1 << 3; + int REPOSITORIES_DISABLED = 1 << 3; /** * Constant used to indicate that a repository manager should only load the * repository if the repository is modifiable. + * * @see IRepository#isModifiable() */ - public static final int REPOSITORY_HINT_MODIFIABLE = 1 << 0; + int REPOSITORY_HINT_MODIFIABLE = 1 << 0; /** - * Adds the repository at the given location to the list of repositories tracked by + * Adds the repository at the given location to the list of repositories tracked by * this repository manager. This method does not attempt to contact or load * the repository, and makes no attempt to determine whether there is a valid * repository at the provided location. @@ -92,27 +103,28 @@ public interface IRepositoryManager extends IQueryable { * If there is a known disabled repository at the given location, it will become * enabled as a result of this method. Thus the caller can be guaranteed that * there is a known, enabled repository at the given location when this method returns. - * + * * @param location The absolute location of the repository to add * @see #isEnabled(URI) */ - public void addRepository(URI location); + void addRepository(URI location); /** * Returns whether a repository at the given location is in the list of repositories * tracked by this repository manager. - * + * * @param location The absolute location of the repository to look for * @return true if the repository is known to this manager, * and false otherwise */ - public boolean contains(URI location); + boolean contains(URI location); /** * Returns the provisioning agent in charge of this repository manager + * * @return The provisioning agent. */ - public IProvisioningAgent getAgent(); + IProvisioningAgent getAgent(); /** * Returns the repository locations known to the repository manager. @@ -121,41 +133,41 @@ public interface IRepositoryManager extends IQueryable { * exists at any of the returned locations at any particular moment in time. * A subsequent attempt to load a repository at any of the given locations may * or may not succeed. - * + * * @param flags an integer bit-mask indicating which repositories should be - * returned. REPOSITORIES_ALL can be used as the mask when + * returned. REPOSITORIES_ALL can be used as the mask when * all enabled repositories should be returned. Disabled repositories are automatically * excluded unless the {@link #REPOSITORIES_DISABLED} flag is set. * @return the locations of the repositories managed by this repository manager. - * + * * @see #REPOSITORIES_ALL * @see #REPOSITORIES_SYSTEM * @see #REPOSITORIES_NON_SYSTEM * @see #REPOSITORIES_LOCAL * @see #REPOSITORIES_DISABLED */ - public URI[] getKnownRepositories(int flags); + URI[] getKnownRepositories(int flags); /** - * Returns the property associated with the repository at the given URI, + * Returns the property associated with the repository at the given URI, * without loading the repository. *

- * Note that only the repository properties referenced below are tracked by the + * Note that only the repository properties referenced below are tracked by the * repository manager itself. For all other properties, this method will return null. - * Only values for the properties that are already known by a repository manager will be returned. + * Only values for the properties that are already known by a repository manager will be returned. *

*

- * If a client wishes to retrieve a property value from a repository - * regardless of the cost of retrieving it, the client should load the + * If a client wishes to retrieve a property value from a repository + * regardless of the cost of retrieving it, the client should load the * repository and then retrieve the property from the repository itself. *

- * + * * @param location the absolute URI of the repository in question * @param key the String key of the property desired * @return the value of the property, or null if the repository - * does not exist, the value does not exist, or the property value + * does not exist, the value does not exist, or the property value * could not be determined without loading the repository. - * + * * @see IRepository#getProperties() * @see #setRepositoryProperty(URI, String, String) * @see IRepository#PROP_NAME @@ -163,10 +175,10 @@ public interface IRepositoryManager extends IQueryable { * @see IRepository#PROP_DESCRIPTION * @see IRepository#PROP_SYSTEM */ - public String getRepositoryProperty(URI location, String key); + String getRepositoryProperty(URI location, String key); /** - * Sets the property associated with the repository at the given URI, + * Sets the property associated with the repository at the given URI, * without loading the repository. *

* This method stores properties in a cache in the repository manager and does @@ -181,7 +193,7 @@ public interface IRepositoryManager extends IQueryable { * To persistently set a property on a repository, clients must load * the repository and call {@link IRepository#setProperty(String, String)}. *

- * + * * @param location the absolute URI of the repository in question * @param key the String key of the property desired * @param value the value to set the property to @@ -192,58 +204,159 @@ public interface IRepositoryManager extends IQueryable { * @see IRepository#PROP_DESCRIPTION * @see IRepository#PROP_SYSTEM */ - public void setRepositoryProperty(URI location, String key, String value); + void setRepositoryProperty(URI location, String key, String value); /** - * Returns the enablement value of a repository. Disabled repositories are known + * Returns the enablement value of a repository. Disabled repositories are known * to the repository manager, but are never used in the context of provisioning - * operations. Disabled repositories are useful as a form of bookmark to indicate that a + * operations. Disabled repositories are useful as a form of bookmark to indicate that a * repository location is of interest, but not currently used. *

* Note that enablement is a property of the repository manager and not a property - * of the affected repository. The enablement of the repository is discarded when + * of the affected repository. The enablement of the repository is discarded when * a repository is removed from the repository manager. - * + * * @param location The absolute location of the repository whose enablement is requested * @return true if the repository is enabled, and - * false if it is not enabled, or if the repository location + * false if it is not enabled, or if the repository location * is not known to the repository manager. * @see #REPOSITORIES_DISABLED * @see #setEnabled(URI, boolean) */ - public boolean isEnabled(URI location); + boolean isEnabled(URI location); /** * Removes the repository at the given location from the list of - * repositories known to this repository manager. The underlying + * repositories known to this repository manager. The underlying * repository is not deleted. This method has no effect if the given * repository is not already known to this repository manager. - * + * * @param location The absolute location of the repository to remove - * @return true if a repository was removed, and + * @return true if a repository was removed, and * false otherwise. */ - public boolean removeRepository(URI location); + boolean removeRepository(URI location); /** * Sets the enablement of a repository. Disabled repositories are known * to the repository manager, but are never used in the context of provisioning - * operation. Disabled repositories are useful as a form of bookmark to indicate that a + * operation. Disabled repositories are useful as a form of bookmark to indicate that a * repository location is of interest, but not currently used. *

* Note that enablement is a property of the repository manager and not a property - * of the affected repository. The enablement of the repository is discarded when + * of the affected repository. The enablement of the repository is discarded when * a repository is removed from the repository manager. *

* This method has no effect if the given repository location is not known to the * repository manager. - * + * * @param location The absolute location of the repository to enable or disable * @param enablement trueto enable the repository, and * false to disable the repository * @see #REPOSITORIES_DISABLED * @see #isEnabled(URI) */ - public void setEnabled(URI location, boolean enablement); + void setEnabled(URI location, boolean enablement); + + + /** + * Creates and returns a new empty repository of the given type at the given location. + *

+ * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + *

+ * + * @param location the absolute location for the new repository + * @param name the name of the new repository + * @param type the kind of repository to create + * @param properties the properties to set on the repository + * @return the newly created repository + * @throws ProvisionException if the repository could not be created. Reasons include: + *
    + *
  • The repository type is unknown.
  • + *
  • There was an error writing to the given repository location.
  • + *
  • A repository already exists at that location.
  • + *
+ * @since 2.8 + */ + IRepository createRepository(URI location, String name, String type, Map properties) + throws ProvisionException; + + /** + * Loads the repository at the given location. If a repository has + * previously been loaded at that location, the same cached repository + * may be returned. + *

+ * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + *

+ * + * @param location the absolute location of the repository to load + * @param monitor a progress monitor, or null if progress + * reporting is not desired + * @return the loaded repository + * @throws ProvisionException if the repository could not be created. Reasons include: + *
    + *
  • There is no existing repository at that location.
  • + *
  • The repository at that location could not be read.
  • + *
+ * @since 2.8 + */ + IRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + + /** + * Loads the repository at the given location. If a repository has + * previously been loaded at that location, the same cached repository may be returned. + *

+ * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + *

+ *

+ * The flags passed in should be taken as a hint for the type of repository to load. If + * the manager cannot load a repository that satisfies these hints, it can fail fast. + *

+ * + * @param location the absolute location of the repository to load + * @param flags bit-wise or of flags to consider when loading the repository + * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) + * @param monitor a progress monitor, or null if progress + * reporting is not desired + * @return the loaded repository + * @throws ProvisionException if the repository could not be created. Reasons include: + *
    + *
  • There is no existing repository at that location.
  • + *
  • The repository at that location could not be read.
  • + *
+ * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE + * @since 2.8 + */ + IRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + + /** + * Refreshes the repository corresponding to the given URL. This method discards + * any cached state held by the repository manager and reloads the repository + * contents. The provided repository location must already be known to the repository + * manager. + * + * @param location The absolute location of the repository to refresh + * @param monitor a progress monitor, or null if progress + * reporting is not desired + * @return The refreshed repository + * @throws ProvisionException if the repository could not be refreshed. Reasons include: + *
    + *
  • The location is not known to the repository manager.
  • + *
  • There is no existing repository at that location.
  • + *
  • The repository at that location could not be read.
  • + *
+ * @since 2.8 + */ + IRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java index ecd5ea36da..089afe593a 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 IBM Corporation and others. + * Copyright (c) 2007, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,9 +23,9 @@ /** * A metadata repository manager is used to create, access, and manipulate - * {@link IArtifactRepository} instances. See {@link IRepositoryManager} - * for a general description of the characteristics of repository managers. - * + * {@link IArtifactRepository} instances. See {@link IRepositoryManager} for a + * general description of the characteristics of repository managers. + * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. * @since 2.0 @@ -34,53 +34,58 @@ public interface IArtifactRepositoryManager extends IRepositoryManagernull to indicate no additional properties are needed * @param destinationRepositoryProperties additional repository specific properties for use in creating the repositor's ArtifactDescriptor, - * , or null to indicate no additional properties are needed + * or null to indicate no additional properties are needed * @return the newly created request object */ - public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map destinationDescriptorProperties, Map destinationRepositoryProperties); + IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, + Map destinationDescriptorProperties, Map destinationRepositoryProperties); /** * Return a new request to mirror the given artifact into the destination repository. + * * @param key the artifact to mirror * @param destination the destination where the artifact will be mirrored - * @param destinationDescriptorProperties additional properties for use in creating the repository's ArtifactDescriptor, + * @param destinationDescriptorProperties additional properties for use in creating the repository's ArtifactDescriptor, * or null to indicate no additional properties are needed * @param destinationRepositoryProperties additional repository specific properties for use in creating the repositor's ArtifactDescriptor, - * , or null to indicate no additional properties are needed - * @param downloadStatsParameters additional customizable parameters for downloading statistics - * , or null to indicate no additional customizable stats parameters + * or null to indicate no additional properties are needed + * @param downloadStatsParameters additional customizable parameters for downloading statistics, + * or null to indicate no additional customizable stats parameters * @return the newly created request object * @see IArtifactRepositoryManager#createMirrorRequest(IArtifactKey, IArtifactRepository, Map, Map) * @since 2.2 */ - public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map destinationDescriptorProperties, Map destinationRepositoryProperties, String downloadStatsParameters); + IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, + Map destinationDescriptorProperties, Map destinationRepositoryProperties, + String downloadStatsParameters); /** - * Creates and returns a new empty artifact repository of the given type at + * Creates and returns a new empty artifact repository of the given type at * the given location. *

* The resulting repository is added to the list of repositories tracked by @@ -88,48 +93,51 @@ public interface IArtifactRepositoryManager extends IRepositoryManager - * + * * @param location the absolute location for the new repository * @param name the name of the new repository * @param type the kind of repository to create * @param properties the properties to set on the repository * @return the newly created repository - * @throws ProvisionException if the repository could not be created. Reasons include: + * @throws ProvisionException if the repository could not be created. Reasons include: *

    *
  • The repository type is unknown.
  • *
  • There was an error writing to the given repository location.
  • *
  • A repository already exists at that location.
  • *
*/ - public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException; + @Override + IArtifactRepository createRepository(URI location, String name, String type, Map properties) + throws ProvisionException; /** - * Loads the repository at the given location. The location is expected to contain - * data that describes a valid artifact repository of a known type. If this manager - * already knows a repository at the given location then that repository is returned. + * Loads the repository at the given location. The location is expected to contain + * data that describes a valid artifact repository of a known type. If a repository has + * previously been loaded at that location, the same cached repository may be returned. *

* The resulting repository is added to the list of repositories tracked by * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} * if they do not want the repository manager to remember the repository for subsequent * load attempts. *

- * - * @param location the absolute location in which to look for a repository description + * + * @param location the absolute location of the repository to load * @param monitor a progress monitor, or null if progress * reporting is not desired - * @return a repository object for the given location - * @throws ProvisionException if the repository could not be created. Reasons include: + * @return the loaded artifact repository + * @throws ProvisionException if the repository could not be created. Reasons include: *
    *
  • There is no existing repository at that location.
  • *
  • The repository at that location could not be read.
  • *
*/ - public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + @Override + IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; /** - * Loads the repository at the given location. The location is expected to contain - * data that describes a valid artifact repository of a known type. If this manager - * already knows a repository at the given location then that repository is returned. + * Loads the repository at the given location. The location is expected to contain + * data that describes a valid artifact repository of a known type. If a repository + * has previously been loaded at that location, the same cached repository may be returned. *

* The resulting repository is added to the list of repositories tracked by * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} @@ -137,41 +145,44 @@ public interface IArtifactRepositoryManager extends IRepositoryManager *

- * The flags passed in should be taken as a hint for the type of repository to load. If + * The flags passed in should be taken as a hint for the type of repository to load. If * the manager cannot load a repository that satisfies these hints, it can fail fast. *

- * @param location the absolute location in which to look for a repository description - * @param flags - bit-wise or of flags to consider when loading the repository + * + * @param location the absolute location of the repository to load + * @param flags bit-wise or of flags to consider when loading the repository * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) * @param monitor a progress monitor, or null if progress * reporting is not desired - * @return a repository object for the given location - * @throws ProvisionException if the repository could not be created. Reasons include: + * @return the loaded artifact repository + * @throws ProvisionException if the repository could not be created. Reasons include: *
    *
  • There is no existing repository at that location.
  • *
  • The repository at that location could not be read.
  • *
* @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE */ - public IArtifactRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + @Override + IArtifactRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; /** * Refreshes the repository corresponding to the given URL. This method discards * any cached state held by the repository manager and reloads the repository * contents. The provided repository location must already be known to the repository * manager. - * + * * @param location The absolute location of the repository to refresh * @param monitor a progress monitor, or null if progress * reporting is not desired * @return The refreshed metadata repository - * @throws ProvisionException if the repository could not be created. Reasons include: + * @throws ProvisionException if the repository could not be refreshed. Reasons include: *
    *
  • The location is not known to the repository manager.
  • *
  • There is no existing repository at that location.
  • *
  • The repository at that location could not be read.
  • *
*/ - public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + @Override + IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; -} \ No newline at end of file +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java index 1d3d541421..0e338f2740 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,9 +23,9 @@ /** * A metadata repository manager is used to create, access, and manipulate - * {@link IMetadataRepository} instances. See {@link IRepositoryManager} - * for a general description of the characteristics of repository managers. - * + * {@link IMetadataRepository} instances. See {@link IRepositoryManager} for a + * general description of the characteristics of repository managers. + * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. * @since 2.0 @@ -34,20 +34,20 @@ public interface IMetadataRepositoryManager extends IRepositoryManager * The resulting repository is added to the list of repositories tracked by @@ -55,13 +55,13 @@ public interface IMetadataRepositoryManager extends IRepositoryManager - * + * * @param location the absolute location for the new repository * @param name the name of the new repository * @param type the kind of repository to create * @param properties the properties to set on the repository * @return the newly created repository - * @throws ProvisionException if the repository could not be created. Reasons include: + * @throws ProvisionException if the repository could not be created. Reasons include: *
    *
  • The repository type is unknown.
  • *
  • There was an error writing to the given repository location.
  • @@ -69,11 +69,13 @@ public interface IMetadataRepositoryManager extends IRepositoryManager * @throws OperationCanceledException if this operation has been canceled */ - public IMetadataRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException, OperationCanceledException; + @Override + IMetadataRepository createRepository(URI location, String name, String type, Map properties) + throws ProvisionException, OperationCanceledException; /** - * Loads a repository corresponding to the given URL. If a repository has - * previously been loaded at the given location, the same cached repository + * Loads the repository at the given location. If a repository has + * previously been loaded at that location, the same cached repository * may be returned. *

    * The resulting repository is added to the list of repositories tracked by @@ -81,24 +83,25 @@ public interface IMetadataRepositoryManager extends IRepositoryManager - * - * @param location The absolute location of the repository to load + * + * @param location the absolute location of the repository to load * @param monitor a progress monitor, or null if progress * reporting is not desired - * @return The loaded metadata repository + * @return the loaded metadata repository * @throws OperationCanceledException if this operation has been canceled - * @throws ProvisionException if the repository could not be created. Reasons include: + * @throws ProvisionException if the repository could not be created. Reasons include: *

      *
    • There is no existing repository at that location.
    • *
    • The repository at that location could not be read.
    • *
    */ - public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException, OperationCanceledException; + @Override + IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) + throws ProvisionException, OperationCanceledException; /** - * Loads a repository corresponding to the given URL. If a repository has - * previously been loaded at the given location, the same cached repository - * may be returned. + * Loads the repository at the given location. If a repository has + * previously been loaded at that location, the same cached repository may be returned. *

    * The resulting repository is added to the list of repositories tracked by * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} @@ -106,43 +109,48 @@ public interface IMetadataRepositoryManager extends IRepositoryManager *

    - * The flags passed in should be taken as a hint for the type of repository to load. If + * The flags passed in should be taken as a hint for the type of repository to load. If * the manager cannot load a repository that satisfies these hints, it can fail fast. *

    - * @param location The absolute location of the repository to load - * @param flags - bit-wise or of flags to consider when loading the repository + * + * @param location the absolute location of the repository to load + * @param flags bit-wise or of flags to consider when loading the repository * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) * @param monitor a progress monitor, or null if progress * reporting is not desired - * @return The loaded metadata repository + * @return the loaded metadata repository * @throws OperationCanceledException if this operation has been canceled - * @throws ProvisionException if the repository could not be created. Reasons include: + * @throws ProvisionException if the repository could not be created. Reasons include: *
      *
    • There is no existing repository at that location.
    • *
    • The repository at that location could not be read.
    • *
    * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE */ - public IMetadataRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException, OperationCanceledException; + @Override + IMetadataRepository loadRepository(URI location, int flags, IProgressMonitor monitor) + throws ProvisionException, OperationCanceledException; /** * Refreshes the repository corresponding to the given URL. This method discards * any cached state held by the repository manager and reloads the repository * contents. The provided repository location must already be known to the repository * manager. - * + * * @param location The absolute location of the repository to refresh * @param monitor a progress monitor, or null if progress * reporting is not desired * @return The refreshed metadata repository * @throws OperationCanceledException if this operation has been canceled - * @throws ProvisionException if the repository could not be refreshed. Reasons include: + * @throws ProvisionException if the repository could not be refreshed. Reasons include: *
      *
    • The location is not known to the repository manager.
    • *
    • There is no existing repository at that location.
    • *
    • The repository at that location could not be read.
    • *
    */ - public IMetadataRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException, OperationCanceledException; + @Override + IMetadataRepository refreshRepository(URI location, IProgressMonitor monitor) + throws ProvisionException, OperationCanceledException; } diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ui.admin/META-INF/MANIFEST.MF index a9fc2f8740..c11798c19b 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.ui.admin/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.p2.ui.admin;singleton:=true -Bundle-Version: 1.3.100.qualifier +Bundle-Version: 1.3.200.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.ui.admin.ProvAdminUIActivator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java index fc452cfa89..91312b0f84 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoriesView.java @@ -68,8 +68,9 @@ protected int getListenerEventTypes() { @Override protected RepositoryTracker getRepositoryTracker() { - if (tracker == null) - tracker = new ArtifactRepositoryTracker(getProvisioningUI()); + if (tracker == null) { + tracker = SingleRepositoryTracker.createArtifactRepositoryTracker(getProvisioningUI()); + } return tracker; } diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java index cf01e65ecf..83b7a1f17b 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoriesView.java @@ -136,8 +136,9 @@ protected void updateCachesForPreferences() { @Override protected RepositoryTracker getRepositoryTracker() { - if (tracker == null) - tracker = new MetadataRepositoryTracker(getProvisioningUI()); + if (tracker == null) { + tracker = SingleRepositoryTracker.createMetadataRepositoryTracker(getProvisioningUI()); + } return tracker; } } diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoryTracker.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoryTracker.java deleted file mode 100644 index 5ea9a6378a..0000000000 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/MetadataRepositoryTracker.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.equinox.internal.p2.ui.admin; - -import java.net.URI; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.equinox.internal.p2.ui.ProvUI; -import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; -import org.eclipse.equinox.p2.core.ProvisionException; -import org.eclipse.equinox.p2.operations.ProvisioningSession; -import org.eclipse.equinox.p2.operations.RepositoryTracker; -import org.eclipse.equinox.p2.repository.IRepository; -import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; -import org.eclipse.equinox.p2.ui.ProvisioningUI; - -public class MetadataRepositoryTracker extends RepositoryTracker { - - ProvisioningUI ui; - - public MetadataRepositoryTracker(ProvisioningUI ui) { - this.ui = ui; - } - - @Override - public URI[] getKnownRepositories(ProvisioningSession session) { - return getMetadataRepositoryManager().getKnownRepositories(getArtifactRepositoryFlags()); - } - - @Override - public void addRepository(URI repoLocation, String nickname, ProvisioningSession session) { - ui.signalRepositoryOperationStart(); - try { - getMetadataRepositoryManager().addRepository(repoLocation); - if (nickname != null) - getMetadataRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_NICKNAME, nickname); - - } finally { - ui.signalRepositoryOperationComplete(new RepositoryEvent(repoLocation, IRepository.TYPE_METADATA, RepositoryEvent.ADDED, true), true); - } - } - - @Override - public void removeRepositories(URI[] repoLocations, ProvisioningSession session) { - ui.signalRepositoryOperationStart(); - try { - for (URI repoLocation : repoLocations) { - getMetadataRepositoryManager().removeRepository(repoLocation); - } - } finally { - ui.signalRepositoryOperationComplete(null, true); - } - } - - @Override - public void refreshRepositories(URI[] locations, ProvisioningSession session, IProgressMonitor monitor) { - ui.signalRepositoryOperationStart(); - SubMonitor mon = SubMonitor.convert(monitor, locations.length * 100); - for (URI location : locations) { - try { - getMetadataRepositoryManager().refreshRepository(location, mon.newChild(100)); - }catch (ProvisionException e) { - //ignore problematic repositories when refreshing - } - } - // We have no idea how many repos may have been added/removed as a result of - // refreshing these, this one, so we do not use a specific repository event to represent it. - ui.signalRepositoryOperationComplete(null, true); - } - - IMetadataRepositoryManager getMetadataRepositoryManager() { - return ProvUI.getMetadataRepositoryManager(ui.getSession()); - } - - @Override - protected boolean contains(URI location, ProvisioningSession session) { - return ProvUI.getMetadataRepositoryManager(session).contains(location); - } -} \ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoryTracker.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/SingleRepositoryTracker.java similarity index 55% rename from bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoryTracker.java rename to bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/SingleRepositoryTracker.java index f12434eccf..badf9b9f5f 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ArtifactRepositoryTracker.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/SingleRepositoryTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hannes Wellmann - Unify ArtifactRepositoryTracker and MetadataRepositoryTracker to one class ******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin; @@ -17,38 +18,53 @@ import java.net.URI; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.equinox.internal.p2.ui.ProvUI; import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.operations.ProvisioningSession; import org.eclipse.equinox.p2.operations.RepositoryTracker; import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.equinox.p2.ui.ProvisioningUI; -public class ArtifactRepositoryTracker extends RepositoryTracker { +public class SingleRepositoryTracker extends RepositoryTracker { - ProvisioningUI ui; + public static RepositoryTracker createMetadataRepositoryTracker(ProvisioningUI ui) { + return new SingleRepositoryTracker(ui, IRepository.TYPE_METADATA, IMetadataRepositoryManager.class); + } + + public static RepositoryTracker createArtifactRepositoryTracker(ProvisioningUI ui) { + return new SingleRepositoryTracker(ui, IRepository.TYPE_ARTIFACT, IArtifactRepositoryManager.class); + } - public ArtifactRepositoryTracker(ProvisioningUI ui) { + private final ProvisioningUI ui; + private final int repositoryType; + private final Class> repositoryManagerType; + + private SingleRepositoryTracker(ProvisioningUI ui, int repositoryType, + Class> repositoryManagerType) { this.ui = ui; + this.repositoryType = repositoryType; + this.repositoryManagerType = repositoryManagerType; } @Override public URI[] getKnownRepositories(ProvisioningSession session) { - return getArtifactRepositoryManager().getKnownRepositories(getArtifactRepositoryFlags()); + return getRepositoryManager().getKnownRepositories(getArtifactRepositoryFlags()); } @Override public void addRepository(URI repoLocation, String nickname, ProvisioningSession session) { ui.signalRepositoryOperationStart(); try { - getArtifactRepositoryManager().addRepository(repoLocation); - if (nickname != null) - getArtifactRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_NICKNAME, nickname); + getRepositoryManager().addRepository(repoLocation); + if (nickname != null) { + getRepositoryManager().setRepositoryProperty(repoLocation, IRepository.PROP_NICKNAME, nickname); + } } finally { ui.signalRepositoryOperationComplete( - new RepositoryEvent(repoLocation, IRepository.TYPE_ARTIFACT, RepositoryEvent.ADDED, true), true); + new RepositoryEvent(repoLocation, repositoryType, RepositoryEvent.ADDED, true), true); } } @@ -57,7 +73,7 @@ public void removeRepositories(URI[] repoLocations, ProvisioningSession session) ui.signalRepositoryOperationStart(); try { for (URI repoLocation : repoLocations) { - getArtifactRepositoryManager().removeRepository(repoLocation); + getRepositoryManager().removeRepository(repoLocation); } } finally { ui.signalRepositoryOperationComplete(null, true); @@ -70,8 +86,8 @@ public void refreshRepositories(URI[] locations, ProvisioningSession session, IP SubMonitor mon = SubMonitor.convert(monitor, locations.length * 100); for (URI location : locations) { try { - getArtifactRepositoryManager().refreshRepository(location, mon.newChild(100)); - }catch (ProvisionException e) { + getRepositoryManager().refreshRepository(location, mon.newChild(100)); + } catch (ProvisionException e) { // ignore problematic repositories when refreshing } } @@ -81,12 +97,12 @@ public void refreshRepositories(URI[] locations, ProvisioningSession session, IP ui.signalRepositoryOperationComplete(null, true); } - IArtifactRepositoryManager getArtifactRepositoryManager() { - return ProvUI.getArtifactRepositoryManager(ui.getSession()); + private IRepositoryManager getRepositoryManager() { + return ui.getSession().getProvisioningAgent().getService(repositoryManagerType); } @Override protected boolean contains(URI location, ProvisioningSession session) { - return ProvUI.getArtifactRepositoryManager(session).contains(location); + return session.getProvisioningAgent().getService(repositoryManagerType).contains(location); } } \ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java index 3d7ff4a4a8..91bb95edc9 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddArtifactRepositoryDialog.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin.dialogs; -import org.eclipse.equinox.internal.p2.ui.admin.ArtifactRepositoryTracker; +import org.eclipse.equinox.internal.p2.ui.admin.SingleRepositoryTracker; import org.eclipse.equinox.internal.p2.ui.dialogs.AddRepositoryDialog; import org.eclipse.equinox.p2.operations.RepositoryTracker; import org.eclipse.equinox.p2.ui.ProvisioningUI; @@ -36,7 +36,7 @@ public AddArtifactRepositoryDialog(Shell parentShell, ProvisioningUI ui) { @Override protected RepositoryTracker getRepositoryTracker() { if (tracker == null) { - tracker = new ArtifactRepositoryTracker(getProvisioningUI()); + tracker = SingleRepositoryTracker.createArtifactRepositoryTracker(getProvisioningUI()); } return tracker; } diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java index 5f9c64b0b6..6739157d98 100644 --- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/dialogs/AddMetadataRepositoryDialog.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.admin.dialogs; -import org.eclipse.equinox.internal.p2.ui.admin.MetadataRepositoryTracker; +import org.eclipse.equinox.internal.p2.ui.admin.SingleRepositoryTracker; import org.eclipse.equinox.internal.p2.ui.dialogs.AddRepositoryDialog; import org.eclipse.equinox.p2.operations.RepositoryTracker; import org.eclipse.equinox.p2.ui.ProvisioningUI; @@ -36,7 +36,7 @@ public AddMetadataRepositoryDialog(Shell parentShell, ProvisioningUI ui) { @Override protected RepositoryTracker getRepositoryTracker() { if (tracker == null) { - tracker = new MetadataRepositoryTracker(getProvisioningUI()); + tracker = SingleRepositoryTracker.createMetadataRepositoryTracker(getProvisioningUI()); } return tracker; }