diff options
author | Pascal Rapicault | 2010-01-13 17:29:41 +0000 |
---|---|---|
committer | Pascal Rapicault | 2010-01-13 17:29:41 +0000 |
commit | 18189f0d42f7375660762dc6c885cf31683ae562 (patch) | |
tree | 17775d847bed9a33f3c68b74db2df75a2139c0bc /bundles/org.eclipse.equinox.p2.repository/src | |
parent | c363f2984a09b73c422e38f4556fd3b23eafe958 (diff) | |
download | rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.gz rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.xz rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.zip |
Merging api branch back to HEADv20100113
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository/src')
39 files changed, 1898 insertions, 203 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeParser.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeParser.java index 057c53f3c..c3d91c1ab 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeParser.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeParser.java @@ -10,13 +10,15 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.persistence; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionRange; + import java.io.*; import java.net.URI; -import java.util.*; +import java.util.ArrayList; +import java.util.List; import javax.xml.parsers.ParserConfigurationException; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; import org.xml.sax.*; @@ -26,30 +28,24 @@ import org.xml.sax.*; */ public class CompositeParser extends XMLParser implements XMLConstants { - private static final Version CURRENT_VERSION = new Version(1, 0, 0); - static final VersionRange XML_TOLERANCE = new VersionRange(CURRENT_VERSION, true, new Version(2, 0, 0), false); + private static final Version CURRENT_VERSION = Version.createOSGi(1, 0, 0); + static final VersionRange XML_TOLERANCE = new VersionRange(CURRENT_VERSION, true, Version.createOSGi(2, 0, 0), false); private static final String REQUIRED_CAPABILITY_ELEMENT = "required"; //$NON-NLS-1$ private static final String REPOSITORY_ELEMENT = "repository"; //$NON-NLS-1$ String repositoryType; private CompositeRepositoryState theState; protected class ChildrenHandler extends AbstractHandler { - private ArrayList children; + private ArrayList<URI> children; public ChildrenHandler(AbstractHandler parentHandler, Attributes attributes) { super(parentHandler, CHILDREN_ELEMENT); String size = parseOptionalAttribute(attributes, COLLECTION_SIZE_ATTRIBUTE); - children = (size != null ? new ArrayList(new Integer(size).intValue()) : new ArrayList(4)); + children = (size != null ? new ArrayList<URI>(new Integer(size).intValue()) : new ArrayList<URI>(4)); } public URI[] getChildren() { - int size = children.size(); - URI[] result = new URI[size]; - int i = 0; - for (Iterator it = children.iterator(); it.hasNext(); i++) { - result[i] = (URI) it.next(); - } - return result; + return children.toArray(new URI[children.size()]); } public void startElement(String name, Attributes attributes) { @@ -67,9 +63,9 @@ public class CompositeParser extends XMLParser implements XMLConstants { URI currentRepo = null; - private List repos; + private List<URI> repos; - public ChildHandler(AbstractHandler parentHandler, Attributes attributes, List repos) { + public ChildHandler(AbstractHandler parentHandler, Attributes attributes, List<URI> repos) { super(parentHandler, CHILD_ELEMENT); String[] values = parseAttributes(attributes, required, optional); this.repos = repos; diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java index 02319fb52..2a5b1672c 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.persistence; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.net.URL; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.core.Activator; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.osgi.util.NLS; /** diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState.java index 83f7795a6..8a5fe9841 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryState.java @@ -24,7 +24,7 @@ public class CompositeRepositoryState { private String provider; private String description; private URI location; - private Map properties; + private Map<String, String> properties; private URI[] children; public void setName(String value) { @@ -75,11 +75,11 @@ public class CompositeRepositoryState { return location; } - public void setProperties(Map value) { + public void setProperties(Map<String, String> value) { properties = value; } - public Map getProperties() { + public Map<String, String> getProperties() { return properties; } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeWriter.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeWriter.java index 00f3e1544..81d064fb5 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeWriter.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/CompositeWriter.java @@ -10,11 +10,12 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.persistence; +import org.eclipse.equinox.p2.metadata.Version; + import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.URI; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; /* * Class used to persist a composite repository. @@ -22,7 +23,7 @@ import org.eclipse.equinox.internal.provisional.p2.metadata.Version; public class CompositeWriter extends XMLWriter implements XMLConstants { private static final String REPOSITORY_ELEMENT = "repository"; //$NON-NLS-1$ - private static final Version CURRENT_VERSION = new Version(1, 0, 0); + private static final Version CURRENT_VERSION = Version.createOSGi(1, 0, 0); public CompositeWriter(OutputStream output, String type) throws UnsupportedEncodingException { super(output, new XMLWriter.ProcessingInstruction[] {XMLWriter.ProcessingInstruction.makeTargetVersionInstruction(type, CURRENT_VERSION)}); diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java index a428bc891..6f4e4448d 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.persistence; +import org.eclipse.equinox.p2.metadata.Version; +import org.eclipse.equinox.p2.metadata.VersionRange; + import java.net.*; import java.util.List; import java.util.StringTokenizer; @@ -19,8 +22,6 @@ import org.eclipse.equinox.internal.p2.core.Activator; import org.eclipse.equinox.internal.p2.core.StringPool; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; @@ -454,7 +455,7 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants { parseAttributes(attributes, noAttributes, noAttributes); } - public TextHandler(AbstractHandler parent, String elementName, Attributes attributes, List texts) { + public TextHandler(AbstractHandler parent, String elementName, Attributes attributes, List<String> texts) { super(parent, elementName); parseAttributes(attributes, noAttributes, noAttributes); } @@ -682,7 +683,7 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants { public VersionRange checkVersionRange(String element, String attribute, String value) { try { - if (value != null && !value.equals("0.0.0")) //$NON-NLS-1$ + if (value != null) return new VersionRange(value); } catch (IllegalArgumentException iae) { invalidAttributeValue(element, attribute, value); diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java index eb11327ce..af517d170 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.persistence; +import org.eclipse.equinox.p2.metadata.Version; + import java.io.*; import java.util.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.Version; +import java.util.Map.Entry; public class XMLWriter implements XMLConstants { @@ -51,7 +53,7 @@ public class XMLWriter implements XMLConstants { } } - private Stack elements; // XML elements that have not yet been closed + private Stack<String> elements; // XML elements that have not yet been closed private boolean open; // Can attributes be added to the current element? private String indent; // used for each level of indentation @@ -60,7 +62,7 @@ public class XMLWriter implements XMLConstants { public XMLWriter(OutputStream output, ProcessingInstruction[] piElements) throws UnsupportedEncodingException { this.pw = new PrintWriter(new OutputStreamWriter(output, "UTF8"), false); //$NON-NLS-1$ println(ProcessingInstruction.XML_UTF8); - this.elements = new Stack(); + this.elements = new Stack<String>(); this.open = false; this.indent = " "; //$NON-NLS-1$ if (piElements != null) { @@ -101,7 +103,7 @@ public class XMLWriter implements XMLConstants { if (this.elements.empty()) { throw new EndWithoutStartError(); } - String name = (String) this.elements.pop(); + String name = this.elements.pop(); if (this.open) { println("/>"); //$NON-NLS-1$ } else { @@ -217,17 +219,16 @@ public class XMLWriter implements XMLConstants { this.pw.flush(); } - public void writeProperties(Map properties) { + public void writeProperties(Map<String, String> properties) { writeProperties(PROPERTIES_ELEMENT, properties); } - public void writeProperties(String propertiesElement, Map properties) { + public void writeProperties(String propertiesElement, Map<String, String> properties) { if (properties != null && properties.size() > 0) { start(propertiesElement); attribute(COLLECTION_SIZE_ATTRIBUTE, properties.size()); - for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) { - String name = (String) iter.next(); - writeProperty(name, (String) properties.get(name)); + for (Entry<String, String> entry : properties.entrySet()) { + writeProperty(entry.getKey(), entry.getValue()); } end(propertiesElement); } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Activator.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Activator.java index 34d943870..695e2874d 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Activator.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Activator.java @@ -1,11 +1,15 @@ /******************************************************************************* - * Copyright (c) 2009, Cloudsmith Inc. - * The code, documentation and other materials contained herein have been - * licensed under the Eclipse Public License - v 1.0 by the copyright holder - * listed above, as the Initial Contributor under such license. The text of - * such license is available at www.eclipse.org. + * Copyright (c) 2009 Cloudsmith Inc 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: + * Cloudsmith Inc - initial API and implementation + * IBM Corporation - ongoing development + * Genuitec - Bug 291926 ******************************************************************************/ - package org.eclipse.equinox.internal.p2.repository; import org.eclipse.ecf.filetransfer.service.IRetrieveFileTransferFactory; @@ -150,7 +154,8 @@ public class Activator implements BundleActivator { for (int i = 0; i < bundles.length; i++) { try { if ((bundles[i].getState() & Bundle.INSTALLED) == 0) { - bundles[i].start(); + bundles[i].start(Bundle.START_ACTIVATION_POLICY); + bundles[i].start(Bundle.START_TRANSIENT); return true; } } catch (BundleException e) { diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java index 24397e5e4..0e4eba8e5 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/CacheManager.java @@ -11,21 +11,22 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.metadata.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.net.URI; -import java.net.URL; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.ecf.filetransfer.UserCancelledException; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; -import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; import org.eclipse.equinox.internal.p2.repository.*; import org.eclipse.equinox.internal.p2.repository.Activator; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.SynchronousProvisioningListener; -import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; -import org.eclipse.equinox.internal.provisional.p2.repository.*; +import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; +import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; +import org.eclipse.equinox.p2.core.IAgentLocation; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.osgi.util.NLS; /** @@ -37,7 +38,12 @@ import org.eclipse.osgi.util.NLS; * was created for the repository. */ public class CacheManager { - private final AgentLocation agentLocation; + /** + * Service name for the internal cache manager service. + */ + public static final String SERVICE_NAME = CacheManager.class.getName(); + + private final IAgentLocation agentLocation; /** * IStateful implementation of BufferedOutputStream. Class is used to get the status from @@ -61,7 +67,7 @@ public class CacheManager { } - public CacheManager(AgentLocation agentLocation) { + public CacheManager(IAgentLocation agentLocation) { this.agentLocation = agentLocation; } @@ -72,7 +78,7 @@ public class CacheManager { private static final String RESUME_DEFAULT = "true"; //$NON-NLS-1$ private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ - private final HashSet knownPrefixes = new HashSet(5); + private final HashSet<String> knownPrefixes = new HashSet<String>(5); /** * Returns a hash of the repository location. @@ -211,8 +217,7 @@ public class CacheManager { * @param repositoryLocation */ void deleteCache(URI repositoryLocation) { - for (Iterator it = knownPrefixes.iterator(); it.hasNext();) { - String prefix = (String) it.next(); + for (String prefix : knownPrefixes) { File[] cacheFiles = getCacheFiles(repositoryLocation, prefix); for (int i = 0; i < cacheFiles.length; i++) { // delete the cache file if it exists @@ -241,8 +246,7 @@ public class CacheManager { * Returns the file corresponding to the data area to be used by the cache manager. */ private File getCacheDirectory() { - URL dataArea = agentLocation.getDataArea(Activator.ID + "/cache/"); //$NON-NLS-1$ - return URLUtil.toFile(dataArea); + return URIUtil.toFile(agentLocation.getDataArea(Activator.ID + "/cache/")); //$NON-NLS-1$ } /** @@ -264,7 +268,7 @@ public class CacheManager { return RepositoryTransport.getInstance(); } - public boolean isResumeEnabled() { + private boolean isResumeEnabled() { String resumeProp = System.getProperty(PROP_RESUMABLE, RESUME_DEFAULT); return Boolean.valueOf(resumeProp).booleanValue(); } @@ -333,7 +337,7 @@ public class CacheManager { * Adds a {@link SynchronousProvisioningListener} to the event bus for * deleting cache files when the corresponding repository is deleted. */ - public void registerRepoEventListener(IProvisioningEventBus eventBus) { + private void registerRepoEventListener(IProvisioningEventBus eventBus) { if (busListener == null) { busListener = new SynchronousProvisioningListener() { public void notify(EventObject o) { @@ -372,7 +376,7 @@ public class CacheManager { * Removes the {@link SynchronousProvisioningListener} that cleans up the * cache file from the event bus. */ - public void unregisterRepoEventListener(IProvisioningEventBus bus) { + private void unregisterRepoEventListener(IProvisioningEventBus bus) { if (bus != null && busListener != null) bus.removeListener(busListener); } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Credentials.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Credentials.java index 0ff55aac9..09500c2db 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Credentials.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/Credentials.java @@ -22,7 +22,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.helpers.DebugHelper; import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI; import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI.AuthenticationInfo; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.equinox.security.storage.*; /** @@ -39,13 +39,13 @@ public class Credentials { /** * Cache of auth information that is not persisted, and modified auth info. */ - private static final Map savedAuthInfo = Collections.synchronizedMap(new HashMap()); + private static final Map<String, AuthenticationInfo> savedAuthInfo = Collections.synchronizedMap(new HashMap<String, AuthenticationInfo>()); /** * Information about retry counts, and prompts canceled by user. The SoftReference is * a Map if not null. The keys are also used as serialization per host. */ - private static Map remembered; + private static Map<String, HostEntry> remembered; /** * Serializes pop up of login/password prompt @@ -118,8 +118,8 @@ public class Credentials { // Start by getting a key to lock on HostEntry hostLock = null; synchronized (Credentials.class) { - Map r = getRemembered(); - hostLock = (HostEntry) r.get(host); + Map<String, HostEntry> r = getRemembered(); + hostLock = r.get(host); if (hostLock == null) { hostLock = new HostEntry(0); r.put(host, hostLock); @@ -321,7 +321,7 @@ public class Credentials { * or <code>null</code> if no information is stored. */ private static AuthenticationInfo restoreFromMemory(String nodeName) { - return (AuthenticationInfo) savedAuthInfo.get(nodeName); + return savedAuthInfo.get(nodeName); } /** @@ -336,7 +336,7 @@ public class Credentials { * @param host */ private static void rememberCancel(String host) { - Map r = getRemembered(); + Map<String, HostEntry> r = getRemembered(); if (r != null) r.put(host, new HostEntry(-1)); } @@ -348,7 +348,7 @@ public class Credentials { * @throws LoginCanceledException */ private static void checkRememberedCancel(String host) throws LoginCanceledException { - Map r = getRemembered(); + Map<String, HostEntry> r = getRemembered(); if (r != null) { Object x = r.get(host); if (x != null && x instanceof HostEntry) @@ -370,9 +370,9 @@ public class Credentials { * @param host */ private static void incrementPromptCount(String host) { - Map r = getRemembered(); + Map<String, HostEntry> r = getRemembered(); if (r != null) { - HostEntry value = (HostEntry) r.get(host); + HostEntry value = r.get(host); if (value == null) r.put(host, value = new HostEntry(1)); else { @@ -389,9 +389,9 @@ public class Credentials { * @return number of time prompt has been performed for a host (or 0 if information is stale) */ private static int getPromptCount(String host) { - Map r = getRemembered(); + Map<String, HostEntry> r = getRemembered(); if (r != null) { - HostEntry value = (HostEntry) r.get(host); + HostEntry value = r.get(host); if (value != null && !value.isStale()) return value.getCount(); } @@ -406,14 +406,13 @@ public class Credentials { public static synchronized void clearPromptCache() { if (remembered == null) return; - Map r = remembered; + Map<String, HostEntry> r = remembered; if (r == null || r.isEmpty()) return; // reset entries rather than creating a new empty map since the entries // are also used as locks - Iterator itor = r.entrySet().iterator(); - while (itor.hasNext()) - ((HostEntry) itor.next()).reset(); + for (HostEntry entry : r.values()) + entry.reset(); } /** @@ -433,17 +432,17 @@ public class Credentials { public static synchronized void clearPromptCache(String host) { if (remembered == null) return; - Map r = remembered; + Map<String, HostEntry> r = remembered; if (r == null) return; - HostEntry value = (HostEntry) r.get(host); + HostEntry value = r.get(host); if (value != null) value.reset(); } - private static synchronized Map getRemembered() { + private static synchronized Map<String, HostEntry> getRemembered() { if (remembered == null) - remembered = Collections.synchronizedMap(new HashMap()); + remembered = Collections.synchronizedMap(new HashMap<String, HostEntry>()); return remembered; } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java index ec9d2985a..6b740e448 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java @@ -1,16 +1,21 @@ /******************************************************************************* - * Copyright (c) 2006-2009, Cloudsmith Inc. - * The code, documentation and other materials contained herein have been - * licensed under the Eclipse Public License - v 1.0 by the copyright holder - * listed above, as the Initial Contributor under such license. The text or - * such license is available at www.eclipse.org. + * Copyright (c) 2006, 2009 Cloudsmith Inc. + * 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: + * Cloudsmith Inc - initial API and implementation + * IBM Corporation - ongoing development + * Genuitec - Bug 291926 ******************************************************************************/ package org.eclipse.equinox.internal.p2.repository; import java.net.URI; import java.text.NumberFormat; -import java.util.*; -import java.util.Map.Entry; +import java.util.SortedMap; +import java.util.TreeMap; import org.eclipse.osgi.util.NLS; /** @@ -49,7 +54,7 @@ public class ProgressStatistics { private int m_reportInterval; - private SortedMap m_recentSpeedMap; + private SortedMap<Long, Long> m_recentSpeedMap; private long m_recentSpeedMapKey; @@ -64,17 +69,15 @@ public class ProgressStatistics { m_current = 0; m_lastReportTime = 0; m_reportInterval = DEFAULT_REPORT_INTERVAL; - m_recentSpeedMap = new TreeMap(); + m_recentSpeedMap = new TreeMap<Long, Long>(); m_recentSpeedMapKey = 0L; m_uri = uri; } public long getAverageSpeed() { long dur = getDuration(); - - if (dur >= 1000) - return m_current / (dur / 1000); - + if (dur > 0) + return (int) (m_current / (dur / 1000.0)); return 0L; } @@ -93,13 +96,11 @@ public class ProgressStatistics { removeObsoleteRecentSpeedData(getDuration() / SPEED_RESOLUTION); long dur = 0L; long amount = 0L; - SortedMap relevantData = m_recentSpeedMap.headMap(new Long(m_recentSpeedMapKey)); + SortedMap<Long, Long> relevantData = m_recentSpeedMap.headMap(new Long(m_recentSpeedMapKey)); - Iterator itor = relevantData.entrySet().iterator(); - while (itor.hasNext()) { - Entry entry = (Entry) itor.next(); + for (Long rl : relevantData.values()) { dur += SPEED_RESOLUTION; - amount += ((Long) entry.getValue()).longValue(); + amount += rl.longValue(); } if (dur >= 1000) @@ -144,7 +145,7 @@ public class ProgressStatistics { synchronized private void registerRecentSpeed(long key, long inc) { Long keyL = new Long(key); - Long currentValueL = (Long) m_recentSpeedMap.get(keyL); + Long currentValueL = m_recentSpeedMap.get(keyL); long currentValue = 0L; if (currentValueL != null) currentValue = currentValueL.longValue(); diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatus.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatus.java index 67fbb9cd0..aae393d0f 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatus.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatus.java @@ -11,13 +11,14 @@ package org.eclipse.equinox.internal.p2.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.FileNotFoundException; import java.net.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.ecf.core.identity.IDCreateException; import org.eclipse.ecf.filetransfer.BrowseFileTransferException; import org.eclipse.ecf.filetransfer.IncomingFileTransferException; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.osgi.util.NLS; /** diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatusHelper.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatusHelper.java index 601a2da4d..ac3d66bd0 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatusHelper.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryStatusHelper.java @@ -10,13 +10,14 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.URI; import org.eclipse.core.runtime.*; import org.eclipse.ecf.filetransfer.BrowseFileTransferException; import org.eclipse.ecf.filetransfer.IncomingFileTransferException; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.osgi.util.NLS; /** @@ -122,7 +123,7 @@ public abstract class RepositoryStatusHelper { public static Throwable unwind(Throwable t) { for (;;) { - Class tc = t.getClass(); + Class<? extends Throwable> tc = t.getClass(); // We don't use instanceof operator since we want // the explicit class, not subclasses. diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryTransport.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryTransport.java index 02d7027b3..717920796 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryTransport.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/RepositoryTransport.java @@ -12,6 +12,8 @@ package org.eclipse.equinox.internal.p2.repository; +import org.eclipse.equinox.p2.core.ProvisionException; + import java.io.*; import java.net.URI; import org.eclipse.core.runtime.*; @@ -19,7 +21,6 @@ import org.eclipse.ecf.core.security.ConnectContextFactory; import org.eclipse.ecf.core.security.IConnectContext; import org.eclipse.ecf.filetransfer.UserCancelledException; import org.eclipse.equinox.internal.p2.repository.Credentials.LoginCanceledException; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.IServiceUI.AuthenticationInfo; import org.eclipse.equinox.internal.provisional.p2.repository.IStateful; import org.eclipse.osgi.util.NLS; diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java index 8670f223e..15c8af8fe 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java @@ -17,10 +17,14 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.equinox.internal.p2.core.Activator; import org.eclipse.equinox.internal.p2.core.helpers.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener; -import org.eclipse.equinox.internal.provisional.p2.repository.*; +import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; +import org.eclipse.equinox.p2.core.*; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.security.storage.EncodingUtils; import org.eclipse.osgi.util.NLS; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -28,15 +32,15 @@ import org.osgi.service.prefs.Preferences; /** * Common code shared between artifact and metadata repository managers. */ -public abstract class AbstractRepositoryManager implements IRepositoryManager, ProvisioningListener { - protected static class RepositoryInfo { +public abstract class AbstractRepositoryManager<T> implements IRepositoryManager<T>, ProvisioningListener { + protected static class RepositoryInfo<R> { public String description; public boolean isEnabled = true; public boolean isSystem = false; public URI location; public String name; public String nickname; - public SoftReference repository; + public SoftReference<IRepository<R>> repository; public String suffix; public RepositoryInfo() { @@ -65,7 +69,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Map of String->RepositoryInfo, where String is the repository key * obtained via getKey(URI). */ - protected Map repositories = null; + protected Map<String, RepositoryInfo<T>> repositories = null; //lock object to be held when referring to the repositories field protected final Object repositoryLock = new Object(); @@ -74,13 +78,15 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Cache List of repositories that are not reachable. Maintain cache * for short duration because repository may become available at any time. */ - protected SoftReference unavailableRepositories; + protected SoftReference<List<URI>> unavailableRepositories; /** * Set used to manage exclusive load locks on repository locations. */ - private Map loadLocks = new HashMap(); + private Map<URI, Thread> loadLocks = new HashMap<URI, Thread>(); protected IProvisioningEventBus eventBus; + private IAgentLocation agentLocation; + protected IProvisioningAgent agent; protected AbstractRepositoryManager() { super(); @@ -92,23 +98,23 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * @param signalAdd whether a repository change event should be fired * @param suffix the suffix used to load the repository, or <code>null</code> if unknown */ - protected void addRepository(IRepository repository, boolean signalAdd, String suffix) { + protected void addRepository(IRepository<T> repository, boolean signalAdd, String suffix) { boolean added = false; synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); String key = getKey(repository.getLocation()); - RepositoryInfo info = (RepositoryInfo) repositories.get(key); + RepositoryInfo<T> info = repositories.get(key); if (info == null) { - info = new RepositoryInfo(); + info = new RepositoryInfo<T>(); added = true; repositories.put(key, info); } - info.repository = new SoftReference(repository); + info.repository = new SoftReference<IRepository<T>>(repository); info.name = repository.getName(); info.description = repository.getDescription(); info.location = repository.getLocation(); - String value = (String) repository.getProperties().get(IRepository.PROP_SYSTEM); + String value = repository.getProperties().get(IRepository.PROP_SYSTEM); if (value != null) info.isSystem = Boolean.valueOf(value).booleanValue(); info.suffix = suffix; @@ -138,7 +144,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * <code>false</code> otherwise. */ private boolean addRepository(URI location, boolean isEnabled, boolean signalAdd) { - RepositoryInfo info = new RepositoryInfo(); + RepositoryInfo<T> info = new RepositoryInfo<T>(); info.location = location; info.isEnabled = isEnabled; boolean added = true; @@ -156,15 +162,15 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return added; } - protected IRepository basicGetRepository(URI location) { + protected IRepository<T> basicGetRepository(URI location) { checkValidLocation(location); synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info == null || info.repository == null) return null; - IRepository repo = (IRepository) info.repository.get(); + IRepository<T> repo = info.repository.get(); //update our repository info because the repository may have changed if (repo != null) addRepository(repo, false, null); @@ -172,7 +178,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } } - public IRepository basicRefreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException { + public IRepository<T> basicRefreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException { checkValidLocation(location); clearNotFound(location); boolean wasEnabled = isEnabled(location); @@ -182,7 +188,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P fail(location, ProvisionException.REPOSITORY_NOT_FOUND); boolean loaded = false; try { - IRepository result = loadRepository(location, monitor, null, 0); + IRepository<T> result = loadRepository(location, monitor, null, 0); loaded = true; setEnabled(location, wasEnabled); return result; @@ -208,7 +214,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P private boolean checkNotFound(URI location) { if (unavailableRepositories == null) return false; - List badRepos = (List) unavailableRepositories.get(); + List<URI> badRepos = unavailableRepositories.get(); if (badRepos == null) return false; return badRepos.contains(location); @@ -218,9 +224,9 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Clear the fact that we tried to load a repository at this location and did not find anything. */ private void clearNotFound(URI location) { - List badRepos; + List<URI> badRepos; if (unavailableRepositories != null) { - badRepos = (List) unavailableRepositories.get(); + badRepos = unavailableRepositories.get(); if (badRepos != null) { badRepos.remove(location); return; @@ -243,11 +249,11 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /* (non-Javadoc) * @see org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager#createRepository(java.net.URL, java.lang.String, java.lang.String, java.util.Map) */ - protected IRepository doCreateRepository(URI location, String name, String type, Map properties) throws ProvisionException { + protected IRepository<T> doCreateRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException { checkValidLocation(location); Assert.isNotNull(name); Assert.isNotNull(type); - IRepository result = null; + IRepository<T> result = null; try { enterLoad(location, new NullProgressMonitor()); boolean loaded = false; @@ -315,7 +321,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P Thread current = Thread.currentThread(); synchronized (loadLocks) { while (true) { - Thread owner = (Thread) loadLocks.get(location); + Thread owner = loadLocks.get(location); if (owner == null || current.equals(owner)) break; if (monitor.isCanceled()) @@ -346,13 +352,13 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Creates and returns a repository using the given repository factory extension. Returns * null if no factory could be found associated with that extension. */ - protected abstract IRepository factoryCreate(URI location, String name, String type, Map properties, IExtension extension) throws ProvisionException; + protected abstract IRepository<T> factoryCreate(URI location, String name, String type, Map<String, String> properties, IExtension extension) throws ProvisionException; /** * Loads and returns a repository using the given repository factory extension. Returns * null if no factory could be found associated with that extension. */ - protected abstract IRepository factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException; + protected abstract IRepository<T> factoryLoad(URI location, IExtension extension, int flags, SubMonitor monitor) throws ProvisionException; private void fail(URI location, int code) throws ProvisionException { String msg = null; @@ -408,7 +414,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P protected String[] getAllSuffixes() { IConfigurationElement[] elements = RegistryFactory.getRegistry().getConfigurationElementsFor(getRepositoryProviderExtensionPointId()); - ArrayList result = new ArrayList(elements.length); + ArrayList<String> result = new ArrayList<String>(elements.length); result.add(getDefaultSuffix()); for (int i = 0; i < elements.length; i++) { if (elements[i].getName().equals(EL_FILTER)) { @@ -417,7 +423,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P result.add(suffix); } } - return (String[]) result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } /** @@ -452,25 +458,27 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - ArrayList result = new ArrayList(); - int i = 0; - for (Iterator it = repositories.values().iterator(); it.hasNext(); i++) { - RepositoryInfo info = (RepositoryInfo) it.next(); + ArrayList<URI> result = new ArrayList<URI>(); + for (RepositoryInfo<T> info : repositories.values()) { if (matchesFlags(info, flags)) result.add(info.location); } - return (URI[]) result.toArray(new URI[result.size()]); + return result.toArray(new URI[result.size()]); } } /** * Return the preference node which is the root for where we store the repository information. + * Returns <code>null</code> if no preferences are available */ Preferences getPreferences() { + if (agentLocation == null) + return null; IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(Activator.getContext(), IPreferencesService.class.getName()); - try { - return prefService.getRootNode().node("/profile/_SELF_/" + getBundleId() + "/" + NODE_REPOSITORIES); //$NON-NLS-1$ //$NON-NLS-2$ + //see ProfileScope for preference path format + String locationString = EncodingUtils.encodeSlashes(agentLocation.getRootLocation().toString()); + return prefService.getRootNode().node("/profile/" + locationString + "/_SELF_/" + getBundleId() + '/' + NODE_REPOSITORIES); //$NON-NLS-1$ //$NON-NLS-2$ } catch (IllegalArgumentException e) { return null; } @@ -517,7 +525,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info == null) return null;// Repository not found if (IRepository.PROP_DESCRIPTION.equals(key)) @@ -541,7 +549,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info == null) return;// Repository not found if (IRepository.PROP_DESCRIPTION.equals(key)) @@ -580,7 +588,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info != null) return info.isEnabled; // Repository not found, return false @@ -588,12 +596,12 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } } - protected IRepository loadRepository(URI location, IProgressMonitor monitor, String type, int flags) throws ProvisionException { + protected IRepository<T> loadRepository(URI location, IProgressMonitor monitor, String type, int flags) throws ProvisionException { checkValidLocation(location); if (monitor == null) monitor = new NullProgressMonitor(); boolean added = false; - IRepository result = null; + IRepository<T> result = null; try { enterLoad(location, monitor); @@ -658,13 +666,13 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return location; } - private IRepository loadRepository(URI location, String suffix, String type, int flags, SubMonitor monitor) throws ProvisionException { + private IRepository<T> loadRepository(URI location, String suffix, String type, int flags, SubMonitor monitor) throws ProvisionException { IExtension[] providers = findMatchingRepositoryExtensions(suffix, type); // Loop over the candidates and return the first one that successfully loads monitor.beginTask("", providers.length * 10); //$NON-NLS-1$ for (int i = 0; i < providers.length; i++) try { - IRepository repo = factoryLoad(location, providers[i], flags, monitor); + IRepository<T> repo = factoryLoad(location, providers[i], flags, monitor); if (repo != null) return repo; } catch (ProvisionException e) { @@ -687,7 +695,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P LogHelper.log(new Status(IStatus.ERROR, getBundleId(), message, t)); } - private boolean matchesFlags(RepositoryInfo info, int flags) { + private boolean matchesFlags(RepositoryInfo<T> info, int flags) { if ((flags & REPOSITORIES_SYSTEM) == REPOSITORIES_SYSTEM) if (!info.isSystem) return false; @@ -736,7 +744,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P /* * Add the given repository object to the preferences and save. */ - private void remember(IRepository repository, String suffix) { + private void remember(IRepository<T> repository, String suffix) { boolean changed = false; Preferences node = getPreferences(); // Ensure we retrieved preferences @@ -753,7 +761,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P changed |= putValue(node, KEY_TYPE, repository.getType()); changed |= putValue(node, KEY_VERSION, repository.getVersion()); //allow repository manager to define system property if it is undefined in the repository itself - String value = (String) repository.getProperties().get(IRepository.PROP_SYSTEM); + String value = repository.getProperties().get(IRepository.PROP_SYSTEM); if (value != null) changed |= putValue(node, KEY_SYSTEM, value); changed |= putValue(node, KEY_SUFFIX, suffix); @@ -771,7 +779,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * @param flush <code>true</code> if the preference node should be flushed to * disk, and <code>false</code> otherwise */ - private boolean remember(RepositoryInfo info, boolean flush) { + private boolean remember(RepositoryInfo<T> info, boolean flush) { boolean changed = false; Preferences node = getPreferences(); // Ensure we retrieved preferences @@ -800,17 +808,17 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P * Cache the fact that we tried to load a repository at this location and did not find anything. */ private void rememberNotFound(URI location) { - List badRepos; + List<URI> badRepos; if (unavailableRepositories != null) { - badRepos = (List) unavailableRepositories.get(); + badRepos = unavailableRepositories.get(); if (badRepos != null) { badRepos.add(location); return; } } - badRepos = new ArrayList(); + badRepos = new ArrayList<URI>(); badRepos.add(location); - unavailableRepositories = new SoftReference(badRepos); + unavailableRepositories = new SoftReference<List<URI>>(badRepos); } public boolean removeRepository(URI toRemove) { @@ -835,7 +843,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } Preferences node = getPreferences(); if (node != null) { - getPreferences().node(repoKey).removeNode(); + node.node(repoKey).removeNode(); saveToPreferences(); } clearNotFound(toRemove); @@ -874,7 +882,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P log("Error removing invalid repository", e); //$NON-NLS-1$ } } - RepositoryInfo info = new RepositoryInfo(); + RepositoryInfo<T> info = new RepositoryInfo<T>(); info.location = location; info.name = child.get(KEY_NAME, null); info.nickname = child.get(KEY_NICKNAME, null); @@ -907,7 +915,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P */ private void restoreRepositories() { synchronized (repositoryLock) { - repositories = new HashMap(); + repositories = new HashMap<String, RepositoryInfo<T>>(); restoreSpecialRepositories(); restoreFromSystemProperty(); restoreFromPreferences(); @@ -942,7 +950,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info == null || info.isEnabled == enablement) return; info.isEnabled = enablement; @@ -952,6 +960,22 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P } /** + * Injects the agent service to be used by this repository manager + * @param agent The agent for this repository manager + */ + public void setAgent(IProvisioningAgent agent) { + this.agent = agent; + } + + /** + * Injects the agent location service to be used by this repository manager + * @param location The agent location + */ + public void setAgentLocation(IAgentLocation location) { + this.agentLocation = location; + } + + /** * Injects the event bus service to be used by this repository manager. * @param bus The event bus being added */ @@ -987,8 +1011,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P boolean changed = false; synchronized (repositoryLock) { if (repositories != null) { - for (Iterator it = repositories.values().iterator(); it.hasNext();) { - RepositoryInfo info = (RepositoryInfo) it.next(); + for (RepositoryInfo<T> info : repositories.values()) { changed |= remember(info, false); } } @@ -1010,7 +1033,7 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - RepositoryInfo info = (RepositoryInfo) repositories.get(getKey(location)); + RepositoryInfo<T> info = repositories.get(getKey(location)); if (info == null || info.suffix == null) return suffixes; //move lastSuffix to the front of the list but preserve order of remaining entries @@ -1026,4 +1049,43 @@ public abstract class AbstractRepositoryManager implements IRepositoryManager, P return suffixes; } + /** + * Performs a query against the contents of each known + * repository, accumulating any objects that satisfy the query in the + * provided collector. + * <p> + * Note that using this method can be quite expensive, as every known + * repository will be loaded in order to query each one. If a + * client wishes to query only certain repositories, it is better to use + * {@link #getKnownRepositories(int)} to filter the list of repositories + * loaded and then query each of the returned repositories. + * <p> + * This method is long-running; progress and cancellation are provided + * by the given progress monitor. + * + * @param query The query to perform against each element in each known repository + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return A collector containing the results of the query + */ + public IQueryResult<T> query(IQuery<T> query, IProgressMonitor monitor) { + URI[] locations = getKnownRepositories(REPOSITORIES_ALL); + List<IRepository<T>> queryables = new ArrayList<IRepository<T>>(locations.length); // use a list since we don't know exactly how many will load + SubMonitor sub = SubMonitor.convert(monitor, locations.length * 10); + for (int i = 0; i < locations.length; i++) { + try { + if (sub.isCanceled()) + throw new OperationCanceledException(); + queryables.add(loadRepository(locations[i], sub.newChild(9), null, 0)); + } catch (ProvisionException e) { + //ignore this repository for this query + } + } + try { + CompoundQueryable<T> compoundQueryable = new CompoundQueryable<T>(queryables); + return compoundQueryable.query(query, sub.newChild(locations.length * 1)); + } finally { + sub.done(); + } + } } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/DebugHelper.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/DebugHelper.java index f230f47c5..b2f599bca 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/DebugHelper.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/DebugHelper.java @@ -11,6 +11,7 @@ package org.eclipse.equinox.internal.p2.repository.helpers; import java.util.*; +import java.util.Map.Entry; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.repository.Activator; import org.eclipse.osgi.service.debug.DebugOptions; @@ -49,7 +50,7 @@ public class DebugHelper { if (keyValueArray == null || keyValueArray.length == 0) debug(name, message); else { - Map params = new LinkedHashMap(keyValueArray.length / 2); + Map<Object, Object> params = new LinkedHashMap<Object, Object>(keyValueArray.length / 2); for (int i = 0; i < keyValueArray.length; i += 2) params.put(keyValueArray[i], keyValueArray[i + 1]); StringBuffer buffer = new StringBuffer(); @@ -95,15 +96,13 @@ public class DebugHelper { return buffer.toString(); } - public static String formatMap(Map map, boolean toString, boolean newLines) { + public static String formatMap(Map<?, ?> map, boolean toString, boolean newLines) { if (map == null || map.size() == 0) return "[]"; //$NON-NLS-1$ StringBuffer buffer = new StringBuffer(); buffer.append('['); - Iterator itor = map.entrySet().iterator(); - while (itor.hasNext()) { - Map.Entry e = (Map.Entry) itor.next(); + for (Entry<?, ?> e : map.entrySet()) { buffer.append(e.getKey()); buffer.append('='); if (toString) diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java index 693231562..050693f9e 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java @@ -15,7 +15,7 @@ import java.io.File; import java.net.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.repository.Activator; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.osgi.util.NLS; public class RepositoryHelper { @@ -53,7 +53,7 @@ public class RepositoryHelper { * @param repository the repository to test * @return the repository */ - public static IRepository validDestinationRepository(IRepository repository) { + public static <T> IRepository<T> validDestinationRepository(IRepository<T> repository) { if (!repository.isModifiable()) throw new IllegalStateException(NLS.bind(Messages.DestinationNotModifiable, repository.getLocation())); return repository; diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryCreationException.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryCreationException.java deleted file mode 100644 index 0a6899ad8..000000000 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryCreationException.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.repository; - -public class RepositoryCreationException extends Exception { - - private static final long serialVersionUID = -5648382121963317100L; - - public RepositoryCreationException(Throwable e) { - super(e); - } - -} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java index 1768f9c91..a62905e9d 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java @@ -12,6 +12,7 @@ package org.eclipse.equinox.internal.provisional.p2.repository; import java.net.URI; import java.util.EventObject; +import org.eclipse.equinox.p2.repository.IRepository; /** * An event indicating a repository was added, removed, changed, diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/ICompositeRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/ICompositeRepository.java index c18060524..1bfada5b9 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/ICompositeRepository.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/ICompositeRepository.java @@ -8,17 +8,20 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.repository; +package org.eclipse.equinox.p2.repository; import java.net.URI; import java.util.List; -public interface ICompositeRepository extends IRepository { +/** + * @since 2.0 + */ +public interface ICompositeRepository<T> extends IRepository<T> { /** * * @return a list of URIs containing the locations of the children repositories */ - public abstract List getChildren(); + public abstract List<URI> getChildren(); /** * Removes all child repositories diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/IRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepository.java index c472b66d1..c8d949853 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/IRepository.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepository.java @@ -8,19 +8,21 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.repository; +package org.eclipse.equinox.p2.repository; import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.equinox.p2.query.IQueryable; /** * Base interface that defines common properties that may be provided by * various kinds of repositories. * * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 */ -public interface IRepository extends IAdaptable { +public interface IRepository<T> extends IAdaptable, IQueryable<T> { /** * The key for a boolean property indicating that the repository * is a system repository. System repositories are implementation details @@ -152,7 +154,7 @@ public interface IRepository extends IAdaptable { * Returns a read-only collection of the properties of the repository. * @return the properties of this repository. */ - public Map getProperties(); + public Map<String, String> getProperties(); /** * Returns <code>true</code> if this repository can be modified. diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/IRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java index 6506ded9e..6c0800393 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/IRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/IRepositoryManager.java @@ -8,9 +8,12 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.p2.repository; +package org.eclipse.equinox.p2.repository; + +import org.eclipse.equinox.p2.query.IQueryable; import java.net.URI; +import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent; /** * The common base class for metadata and artifact repository managers. @@ -25,8 +28,9 @@ import java.net.URI; * </p> * * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 */ -public interface IRepositoryManager { +public interface IRepositoryManager<T> extends IQueryable<T> { /** * Constant used to indicate that all enabled repositories are of interest. */ @@ -67,7 +71,9 @@ public interface IRepositoryManager { /** * Adds the repository at the given location to the list of repositories tracked by - * this repository manager. + * this repository manager. This method does not attempt to contact or load + * the repository, and makes no attempt to determine whether there is a valid + * repository at the provided location. * <p> * If there is a known disabled repository at the given location, it will become * enabled as a result of this method. Thus the caller can be guaranteed that diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactDescriptorQuery.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactDescriptorQuery.java new file mode 100644 index 000000000..1347b8ff0 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactDescriptorQuery.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.p2.repository.artifact; + +import org.eclipse.equinox.p2.metadata.VersionRange; + +import org.eclipse.equinox.p2.query.MatchQuery; +import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor; + +/** + * An implementation of IArtifactQuery that matches IArtifactDescriptors + * @since 2.0 + */ +public class ArtifactDescriptorQuery extends MatchQuery<IArtifactDescriptor> { + public static final ArtifactDescriptorQuery ALL_DESCRIPTORS = new ArtifactDescriptorQuery(); + private VersionRange range = null; + private String id = null; + private String format = null; + private ArtifactDescriptor descriptor = null; + private IArtifactRepository repository = null; + + /** + * The query will match descriptors with the given id, version and format + * If any parameter is null, that attribute will be ignored + * @param id - the id to match, or null + * @param versionRange - the version range to match or null + * @param format - {@link IArtifactDescriptor#FORMAT} value to match, or null + */ + public ArtifactDescriptorQuery(String id, VersionRange versionRange, String format) { + this(id, versionRange, format, null); + } + + /** + * The query will match descriptors with the given id, version range, format and repository + * if any parameter is null, that attribute will be ignored + * @param id - the id to match, or null + * @param versionRange - the version range to match or null + * @param format - {@link IArtifactDescriptor#FORMAT} value to match, or null + * @param repository + */ + public ArtifactDescriptorQuery(String id, VersionRange versionRange, String format, IArtifactRepository repository) { + this.id = id; + this.range = versionRange; + this.format = format; + this.repository = repository; + } + + public ArtifactDescriptorQuery() { + //matches everything + } + + /** + * The query will match candidate descriptors where + * new ArtifactDescriptor(descriptor).equals(new ArtifactDescriptor(candidate)) + * @param descriptor + */ + public ArtifactDescriptorQuery(IArtifactDescriptor descriptor) { + this.descriptor = (descriptor.getClass() == ArtifactDescriptor.class) ? (ArtifactDescriptor) descriptor : new ArtifactDescriptor(descriptor); + } + + public boolean isMatch(IArtifactDescriptor candidate) { + if (descriptor != null) + return matchDescriptor(candidate); + + if (id != null && !id.equals(candidate.getArtifactKey().getId())) + return false; + + if (range != null && !range.isIncluded(candidate.getArtifactKey().getVersion())) + return false; + + if (format != null && !format.equals(candidate.getProperty(IArtifactDescriptor.FORMAT))) + return false; + + if (repository != null && repository != candidate.getRepository()) + return false; + + return true; + } + + protected boolean matchDescriptor(IArtifactDescriptor candidate) { + ArtifactDescriptor candidateDescriptor = (candidate.getClass() == ArtifactDescriptor.class) ? (ArtifactDescriptor) candidate : new ArtifactDescriptor(candidate); + return descriptor.equals(candidateDescriptor); + } + + public Boolean getExcludeArtifactDescriptors() { + return Boolean.FALSE; + } + + public Boolean getExcludeArtifactKeys() { + return Boolean.TRUE; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactKeyQuery.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactKeyQuery.java new file mode 100644 index 000000000..0d48ccabf --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/ArtifactKeyQuery.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.equinox.p2.repository.artifact; + +import org.eclipse.equinox.p2.metadata.VersionRange; + +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.MatchQuery; + +/** + * An IArtifactQuery returning matching IArtifactKey objects. + * @since 2.0 + */ +public class ArtifactKeyQuery extends MatchQuery<IArtifactKey> { + public static final ArtifactKeyQuery ALL_KEYS = new ArtifactKeyQuery(); + + private String id; + private String classifier; + private VersionRange range; + private IArtifactKey artifactKey; + + /** + * Pass the id and/or version range to match IArtifactKeys against. + * Passing null results in matching any id/version + * @param classifier The artifact key classifier, or <code>null</code> + * @param id The artifact key id, or <code>null</code> + * @param range A version range, or <code>null</code> + */ + public ArtifactKeyQuery(String classifier, String id, VersionRange range) { + this.id = id; + this.classifier = classifier; + this.range = range; + } + + public ArtifactKeyQuery() { + //matches everything + } + + public ArtifactKeyQuery(IArtifactKey key) { + this.artifactKey = key; + } + + public boolean isMatch(IArtifactKey key) { + if (artifactKey != null) + return matchKey(key); + + if (classifier != null && !key.getClassifier().equals(classifier)) + return false; + + if (id != null && !key.getId().equals(id)) + return false; + + if (range != null && !range.isIncluded(key.getVersion())) + return false; + + return true; + } + + protected boolean matchKey(IArtifactKey candidate) { + return artifactKey.equals(candidate); + } + + // We are interested in IArtifactKey objects + public Boolean getExcludeArtifactKeys() { + return Boolean.FALSE; + } + + // We are not interested in IArtifactDescriptor objects + public Boolean getExcludeArtifactDescriptors() { + return Boolean.TRUE; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactDescriptor.java new file mode 100644 index 000000000..4d64628d3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactDescriptor.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact; + +import java.util.Map; +import org.eclipse.equinox.p2.metadata.IArtifactKey; + +/** + * An artifact descriptor describes an artifact stored in some artifact repository. The + * descriptor defines the artifact it contains, as well as any processing steps that + * must be performed when the artifact is transferred out of the repository (such + * as decompression, error checking, etc). + * + * @since 2.0 + */ +public interface IArtifactDescriptor { + + /** + * An artifact descriptor property (value "download.size") indicating the number + * of bytes that will be transferred when this artifact is transferred out of the repository. + */ + public static final String DOWNLOAD_SIZE = "download.size"; //$NON-NLS-1$ + /** + * An artifact descriptor property (value "artifact.size") indicating the size in + * bytes of the artifact in its native format (after processing steps have been applied). + */ + public static final String ARTIFACT_SIZE = "artifact.size"; //$NON-NLS-1$ + /** + * An artifact descriptor property (value "download.md5") indicating the MD5 + * checksum of the artifact bytes that are transferred. + */ + public static final String DOWNLOAD_MD5 = "download.md5"; //$NON-NLS-1$ + /** + * An artifact descriptor property (value "download.contentType") indicating the + * content type of the artifact bytes that are transferred. + */ + public static final String DOWNLOAD_CONTENTTYPE = "download.contentType"; //$NON-NLS-1$ + /** + * An content type (value "application/zip") indicating the content is a zip file. + */ + public static final String TYPE_ZIP = "application/zip"; //$NON-NLS-1$ + /** + * An artifact descriptor property (value "artifact.md5") indicating the MD5 + * checksum of the artifact bytes in its native format (after processing steps have + * been applied). + */ + public static final String ARTIFACT_MD5 = "artifact.md5"; //$NON-NLS-1$ + + /** + * An artifact descriptor property (value "format") indicating the storage format + * of the artifact in the repository. + * @see #FORMAT_PACKED + */ + public static final String FORMAT = "format"; //$NON-NLS-1$ + + /** + * A property value for the {@link #FORMAT} artifact descriptor property (value "packed") + * indicating the storage format is using pack200 compression. + * @see #FORMAT + */ + public static final String FORMAT_PACKED = "packed"; //$NON-NLS-1$ + + /** + * Return the key for the artifact described by this descriptor. + * @return the key associated with this descriptor + */ + public abstract IArtifactKey getArtifactKey(); + + /** + * Return the value of the given property in this descriptor <code>null</code> + * is returned if no such property exists + * @param key the property key to look for + * @return the value of the given property or <code>null</code> + */ + public abstract String getProperty(String key); + + /** + * Returns a read-only collection of the properties of the artifact descriptor. + * @return the properties of this artifact descriptor. + */ + public Map<String, String> getProperties(); + + /** + * Return the list of processing steps associated with this descriptor. + * An empty set of steps implies that this descriptor describes a complete + * copy of the artifact in its native form. If one or more steps are present, + * they may be performed when the artifact is transferred from the repository + * that contains it. + * + * @return the list of processing steps for this descriptor + */ + public abstract IProcessingStepDescriptor[] getProcessingSteps(); + + /** + * Return the artifact repository that holds the artifact described by this descriptor. + * <code>null</code> is returned if this descriptor is not held in a repository. + * + * @return the repository holding this artifact or <code>null</code> if none. + */ + public abstract IArtifactRepository getRepository(); +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepository.java new file mode 100644 index 000000000..fd442f9c1 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepository.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact; + +import java.io.OutputStream; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.query.IQueryable; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.artifact.spi.AbstractArtifactRepository; + +/** + * A repository containing artifacts. + * <p> + * This interface is not intended to be implemented by clients. Artifact repository + * implementations must subclass {@link AbstractArtifactRepository} rather than + * implementing this interface directly. + * </p> + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IArtifactRepository extends IRepository<IArtifactKey> { + + /** + * The return code to use when a client could/should retry a failed getArtifact() operation. + * For example, the repository may have additional mirrors that could be consulted. + */ + public static int CODE_RETRY = 13; + + /** + * Create an instance of IArtifactDescriptor based on the given key + * @param key + * @return a new instanceof of IArtifactDescriptor + */ + public IArtifactDescriptor createArtifactDescriptor(IArtifactKey key); + + /** + * Add the given descriptor to the set of descriptors in this repository. This is + * a relatively low-level operation that should be used only when the actual related + * content is in this repository and the given descriptor accurately describes + * that content. + * @param descriptor the descriptor to add. + */ + public void addDescriptor(IArtifactDescriptor descriptor); + + /** + * Add the given artifact descriptors to this repository + * @param descriptors the artifact descriptors to add + */ + public void addDescriptors(IArtifactDescriptor[] descriptors); + + /** + * Returns true if this repository contains the given descriptor. + * @param descriptor the descriptor to query + * @return true if the given descriptor is already in this repository + */ + public boolean contains(IArtifactDescriptor descriptor); + + /** + * Returns true if this repository contains the given artifact key. + * @param key the key to query + * @return true if the given key is already in this repository + */ + public boolean contains(IArtifactKey key); + + /** + * Write to the given output stream the bytes represented by the artifact descriptor processed by the processing steps of the given descriptor. + */ + public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); + + /** + * Write to the given output stream the bytes represented by the artifact descriptor without processing by the steps of the given descriptor. + */ + public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); + + /** + * Return the set of artifact descriptors describing the ways that this repository + * can supply the artifact associated with the given artifact key + * @param key the artifact key to lookup + * @return the descriptors associated with the given key + */ + public IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key); + + /** + * Executes the given artifact requests on this byte server. + * @param requests The artifact requests + * @param monitor + * @return a status object that is <code>OK</code> if requests were + * processed successfully. Otherwise, a status indicating information, + * warnings, or errors that occurred while executing the artifact requests + */ + public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor); + + /** + * Open an output stream to which a client can write the data for the given + * artifact descriptor. + * @param descriptor the descriptor describing the artifact data to be written to the + * resultant stream + * @return the stream to which the artifact content can be written. The returned output + * stream may implement <code>IStateful</code>. + * @throws ProvisionException if the output stream could not be created. Reasons include: + * <ul> + * <li>An I/O exception occurred (@link {@link ProvisionException#REPOSITORY_FAILED_WRITE}) .</li> + * <li>An artifact already exists at that location ({@link ProvisionException#ARTIFACT_EXISTS}).</li> + * </ul> + */ + public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException; + + /** + * Returns a queryable that can be queried for artifact descriptors contained in this repository + * @return The queryable of artifact descriptors + */ + public IQueryable<IArtifactDescriptor> descriptorQueryable(); + + /** + * Remove the all keys, descriptors, and contents from this repository. + */ + public void removeAll(); + + /** + * Remove the given descriptor and its corresponding content in this repository. + * @param descriptor the descriptor to remove. + */ + public void removeDescriptor(IArtifactDescriptor descriptor); + + /** + * Remove the given key and all related content and descriptors from this repository. + * @param key the key to remove. + */ + public void removeDescriptor(IArtifactKey key); + +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java new file mode 100644 index 000000000..c86defc10 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRepositoryManager.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.IRepositoryManager; + +/** + * A metadata repository manager is used to create, access, and manipulate + * {@link IArtifactRepository} instances. See {@link IRepositoryManager} + * for a general description of the characteristics of repository managers. + * + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IArtifactRepositoryManager extends IRepositoryManager<IArtifactKey> { + /** + * The name used for obtaining a reference to the metadata repository manager service + */ + public static final String SERVICE_NAME = IArtifactRepositoryManager.class.getName(); + + public static final IArtifactRequest[] NO_ARTIFACT_REQUEST = new IArtifactRequest[0]; + + /** + * Repository type for a simple repository based on a URL or local file system location. + */ + public static final String TYPE_SIMPLE_REPOSITORY = "org.eclipse.equinox.p2.artifact.repository.simpleRepository"; //$NON-NLS-1$ + public static final String TYPE_COMPOSITE_REPOSITORY = "org.eclipse.equinox.p2.artifact.repository.compositeRepository"; //$NON-NLS-1$ + + /** + * Return a new request to mirror the given artifact into the destination repository. + * @param key the artifact to mirror + * @param destination the destination where the artifact will be mirrored + * @param destinationDescriptorProperties additional properties for use in creating the repository's ArtifactDescriptor, + * or <code>null</code> to indicate no additional properties are needed + * @param destinationRepositoryProperties additional repository specific properties for use in creating the repositor's ArtifactDescriptor, + * , or <code>null</code> to indicate no additional properties are needed + * @return the newly created request object + */ + public IArtifactRequest createMirrorRequest(IArtifactKey key, IArtifactRepository destination, Map<String, String> destinationDescriptorProperties, Map<String, String> destinationRepositoryProperties); + + /** + * Creates and returns a new empty artifact repository of the given type at + * the given location. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * + * @param location the absolute location for the new repository + * @param name the name of the new repository + * @param type the kind of repository to create + * @param properties the properties to set on the repository + * @return the newly created repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>The repository type is unknown.</li> + * <li>There was an error writing to the given repository location.</li> + * <li>A repository already exists at that location.</li> + * </ul> + */ + public IArtifactRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException; + + /** + * Loads the repository at the given location. The location is expected to contain + * data that describes a valid artifact repository of a known type. If this manager + * already knows a repository at the given location then that repository is returned. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * + * @param location the absolute location in which to look for a repository description + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return a repository object for the given location + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public IArtifactRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + + /** + * Loads the repository at the given location. The location is expected to contain + * data that describes a valid artifact repository of a known type. If this manager + * already knows a repository at the given location then that repository is returned. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * <p> + * The flags passed in should be taken as a hint for the type of repository to load. If + * the manager cannot load a repository that satisfies these hints, it can fail fast. + * </p> + * @param location the absolute location in which to look for a repository description + * @param flags - bit-wise or of flags to consider when loading the repository + * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return a repository object for the given location + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE + */ + public IArtifactRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + + /** + * Refreshes the repository corresponding to the given URL. This method discards + * any cached state held by the repository manager and reloads the repository + * contents. The provided repository location must already be known to the repository + * manager. + * + * @param location The absolute location of the repository to refresh + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return The refreshed metadata repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>The location is not known to the repository manager.</li> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public IArtifactRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRequest.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRequest.java new file mode 100644 index 000000000..bced2464c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IArtifactRequest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.p2.repository.artifact; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.metadata.IArtifactKey; + +/** + * Represents a request to transfer an artifact from an artifact repository. When the + * request is executed against a repository, it will be executed and the result + * of the execution will become available. + * + * @see IArtifactRepositoryManager#createMirrorRequest(IArtifactKey, IArtifactRepository, java.util.Map, java.util.Map) + * @see IArtifactRepository#getArtifacts(IArtifactRequest[], IProgressMonitor) + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IArtifactRequest { + + /** + * Returns the key for the artifact that is being requested + * + * @return The requested artifact key + */ + public IArtifactKey getArtifactKey(); + + /** + * Returns the result of the executed artifact request, or <code>null</code> if + * the request has never been executed. Artifact requests are executed by invoking + * {@link IArtifactRepository#getArtifacts(IArtifactRequest[], IProgressMonitor)}. + * + * @return The result of the previous perform call, or <code>null</code> + */ + public IStatus getResult(); +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IFileArtifactRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IFileArtifactRepository.java new file mode 100644 index 000000000..78a7701d3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IFileArtifactRepository.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact; + +import java.io.File; +import org.eclipse.equinox.p2.metadata.IArtifactKey; + +/** + * @since 2.0 + */ +public interface IFileArtifactRepository extends IArtifactRepository { + /** + * Return the location of the full local file corresponding to the given + * artifact key to the given key, or <code>null</code> if not available. + * + * @return the location of the requested artifact or<code>null</code> if not available + */ + public File getArtifactFile(IArtifactKey key); + + /** + * Return the location of the local file corresponding to the given + * artifact descriptor, or <code>null</code> if not available. + * + * @return the location of the requested descriptor or<code>null</code> if not available + */ + public File getArtifactFile(IArtifactDescriptor descriptor); +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IProcessingStepDescriptor.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IProcessingStepDescriptor.java new file mode 100644 index 000000000..5b45e0279 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/IProcessingStepDescriptor.java @@ -0,0 +1,45 @@ +/******************************************************************************* +* Copyright (c) 2010 EclipseSource 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: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact; + +/** + * Describes a processing step. Processing steps are pieces of code that participate + * in the the transfer of an artifact between artifact repositories. A step may alter + * the shape of the artifact from its storage format in the repository (such as performing + * compression), or it may perform additional checks on the transferred bytes such as + * checksums or signature verification. + * + * @see IArtifactDescriptor#getProcessingSteps() + * @since 2.0 + */ +public interface IProcessingStepDescriptor { + + /** + * Returns the fully qualified id of the processing step extension. + * + * @return The fully qualified processing step extension id + */ + public abstract String getProcessorId(); + + public abstract String getData(); + + /** + * Returns whether the successful execution of this processing step is + * required for the transfer to be successful. If the processing step extension + * is not installed, or fails to execute, then the artifact transfer will fail if the + * step is required. Failure of optional steps will result in warnings but not prevent + * the transfer from succeeding. + * + * @return <code>true</code> if the transfer will fail if this step does not succeed, + * and <code>false</code> otherwise + */ + public abstract boolean isRequired(); + +}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/AbstractArtifactRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/AbstractArtifactRepository.java new file mode 100644 index 000000000..fd7bddb67 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/AbstractArtifactRepository.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact.spi; + +import org.eclipse.equinox.p2.repository.spi.AbstractRepository; + +import java.io.OutputStream; +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.metadata.IArtifactKey; +import org.eclipse.equinox.p2.repository.artifact.*; + +/** + * The common base class for all artifact repository implementations. Clients must + * subclass this class to create their own repository implementations. + * <p> + * This base class provides default implementations of all methods that modify the repository. + * These default methods throw an exception if {@link #isModifiable()} returns <code>false</code>. + * Therefore a client can implement a read-only repository by overriding only the abstract methods. + * @since 2.0 + */ +public abstract class AbstractArtifactRepository extends AbstractRepository<IArtifactKey> implements IArtifactRepository { + + protected AbstractArtifactRepository(String name, String type, String version, URI location, String description, String provider, Map<String, String> properties) { + super(name, type, version, location, description, provider, properties); + } + + public abstract boolean contains(IArtifactDescriptor descriptor); + + public abstract boolean contains(IArtifactKey key); + + public abstract IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor); + + public abstract IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key); + + public abstract IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor); + + public abstract OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException; + + public void addDescriptor(IArtifactDescriptor descriptor) { + assertModifiable(); + } + + public void addDescriptors(IArtifactDescriptor[] descriptors) { + assertModifiable(); + } + + public void removeDescriptor(IArtifactDescriptor descriptor) { + assertModifiable(); + } + + public void removeDescriptor(IArtifactKey key) { + assertModifiable(); + } + + public void removeAll() { + assertModifiable(); + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof AbstractArtifactRepository)) { + return false; + } + if (URIUtil.sameURI(getLocation(), ((AbstractArtifactRepository) o).getLocation())) + return true; + return false; + } + + public int hashCode() { + return (this.getLocation().toString().hashCode()) * 87; + } + + public IArtifactDescriptor createArtifactDescriptor(IArtifactKey key) { + return new ArtifactDescriptor(key); + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactDescriptor.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactDescriptor.java new file mode 100644 index 000000000..8f82ba1a0 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactDescriptor.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact.spi; + +import java.util.Arrays; +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.*; + +/** + * This represents information about a given artifact stored on a particular byte server. + * @since 2.0 + */ +public class ArtifactDescriptor implements IArtifactDescriptor { + private static final IProcessingStepDescriptor[] EMPTY_STEPS = new ProcessingStepDescriptor[0]; + + protected IArtifactKey key; // The key associated with this artifact + + // The list of post processing steps that must be applied one the artifact once it + // has been downloaded (e.g, unpack, then md5 checksum, then...) + protected IProcessingStepDescriptor[] processingSteps = EMPTY_STEPS; + + protected Map<String, String> properties = new OrderedProperties(); + protected transient IArtifactRepository repository; + + public ArtifactDescriptor(IArtifactDescriptor base) { + super(); + key = base.getArtifactKey(); + processingSteps = base.getProcessingSteps(); + properties.putAll(base.getProperties()); + repository = base.getRepository(); + } + + public ArtifactDescriptor(ArtifactDescriptor base) { + super(); + key = base.key; + processingSteps = base.processingSteps; + properties.putAll(base.properties); + repository = base.repository; + } + + public ArtifactDescriptor(IArtifactKey key) { + super(); + this.key = key; + } + + public IArtifactKey getArtifactKey() { + return key; + } + + public String getProperty(String propertyKey) { + return properties.get(propertyKey); + } + + public void setProperty(String key, String value) { + if (value == null) + properties.remove(key); + else + properties.put(key, value); + } + + public void addProperties(Map<String, String> additionalProperties) { + properties.putAll(additionalProperties); + } + + /** + * Returns a read-only collection of the properties of the artifact descriptor. + * @return the properties of this artifact descriptor. + */ + public Map<String, String> getProperties() { + return OrderedProperties.unmodifiableProperties(properties); + } + + public IProcessingStepDescriptor[] getProcessingSteps() { + return processingSteps; + } + + public void setProcessingSteps(IProcessingStepDescriptor[] value) { + processingSteps = value == null ? EMPTY_STEPS : value; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + // Other implementations of IArtifactDescriptor must not be considered equal + if (!(obj.getClass().equals(getClass()))) + return false; + + ArtifactDescriptor other = (ArtifactDescriptor) obj; + if (key == null) { + if (other.getArtifactKey() != null) + return false; + } else if (!key.equals(other.getArtifactKey())) + return false; + + if (!Arrays.equals(processingSteps, other.getProcessingSteps())) + return false; + + String format = getProperty(FORMAT); + String otherFormat = other.getProperty(FORMAT); + if (format != null ? !format.equals(otherFormat) : otherFormat != null) + return false; + + return true; + } + + public int hashCode() { + String format = getProperty(FORMAT); + + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + Arrays.asList(processingSteps).hashCode(); + result = prime * result + (format != null ? format.hashCode() : 0); + return result; + } + + public IArtifactRepository getRepository() { + return repository; + } + + public void setRepository(IArtifactRepository value) { + repository = value; + } + + public String toString() { + String format = getProperty(IArtifactDescriptor.FORMAT); + if (format == null) + return "canonical: " + key.toString(); //$NON-NLS-1$ + return format + ": " + key.toString(); //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactRepositoryFactory.java new file mode 100644 index 000000000..ead8d661c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ArtifactRepositoryFactory.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact.spi; + +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; + +/** + * An artifact repository factory is responsible for creating and loading instances + * of a particular type of artifact repository. Factories are provided via the + * <tt>org.eclipse.equinox.p2.artifact.repository.artifactRepositories</tt> extension point. + * @since 2.0 + */ +public abstract class ArtifactRepositoryFactory { + + private IProvisioningAgent agent; + + /** + * Creates and returns a new empty artifact repository of the given type at + * the given location. + * + * @param location the location for the new repository + * @param name the name of the new repository + * @param type the kind of repository to create + * @param properties the properties to set on the repository + * @return the newly created repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>The repository type is unknown.</li> + * <li>There was an error writing to the given repository location.</li> + * <li>A repository already exists at that location.</li> + * </ul> + */ + public abstract IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException; + + /** + * Returns the provisioning agent associated with this factory, or <code>null</code> + * if this factory is not associated with an agent. + * @return The provisioning agent, or <code>null</code> + */ + protected IProvisioningAgent getAgent() { + return agent; + } + + /** + * Loads and returns the repository of this factory's type at the given location. + * <p> + * The error code returned in the case of failure is significant. In particular an + * error code of {@link ProvisionException#REPOSITORY_FAILED_READ} indicates + * that the location definitely identifies a repository of this type, but an error occurred + * while loading the repository. The repository manager will not attempt to load + * a repository from that location using any other factory. An error code of + * {@link ProvisionException#REPOSITORY_NOT_FOUND} indicates there is no + * repository of this type at the given location, and the repository manager is free + * to try again with a different repository factory. + * </p> + * <p> + * The flags passed in should be taken as a hint for the type of repository to load. If + * the factory knows it will not load a repository that satisfies these hints, it can fail + * fast and return null. + * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE + * </p> + * @param location the location in which to look for a repository description + * @param flags to consider while loading the repository + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return a repository object for the given location + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public abstract IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + + /** + * Sets the provisioning agent associated with this repository factory. This method + * is called by the provisioning agent to provide access to the agent instance. This + * method is not intended to be called by clients. + * + * @param agent The provisioning agent + */ + public void setAgent(IProvisioningAgent agent) { + this.agent = agent; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ProcessingStepDescriptor.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ProcessingStepDescriptor.java new file mode 100644 index 000000000..95261f4ce --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/artifact/spi/ProcessingStepDescriptor.java @@ -0,0 +1,103 @@ +/******************************************************************************* +* Copyright (c) 2007, 2009 compeople AG 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: +* compeople AG (Stefan Liebig) - initial API and implementation +*******************************************************************************/ +package org.eclipse.equinox.p2.repository.artifact.spi; + +import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor; + +/** + * @since 2.0 + */ +public class ProcessingStepDescriptor implements IProcessingStepDescriptor { + + private final String processorId; //the operation to be applied (e.g: unpack, md5, signature verification, etc.) + private final String data; //data requested for the processing (eg. expected checksum) + private final boolean required; //whether the step is optional or not + + /** + * Create a processing step description. + * + * @param processorId + * @param data + * @param required + */ + public ProcessingStepDescriptor(String processorId, String data, boolean required) { + super(); + this.processorId = processorId; + this.data = data; + this.required = required; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor#getProcessorId() + */ + public String getProcessorId() { + return processorId; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor#getData() + */ + public String getData() { + return data; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor#isRequired() + */ + public boolean isRequired() { + return required; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((data == null) ? 0 : data.hashCode()); + result = prime * result + ((processorId == null) ? 0 : processorId.hashCode()); + result = prime * result + (required ? 1231 : 1237); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof IProcessingStepDescriptor)) + return false; + final IProcessingStepDescriptor other = (IProcessingStepDescriptor) obj; + if (data == null) { + if (other.getData() != null) + return false; + } else if (!data.equals(other.getData())) + return false; + if (processorId == null) { + if (other.getProcessorId() != null) + return false; + } else if (!processorId.equals(other.getProcessorId())) + return false; + if (required != other.isRequired()) + return false; + return true; + } + + /** + * Returns a string representation of this descriptor for debugging purposes only. + */ + public String toString() { + return "Processor: " + processorId + (required ? "(req)" : "(notReq)") + " ,data: " + data; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java new file mode 100644 index 000000000..88be97f9d --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * 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.p2.repository.metadata; + +import java.net.URI; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository; + +/** + * A metadata repository stores information about a set of installable units + * <p> + * This interface is not intended to be implemented by clients. Metadata repository + * implementations must subclass {@link AbstractMetadataRepository} rather than + * implementing this interface directly. + * </p> + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IMetadataRepository extends IRepository<IInstallableUnit> { + + /** + * Add the given installable units to this repository + * @param installableUnits the installable units to add + */ + public void addInstallableUnits(IInstallableUnit[] installableUnits); + + /** + * Adds a reference to another repository to this repository. When a repository + * is loaded by {@link IMetadataRepositoryManager}, its references + * are automatically added to the repository manager's set of known repositories. + * <p> + * Note that this method does not add the <b>contents</b> of the given + * repository to this repository, but merely adds the location of another + * repository to the metadata of this repository. + * <p> + * The {@link IRepository#ENABLED} option flag controls whether the + * referenced repository should be marked as enabled when added to the repository + * manager. If this flag is set, the repository will be marked as enabled when + * added to the repository manager. If this flag is missing, the repository will + * be marked as disabled. + * + * @param location the location of the repository to add + * @param nickname The nickname of the repository, or <code>null</code> + * @param type the repository type (currently either {@link IRepository#TYPE_METADATA} + * or {@link IRepository#TYPE_ARTIFACT}). + * @param options bit-wise or of option constants (currently either + * {@link IRepository#ENABLED} or {@link IRepository#NONE}). + * @see IMetadataRepositoryManager#setEnabled(URI, boolean) + */ + public void addReference(URI location, String nickname, int type, int options); + + /** + * Removes all installable units that match the given query from this repository. + * + * @param installableUnits the installable units to remove + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return <code>true</code> if any units were actually removed, and + * <code>false</code> otherwise + */ + public boolean removeInstallableUnits(IInstallableUnit[] installableUnits, IProgressMonitor monitor); + + /** + * Remove all installable units from this repository. + */ + public void removeAll(); + +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java new file mode 100644 index 000000000..8862e6161 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepositoryManager.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.metadata; + +import org.eclipse.equinox.p2.core.ProvisionException; + +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.IRepositoryManager; + +/** + * A metadata repository manager is used to create, access, and manipulate + * {@link IMetadataRepository} instances. See {@link IRepositoryManager} + * for a general description of the characteristics of repository managers. + * + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IMetadataRepositoryManager extends IRepositoryManager<IInstallableUnit> { + /** + * The name used for obtaining a reference to the metadata repository manager service + */ + public static final String SERVICE_NAME = IMetadataRepositoryManager.class.getName(); + + /** + * Repository type for a simple repository based on a URL or local file system location. + */ + public static final String TYPE_SIMPLE_REPOSITORY = "org.eclipse.equinox.p2.metadata.repository.simpleRepository"; //$NON-NLS-1$ + public static final String TYPE_COMPOSITE_REPOSITORY = "org.eclipse.equinox.p2.metadata.repository.compositeRepository"; //$NON-NLS-1$ + + /** + * Creates and returns a new empty metadata repository of the given type at + * the given location. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * + * @param location the absolute location for the new repository + * @param name the name of the new repository + * @param type the kind of repository to create + * @param properties the properties to set on the repository + * @return the newly created repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>The repository type is unknown.</li> + * <li>There was an error writing to the given repository location.</li> + * <li>A repository already exists at that location.</li> + * </ul> + */ + public IMetadataRepository createRepository(URI location, String name, String type, Map<String, String> properties) throws ProvisionException; + + /** + * Loads a repository corresponding to the given URL. If a repository has + * previously been loaded at the given location, the same cached repository + * may be returned. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * + * @param location The absolute location of the repository to load + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return The loaded metadata repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + + /** + * Loads a repository corresponding to the given URL. If a repository has + * previously been loaded at the given location, the same cached repository + * may be returned. + * <p> + * The resulting repository is added to the list of repositories tracked by + * the repository manager. Clients must make a subsequent call to {@link #removeRepository(URI)} + * if they do not want the repository manager to remember the repository for subsequent + * load attempts. + * </p> + * <p> + * The flags passed in should be taken as a hint for the type of repository to load. If + * the manager cannot load a repository that satisfies these hints, it can fail fast. + * </p> + * @param location The absolute location of the repository to load + * @param flags - bit-wise or of flags to consider when loading the repository + * (currently only {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} is supported) + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return The loaded metadata repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + * @see IRepositoryManager#REPOSITORY_HINT_MODIFIABLE + */ + public IMetadataRepository loadRepository(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + + /** + * Refreshes the repository corresponding to the given URL. This method discards + * any cached state held by the repository manager and reloads the repository + * contents. The provided repository location must already be known to the repository + * manager. + * + * @param location The absolute location of the repository to refresh + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return The refreshed metadata repository + * @throws ProvisionException if the repository could not be refreshed. Reasons include: + * <ul> + * <li>The location is not known to the repository manager.</li> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public IMetadataRepository refreshRepository(URI location, IProgressMonitor monitor) throws ProvisionException; + + /** + * Validates a given URL and returns a status indicating whether a valid repository is likely + * to be found at the given URL. Callers must assume that the validity of a + * repository location cannot be completely determined until an attempt to load + * the repository is made. + * + * @param location The absolute location of the repository to validate + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return A status indicating whether a valid repository is likely located at the + * location. A status with severity <code>OK</code> indicates that the repository is + * likely to be loadable, or that as much validation as could be done was successful. + * Reasons for a non-OK status include: + * <ul> + * <li>The specified location is not a valid repository location.</li> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public IStatus validateRepositoryLocation(URI location, IProgressMonitor monitor); +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java new file mode 100644 index 000000000..e130ed70a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.metadata.spi; + +import org.eclipse.equinox.p2.metadata.Version; + +import org.eclipse.equinox.p2.repository.spi.RepositoryReference; + +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.spi.AbstractRepository; + +/** + * The common base class for all metadata repositories. + * <p> + * Clients may subclass this class. + * <p> + * @since 2.0 + */ +public abstract class AbstractMetadataRepository extends AbstractRepository<IInstallableUnit> implements IMetadataRepository { + + //TODO Consider removing from abstract class, this is currently an implementation detail of the simple metadata repo parser + public static class RepositoryState { + public String Name; + public String Type; + public Version Version; + public String Provider; + public String Description; + public URI Location; + public Map<String, String> Properties; + public IInstallableUnit[] Units; + public RepositoryReference[] Repositories; + } + + public AbstractMetadataRepository() { + super("noName", "noType", "noVersion", null, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + //TODO Consider removing from abstract class, this is currently an implementation detail of the simple metadata repo parser + public abstract void initialize(RepositoryState state); + + protected AbstractMetadataRepository(String name, String type, String version, URI location, String description, String provider, Map<String, String> properties) { + super(name, type, version, location, description, provider, properties); + } + + public void addInstallableUnits(IInstallableUnit[] installableUnit) { + assertModifiable(); + } + + public void addReference(URI repositoryLocation, String nickname, int repositoryType, int options) { + assertModifiable(); + } + + public void removeAll() { + assertModifiable(); + } + + public boolean removeInstallableUnits(IInstallableUnit[] installableUnits, IProgressMonitor monitor) { + assertModifiable(); + return false; + } + +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/MetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/MetadataRepositoryFactory.java new file mode 100644 index 000000000..2dc550f1a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/MetadataRepositoryFactory.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.metadata.spi; + +import java.net.URI; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; + +/** + * A metadata repository factory is responsible for creating and loading instances + * of a particular type of metadata repository. Factories are provided via the + * <tt>org.eclipse.equinox.p2.metadata.repository.metadataRepositories</tt> extension point. + * @since 2.0 + */ +public abstract class MetadataRepositoryFactory { + private IProvisioningAgent agent; + + /** + * Creates and returns a new empty metadata repository of the given type at + * the given location. + * + * @param location the location for the new repository + * @param name the name of the new repository + * @param type the kind of repository to create + * @param properties the properties to set on the repository + * @return the newly created repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>The repository type is not supported by this factory.</li> + * <li>There was an error writing to the given repository location.</li> + * </ul> + */ + public abstract IMetadataRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException; + + /** + * Returns the provisioning agent associated with this factory, or <code>null</code> + * if this factory is not associated with an agent. + * @return The provisioning agent, or <code>null</code> + */ + protected IProvisioningAgent getAgent() { + return agent; + } + + /** + * Loads a repository corresponding to the given URL. + * <p> + * The error code returned in the case of failure is significant. In particular an + * error code of {@link ProvisionException#REPOSITORY_FAILED_READ} indicates + * that the location definitely identifies a repository of this type, but an error occurred + * while loading the repository. The repository manager will not attempt to load + * a repository from that location using any other factory. An error code of + * {@link ProvisionException#REPOSITORY_NOT_FOUND} indicates there is no + * repository of this type at the given location, and the repository manager is free + * to try again with a different repository factory. + * </p> + * <p> + * The flags passed in should be taken as a hint for the type of repository to load. If + * the factory knows it will not load a repository that satisfies these hints, it can fail + * fast and return null.<br> + * See {@link IRepositoryManager#REPOSITORY_HINT_MODIFIABLE} + * </p> + * @param location The location of the repository to load + * @param flags to consider while loading the repository + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return The loaded metadata repository + * @throws ProvisionException if the repository could not be created. Reasons include: + * <ul> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public abstract IMetadataRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException; + + /** + * Sets the provisioning agent associated with this repository factory. + * @param agent The provisioning agent + */ + public void setAgent(IProvisioningAgent agent) { + this.agent = agent; + } + + /** + * Validates a candidate repository URL and returns a status indicating the + * likelihood of a valid repository being located at the location. Implementors + * should make all attempts to validate the URL that can be made without + * actually loading the repository. The computation for this method must be + * significantly faster than loading the repository. Early detectable error + * conditions, such as the non-existence of the location, or an inability to read + * the location, should be determined in this method. + * + * @param location The location of the repository to validate + * @param monitor a progress monitor, or <code>null</code> if progress + * reporting is not desired + * @return A status indicating whether a valid repository is likely located at the + * location. A status with severity <code>OK</code> indicates that the repository is + * likely to be loadable, or that as much validation as could be done was successful. + * Reasons for a non-OK status include: + * <ul> + * <li>The specified location is not a valid repository location.</li> + * <li>There is no existing repository at that location.</li> + * <li>The repository at that location could not be read.</li> + * </ul> + */ + public abstract IStatus validate(URI location, IProgressMonitor monitor); +} diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/repository/AbstractRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/spi/AbstractRepository.java index c2a626edc..5cb14b01f 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/spi/p2/repository/AbstractRepository.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/spi/AbstractRepository.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 @@ -8,13 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.equinox.internal.provisional.spi.p2.repository; +package org.eclipse.equinox.p2.repository.spi; import java.net.URI; import java.util.Map; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; +import org.eclipse.equinox.p2.repository.IRepository; /** * AbstractRepository defines common properties that may be provided by various kinds @@ -22,17 +22,19 @@ import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; * <p> * Clients may extend this class. * </p> +* @param <T> the type of object that can be queried for in this repository + * @since 2.0 */ -public abstract class AbstractRepository extends PlatformObject implements IRepository { +public abstract class AbstractRepository<T> extends PlatformObject implements IRepository<T> { protected String description; protected transient URI location; protected String name; - protected Map properties = new OrderedProperties(); + protected Map<String, String> properties = new OrderedProperties(); protected String provider; protected String type; protected String version; - protected AbstractRepository(String name, String type, String version, URI location, String description, String provider, Map properties) { + protected AbstractRepository(String name, String type, String version, URI location, String description, String provider, Map<String, String> properties) { this.name = name; this.type = type; this.version = version; @@ -83,7 +85,7 @@ public abstract class AbstractRepository extends PlatformObject implements IRepo * Returns a read-only collection of the properties of the repository. * @return the properties of this repository. */ - public synchronized Map getProperties() { + public synchronized Map<String, String> getProperties() { return OrderedProperties.unmodifiableProperties(properties); } @@ -125,7 +127,7 @@ public abstract class AbstractRepository extends PlatformObject implements IRepo public synchronized String setProperty(String key, String value) { assertModifiable(); - return (String) (value == null ? properties.remove(key) : properties.put(key, value)); + return (value == null ? properties.remove(key) : properties.put(key, value)); } public synchronized void setProvider(String provider) { diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/spi/RepositoryReference.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/spi/RepositoryReference.java new file mode 100644 index 000000000..b50398f41 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/spi/RepositoryReference.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.repository.spi; + +import java.net.URI; + +/** + * Serialization helper class for repository references. + * @since 2.0 + */ +public class RepositoryReference { + public URI Location; + public int Type; + public int Options; + public String Nickname; + + public RepositoryReference(URI location, String nickname, int type, int options) { + this.Location = location; + this.Type = type; + this.Options = options; + this.Nickname = nickname; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RepositoryReference other = (RepositoryReference) obj; + if (Location == null) { + if (other.Location != null) + return false; + } else if (!Location.equals(other.Location)) + return false; + if (Type != other.Type) + return false; + return true; + } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((Location == null) ? 0 : Location.hashCode()); + result = prime * result + Type; + return result; + } + +}
\ No newline at end of file |