diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository')
20 files changed, 738 insertions, 358 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java index ee7fcd4a3..6a41d2d38 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; @@ -22,22 +24,28 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { private static BundleContext context; private ServiceRegistration repositoryManagerRegistration; - private ArtifactRepositoryManager repositoryManager; - private ServiceTracker busTracker; + private static final Map<ArtifactRepositoryManager, IProvisioningAgent> createdManagers = new HashMap<ArtifactRepositoryManager, IProvisioningAgent>(); + private ServiceTracker agentTracker; public static BundleContext getContext() { return Activator.context; } + /** + * Remember an artifact repository manager so we can shut it down when the bundle stops + */ + static void addManager(ArtifactRepositoryManager manager, IProvisioningAgent agent) { + synchronized (createdManagers) { + createdManagers.put(manager, agent); + } + } + public void start(BundleContext aContext) throws Exception { Activator.context = aContext; - repositoryManager = new ArtifactRepositoryManager(); - repositoryManagerRegistration = aContext.registerService(IArtifactRepositoryManager.class.getName(), repositoryManager, null); - - // need to track event bus coming and going to make sure cache gets cleaned on - // repository removals - busTracker = new ServiceTracker(context, IProvisioningEventBus.SERVICE_NAME, this); - busTracker.open(); + // need to track agent so we can register global artifact repository manager + String filter = "(&(objectClass=" + IProvisioningAgent.SERVICE_NAME + ")(agent.current=true))"; //$NON-NLS-1$ //$NON-NLS-2$ + agentTracker = new ServiceTracker(context, aContext.createFilter(filter), this); + agentTracker.open(); } public void stop(BundleContext aContext) throws Exception { @@ -45,28 +53,33 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer { if (repositoryManagerRegistration != null) repositoryManagerRegistration.unregister(); repositoryManagerRegistration = null; - if (repositoryManager != null) { - repositoryManager.shutdown(); - repositoryManager = null; + synchronized (createdManagers) { + for (ArtifactRepositoryManager manager : createdManagers.keySet()) { + manager.shutdown(); + IProvisioningAgent agent = createdManagers.get(manager); + agent.unregisterService(IArtifactRepositoryManager.SERVICE_NAME, manager); + } + createdManagers.clear(); } - busTracker.close(); + agentTracker.close(); } public Object addingService(ServiceReference reference) { - IProvisioningEventBus bus = (IProvisioningEventBus) context.getService(reference); - if (repositoryManager != null) - repositoryManager.setEventBus(bus); - return bus; + //when someone registers the agent service, register a repository manager service + IProvisioningAgent agent = (IProvisioningAgent) context.getService(reference); + repositoryManagerRegistration = context.registerService(IArtifactRepositoryManager.SERVICE_NAME, agent.getService(IArtifactRepositoryManager.SERVICE_NAME), null); + return agent; } public void modifiedService(ServiceReference reference, Object service) { // ignored - } public void removedService(ServiceReference reference, Object service) { - if (repositoryManager != null) - repositoryManager.unsetEventBus((IProvisioningEventBus) service); + //the agent is going away so withdraw our service + if (repositoryManagerRegistration != null) { + repositoryManagerRegistration.unregister(); + repositoryManagerRegistration = null; + } } - } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java index 39f807b30..901457a8e 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; +import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; +import org.eclipse.equinox.p2.core.IAgentLocation; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; /** * Service factory providing {@link IArtifactRepositoryManager} instances. @@ -20,7 +22,11 @@ import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; public class ArtifactRepositoryComponent implements IAgentServiceFactory { public Object createService(IProvisioningAgent agent) { - return new ArtifactRepositoryManager(); + final ArtifactRepositoryManager manager = new ArtifactRepositoryManager(); + manager.setEventBus((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME)); + manager.setAgentLocation((IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME)); + manager.setAgent(agent); + Activator.addManager(manager, agent); + return manager; } - } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java index 46811e78f..21e54aa6f 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2010 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 @@ -12,17 +12,18 @@ package org.eclipse.equinox.internal.p2.artifact.repository; import java.net.URI; -import java.util.*; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; /** * Default implementation of {@link IArtifactRepositoryManager}. @@ -30,7 +31,7 @@ import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.Artif * TODO the current assumption that the "location" is the dir/root limits us to * having just one repository in a given URL.. */ -public class ArtifactRepositoryManager extends AbstractRepositoryManager implements IArtifactRepositoryManager { +public class ArtifactRepositoryManager extends AbstractRepositoryManager<IArtifactKey> implements IArtifactRepositoryManager { public ArtifactRepositoryManager() { super(); @@ -40,25 +41,31 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme super.addRepository(repository, true, null); } - public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Properties destinationDescriptorProperties, Properties destinationRepositoryProperties) { + public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties) { return new MirrorRequest(key, destination, destinationDescriptorProperties, destinationRepositoryProperties); } - public IArtifactRepository createRepository(URI location, String name, String type, Map properties) throws ProvisionException { + public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException { return (IArtifactRepository) doCreateRepository(location, name, type, properties); } - protected IRepository factoryCreate(URI location, String name, String type, Map properties, IExtension extension) throws ProvisionException { + public IArtifactRepository getRepository(URI location) { + return (IArtifactRepository) basicGetRepository(location); + } + + protected IRepository<IArtifactKey> factoryCreate(URI location, String name, String type, Map<String, String> properties, IExtension extension) throws ProvisionException { ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; + factory.setAgent(agent); return factory.create(location, name, type, properties); } - protected IRepository factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException { + protected IRepository<IArtifactKey> factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException { ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) createExecutableExtension(extension, EL_FACTORY); if (factory == null) return null; + factory.setAgent(agent); return factory.load(location, flags, monitor.newChild(10)); } @@ -102,12 +109,14 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme */ protected void restoreSpecialRepositories() { // TODO while recreating, we may want to have proxies on repo instead of the real repo object to limit what is activated. - AgentLocation location = (AgentLocation) ServiceHelper.getService(Activator.getContext(), AgentLocation.class.getName()); + IAgentLocation location = (IAgentLocation) ServiceHelper.getService(Activator.getContext(), IAgentLocation.class.getName()); if (location == null) // TODO should do something here since we are failing to restore. return; + URI cacheLocation = URIUtil.append(location.getDataArea("org.eclipse.equinox.p2.core"), "cache/"); //$NON-NLS-1$ //$NON-NLS-2$ + try { - loadRepository(location.getArtifactRepositoryURI(), null); + loadRepository(cacheLocation, null); return; } catch (ProvisionException e) { // log but still continue and try to create a new one @@ -115,9 +124,9 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager impleme LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while loading download cache.", e)); //$NON-NLS-1$ } try { - Map properties = new HashMap(1); + Map<String, String> properties = new HashMap<String, String>(1); properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); - createRepository(location.getArtifactRepositoryURI(), "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ + createRepository(cacheLocation, "download cache", TYPE_SIMPLE_REPOSITORY, properties); //$NON-NLS-1$ } catch (ProvisionException e) { LogHelper.log(e); } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java index 352daa6d1..6fe6fc267 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRequest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -11,9 +11,9 @@ package org.eclipse.equinox.internal.p2.artifact.repository; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; /** * Base class for all requests on an {@link IArtifactRepository}. 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 411fc37f7..d51ed96c4 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 @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 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 *******************************************************************************/ @@ -18,18 +18,19 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -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.repository.ICompositeRepository; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.ICompositeRepository; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository; import org.eclipse.osgi.util.NLS; -public class CompositeArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, ICompositeRepository { +public class CompositeArtifactRepository extends AbstractArtifactRepository implements ICompositeRepository<IArtifactKey> { static final public String REPOSITORY_TYPE = CompositeArtifactRepository.class.getName(); static final private Integer REPOSITORY_VERSION = new Integer(1); @@ -40,16 +41,19 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl // keep a list of the child URIs. they can be absolute or relative. they may or may not point // to a valid reachable repo - private List childrenURIs = new ArrayList(); + private List<URI> childrenURIs = new ArrayList<URI>(); // keep a list of the repositories that we have successfully loaded - private List loadedRepos = new ArrayList(); + private List<ChildInfo> loadedRepos = new ArrayList<ChildInfo>(); + private IArtifactRepositoryManager manager; /** * Create a Composite repository in memory. * @return the repository or null if unable to create one */ - public static CompositeArtifactRepository createMemoryComposite() { - IArtifactRepositoryManager manager = getManager(); + public static CompositeArtifactRepository createMemoryComposite(IProvisioningAgent agent) { + if (agent == null) + return null; + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); if (manager == null) return null; try { @@ -71,21 +75,23 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return null; } - static private IArtifactRepositoryManager getManager() { - return (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); + private IArtifactRepositoryManager getManager() { + return manager; } /* * This is only called by the parser when loading a repository. */ - public CompositeArtifactRepository(CompositeRepositoryState state) { + CompositeArtifactRepository(IArtifactRepositoryManager manager, CompositeRepositoryState state) { super(state.getName(), state.getType(), state.getVersion(), state.getLocation(), state.getDescription(), state.getProvider(), state.getProperties()); + this.manager = manager; for (int i = 0; i < state.getChildren().length; i++) addChild(state.getChildren()[i], false); } - public CompositeArtifactRepository(URI location, String repositoryName, Map properties) { + CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties) { super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); + this.manager = manager; save(); } @@ -103,7 +109,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl result.setProvider(getProvider()); result.setProperties(getProperties()); // it is important to directly access the field so we have the relative URIs - result.setChildren((URI[]) childrenURIs.toArray(new URI[childrenURIs.size()])); + result.setChildren(childrenURIs.toArray(new URI[childrenURIs.size()])); return result; } @@ -112,7 +118,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl * in it. Return a boolean value indicating whether or not the object was * actually added. */ - private static boolean add(List list, Object obj) { + private static <T> boolean add(List<T> list, T obj) { return list.contains(obj) ? false : list.add(obj); } @@ -163,21 +169,21 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } } - public boolean addChild(URI childURI, String comparatorID) { - try { - IArtifactRepository repo = load(childURI); - if (isSane(repo, comparatorID)) { - addChild(childURI); - //Add was successful - return true; - } - } catch (ProvisionException e) { - LogHelper.log(e); - } - - //Add was not successful - return false; - } + // public boolean addChild(URI childURI, String comparatorID) { + // try { + // IArtifactRepository repo = load(childURI); + // if (isSane(repo, comparatorID)) { + // addChild(childURI); + // //Add was successful + // return true; + // } + // } catch (ProvisionException e) { + // LogHelper.log(e); + // } + // + // //Add was not successful + // return false; + // } public void removeChild(URI childURI) { boolean removed = childrenURIs.remove(childURI); @@ -190,13 +196,12 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl if (removed) { // we removed the child from the list so remove the associated repo object as well ChildInfo found = null; - for (Iterator iter = loadedRepos.iterator(); found == null && iter.hasNext();) { - ChildInfo current = (ChildInfo) iter.next(); + for (ChildInfo current : loadedRepos) { URI repoLocation = current.repo.getLocation(); - if (URIUtil.sameURI(childURI, repoLocation)) - found = current; - else if (URIUtil.sameURI(other, repoLocation)) + if (URIUtil.sameURI(childURI, repoLocation) || URIUtil.sameURI(other, repoLocation)) { found = current; + break; + } } if (found != null) loadedRepos.remove(found); @@ -210,10 +215,18 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl save(); } - public List getChildren() { - List result = new ArrayList(); - for (Iterator iter = childrenURIs.iterator(); iter.hasNext();) - result.add(URIUtil.makeAbsolute((URI) iter.next(), location)); + public List<URI> getChildren() { + List<URI> result = new ArrayList<URI>(); + for (URI uri : childrenURIs) + result.add(URIUtil.makeAbsolute(uri, location)); + return result; + } + + public List<IArtifactRepository> getLoadedChildren() { + List<IArtifactRepository> result = new ArrayList<IArtifactRepository>(loadedRepos.size()); + for (ChildInfo info : loadedRepos) { + result.add(info.repo); + } return result; } @@ -262,8 +275,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public boolean contains(IArtifactKey key) { - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + for (ChildInfo current : loadedRepos) { if (current.isGood() && current.repo.contains(key)) return true; } @@ -271,8 +283,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public boolean contains(IArtifactDescriptor descriptor) { - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + for (ChildInfo current : loadedRepos) { if (current.isGood() && current.repo.contains(descriptor)) return true; } @@ -280,36 +291,24 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { - ArrayList result = new ArrayList(); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); + ArrayList<IArtifactDescriptor> result = new ArrayList<IArtifactDescriptor>(); + for (ChildInfo current : loadedRepos) { if (current.isGood()) { IArtifactDescriptor[] tempResult = current.repo.getArtifactDescriptors(key); for (int i = 0; i < tempResult.length; i++) add(result, tempResult[i]); } } - return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); - } - - public IArtifactKey[] getArtifactKeys() { - ArrayList result = new ArrayList(); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - ChildInfo current = (ChildInfo) repositoryIterator.next(); - if (current.isGood()) { - IArtifactKey[] tempResult = current.repo.getArtifactKeys(); - for (int i = 0; i < tempResult.length; i++) - add(result, tempResult[i]); - } - } - return (IArtifactKey[]) result.toArray(new IArtifactKey[result.size()]); + return result.toArray(new IArtifactDescriptor[result.size()]); } public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); MultiStatus multiStatus = new MultiStatus(Activator.ID, IStatus.OK, Messages.message_childrenRepos, null); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext() && requests.length > 0;) { - IArtifactRepository current = ((ChildInfo) repositoryIterator.next()).repo; + for (ChildInfo childInfo : loadedRepos) { + if (requests.length == 0) + break; + IArtifactRepository current = childInfo.repo; IArtifactRequest[] applicable = getRequestsForRepository(current, requests); IStatus dlStatus = current.getArtifacts(applicable, subMonitor.newChild(requests.length)); multiStatus.add(dlStatus); @@ -333,8 +332,8 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IStatus getRawOrNormalArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor, boolean raw) { - for (Iterator childIterator = loadedRepos.iterator(); childIterator.hasNext();) { - ChildInfo current = (ChildInfo) childIterator.next(); + for (Iterator<ChildInfo> childIterator = loadedRepos.iterator(); childIterator.hasNext();) { + ChildInfo current = childIterator.next(); if (current.isGood() && current.repo.contains(descriptor)) { // Child hasn't failed & contains descriptor IStatus status = raw ? current.repo.getRawArtifact(descriptor, destination, monitor) : current.repo.getArtifact(descriptor, destination, monitor); @@ -360,7 +359,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IArtifactRequest[] filterUnfetched(IArtifactRequest[] requests) { - ArrayList filteredRequests = new ArrayList(); + ArrayList<IArtifactRequest> filteredRequests = new ArrayList<IArtifactRequest>(); for (int i = 0; i < requests.length; i++) { if (requests[i].getResult() == null || !requests[i].getResult().isOK()) { filteredRequests.add(requests[i]); @@ -373,18 +372,18 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl } private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository, IArtifactRequest[] requests) { - ArrayList applicable = new ArrayList(); + ArrayList<IArtifactRequest> applicable = new ArrayList<IArtifactRequest>(); for (int i = 0; i < requests.length; i++) { if (repository.contains(requests[i].getArtifactKey())) applicable.add(requests[i]); } - return (IArtifactRequest[]) applicable.toArray(new IArtifactRequest[applicable.size()]); + return applicable.toArray(new IArtifactRequest[applicable.size()]); } private void save() { if (!isModifiable()) return; - boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ + boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ OutputStream os = null; try { URI actualLocation = getActualLocation(location, false); @@ -433,73 +432,73 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return repo; } - /** - * A method to check if the content of a repository is consistent with the other children by - * comparing content using the artifactComparator specified by the comparatorID - * @param toCheckRepo the repository to check - * @param comparatorID - * @return <code>true</code> if toCheckRepo is consistent, <code>false</code> if toCheckRepo - * contains an equal descriptor to that of a child and they refer to different artifacts on disk. - */ - private boolean isSane(IArtifactRepository toCheckRepo, String comparatorID) { - IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); - for (Iterator repositoryIterator = loadedRepos.iterator(); repositoryIterator.hasNext();) { - IArtifactRepository current = ((ChildInfo) repositoryIterator.next()).repo; - if (!current.equals(toCheckRepo)) { - if (!isSane(toCheckRepo, current, comparator)) - return false; - } - } - return true; - } - - /* - * Check the two given repositories against each other using the given comparator. - */ - private boolean isSane(IArtifactRepository one, IArtifactRepository two, IArtifactComparator comparator) { - IArtifactKey[] toCheckKeys = one.getArtifactKeys(); - for (int i = 0; i < toCheckKeys.length; i++) { - IArtifactKey key = toCheckKeys[i]; - if (!two.contains(key)) - continue; - IArtifactDescriptor[] toCheckDescriptors = one.getArtifactDescriptors(key); - IArtifactDescriptor[] currentDescriptors = two.getArtifactDescriptors(key); - for (int j = 0; j < toCheckDescriptors.length; j++) { - if (!two.contains(toCheckDescriptors[j])) - continue; - for (int k = 0; k < currentDescriptors.length; k++) { - if (currentDescriptors[k].equals(toCheckDescriptors[j])) { - IStatus compareResult = comparator.compare(two, currentDescriptors[k], two, toCheckDescriptors[j]); - if (!compareResult.isOK()) { - LogHelper.log(compareResult); - return false; - } - break; - } - } - } - } - return true; - } - - /** - * A method that verifies that all children with matching artifact descriptors contain the same set of bytes - * The verification is done using the artifactComparator specified by comparatorID - * Assumes more valuable logging and output is the responsibility of the artifactComparator implementation. - * @param comparatorID - * @returns true if the repository is consistent, false if two equal descriptors refer to different artifacts on disk. - */ - public boolean validate(String comparatorID) { - IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); - ChildInfo[] repos = (ChildInfo[]) loadedRepos.toArray(new ChildInfo[loadedRepos.size()]); - for (int outer = 0; outer < repos.length; outer++) { - for (int inner = outer + 1; inner < repos.length; inner++) { - if (!isSane(repos[outer].repo, repos[inner].repo, comparator)) - return false; - } - } - return true; - } + // /** + // * A method to check if the content of a repository is consistent with the other children by + // * comparing content using the artifactComparator specified by the comparatorID + // * @param toCheckRepo the repository to check + // * @param comparatorID + // * @return <code>true</code> if toCheckRepo is consistent, <code>false</code> if toCheckRepo + // * contains an equal descriptor to that of a child and they refer to different artifacts on disk. + // */ + // private boolean isSane(IArtifactRepository toCheckRepo, String comparatorID) { + // IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); + // for (ChildInfo childInfo : loadedRepos) { + // IArtifactRepository current = childInfo.repo; + // if (!current.equals(toCheckRepo)) { + // if (!isSane(toCheckRepo, current, comparator)) + // return false; + // } + // } + // return true; + // } + // + // /* + // * Check the two given repositories against each other using the given comparator. + // */ + // private boolean isSane(IArtifactRepository one, IArtifactRepository two, IArtifactComparator comparator) { + // IQueryResult<IArtifactKey> toCheckKeys = one.query(ArtifactKeyQuery.ALL_KEYS, null); + // for (Iterator<IArtifactKey> iterator = toCheckKeys.iterator(); iterator.hasNext();) { + // IArtifactKey key = iterator.next(); + // if (!two.contains(key)) + // continue; + // IArtifactDescriptor[] toCheckDescriptors = one.getArtifactDescriptors(key); + // IArtifactDescriptor[] currentDescriptors = two.getArtifactDescriptors(key); + // for (int j = 0; j < toCheckDescriptors.length; j++) { + // if (!two.contains(toCheckDescriptors[j])) + // continue; + // for (int k = 0; k < currentDescriptors.length; k++) { + // if (currentDescriptors[k].equals(toCheckDescriptors[j])) { + // IStatus compareResult = comparator.compare(two, currentDescriptors[k], two, toCheckDescriptors[j]); + // if (!compareResult.isOK()) { + // LogHelper.log(compareResult); + // return false; + // } + // break; + // } + // } + // } + // } + // return true; + // } + // + // /** + // * A method that verifies that all children with matching artifact descriptors contain the same set of bytes + // * The verification is done using the artifactComparator specified by comparatorID + // * Assumes more valuable logging and output is the responsibility of the artifactComparator implementation. + // * @param comparatorID + // * @returns true if the repository is consistent, false if two equal descriptors refer to different artifacts on disk. + // */ + // private boolean validate(String comparatorID) { + // IArtifactComparator comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID); + // ChildInfo[] repos = loadedRepos.toArray(new ChildInfo[loadedRepos.size()]); + // for (int outer = 0; outer < repos.length; outer++) { + // for (int inner = outer + 1; inner < repos.length; inner++) { + // if (!isSane(repos[outer].repo, repos[inner].repo, comparator)) + // return false; + // } + // } + // return true; + // } private static class ChildInfo { IArtifactRepository repo; @@ -517,4 +516,26 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl return good; } } + + public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor) { + // Query all the all the repositories this composite repo contains + List<IArtifactRepository> repos = new ArrayList<IArtifactRepository>(); + for (ChildInfo info : loadedRepos) { + if (info.isGood()) + repos.add(info.repo); + } + CompoundQueryable<IArtifactKey> queryable = new CompoundQueryable<IArtifactKey>(repos); + return queryable.query(query, monitor); + } + + public IQueryable<IArtifactDescriptor> descriptorQueryable() { + // Query all the all the repositories this composite repo contains + List<IQueryable<IArtifactDescriptor>> repos = new ArrayList<IQueryable<IArtifactDescriptor>>(); + for (ChildInfo info : loadedRepos) { + if (info.isGood()) + repos.add(info.repo.descriptorQueryable()); + } + CompoundQueryable<IArtifactDescriptor> queryable = new CompoundQueryable<IArtifactDescriptor>(repos); + return queryable; + } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java index e587abfca..a37216807 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepositoryFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 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 @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; + +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.net.URI; import java.util.Map; @@ -21,14 +25,19 @@ import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO; import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; import org.eclipse.equinox.internal.p2.repository.Transport; -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.repository.IRepositoryManager; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.ArtifactRepositoryFactory; +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.osgi.util.NLS; public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactory { + private IArtifactRepositoryManager getManager() { + if (getAgent() != null) + return (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME); + return null; + } + public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException { final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ long time = 0; @@ -95,7 +104,7 @@ public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactor CompositeRepositoryState resultState = io.read(localFile.toURL(), descriptorStream, CompositeArtifactRepository.PI_REPOSITORY_TYPE, sub.newChild(100)); if (resultState.getLocation() == null) resultState.setLocation(location); - CompositeArtifactRepository result = new CompositeArtifactRepository(resultState); + CompositeArtifactRepository result = new CompositeArtifactRepository(getManager(), resultState); if (Tracing.DEBUG_METADATA_PARSING) { time += System.currentTimeMillis(); Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ @@ -117,8 +126,8 @@ public class CompositeArtifactRepositoryFactory extends ArtifactRepositoryFactor } } - public IArtifactRepository create(URI location, String name, String type, Map properties) { - return new CompositeArtifactRepository(location, name, properties); + public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) { + return new CompositeArtifactRepository(getManager(), location, name, properties); } private Transport getTransport() { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java new file mode 100644 index 000000000..1035f1420 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/FlatteningIterator.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 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.internal.p2.artifact.repository; + +import java.util.*; + +/** + * An iterator over values that are provided by iterating over collections. + */ +public class FlatteningIterator<T> implements Iterator<T> { + private static final Object NO_ELEMENT = new Object(); + private final Iterator<? extends Collection<T>> collectionIterator; + private Iterator<T> currentIterator; + + private T nextObject = noElement(); + + public FlatteningIterator(Iterator<? extends Collection<T>> collectionIterator) { + this.collectionIterator = collectionIterator; + } + + public boolean hasNext() { + return positionNext(); + } + + public T next() { + if (!positionNext()) + throw new NoSuchElementException(); + + T nxt = nextObject; + nextObject = noElement(); + return nxt; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + private boolean positionNext() { + if (nextObject != NO_ELEMENT) + return true; + + while (currentIterator == null || !currentIterator.hasNext()) { + if (!collectionIterator.hasNext()) + return false; + currentIterator = collectionIterator.next().iterator(); + } + nextObject = currentIterator.next(); + return true; + } + + @SuppressWarnings("unchecked") + private static <T> T noElement() { + return (T) NO_ELEMENT; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java index c15f22c0d..1353e18b5 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java @@ -17,6 +17,7 @@ public class Messages extends NLS { public static String artifact_not_found; public static String available_already_in; + public static String no_location; public static String downloading; public static String error_closing_stream; public static String io_failedRead; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java index 5623b78e5..6e2585445 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorRequest.java @@ -1,54 +1,56 @@ /******************************************************************************* - * Copyright (c) 2007, 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: + * Copyright (c) 2007, 2010 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 * Compeople AG (Stefan Liebig) - various ongoing maintenance * Genuitec LLC - various bug fixes *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; -import java.util.Properties; +import java.util.HashMap; +import java.util.Map; import org.eclipse.core.runtime.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; +import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactDescriptor; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler; -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.repository.IStateful; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; import org.eclipse.osgi.util.NLS; /** * A request to mirror (copy) an artifact into a given destination artifact repository. */ public class MirrorRequest extends ArtifactRequest { - private static final ProcessingStepDescriptor[] EMPTY_STEPS = new ProcessingStepDescriptor[0]; - protected final IArtifactRepository target; - private final Properties targetDescriptorProperties; - private final Properties targetRepositoryProperties; + private final Map<String, String> targetDescriptorProperties; + private final Map<String, String> targetRepositoryProperties; protected IArtifactDescriptor descriptor; - public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Properties targetDescriptorProperties, Properties targetRepositoryProperties) { + public MirrorRequest(IArtifactKey key, IArtifactRepository targetRepository, Map<String, String> targetDescriptorProperties, Map<String, String> targetRepositoryProperties) { super(key); target = targetRepository; if (targetDescriptorProperties == null || targetDescriptorProperties.isEmpty()) { this.targetDescriptorProperties = null; } else { - this.targetDescriptorProperties = new Properties(); + this.targetDescriptorProperties = new HashMap<String, String>(); this.targetDescriptorProperties.putAll(targetDescriptorProperties); } if (targetRepositoryProperties == null || targetRepositoryProperties.isEmpty()) { this.targetRepositoryProperties = null; } else { - this.targetRepositoryProperties = new Properties(); + this.targetRepositoryProperties = new HashMap<String, String>(); this.targetRepositoryProperties.putAll(targetRepositoryProperties); } } @@ -91,7 +93,7 @@ public class MirrorRequest extends ArtifactRequest { return; } - ArtifactDescriptor destinationDescriptor = getDestinationDescriptor(descriptor); + IArtifactDescriptor destinationDescriptor = getDestinationDescriptor(descriptor); IStatus status = transfer(destinationDescriptor, descriptor, monitor); // if ok, cancelled or transfer has already been done with the canonical form return with status set if (status.getSeverity() == IStatus.CANCEL) { @@ -125,21 +127,21 @@ public class MirrorRequest extends ArtifactRequest { setResult(new MultiStatus(Activator.ID, canonicalStatus.getCode() != 0 ? canonicalStatus.getCode() : status.getCode(), new IStatus[] {status, canonicalStatus}, Messages.MirrorRequest_multipleDownloadProblems, null)); } - private ArtifactDescriptor getDestinationDescriptor(IArtifactDescriptor sourceDescriptor) { + private IArtifactDescriptor getDestinationDescriptor(IArtifactDescriptor sourceDescriptor) { // Get the descriptor to use to store the artifact // Since we are mirroring, ensure we clear out data from the original descriptor that may // not apply in the new repo location. // TODO this is brittle. perhaps the repo itself should do this? there are cases where // we really do need to give the repo the actual descriptor to use however... - ArtifactDescriptor destinationDescriptor = new ArtifactDescriptor(sourceDescriptor); - destinationDescriptor.setProcessingSteps(EMPTY_STEPS); - destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, null); - destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, null); - destinationDescriptor.setProperty(IArtifactDescriptor.FORMAT, null); - if (targetDescriptorProperties != null) - destinationDescriptor.addProperties(targetDescriptorProperties); - if (targetRepositoryProperties != null) - destinationDescriptor.addRepositoryProperties(targetRepositoryProperties); + IArtifactDescriptor destinationDescriptor = target.createArtifactDescriptor(sourceDescriptor.getArtifactKey()); + // destinationDescriptor.setProcessingSteps(EMPTY_STEPS); + // destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_MD5, null); + // destinationDescriptor.setProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE, null); + // destinationDescriptor.setProperty(IArtifactDescriptor.FORMAT, null); + if (targetDescriptorProperties != null && destinationDescriptor instanceof ArtifactDescriptor) + ((ArtifactDescriptor) destinationDescriptor).addProperties(targetDescriptorProperties); + if (targetRepositoryProperties != null && destinationDescriptor instanceof SimpleArtifactDescriptor) + ((SimpleArtifactDescriptor) destinationDescriptor).addRepositoryProperties(targetRepositoryProperties); return destinationDescriptor; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java index 8104d23e8..6fb6259de 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java @@ -21,7 +21,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; import org.eclipse.equinox.internal.p2.repository.DownloadStatus; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; import org.w3c.dom.*; import org.xml.sax.InputSource; @@ -39,7 +39,7 @@ public class MirrorSelector { /** * Encapsulates information about a single mirror */ - public static class MirrorInfo implements Comparable { + public static class MirrorInfo implements Comparable<MirrorInfo> { long bytesPerSecond; int failureCount; private final int initialRank; @@ -57,10 +57,7 @@ public class MirrorSelector { /** * Comparison used to sort mirrors. */ - public int compareTo(Object o) { - if (!(o instanceof MirrorInfo)) - return 0; - MirrorInfo that = (MirrorInfo) o; + public int compareTo(MirrorInfo that) { //less failures is better if (this.failureCount != that.failureCount) return this.failureCount - that.failureCount; @@ -91,7 +88,7 @@ public class MirrorSelector { MirrorInfo[] mirrors; - private final IRepository repository; + private final IRepository<?> repository; private final Random random = new Random(); @@ -100,10 +97,10 @@ public class MirrorSelector { * not contacted and the mirrorsURL document is not parsed until a * mirror location request is sent. */ - public MirrorSelector(IRepository repository) { + public MirrorSelector(IRepository<?> repository) { this.repository = repository; try { - String base = (String) repository.getProperties().get(IRepository.PROP_MIRRORS_BASE_URL); + String base = repository.getProperties().get(IRepository.PROP_MIRRORS_BASE_URL); if (base != null) { this.baseURI = new URI(base); } else { @@ -204,7 +201,7 @@ public class MirrorSelector { private MirrorInfo[] initMirrors(IProgressMonitor monitor) { if (mirrors != null) return mirrors; - String mirrorsURL = (String) repository.getProperties().get(IRepository.PROP_MIRRORS_URL); + String mirrorsURL = repository.getProperties().get(IRepository.PROP_MIRRORS_URL); if (mirrorsURL != null) mirrors = computeMirrors(mirrorsURL, monitor); return mirrors; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java index 3c82b5565..3c2432543 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java @@ -14,10 +14,10 @@ import java.io.OutputStream; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier; import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.osgi.util.NLS; public class RawMirrorRequest extends MirrorRequest { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java index 55330678a..2108b52f4 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/SignatureVerifier.java @@ -78,7 +78,7 @@ public class SignatureVerifier extends ProcessingStep { } catch (GeneralSecurityException e) { return new Status(IStatus.ERROR, Activator.ID, Messages.SignatureVerification_failedRead + inputFile, e); } - ArrayList allStatus = new ArrayList(0); + ArrayList<IStatus> allStatus = new ArrayList<IStatus>(0); SignedContentEntry[] entries = signedContent.getSignedEntries(); for (int i = 0; i < entries.length; i++) try { @@ -90,7 +90,7 @@ public class SignatureVerifier extends ProcessingStep { break; } if (allStatus.size() > 0) - return new MultiStatus(Activator.ID, IStatus.ERROR, (IStatus[]) allStatus.toArray(new IStatus[allStatus.size()]), Messages.SignatureVerification_invalidFileContent + inputFile, null); + return new MultiStatus(Activator.ID, IStatus.ERROR, allStatus.toArray(new IStatus[allStatus.size()]), Messages.SignatureVerification_invalidFileContent + inputFile, null); return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties index 9b80fc9ef..eed154d94 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties @@ -10,6 +10,7 @@ ############################################################################### artifact_not_found=Artifact not found: {0}. available_already_in=The artifact is already available in the repository {0}. +no_location=No location for {0}. downloading=Downloading {0} error_closing_stream=Error closing the output stream for {0} on repository {1}. diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java index e3697cbee..bf6fed250 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/BlobStore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -12,7 +12,6 @@ package org.eclipse.equinox.internal.p2.artifact.repository.simple; import java.io.*; import java.net.URI; -import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.URIUtil; @@ -93,9 +92,9 @@ public class BlobStore { /** * Delete all of the blobs in the given set. */ - public void deleteBlobs(Set set) { - for (Iterator i = set.iterator(); i.hasNext();) - deleteBlob((byte[]) i.next()); + public void deleteBlobs(Set<byte[]> set) { + for (byte[] blob : set) + deleteBlob(blob); } public URI fileFor(byte[] uuid) { diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java index 0001a2804..69aee86ef 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/DownloadJob.java @@ -13,12 +13,12 @@ import java.util.LinkedList; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRequest; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest; public class DownloadJob extends Job { static final Object FAMILY = new Object(); - private LinkedList requestsPending; + private LinkedList<IArtifactRequest> requestsPending; private SimpleArtifactRepository repository; private IProgressMonitor masterMonitor; private MultiStatus overallStatus; @@ -28,7 +28,7 @@ public class DownloadJob extends Job { setSystem(true); } - void initialize(SimpleArtifactRepository repository, LinkedList requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) { + void initialize(SimpleArtifactRepository repository, LinkedList<IArtifactRequest> requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) { this.repository = repository; this.requestsPending = requestsPending; this.masterMonitor = masterMonitor; @@ -53,7 +53,7 @@ public class DownloadJob extends Job { synchronized (requestsPending) { if (requestsPending.isEmpty()) break; - request = (IArtifactRequest) requestsPending.removeFirst(); + request = requestsPending.removeFirst(); } if (masterMonitor.isCanceled()) return Status.CANCEL_STATUS; diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java index de962a7c7..80b6b3e44 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/Mapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -53,7 +53,7 @@ public class Mapper { public URI map(URI repositoryLocation, String classifier, String id, String version, String format) { String locationString = URIUtil.toUnencodedString(repositoryLocation); - Dictionary values = new Hashtable(5); + Dictionary<String, Object> values = new Hashtable<String, Object>(5); if (repositoryLocation != null) values.put(REPOURL, locationString); diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java new file mode 100644 index 000000000..e458813ee --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactDescriptor.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.internal.p2.artifact.repository.simple; + +import java.util.Map; +import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; + +public class SimpleArtifactDescriptor extends ArtifactDescriptor { + public static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$ + + protected Map<String, String> repositoryProperties = new OrderedProperties(); + + public SimpleArtifactDescriptor(IArtifactKey key) { + super(key); + } + + public SimpleArtifactDescriptor(IArtifactDescriptor base) { + super(base); + } + + public SimpleArtifactDescriptor(SimpleArtifactDescriptor base) { + super(base); + } + + public String getRepositoryProperty(String propertyKey) { + return repositoryProperties.get(propertyKey); + } + + public void setRepositoryProperty(String key, String value) { + if (value == null) + repositoryProperties.remove(key); + else + repositoryProperties.put(key, value); + } + + public void addRepositoryProperties(Map<String, String> additionalProperties) { + repositoryProperties.putAll(additionalProperties); + } + + /** + * Returns a read-only collection of the repository properties of the artifact descriptor. + * @return the repository properties of this artifact descriptor. + */ + public Map<String, String> getRepositoryProperties() { + return OrderedProperties.unmodifiableProperties(repositoryProperties); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || !(obj instanceof SimpleArtifactDescriptor)) + return false; + + SimpleArtifactDescriptor other = (SimpleArtifactDescriptor) obj; + + //Properties affecting SimpleArtifactRepository#getLocation + String locationProperty = getRepositoryProperty(ARTIFACT_REFERENCE); + String otherProperty = other.getRepositoryProperty(ARTIFACT_REFERENCE); + // want not null and the same, or both null + if (locationProperty != null ? !locationProperty.equals(otherProperty) : otherProperty != null) + return false; + + return super.equals(obj); + } + + public int hashCode() { + int superHash = super.hashCode(); + String ref = getRepositoryProperty(ARTIFACT_REFERENCE); + if (ref != null) + return 31 * superHash + ref.hashCode(); + return superHash; + } +} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index fc225be63..127c7851b 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -1,11 +1,11 @@ /******************************************************************************* - * Copyright (c) 2007, 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: + * Copyright (c) 2007, 2010 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 * Genuitec, LLC - support for multi-threaded downloads *******************************************************************************/ @@ -15,6 +15,7 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.util.*; +import java.util.Map.Entry; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import org.eclipse.core.runtime.*; @@ -26,13 +27,15 @@ import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; import org.eclipse.equinox.internal.p2.repository.Transport; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*; -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.repository.IRepository; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; -import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.*; +import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; import org.eclipse.osgi.util.NLS; public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository { @@ -197,12 +200,14 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme static final private Integer REPOSITORY_VERSION = new Integer(1); private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ - protected Set artifactDescriptors = new HashSet(); - protected Map artifactMap = new HashMap(); + protected Set<SimpleArtifactDescriptor> artifactDescriptors = new HashSet<SimpleArtifactDescriptor>(); + /** + * Map<IArtifactKey,List<IArtifactDescriptor>> containing the index of artifacts in the repository. + */ + protected Map<IArtifactKey, List<IArtifactDescriptor>> artifactMap = new HashMap<IArtifactKey, List<IArtifactDescriptor>>(); private transient BlobStore blobStore; transient private Mapper mapper = new Mapper(); - static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$ static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ private static final int DEFAULT_MAX_THREADS = 4; @@ -250,19 +255,19 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme /* * This is only called by the parser when loading a repository. */ - SimpleArtifactRepository(String name, String type, String version, String description, String provider, Set artifacts, String[][] mappingRules, Map properties) { + SimpleArtifactRepository(String name, String type, String version, String description, String provider, Set<SimpleArtifactDescriptor> artifacts, String[][] mappingRules, Map<String, String> properties) { super(name, type, version, null, description, provider, properties); this.artifactDescriptors.addAll(artifacts); this.mappingRules = mappingRules; - for (Iterator it = artifactDescriptors.iterator(); it.hasNext();) - mapDescriptor((IArtifactDescriptor) it.next()); + for (SimpleArtifactDescriptor desc : artifactDescriptors) + mapDescriptor(desc); } private void mapDescriptor(IArtifactDescriptor descriptor) { IArtifactKey key = descriptor.getArtifactKey(); - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) { - descriptors = new ArrayList(); + descriptors = new ArrayList<IArtifactDescriptor>(); artifactMap.put(key, descriptors); } descriptors.add(descriptor); @@ -270,7 +275,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme private void unmapDescriptor(IArtifactDescriptor descriptor) { IArtifactKey key = descriptor.getArtifactKey(); - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) return; @@ -279,13 +284,13 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme artifactMap.remove(key); } - public SimpleArtifactRepository(String repositoryName, URI location, Map properties) { + public SimpleArtifactRepository(String repositoryName, URI location, Map<String, String> properties) { super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties); initializeAfterLoad(location); if (properties != null) { if (properties.containsKey(PUBLISH_PACK_FILES_AS_SIBLINGS)) { synchronized (this) { - String newValue = (String) properties.get(PUBLISH_PACK_FILES_AS_SIBLINGS); + String newValue = properties.get(PUBLISH_PACK_FILES_AS_SIBLINGS); if (Boolean.TRUE.toString().equals(newValue)) { mappingRules = PACKED_MAPPING_RULES; } else { @@ -299,37 +304,57 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized void addDescriptor(IArtifactDescriptor toAdd) { - // TODO perhaps the argument here should be ArtifactDescriptor. IArtifactDescriptors are for - // people who are reading the repository. - // TODO: here we may want to ensure that the artifact has not been added concurrently - ((ArtifactDescriptor) toAdd).setRepository(this); - artifactDescriptors.add(toAdd); - mapDescriptor(toAdd); + if (artifactDescriptors.contains(toAdd)) + return; + + SimpleArtifactDescriptor internalDescriptor = createInternalDescriptor(toAdd); + artifactDescriptors.add(internalDescriptor); + mapDescriptor(internalDescriptor); save(); } - public synchronized void addDescriptors(IArtifactDescriptor[] descriptors) { + public IArtifactDescriptor createArtifactDescriptor(IArtifactKey key) { + return new SimpleArtifactDescriptor(key); + } + + private SimpleArtifactDescriptor createInternalDescriptor(IArtifactDescriptor descriptor) { + SimpleArtifactDescriptor internal = new SimpleArtifactDescriptor(descriptor); + + internal.setRepository(this); + if (isFolderBased(descriptor)) + internal.setRepositoryProperty(ARTIFACT_FOLDER, Boolean.TRUE.toString()); + if (descriptor instanceof SimpleArtifactDescriptor) { + Map<String, String> repoProperties = ((SimpleArtifactDescriptor) descriptor).getRepositoryProperties(); + for (Entry<String, String> entry : repoProperties.entrySet()) { + internal.setRepositoryProperty(entry.getKey(), entry.getValue()); + } + } + return internal; + } + public synchronized void addDescriptors(IArtifactDescriptor[] descriptors) { for (int i = 0; i < descriptors.length; i++) { - ((ArtifactDescriptor) descriptors[i]).setRepository(this); - artifactDescriptors.add(descriptors[i]); - mapDescriptor(descriptors[i]); + if (artifactDescriptors.contains(descriptors[i])) + continue; + SimpleArtifactDescriptor internalDescriptor = createInternalDescriptor(descriptors[i]); + artifactDescriptors.add(internalDescriptor); + mapDescriptor(internalDescriptor); } save(); } private synchronized OutputStream addPostSteps(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { - ArrayList steps = new ArrayList(); + ArrayList<ProcessingStep> steps = new ArrayList<ProcessingStep>(); steps.add(new SignatureVerifier()); if (steps.isEmpty()) return destination; - ProcessingStep[] stepArray = (ProcessingStep[]) steps.toArray(new ProcessingStep[steps.size()]); + ProcessingStep[] stepArray = steps.toArray(new ProcessingStep[steps.size()]); // TODO should probably be using createAndLink here return handler.link(stepArray, destination, monitor); } private OutputStream addPreSteps(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { - ArrayList steps = new ArrayList(); + ArrayList<ProcessingStep> steps = new ArrayList<ProcessingStep>(); if (IArtifactDescriptor.TYPE_ZIP.equals(descriptor.getProperty(IArtifactDescriptor.DOWNLOAD_CONTENTTYPE))) steps.add(new ZipVerifierStep()); if (MD5_CHECK_ENABLED && descriptor.getProperty(IArtifactDescriptor.DOWNLOAD_MD5) != null) @@ -337,7 +362,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme // Add steps here if needed if (steps.isEmpty()) return destination; - ProcessingStep[] stepArray = (ProcessingStep[]) steps.toArray(new ProcessingStep[steps.size()]); + ProcessingStep[] stepArray = steps.toArray(new ProcessingStep[steps.size()]); // TODO should probably be using createAndLink here return handler.link(stepArray, destination, monitor); } @@ -367,7 +392,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized boolean contains(IArtifactDescriptor descriptor) { - return artifactDescriptors.contains(descriptor); + SimpleArtifactDescriptor simpleDescriptor = createInternalDescriptor(descriptor); + return artifactDescriptors.contains(simpleDescriptor); } public synchronized boolean contains(IArtifactKey key) { @@ -404,7 +430,12 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * descriptor existed in the repository, and was successfully removed. */ private boolean doRemoveArtifact(IArtifactDescriptor descriptor) { - if (((ArtifactDescriptor) descriptor).getRepositoryProperty(ArtifactDescriptor.ARTIFACT_REFERENCE) == null) { + SimpleArtifactDescriptor simple = null; + if (descriptor instanceof SimpleArtifactDescriptor) + simple = (SimpleArtifactDescriptor) descriptor; + else + simple = createInternalDescriptor(descriptor); + if (simple.getRepositoryProperty(SimpleArtifactDescriptor.ARTIFACT_REFERENCE) == null) { File file = getArtifactFile(descriptor); if (file == null) return false; @@ -446,7 +477,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme //download from the best available mirror URI baseLocation = getLocation(descriptor); if (baseLocation == null) - return new Status(IStatus.ERROR, Activator.ID, "Can not find the location of " + descriptor); + return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.no_location, descriptor)); URI mirrorLocation = getMirror(baseLocation, monitor); IStatus status = downloadArtifact(descriptor, mirrorLocation, destination, monitor); IStatus result = reportStatus(descriptor, destination, status); @@ -494,6 +525,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return mirrors.getMirrorLocation(baseLocation, monitor); } + @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { // if we are adapting to file or writable repositories then make sure we have a file location if (adapter == IFileArtifactRepository.class) @@ -523,11 +555,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { - Collection result = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> result = artifactMap.get(key); if (result == null) return new IArtifactDescriptor[0]; - return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); + return result.toArray(new IArtifactDescriptor[result.size()]); } public File getArtifactFile(IArtifactDescriptor descriptor) { @@ -544,14 +576,9 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return getArtifactFile(descriptor); } - public synchronized IArtifactKey[] getArtifactKeys() { - // there may be more descriptors than keys to collect up the unique keys - return (IArtifactKey[]) artifactMap.keySet().toArray(new IArtifactKey[artifactMap.keySet().size()]); - } - public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); - LinkedList requestsPending = new LinkedList(Arrays.asList(requests)); + LinkedList<IArtifactRequest> requestsPending = new LinkedList<IArtifactRequest>(Arrays.asList(requests)); int numberOfJobs = Math.min(requests.length, getMaximumThreads()); if (numberOfJobs <= 1 || (!isForceThreading() && isLocal())) { @@ -591,12 +618,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { - Collection descriptors = (Collection) artifactMap.get(key); + List<IArtifactDescriptor> descriptors = artifactMap.get(key); if (descriptors == null) return null; - for (Iterator iterator = descriptors.iterator(); iterator.hasNext();) { - IArtifactDescriptor desc = (IArtifactDescriptor) iterator.next(); + for (IArtifactDescriptor desc : descriptors) { // look for a descriptor that matches the key and is "complete" if (desc.getArtifactKey().equals(key) && desc.getProcessingSteps().length == 0) return desc; @@ -604,7 +630,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme return null; } - public synchronized Set getDescriptors() { + public synchronized Set<SimpleArtifactDescriptor> getDescriptors() { return artifactDescriptors; } @@ -615,7 +641,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * this arrangement "flat but packed". */ private boolean flatButPackedEnabled(IArtifactDescriptor descriptor) { - return Boolean.TRUE.toString().equals(getProperties().get(PUBLISH_PACK_FILES_AS_SIBLINGS)) && PACKED_FORMAT.equals(descriptor.getProperty(IArtifactDescriptor.FORMAT)); + return Boolean.TRUE.toString().equals(getProperties().get(PUBLISH_PACK_FILES_AS_SIBLINGS)) && IArtifactDescriptor.FORMAT_PACKED.equals(descriptor.getProperty(IArtifactDescriptor.FORMAT)); } /** @@ -638,8 +664,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme try { // if the artifact is just a reference then return the reference location - if (descriptor instanceof ArtifactDescriptor) { - String artifactReference = ((ArtifactDescriptor) descriptor).getRepositoryProperty(ArtifactDescriptor.ARTIFACT_REFERENCE); + if (descriptor instanceof SimpleArtifactDescriptor) { + String artifactReference = ((SimpleArtifactDescriptor) descriptor).getRepositoryProperty(SimpleArtifactDescriptor.ARTIFACT_REFERENCE); if (artifactReference != null) { try { return new URI(artifactReference); @@ -672,7 +698,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme */ private int getMaximumThreads() { try { - String maxThreadString = (String) getProperties().get(PROP_MAX_THREADS); + String maxThreadString = getProperties().get(PROP_MAX_THREADS); if (maxThreadString != null) return Math.max(1, Integer.parseInt(maxThreadString)); } catch (NumberFormatException nfe) { @@ -685,9 +711,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme assertModifiable(); // Create a copy of the original descriptor that we can manipulate and add to our repo. - ArtifactDescriptor newDescriptor = new ArtifactDescriptor(descriptor); - if (isFolderBased(descriptor)) - newDescriptor.setRepositoryProperty(ARTIFACT_FOLDER, Boolean.TRUE.toString()); + ArtifactDescriptor newDescriptor = createInternalDescriptor(descriptor); // Check if the artifact is already in this repository, check the newDescriptor instead of the original // since the implementation of hash/equals on the descriptor matters here. @@ -764,13 +788,12 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } // use this method to setup any transient fields etc after the object has been restored from a stream - public synchronized void initializeAfterLoad(URI location) { - this.location = location; - blobStore = new BlobStore(getBlobStoreLocation(location), 128); + public synchronized void initializeAfterLoad(URI repoLocation) { + this.location = repoLocation; + blobStore = new BlobStore(getBlobStoreLocation(repoLocation), 128); initializeMapper(); - for (Iterator i = artifactDescriptors.iterator(); i.hasNext();) { - ((ArtifactDescriptor) i.next()).setRepository(this); - } + for (SimpleArtifactDescriptor desc : artifactDescriptors) + desc.setRepository(this); } private synchronized void initializeMapper() { @@ -779,13 +802,17 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } private boolean isFolderBased(IArtifactDescriptor descriptor) { - // if the artifact is just a reference then return the reference location - if (descriptor instanceof ArtifactDescriptor) { - String useArtifactFolder = ((ArtifactDescriptor) descriptor).getRepositoryProperty(ARTIFACT_FOLDER); + // This is called from createInternalDescriptor, so if we aren't a + // SimpleArtifactDescriptor then just check the descriptor properties instead + // of creating the interla descriptor. + SimpleArtifactDescriptor internalDescriptor = null; + if (descriptor instanceof SimpleArtifactDescriptor) + internalDescriptor = (SimpleArtifactDescriptor) descriptor; + if (internalDescriptor != null) { + String useArtifactFolder = internalDescriptor.getRepositoryProperty(ARTIFACT_FOLDER); if (useArtifactFolder != null) return Boolean.valueOf(useArtifactFolder).booleanValue(); } - //TODO: refactor this when the artifact folder property is consistently set in repository properties return Boolean.valueOf(descriptor.getProperty(ARTIFACT_FOLDER)).booleanValue(); } @@ -809,7 +836,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public synchronized void removeAll() { - IArtifactDescriptor[] toRemove = (IArtifactDescriptor[]) artifactDescriptors.toArray(new IArtifactDescriptor[artifactDescriptors.size()]); + IArtifactDescriptor[] toRemove = artifactDescriptors.toArray(new IArtifactDescriptor[artifactDescriptors.size()]); boolean changed = false; for (int i = 0; i < toRemove.length; i++) changed |= doRemoveArtifact(toRemove[i]); @@ -873,7 +900,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } public void save() { - boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ + boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$ save(compress); } @@ -936,7 +963,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } save(); //force repository manager to reload this repository because it caches properties - ArtifactRepositoryManager manager = (ArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); + ArtifactRepositoryManager manager = (ArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME); if (manager.removeRepository(getLocation())) manager.addRepository(this); return oldValue; @@ -949,4 +976,18 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme public String toString() { return location.toString(); } + + public IQueryable<IArtifactDescriptor> descriptorQueryable() { + final Collection<List<IArtifactDescriptor>> descs = artifactMap.values(); + return new IQueryable<IArtifactDescriptor>() { + + public IQueryResult<IArtifactDescriptor> query(IQuery<IArtifactDescriptor> query, IProgressMonitor monitor) { + return query.perform(new FlatteningIterator<IArtifactDescriptor>(descs.iterator())); + } + }; + } + + public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor) { + return query.perform(artifactMap.keySet().iterator()); + } } diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java new file mode 100644 index 000000000..a3aec4822 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 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.internal.p2.artifact.repository.simple; + +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import java.io.*; +import java.net.URI; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.artifact.repository.Activator; +import org.eclipse.equinox.internal.p2.artifact.repository.Messages; +import org.eclipse.equinox.internal.p2.core.helpers.Tracing; +import org.eclipse.equinox.internal.p2.repository.RepositoryTransport; +import org.eclipse.equinox.internal.p2.repository.Transport; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; +import org.eclipse.osgi.util.NLS; + +public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory { + public SimpleArtifactRepositoryFactory() { + super(); + } + + public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException { + final String PROTOCOL_FILE = "file"; //$NON-NLS-1$ + long time = 0; + final String debugMsg = "Restoring artifact repository "; //$NON-NLS-1$ + if (Tracing.DEBUG_METADATA_PARSING) { + Tracing.debug(debugMsg + location); + time = -System.currentTimeMillis(); + } + File localFile = null; + boolean local = false; + try { + SubMonitor sub = SubMonitor.convert(monitor, 300); + OutputStream artifacts = null; + // try with compressed + boolean compress = true; + if (PROTOCOL_FILE.equals(location.getScheme())) { + local = true; + localFile = URIUtil.toFile(SimpleArtifactRepository.getActualLocation(location, true)); + if (!localFile.exists()) { + localFile = URIUtil.toFile(SimpleArtifactRepository.getActualLocation(location, false)); + compress = false; + } + } else { + //not local, return null if the caller wanted a modifiable repo + if ((flags & IRepositoryManager.REPOSITORY_HINT_MODIFIABLE) > 0) { + return null; + } + + //download to local temp file + localFile = File.createTempFile("artifacts", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ + try { + artifacts = new BufferedOutputStream(new FileOutputStream(localFile)); + IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress), artifacts, sub.newChild(100)); + if (!status.isOK()) { + // not meaningful to continue on an authentication exception (user will likely just be prompted again) + if (status.getCode() == ProvisionException.REPOSITORY_FAILED_AUTHENTICATION) + throw new ProvisionException(status); + // retry uncompressed + compress = false; + status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress), artifacts, sub.newChild(100)); + if (!status.isOK()) + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null)); + } + } finally { + if (artifacts != null) + artifacts.close(); + } + } + InputStream descriptorStream = null; + try { + descriptorStream = new BufferedInputStream(new FileInputStream(localFile)); + if (compress) { + URI actualLocation = SimpleArtifactRepository.getActualLocation(location, false); + JarInputStream jInStream = new JarInputStream(descriptorStream); + JarEntry jarEntry = jInStream.getNextJarEntry(); + String filename = URIUtil.lastSegment(actualLocation); + while (jarEntry != null && filename != null && !(filename.equals(jarEntry.getName()))) { + jarEntry = jInStream.getNextJarEntry(); + } + if (jarEntry == null) { + //there is a jar but the entry is missing or invalid, so treat this as an invalid repository + throw new IOException(NLS.bind(Messages.io_invalidLocation, actualLocation.getPath())); + } + descriptorStream = jInStream; + } + SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO(); + SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(localFile.toURL(), descriptorStream, sub.newChild(100)); + result.initializeAfterLoad(location); + if (Tracing.DEBUG_METADATA_PARSING) { + time += System.currentTimeMillis(); + Tracing.debug(debugMsg + "time (ms): " + time); //$NON-NLS-1$ + } + return result; + } finally { + if (descriptorStream != null) + descriptorStream.close(); + } + } catch (FileNotFoundException e) { + String msg = NLS.bind(Messages.io_failedRead, location); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, msg, e)); + } catch (IOException e) { + String msg = NLS.bind(Messages.io_failedRead, location); + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + } finally { + if (!local && localFile != null && !localFile.delete()) + localFile.deleteOnExit(); + } + } + + public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) { + return new SimpleArtifactRepository(name, location, properties); + } + + private Transport getTransport() { + return RepositoryTransport.getInstance(); + } +} diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java index 85333d106..477aac105 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2010 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 @@ -10,8 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.artifact.repository.simple; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionRange; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor; import java.io.*; import java.net.URL; @@ -25,11 +29,8 @@ import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; import org.eclipse.equinox.internal.p2.persistence.XMLParser; import org.eclipse.equinox.internal.p2.persistence.XMLWriter; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; -import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor; -import org.eclipse.equinox.internal.provisional.p2.core.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.*; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; import org.xml.sax.*; @@ -109,9 +110,9 @@ public class SimpleArtifactRepositoryIO { // Constants defining the structure of the XML for a SimpleArtifactRepository // A format version number for simple artifact repository XML. - public static final Version COMPATIBLE_VERSION = new Version(1, 0, 0); - public static final Version CURRENT_VERSION = new Version(1, 1, 0); - public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, new Version(2, 0, 0), false); + public static final Version COMPATIBLE_VERSION = Version.createOSGi(1, 0, 0); + public static final Version CURRENT_VERSION = Version.createOSGi(1, 1, 0); + public static final VersionRange XML_TOLERANCE = new VersionRange(COMPATIBLE_VERSION, true, Version.createOSGi(2, 0, 0), false); // Constants for processing instructions public static final String PI_REPOSITORY_TARGET = "artifactRepository"; //$NON-NLS-1$ @@ -176,11 +177,10 @@ public class SimpleArtifactRepositoryIO { } } - private void writeArtifacts(Set artifactDescriptors) { + private void writeArtifacts(Set<SimpleArtifactDescriptor> artifactDescriptors) { start(ARTIFACTS_ELEMENT); attribute(COLLECTION_SIZE_ATTRIBUTE, artifactDescriptors.size()); - for (Iterator iter = artifactDescriptors.iterator(); iter.hasNext();) { - ArtifactDescriptor descriptor = (ArtifactDescriptor) iter.next(); + for (SimpleArtifactDescriptor descriptor : artifactDescriptors) { IArtifactKey key = descriptor.getArtifactKey(); start(ARTIFACT_ELEMENT); attribute(ARTIFACT_CLASSIFIER_ATTRIBUTE, key.getClassifier()); @@ -194,7 +194,7 @@ public class SimpleArtifactRepositoryIO { end(ARTIFACTS_ELEMENT); } - private void writeProcessingSteps(ProcessingStepDescriptor[] processingSteps) { + private void writeProcessingSteps(IProcessingStepDescriptor[] processingSteps) { if (processingSteps.length > 0) { start(PROCESSING_STEPS_ELEMENT); attribute(COLLECTION_SIZE_ATTRIBUTE, processingSteps.length); @@ -326,9 +326,9 @@ public class SimpleArtifactRepositoryIO { if (isValidXML()) { String[][] mappingRules = (mappingRulesHandler == null ? new String[0][0] // : mappingRulesHandler.getMappingRules()); - Map properties = (propertiesHandler == null ? new OrderedProperties(0) // + Map<String, String> properties = (propertiesHandler == null ? new OrderedProperties(0) // : propertiesHandler.getProperties()); - Set artifacts = (artifactsHandler == null ? new HashSet(0) // + Set<SimpleArtifactDescriptor> artifacts = (artifactsHandler == null ? new HashSet<SimpleArtifactDescriptor>(0) // : artifactsHandler.getArtifacts()); repository = new SimpleArtifactRepository(attrValues[0], attrValues[1], attrValues[2], attrValues[3], // attrValues[4], artifacts, mappingRules, properties); @@ -338,18 +338,18 @@ public class SimpleArtifactRepositoryIO { protected class MappingRulesHandler extends AbstractHandler { - private List mappingRules; + private List<String[]> mappingRules; public MappingRulesHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, MAPPING_RULES_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - mappingRules = (size != null ? new ArrayList(new Integer(size).intValue()) : new ArrayList(4)); + mappingRules = (size != null ? new ArrayList<String[]>(new Integer(size).intValue()) : new ArrayList<String[]>(4)); } public String[][] getMappingRules() { String[][] rules = new String[mappingRules.size()][2]; for (int index = 0; index < mappingRules.size(); index++) { - String[] ruleAttributes = (String[]) mappingRules.get(index); + String[] ruleAttributes = mappingRules.get(index); rules[index] = ruleAttributes; } return rules; @@ -368,7 +368,7 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {MAPPING_RULE_FILTER_ATTRIBUTE, MAPPING_RULE_OUTPUT_ATTRIBUTE}; - public MappingRuleHandler(AbstractHandler parentHandler, Attributes attributes, List mappingRules) { + public MappingRuleHandler(AbstractHandler parentHandler, Attributes attributes, List<String[]> mappingRules) { super(parentHandler, MAPPING_RULE_ELEMENT); mappingRules.add(parseRequiredAttributes(attributes, required)); } @@ -380,15 +380,15 @@ public class SimpleArtifactRepositoryIO { protected class ArtifactsHandler extends AbstractHandler { - private Set artifacts; + private Set<SimpleArtifactDescriptor> artifacts; public ArtifactsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, ARTIFACTS_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - artifacts = (size != null ? new LinkedHashSet(new Integer(size).intValue()) : new LinkedHashSet(4)); + artifacts = (size != null ? new LinkedHashSet<SimpleArtifactDescriptor>(new Integer(size).intValue()) : new LinkedHashSet<SimpleArtifactDescriptor>(4)); } - public Set getArtifacts() { + public Set<SimpleArtifactDescriptor> getArtifacts() { return artifacts; } @@ -405,20 +405,20 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {ARTIFACT_CLASSIFIER_ATTRIBUTE, ID_ATTRIBUTE, VERSION_ATTRIBUTE}; - private Set artifacts; - ArtifactDescriptor currentArtifact = null; + private Set<SimpleArtifactDescriptor> artifacts; + SimpleArtifactDescriptor currentArtifact = null; private PropertiesHandler propertiesHandler = null; private PropertiesHandler repositoryPropertiesHandler = null; private ProcessingStepsHandler processingStepsHandler = null; - public ArtifactHandler(AbstractHandler parentHandler, Attributes attributes, Set artifacts) { + public ArtifactHandler(AbstractHandler parentHandler, Attributes attributes, Set<SimpleArtifactDescriptor> artifacts) { super(parentHandler, ARTIFACT_ELEMENT); this.artifacts = artifacts; String[] values = parseRequiredAttributes(attributes, required); Version version = checkVersion(ARTIFACT_ELEMENT, VERSION_ATTRIBUTE, values[2]); // TODO: resolve access restriction on ArtifactKey construction - currentArtifact = new ArtifactDescriptor(new ArtifactKey(values[0], values[1], version)); + currentArtifact = new SimpleArtifactDescriptor(new ArtifactKey(values[0], values[1], version)); } public void startElement(String name, Attributes attributes) { @@ -447,13 +447,13 @@ public class SimpleArtifactRepositoryIO { protected void finished() { if (isValidXML() && currentArtifact != null) { - Map properties = (propertiesHandler == null ? new OrderedProperties(0) : propertiesHandler.getProperties()); + Map<String, String> properties = (propertiesHandler == null ? new OrderedProperties(0) : propertiesHandler.getProperties()); currentArtifact.addProperties(properties); properties = (repositoryPropertiesHandler == null ? new OrderedProperties(0) : repositoryPropertiesHandler.getProperties()); currentArtifact.addRepositoryProperties(properties); - ProcessingStepDescriptor[] processingSteps = (processingStepsHandler == null ? new ProcessingStepDescriptor[0] // + IProcessingStepDescriptor[] processingSteps = (processingStepsHandler == null ? new ProcessingStepDescriptor[0] // : processingStepsHandler.getProcessingSteps()); currentArtifact.setProcessingSteps(processingSteps); artifacts.add(currentArtifact); @@ -463,16 +463,16 @@ public class SimpleArtifactRepositoryIO { protected class ProcessingStepsHandler extends AbstractHandler { - private List processingSteps; + private List<IProcessingStepDescriptor> processingSteps; public ProcessingStepsHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, PROCESSING_STEPS_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - processingSteps = (size != null ? new ArrayList(new Integer(size).intValue()) : new ArrayList(4)); + processingSteps = (size != null ? new ArrayList<IProcessingStepDescriptor>(new Integer(size).intValue()) : new ArrayList<IProcessingStepDescriptor>(4)); } - public ProcessingStepDescriptor[] getProcessingSteps() { - return (ProcessingStepDescriptor[]) processingSteps.toArray(new ProcessingStepDescriptor[processingSteps.size()]); + public IProcessingStepDescriptor[] getProcessingSteps() { + return processingSteps.toArray(new ProcessingStepDescriptor[processingSteps.size()]); } public void startElement(String name, Attributes attributes) { @@ -489,7 +489,7 @@ public class SimpleArtifactRepositoryIO { private final String[] required = new String[] {ID_ATTRIBUTE, STEP_REQUIRED_ATTRIBUTE}; private final String[] optional = new String[] {STEP_DATA_ATTRIBUTE}; - public ProcessingStepHandler(AbstractHandler parentHandler, Attributes attributes, List processingSteps) { + public ProcessingStepHandler(AbstractHandler parentHandler, Attributes attributes, List<IProcessingStepDescriptor> processingSteps) { super(parentHandler, PROCESSING_STEP_ELEMENT); String[] attributeValues = parseAttributes(attributes, required, optional); processingSteps.add(new ProcessingStepDescriptor(attributeValues[0], attributeValues[2], checkBoolean(PROCESSING_STEP_ELEMENT, STEP_REQUIRED_ATTRIBUTE, attributeValues[1]).booleanValue())); |