Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSusan Franklin2008-01-07 23:04:49 +0000
committerSusan Franklin2008-01-07 23:04:49 +0000
commit1c3406f15cc85eff155e4c4fa451209df91d59bb (patch)
treeeb9aaf988e62423c58ed55728bc3c221aa597ecb /bundles/org.eclipse.equinox.p2.artifact.repository/src
parente5e0fd273caee15aee957f2ef8313be64aed77b9 (diff)
downloadrt.equinox.p2-1c3406f15cc85eff155e4c4fa451209df91d59bb.tar.gz
rt.equinox.p2-1c3406f15cc85eff155e4c4fa451209df91d59bb.tar.xz
rt.equinox.p2-1c3406f15cc85eff155e4c4fa451209df91d59bb.zip
Bug 214524 - [prov] [repo] Need access to "implementation only" key without loading repository
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java55
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/p2/artifact/repository/IArtifactRepositoryManager.java63
2 files changed, 113 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
index c64432798..ad6cd3c43 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
@@ -19,6 +19,7 @@ import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifact
import org.eclipse.equinox.internal.p2.core.helpers.*;
import org.eclipse.equinox.p2.artifact.repository.*;
import org.eclipse.equinox.p2.core.location.AgentLocation;
+import org.eclipse.equinox.p2.core.repository.IRepository;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.spi.p2.artifact.repository.IArtifactRepositoryFactory;
import org.osgi.service.prefs.BackingStoreException;
@@ -32,6 +33,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
String description;
URL location;
String name;
+ boolean implementationOnly = false;
SoftReference repository;
}
@@ -45,6 +47,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
private static final String KEY_TYPE = "type"; //$NON-NLS-1$
private static final String KEY_URL = "url"; //$NON-NLS-1$
private static final String KEY_VERSION = "version"; //$NON-NLS-1$
+ private static final String KEY_IMPLEMENTATION_ONLY = "implementationOnly"; //$NON-NLS-1$
private static final String NODE_REPOSITORIES = "repositories"; //$NON-NLS-1$
/**
@@ -65,6 +68,8 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
info.name = repository.getName();
info.description = repository.getDescription();
info.location = repository.getLocation();
+ String value = (String) repository.getProperties().get(IRepository.IMPLEMENTATION_ONLY_KEY);
+ info.implementationOnly = value == null ? false : Boolean.valueOf(value).booleanValue();
synchronized (repositoryLock) {
if (repositories == null)
restoreRepositories();
@@ -176,20 +181,33 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
return location.toExternalForm().replace('/', '_');
}
- public URL[] getKnownRepositories() {
+ public URL[] getKnownRepositories(int flags) {
synchronized (repositoryLock) {
if (repositories == null)
restoreRepositories();
- URL[] result = new URL[repositories.size()];
+ ArrayList result = new ArrayList();
int i = 0;
for (Iterator it = repositories.values().iterator(); it.hasNext(); i++) {
RepositoryInfo info = (RepositoryInfo) it.next();
- result[i] = info.location;
+ if (matchesFlags(info, flags))
+ result.add(info.location);
}
- return result;
+ return (URL[]) result.toArray(new URL[result.size()]);
}
}
+ private boolean matchesFlags(RepositoryInfo info, int flags) {
+ if ((flags & REPOSITORIES_IMPLEMENTATION_ONLY) == REPOSITORIES_IMPLEMENTATION_ONLY)
+ if (!info.implementationOnly)
+ return false;
+ if ((flags & REPOSITORIES_PUBLIC_ONLY) == REPOSITORIES_PUBLIC_ONLY)
+ if (info.implementationOnly)
+ return false;
+ if ((flags & REPOSITORIES_LOCAL_ONLY) == REPOSITORIES_LOCAL_ONLY)
+ return "file".equals(info.location.getProtocol()); //$NON-NLS-1$
+ return true;
+ }
+
/*
* Return the root preference node where we store the repository information.
*/
@@ -267,6 +285,9 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
value = repository.getVersion();
if (value != null)
node.put(KEY_VERSION, value);
+ value = (String) repository.getProperties().get(IRepository.IMPLEMENTATION_ONLY_KEY);
+ if (value != null)
+ node.put(KEY_IMPLEMENTATION_ONLY, value);
value = repository.getLocation().toExternalForm();
node.put(KEY_URL, value);
saveToPreferences();
@@ -278,6 +299,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
private void remember(RepositoryInfo info) {
Preferences node = getPreferences().node(getKey(info.location));
node.put(KEY_URL, info.location.toExternalForm());
+ node.put(KEY_IMPLEMENTATION_ONLY, Boolean.toString(info.implementationOnly));
if (info.description != null)
node.put(KEY_DESCRIPTION, info.description);
if (info.name != null)
@@ -338,6 +360,7 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
info.location = new URL(locationString);
info.name = child.get(KEY_NAME, null);
info.description = child.get(KEY_DESCRIPTION, null);
+ info.implementationOnly = child.getBoolean(KEY_IMPLEMENTATION_ONLY, false);
repositories.put(getKey(info.location), info);
} catch (MalformedURLException e) {
log("Error while restoring repository: " + locationString, e); //$NON-NLS-1$
@@ -383,4 +406,28 @@ public class ArtifactRepositoryManager implements IArtifactRepositoryManager {
log("Error while saving repositories in preferences", e); //$NON-NLS-1$
}
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.equinox.p2.artifact.repository.IArtifactRepositoryManager#getRepositoryProperty(java.net.URL, java.lang.String)
+ */
+ public String getRepositoryProperty(URL location, String key) {
+ synchronized (repositoryLock) {
+ if (repositories == null)
+ restoreRepositories();
+ for (Iterator it = repositories.values().iterator(); it.hasNext();) {
+ RepositoryInfo info = (RepositoryInfo) it.next();
+ if (URLUtil.sameURL(info.location, location)) {
+ if (PROP_DESCRIPTION.equals(key))
+ return info.description;
+ if (PROP_NAME.equals(key))
+ return info.name;
+ // Key not known, return null
+ return null;
+ }
+ }
+ // Repository not found, return null
+ return null;
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/p2/artifact/repository/IArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/p2/artifact/repository/IArtifactRepositoryManager.java
index d908f50f7..67effe49d 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/p2/artifact/repository/IArtifactRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/p2/artifact/repository/IArtifactRepositoryManager.java
@@ -14,9 +14,36 @@ import java.net.URL;
import java.util.Properties;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.equinox.p2.core.repository.IRepository;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
public interface IArtifactRepositoryManager {
+ /**
+ * Constant used to indicate that all repositories are of interest.
+ */
+ public static final int REPOSITORIES_ALL = 0;
+ /**
+ * Constant used to indicate that implementation-only repositories are of interest.
+ */
+ public static final int REPOSITORIES_IMPLEMENTATION_ONLY = 1 << 1;
+ /**
+ * Constant used to indicate that public (non-implementation-only) repositories are of interest.
+ */
+ public static final int REPOSITORIES_PUBLIC_ONLY = 1 << 2;
+ /**
+ * Constant used to indicate that local repositories are of interest.
+ */
+ public static final int REPOSITORIES_LOCAL_ONLY = 1 << 3;
+
+ /**
+ * Property key used to query a repository's name without loading the repository first.
+ */
+ public static final String PROP_NAME = "name"; //$NON-NLS-1$
+ /**
+ * Property key used to query a repository's description without loading the repository first.
+ */
+ public static final String PROP_DESCRIPTION = "description"; //$NON-NLS-1$
+
public static final IArtifactRequest[] NO_ARTIFACT_REQUEST = new IArtifactRequest[0];
/**
@@ -71,9 +98,43 @@ public interface IArtifactRepositoryManager {
* A subsequent attempt to load a repository at any of the given locations may
* or may not succeed.
*
+ * @param flags an integer bit-mask indicating which repositories should be
+ * returned. <code>REPOSITORIES_ALL</code> can be used as the mask when
+ * all repositories should be returned.
+ *
* @return the locations of the repositories managed by this repository manager.
+ *
+ * @see #REPOSITORIES_ALL
+ * @see #REPOSITORIES_IMPLEMENTATION_ONLY
+ * @see #REPOSITORIES_LOCAL_ONLY
+ * @see #REPOSITORIES_PUBLIC_ONLY
+ */
+ public URL[] getKnownRepositories(int flags);
+
+ /**
+ * Returns the property associated with the repository at the given URL,
+ * without loading the repository.
+ * <p>
+ * Note that some properties for a repository can only be
+ * determined when that repository is loaded. This method will return <code>null</code>
+ * for such properties. Only values for the properties that are already
+ * known by a repository manager will be returned.
+ * <p>
+ * If a client wishes to retrieve a property value from a repository
+ * regardless of the cost of retrieving it, the client should load the
+ * repository and then retrieve the property from the repository itself.
+ *
+ * @param location the URL of the repository in question
+ * @param key the String key of the property desired
+ * @return the value of the property, or <code>null</code> if the repository
+ * does not exist, the value does not exist, or the property value
+ * could not be determined without loading the repository.
+ *
+ * @see #loadRepository(URL, IProgressMonitor)
+ * @see IRepository#getProperties()
+ *
*/
- public URL[] getKnownRepositories();
+ public String getRepositoryProperty(URL location, String key);
/**
* Loads the repository at the given location. The location is expected to contain

Back to the top