diff options
author | Pascal Rapicault | 2009-04-23 18:33:44 +0000 |
---|---|---|
committer | Pascal Rapicault | 2009-04-23 18:33:44 +0000 |
commit | 9fcfced640aa4e4e24f51c88aadd2d6787a07c13 (patch) | |
tree | 81cc2fe29b3a4504e616b695f32e963bd3bd27ef /bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository | |
parent | f4183426a566f3c3d9be31c08bd60e4ebf660f1a (diff) | |
download | rt.equinox.p2-9fcfced640aa4e4e24f51c88aadd2d6787a07c13.tar.gz rt.equinox.p2-9fcfced640aa4e4e24f51c88aadd2d6787a07c13.tar.xz rt.equinox.p2-9fcfced640aa4e4e24f51c88aadd2d6787a07c13.zip |
Bug 265550 - Review Ant task consistency
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository')
8 files changed, 624 insertions, 162 deletions
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 f640754c4..d02c1b4ce 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 @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; -import java.net.URI; -import java.net.URISyntaxException; +import java.net.*; import java.util.*; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; @@ -22,13 +22,13 @@ import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifact import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.repository.*; +import org.eclipse.osgi.util.NLS; public abstract class AbstractApplication { + protected boolean removeAddedRepositories = true; - protected List sourceArtifactRepositories = new ArrayList(); - protected List sourceMetadataRepositories = new ArrayList(); + protected List sourceRepositories = new ArrayList(); //List of repository descriptors protected List artifactReposToRemove = new ArrayList(); protected List metadataReposToRemove = new ArrayList(); protected List sourceIUs = new ArrayList(); @@ -40,92 +40,89 @@ public abstract class AbstractApplication { private CompositeMetadataRepository compositeMetadataRepository = null; private CompositeArtifactRepository compositeArtifactRepository = null; - public void addSourceMetadataRepository(String location) { - URI uri = Activator.getURI(location); - if (uri != null) - sourceMetadataRepositories.add(RepositoryHelper.localRepoURIHelper(uri)); - } - - public void addSourceMetadataRepository(URI location) { - if (location != null) - sourceMetadataRepositories.add(RepositoryHelper.localRepoURIHelper(location)); - } - - public List getSourceMetadataRepositories() { - return sourceMetadataRepositories; - } - - public void addSourceArtifactRepository(String location) { - URI uri = Activator.getURI(location); - if (uri != null) - sourceArtifactRepositories.add(RepositoryHelper.localRepoURIHelper(uri)); - } - - public void addSourceArtifactRepository(URI location) { - if (location != null) - sourceArtifactRepositories.add(RepositoryHelper.localRepoURIHelper(location)); - } - public void setSourceIUs(List ius) { sourceIUs = ius; } protected void finalizeRepositories() throws ProvisionException { - IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); - for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) - artifactRepositoryManager.removeRepository((URI) iter.next()); - IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); - for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) - metadataRepositoryManager.removeRepository((URI) iter.next()); + if (removeAddedRepositories) { + IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); + for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) + artifactRepositoryManager.removeRepository((URI) iter.next()); + IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); + for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) + metadataRepositoryManager.removeRepository((URI) iter.next()); + } } public void initializeRepos(IProgressMonitor progress) throws ProvisionException { IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); - if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { - for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { - URI repoLocation = (URI) iter.next(); - if (!artifactRepositoryManager.contains(repoLocation)) - artifactReposToRemove.add(repoLocation); - artifactRepositoryManager.loadRepository(repoLocation, 0, progress); - } - } - IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); - if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) { - for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) { - URI repoLocation = (URI) iter.next(); - if (!metadataRepositoryManager.contains(repoLocation)) - metadataReposToRemove.add(repoLocation); - metadataRepositoryManager.loadRepository(repoLocation, 0, progress); + URI curLocation = null; + try { + for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { + RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + 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 + 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); + } + throw e; } - processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); + } + + //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); + return manager.loadRepository(location, flags, monitor); } private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { - if (destinationRepos.size() != 2) { - throw new ProvisionException("Too many or too few destination repositories."); + RepositoryDescriptor artifactRepoDescriptor = null; + RepositoryDescriptor metadataRepoDescriptor = null; + + Iterator iter = destinationRepos.iterator(); + while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) { + RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + if (repo.isArtifact() && artifactRepoDescriptor == null) + artifactRepoDescriptor = repo; + if (repo.isMetadata() && metadataRepoDescriptor == null) + metadataRepoDescriptor = repo; } - RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); - RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); - destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); - destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); + + 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 IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { + protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { try { - if (!mgr.contains(toInit.getRepoLocation())) - metadataReposToRemove.add(toInit.getRepoLocation()); - IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); - if (repository != null && repository.isModifiable()) { - if (toInit.getName() != null) - repository.setName(toInit.getName()); - if (!toInit.isAppend()) - repository.removeAll(); + 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 } @@ -133,51 +130,63 @@ public abstract class AbstractApplication { IMetadataRepository source = null; try { if (toInit.getFormat() != null) - source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null); + source = mgr.loadRepository(toInit.getFormat(), 0, null); } catch (ProvisionException e) { //Ignore. - } catch (URISyntaxException e) { - //Ignore } //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. - 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); + 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()); + } } - private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException { + protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException { try { - if (!mgr.contains(toInit.getRepoLocation())) - artifactReposToRemove.add(toInit.getRepoLocation()); - IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); - if (repository != null && repository.isModifiable()) { - if (toInit.getName() != null) - repository.setName(toInit.getName()); - if (!toInit.isAppend()) - repository.removeAll(); + IArtifactRepository 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 } IArtifactRepository source = null; try { if (toInit.getFormat() != null) - source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null); + source = mgr.loadRepository(toInit.getFormat(), 0, null); } catch (ProvisionException e) { //Ignore. - } catch (URISyntaxException e) { - //Ignore } //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. // TODO for now create a Simple repo by default. - IArtifactRepository 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); - if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) - result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ - return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); + try { + IArtifactRepository 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); + if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) + result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ + return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); + } catch (UnsupportedOperationException e) { + throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause()); + } + } + + protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) { + if (repository != null && repository.isModifiable()) { + if (descriptor.getName() != null) + repository.setName(descriptor.getName()); + 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(); + return true; + } + return false; } public IMetadataRepository getCompositeMetadataRepository() { @@ -187,8 +196,10 @@ public abstract class AbstractApplication { } catch (URISyntaxException e) { //Can't happen } - for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) { - compositeMetadataRepository.addChild((URI) iter.next()); + for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { + RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + if (repo.isMetadata()) + compositeMetadataRepository.addChild(repo.getRepoLocation()); } } return compositeMetadataRepository; @@ -197,20 +208,34 @@ public abstract class AbstractApplication { public IArtifactRepository getCompositeArtifactRepository() { if (compositeArtifactRepository == null) { try { - compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$ + compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$ } catch (URISyntaxException e) { //Can't happen } - for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { - compositeArtifactRepository.addChild((URI) iter.next()); + for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { + RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); + if (repo.isArtifact()) + compositeArtifactRepository.addChild(repo.getRepoLocation()); } } return compositeArtifactRepository; } + public boolean hasArtifactSources() { + return ((ICompositeRepository) getCompositeArtifactRepository()).getChildren().size() > 0; + } + + public boolean hasMetadataSources() { + return ((ICompositeRepository) getCompositeMetadataRepository()).getChildren().size() > 0; + } + public abstract IStatus run(IProgressMonitor monitor) throws ProvisionException; public void addDestination(RepositoryDescriptor descriptor) { destinationRepos.add(descriptor); } + + public void addSource(RepositoryDescriptor repo) { + sourceRepositories.add(repo); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java index 9270600e9..5c101ea89 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java @@ -19,6 +19,7 @@ import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifact import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.osgi.util.NLS; import org.osgi.framework.*; import org.osgi.service.packageadmin.PackageAdmin; @@ -43,7 +44,7 @@ public class Activator implements BundleActivator { // TODO needed to do this to ensure the profile registry was registered Bundle bundle = getBundle("org.eclipse.equinox.p2.exemplarysetup"); //$NON-NLS-1$ if (bundle == null) - throw new ProvisionException("Unable to start exemplarysetup bundle."); + throw new ProvisionException(Messages.unable_to_start_exemplarysetup); bundle.start(Bundle.START_TRANSIENT); } @@ -64,7 +65,7 @@ public class Activator implements BundleActivator { try { return URIUtil.fromString(spec); } catch (URISyntaxException e) { - LogHelper.log(new Status(IStatus.WARNING, ID, "Unable to process as URI: " + spec, e)); + LogHelper.log(new Status(IStatus.WARNING, ID, NLS.bind(Messages.unable_to_process_uri, spec), e)); } return null; } @@ -75,7 +76,7 @@ public class Activator implements BundleActivator { public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException { IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(getBundleContext(), IArtifactRepositoryManager.class.getName()); if (manager == null) - throw new ProvisionException("Unable to acquire artifact repository manager service."); + throw new ProvisionException(Messages.no_artifactRepo_manager); return manager; } @@ -85,7 +86,7 @@ public class Activator implements BundleActivator { static IProfileRegistry getProfileRegistry() throws ProvisionException { IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(getBundleContext(), IProfileRegistry.class.getName()); if (registry == null) - throw new ProvisionException("Unable to acquire profile registry service."); + throw new ProvisionException(Messages.no_profile_registry); return registry; } @@ -95,7 +96,7 @@ public class Activator implements BundleActivator { public static synchronized Bundle getBundle(String symbolicName) throws ProvisionException { PackageAdmin packageAdmin = (PackageAdmin) ServiceHelper.getService(getBundleContext(), PackageAdmin.class.getName()); if (packageAdmin == null) - throw new ProvisionException("Unable to acquire package admin service."); + throw new ProvisionException(Messages.no_package_admin); Bundle[] bundles = packageAdmin.getBundles(symbolicName, null); if (bundles == null) return null; @@ -113,7 +114,7 @@ public class Activator implements BundleActivator { public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(getBundleContext(), IMetadataRepositoryManager.class.getName()); if (manager == null) - throw new ProvisionException("Unable to acquire metadata repository manager service."); + throw new ProvisionException(Messages.no_metadataRepo_manager); return manager; } } 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 new file mode 100644 index 000000000..dd5fa9fe8 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools; + +import java.net.MalformedURLException; +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; +import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository; +import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.osgi.util.NLS; + +public class CompositeRepositoryApplication extends AbstractApplication { + private List childrenToAdd = new ArrayList(); + private List childrenToRemove = new ArrayList(); + private boolean failOnExists = false; + + public IStatus run(IProgressMonitor monitor) throws ProvisionException { + try { + initializeRepos(new NullProgressMonitor()); + // load repository + ICompositeRepository metadataRepo = (ICompositeRepository) destinationMetadataRepository; + ICompositeRepository artifactRepo = (ICompositeRepository) destinationArtifactRepository; + + // Remove children from the Composite Repositories + for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) { + RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); + if (child.isArtifact() && artifactRepo != null) + artifactRepo.removeChild(child.getRepoLocation()); + if (child.isMetadata() && metadataRepo != null) + metadataRepo.removeChild(child.getRepoLocation()); + } + + // Add children to the Composite Repositories + for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) { + RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); + if (child.isArtifact() && artifactRepo != null) + artifactRepo.addChild(child.getRepoLocation()); + if (child.isMetadata() && metadataRepo != null) + metadataRepo.addChild(child.getRepoLocation()); + } + return Status.OK_STATUS; + } finally { + finalizeRepositories(); + } + } + + public void addChild(RepositoryDescriptor child) { + childrenToAdd.add(child); + } + + public void removeChild(RepositoryDescriptor child) { + childrenToRemove.add(child); + } + + public void setFailOnExists(boolean value) { + failOnExists = value; + } + + 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. + } + //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; + } + } + + 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()))); + 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 e; + } + } + + IMetadataRepository source = null; + try { + if (toInit.getFormat() != null) + source = mgr.loadRepository(toInit.getFormat(), 0, null); + } catch (ProvisionException e) { + //Ignore + } + //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); + initRepository(repo, toInit); + return repo; + } catch (IllegalStateException e) { + mgr.removeRepository(toInit.getRepoLocation()); + throw e; + } + } + + /* + * Determine if the repository is valid for this operation + */ + private boolean 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) + 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; + } + + /* + * Initialize a new repository + */ + private void initRepository(IRepository repository, RepositoryDescriptor desc) { + RepositoryHelper.validDestinationRepository(repository); + if (desc.isCompressed() && !repository.getProperties().containsKey(IRepository.PROP_COMPRESSED)) + repository.setProperty(IRepository.PROP_COMPRESSED, String.valueOf(true)); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java index 43e2f1374..e708b52c0 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java @@ -20,6 +20,41 @@ public class Messages extends NLS { public static String exception_noEngineService; public static String exception_needIUsOrNonEmptyRepo; public static String exception_needDestinationRepo; + public static String exception_onlyOneComparator; + + public static String AbstractApplication_no_valid_destinations; + + public static String AbstractRepositoryTask_unableToFind; + + public static String CompositeRepository_composite_repository_exists; + public static String CompositeRepository_create_colocated_composite_repos; + public static String CompositeRepository_creating_composite_repositories; + public static String CompositeRepository_default_artifactRepo_name; + public static String CompositeRepository_default_metadataRepo_name; + + public static String no_valid_IUs; + public static String no_artifactRepo_manager; + public static String no_metadataRepo_manager; + public static String no_package_admin; + public static String no_profile_registry; + public static String unable_to_process_uri; + public static String unable_to_start_exemplarysetup; + public static String unknown_repository_type; + + public static String MirrorApplication_no_IUs; + public static String MirrorApplication_set_source_repositories; + + public static String ProcessRepo_location_not_url; + public static String ProcessRepo_must_be_local; + + public static String Repo2Runnable_no_destination_repository; + public static String Repo2Runnable_no_engine; + + public static String Repo2RunnableTask_error_transforming_repository; + + public static String SlicingOption_invalid_platform; + public static String exception_invalidDestination; + public static String exception_invalidSource; static { // initialize resource bundles 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 bea81c67d..d02323a81 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 @@ -10,45 +10,73 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; +import java.io.File; +import java.net.URI; import java.util.ArrayList; import java.util.Iterator; import org.eclipse.core.runtime.*; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring; +import org.eclipse.equinox.internal.p2.artifact.mirror.*; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; import org.eclipse.equinox.internal.provisional.p2.query.Collector; import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; public class MirrorApplication extends AbstractApplication { + private static final String LOG_ROOT = "p2.mirror"; //$NON-NLS-1$ + protected SlicingOptions slicingOptions = new SlicingOptions(); + private URI baseline; + private String comparatorID; + private boolean compare = false; + private boolean failOnError = true; + private boolean raw = true; + private boolean verbose = false; + private boolean validate = false; + + private File mirrorLogFile; // file to log mirror output to (optional) + private File comparatorLogFile; // file to comparator output to (optional) + private IArtifactMirrorLog mirrorLog; + private IArtifactMirrorLog comparatorLog; + public Object start(IApplicationContext context) throws Exception { run(null); return IApplication.EXIT_OK; } public IStatus run(IProgressMonitor monitor) throws ProvisionException { + IStatus mirrorStatus = Status.OK_STATUS; try { validate(); initializeRepos(new NullProgressMonitor()); + initializeIUs(); IQueryable slice = slice(new NullProgressMonitor()); - IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); - if (mirrorStatus.getSeverity() == IStatus.ERROR) { - return mirrorStatus; + if (destinationArtifactRepository != null) { + initializeLogs(); + mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); + if (mirrorStatus.getSeverity() == IStatus.ERROR) + return mirrorStatus; } - mirrorMetadata(slice, new NullProgressMonitor()); + if (destinationMetadataRepository != null) + mirrorMetadata(slice, new NullProgressMonitor()); } finally { finalizeRepositories(); + finalizeLogs(); } - return Status.OK_STATUS; + if (mirrorStatus.isOK()) + return Status.OK_STATUS; + return mirrorStatus; } - private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) { + private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException { Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); ArrayList keys = new ArrayList(ius.size()); for (Iterator iterator = ius.iterator(); iterator.hasNext();) { @@ -58,9 +86,33 @@ public class MirrorApplication extends AbstractApplication { keys.add(iuKeys[i]); } } - Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true); - mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); - return mirror.run(true, false); + Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw); + + mirror.setCompare(compare); + mirror.setComparatorId(comparatorID); + mirror.setBaseline(initializeBaseline()); + mirror.setValidate(validate); + + // If IUs have been specified then only they should be mirrored, otherwise mirror everything. + if (keys.size() > 0) + mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); + + if (comparatorLog != null) + mirror.setComparatorLog(comparatorLog); + + IStatus result = mirror.run(failOnError, verbose); + + if (mirrorLog != null) + mirrorLog.log(result); + else + LogHelper.log(result); + return result; + } + + private IArtifactRepository initializeBaseline() throws ProvisionException { + if (baseline == null) + return null; + return addRepository(Activator.getArtifactRepositoryManager(), baseline, 0, null); } private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) { @@ -75,21 +127,145 @@ public class MirrorApplication extends AbstractApplication { * to add more if they wish) */ private void validate() throws ProvisionException { - if (sourceMetadataRepositories == null) - throw new ProvisionException("Need to set the source metadata repository location."); - if (sourceIUs == null) - throw new ProvisionException("Mirroring root needs to be specified."); - //TODO Check that the IU is in repo + if (sourceRepositories.isEmpty()) + throw new ProvisionException(Messages.MirrorApplication_set_source_repositories); + } + + /* + * If no IUs have been specified we want to mirror them all + */ + private void initializeIUs() throws ProvisionException { + if (sourceIUs == null || sourceIUs.isEmpty()) { + sourceIUs = new ArrayList(); + IMetadataRepository metadataRepo = getCompositeMetadataRepository(); + Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null); + + for (Iterator iter = collector.iterator(); iter.hasNext();) { + IInstallableUnit iu = (IInstallableUnit) iter.next(); + sourceIUs.add(iu); + } + + if (collector.size() == 0 && destinationMetadataRepository != null) { + throw new ProvisionException(Messages.MirrorApplication_no_IUs); + } + } else { + //TODO Check that the IU is in repo + } + } + + /* + * Initialize logs, if applicable + */ + private void initializeLogs() { + if (compare && comparatorLogFile != null) + comparatorLog = getLog(comparatorLogFile, comparatorID); + if (mirrorLog == null && mirrorLogFile != null) + mirrorLog = getLog(mirrorLogFile, LOG_ROOT); + } + + /* + * Finalize logs, if applicable + */ + private void finalizeLogs() { + if (comparatorLog != null) + comparatorLog.close(); + if (mirrorLog != null) + mirrorLog.close(); } - private IQueryable slice(IProgressMonitor monitor) { + /* + * Get the log for a location + */ + private IArtifactMirrorLog getLog(File location, String root) { + String absolutePath = location.getAbsolutePath(); + if (absolutePath.toLowerCase().endsWith(".xml")) //$NON-NLS-1$ + return new XMLMirrorLog(absolutePath, 0, root); + return new FileMirrorLog(absolutePath, 0, root); + } + + private IQueryable slice(IProgressMonitor monitor) throws ProvisionException { if (slicingOptions == null) slicingOptions = new SlicingOptions(); PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), slicingOptions.getFilter(), slicingOptions.includeOptionalDependencies(), slicingOptions.isEverythingGreedy(), slicingOptions.forceFilterTo(), slicingOptions.considerStrictDependencyOnly()); - return slicer.slice((IInstallableUnit[]) sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor); + IQueryable slice = slicer.slice((IInstallableUnit[]) sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor); + if (slice == null) + throw new ProvisionException(slicer.getStatus()); + return slice; } public void setSlicingOptions(SlicingOptions options) { slicingOptions = options; } + + /* + * Set the location of the baseline repository. (used in comparison) + */ + public void setBaseline(URI baseline) { + this.baseline = baseline; + compare = true; + } + + /* + * Set the identifier of the comparator to use. + */ + public void setComparatorID(String value) { + comparatorID = value; + compare = true; + } + + /* + * Set whether or not the application should be calling a comparator when mirroring. + */ + public void setCompare(boolean value) { + compare = value; + } + + /* + * Set whether or not we should ignore errors when running the mirror application. + */ + public void setIgnoreErrors(boolean value) { + failOnError = !value; + } + + /* + * Set whether or not the the artifacts are raw. + */ + public void setRaw(boolean value) { + raw = value; + } + + /* + * Set whether or not the mirror application should be run in verbose mode. + */ + public void setVerbose(boolean value) { + verbose = value; + } + + /* + * Set the location of the log for comparator output + */ + public void setComparatorLog(File comparatorLog) { + this.comparatorLogFile = comparatorLog; + } + + /* + * Set the location of the log for mirroring. + */ + public void setLog(File mirrorLog) { + this.mirrorLogFile = mirrorLog; + } + + /* + * Set the ArtifactMirror log + */ + public void setLog(IArtifactMirrorLog log) { + mirrorLog = log; + } + + /* + * Set if the artifact mirror should be validated + */ + public void setValidate(boolean value) { + validate = value; + } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java index 5c77f1d76..b04f3ff7a 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; -import java.net.URI; import java.net.URISyntaxException; import java.util.*; import org.eclipse.core.runtime.*; @@ -27,7 +26,6 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; -import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.query.Collector; /** @@ -165,11 +163,11 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { return; } // get all IUs from the repos - if (sourceMetadataRepositories == null || sourceMetadataRepositories.isEmpty()) + if (!hasMetadataSources()) throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo); - for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) { - processedIUs.addAll(getAllIUs((URI) iter.next(), monitor).toCollection()); - } + + processedIUs.addAll(getAllIUs(getCompositeMetadataRepository(), monitor).toCollection()); + if (processedIUs.isEmpty()) throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo); } @@ -188,15 +186,13 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { /* * Return a collector over all the IUs contained in the given repository. */ - private Collector getAllIUs(URI location, IProgressMonitor monitor) throws ProvisionException { + private Collector getAllIUs(IMetadataRepository repository, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 2); - IMetadataRepositoryManager manager = Activator.getMetadataRepositoryManager(); - if (!manager.contains(location)) - metadataReposToRemove.add(location); - IMetadataRepository repository = manager.loadRepository(location, progress.newChild(1)); - Collector result = new Collector(); - repository.query(InstallableUnitQuery.ANY, result, progress.newChild(1)).iterator(); - return result; + try { + return repository.query(InstallableUnitQuery.ANY, new Collector(), progress.newChild(1)); + } finally { + progress.done(); + } } /* @@ -242,19 +238,15 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { String arg = args[++i]; if (option.equalsIgnoreCase("-source")) { //$NON-NLS-1$ - addSourceArtifactRepository(arg); - addSourceMetadataRepository(arg); + RepositoryDescriptor source = new RepositoryDescriptor(); + source.setLocation(URIUtil.fromString(arg)); + addSource(source); } if (option.equalsIgnoreCase("-destination")) { //$NON-NLS-1$ - RepositoryDescriptor artifact = new RepositoryDescriptor(); - artifact.setLocation(URIUtil.fromString(arg)); - artifact.setKind("A"); //$NON-NLS-1$ - addDestination(artifact); - RepositoryDescriptor metadata = new RepositoryDescriptor(); - metadata.setLocation(URIUtil.fromString(arg)); - metadata.setKind("M"); //$NON-NLS-1$ - addDestination(metadata); + RepositoryDescriptor destination = new RepositoryDescriptor(); + destination.setLocation(URIUtil.fromString(arg)); + addDestination(destination); } } } @@ -266,7 +258,7 @@ public class Repo2Runnable extends AbstractApplication implements IApplication { * to add more if they wish) */ private void validate() throws ProvisionException { - if (sourceMetadataRepositories == null && sourceIUs == null) + if (!hasMetadataSources() && sourceIUs == null) throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo); if (destinationArtifactRepository == null) throw new ProvisionException(Messages.exception_needDestinationRepo); diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java index a93f05f85..0ae76a135 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java @@ -10,18 +10,23 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; - import java.net.URI; +import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; +import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.osgi.util.NLS; public class RepositoryDescriptor { + public static final int TYPE_BOTH = -1; + public static final String KIND_ARTIFACT = "A"; //$NON-NLS-1$ + public static final String KIND_METADATA = "M"; //$NON-NLS-1$ + private boolean compressed = true; private boolean append = true; private String name = null; private URI location = null; - private String format = null; - private int kind; + private URI format = null; + private int kind = TYPE_BOTH; public void setCompressed(boolean compress) { compressed = compress; @@ -32,11 +37,11 @@ public class RepositoryDescriptor { } public void setLocation(URI repoLocation) { - location = repoLocation; + location = RepositoryHelper.localRepoURIHelper(repoLocation); } - public void setFormat(String format) { - this.format = format; + public void setFormat(URI format) { + this.format = RepositoryHelper.localRepoURIHelper(format); } public void setAppend(boolean appendMode) { @@ -59,7 +64,7 @@ public class RepositoryDescriptor { return location; } - public String getFormat() { + public URI getFormat() { return format; } @@ -67,11 +72,38 @@ public class RepositoryDescriptor { return kind; } + public boolean isBoth() { + return kind == TYPE_BOTH; + } + + public boolean isArtifact() { + return kind == TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT; + } + + public boolean isMetadata() { + return kind == TYPE_BOTH || kind == IRepository.TYPE_METADATA; + } + public void setKind(String repoKind) { - if (repoKind.startsWith("m") || repoKind.startsWith("M")) //$NON-NLS-1$//$NON-NLS-2$ - kind = IRepository.TYPE_METADATA; + kind = determineKind(repoKind); + } + + /* + * Determine the repository type + */ + public static int determineKind(String repoKind) { + if (kindMatches(repoKind, KIND_METADATA)) + return IRepository.TYPE_METADATA; + else if (kindMatches(repoKind, KIND_ARTIFACT)) + return IRepository.TYPE_ARTIFACT; + + throw new IllegalArgumentException(NLS.bind(Messages.unknown_repository_type, repoKind)); + } - if (repoKind.startsWith("a") || repoKind.startsWith("A")) //$NON-NLS-1$//$NON-NLS-2$ - kind = IRepository.TYPE_ARTIFACT; + /* + * Determine if the repository kind matches the identifier kind + */ + public static boolean kindMatches(String repoKind, String kindIdentifier) { + return repoKind.startsWith(kindIdentifier) || repoKind.startsWith(kindIdentifier.toLowerCase()); } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties index 111d5931e..0e0a8162d 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties @@ -8,10 +8,38 @@ # Contributors: # IBM Corporation - initial API and implementation ############################################################################### -exception_destinationNotModifiable = The destination repository must be modifiable: {0}. +AbstractApplication_no_valid_destinations=Unable to locate a valid destination repository. +AbstractRepositoryTask_unableToFind=Unable to find: {0} + +CompositeRepository_default_metadataRepo_name=Composite Metadata Repository +CompositeRepository_default_artifactRepo_name=Composite Artifact Repository +CompositeRepository_create_colocated_composite_repos=Creating co-located composite repositories. +CompositeRepository_composite_repository_exists=Composite repository already exists at location: {0} +CompositeRepository_creating_composite_repositories=Creating Composite Repositories +CompositeRepository_default_artifactRepo_name=Composite Artifact Repository +CompositeRepository_default_metadataRepo_name=Composite Artifact Repository + +no_valid_IUs=Need to specify either a non-empty source metadata repository or a valid list of IUs. +no_artifactRepo_manager=Unable to acquire artifact repository manager service. +no_metadataRepo_manager=Unable to acquire metadata repository manager service. +no_package_admin=Unable to acquire package admin service. +no_profile_registry=Unable to acquire profile registry service. +unable_to_process_uri=Unable to process as URI: {0} +unable_to_start_exemplarysetup=Unable to start exemplarysetup bundle. +unknown_repository_type=Repository is of an unknown type: {0} +MirrorApplication_no_IUs=No IUs specified and no IUs obtained from metadata repositories. +MirrorApplication_set_source_repositories=Need to set the source repository location(s). +ProcessRepo_location_not_url=Repository location {0} must be a URL. +ProcessRepo_must_be_local=Repository must be local: {0} + +SlicingOption_invalid_platform=Invalid platform filter format: {0}. +exception_destinationNotModifiable = The destination repository must be modifiable: {0}. +exception_invalidDestination=Invalid destination repository location: {0}. +exception_invalidSource=Invalid source repository location: {0}. exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}. exception_notLocalFileRepo= {0} is not a local file based repository. exception_noEngineService=Unable to acquire engine service. exception_needIUsOrNonEmptyRepo=Need to specify either a non-empty source metadata repository or a valid list of IUs. -exception_needDestinationRepo=Need to set the destination artifact repository location.
\ No newline at end of file +exception_needDestinationRepo=Need to set the destination artifact repository location. +exception_onlyOneComparator=Only one comparator should be defined.
\ No newline at end of file |