Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java47
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java18
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactLockingTest.java8
4 files changed, 56 insertions, 34 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
index 043ba761d..ffe716f3f 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
@@ -10,6 +10,14 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
+import org.eclipse.osgi.service.datalocation.Location;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -17,7 +25,10 @@ public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.equinox.p2.artifact.repository"; //$NON-NLS-1$
public static final String REPO_PROVIDER_XPT = ID + '.' + "artifactRepositories"; //$NON-NLS-1$
+ private Map<URI, Location> locationCache = null;
+
private static BundleContext context;
+ private static Activator instance;
public static BundleContext getContext() {
return Activator.context;
@@ -25,9 +36,45 @@ public class Activator implements BundleActivator {
public void start(BundleContext aContext) throws Exception {
Activator.context = aContext;
+ Activator.instance = this;
+ this.locationCache = new HashMap<URI, Location>();
}
public void stop(BundleContext aContext) throws Exception {
Activator.context = null;
+ Activator.instance = null;
+ this.locationCache = null;
+ }
+
+ public static Activator getInstance() {
+ return Activator.instance;
+ }
+
+ /**
+ * Returns the lock location for a given artifact repository
+ * @param repositoryLocation A URI pointing to an artifact repository. Currently only
+ * file:// repositories are supported
+ * @return The Location that can be locked when using an artifact repository
+ * @throws IOException Thrown if a Location can not be created
+ */
+ public synchronized Location getLockLocation(URI repositoryLocation) throws IOException {
+ if (locationCache.containsKey(repositoryLocation)) {
+ return locationCache.get(repositoryLocation);
+ }
+ Location anyLoc = (Location) ServiceHelper.getService(Activator.getContext(), Location.class.getName());
+ File repositoryFile = URIUtil.toFile(repositoryLocation);
+ Location location = anyLoc.createLocation(null, getLockFile(repositoryLocation).toURL(), !repositoryFile.canWrite());
+ location.set(getLockFile(repositoryLocation).toURL(), false);
+ locationCache.put(repositoryLocation, location);
+ return location;
+ }
+
+ private File getLockFile(URI repositoryLocation) throws IOException {
+ if (!URIUtil.isFileURI(repositoryLocation)) {
+ throw new IOException("Cannot lock a non file based repository"); //$NON-NLS-1$
+ }
+ URI result = URIUtil.append(repositoryLocation, ".artifactlock"); //$NON-NLS-1$
+ return URIUtil.toFile(result);
}
+
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
index 53223540b..7a71e8b23 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
@@ -27,7 +27,6 @@ import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier;
import org.eclipse.equinox.internal.p2.artifact.repository.*;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.internal.p2.metadata.expression.CompoundIterator;
import org.eclipse.equinox.internal.p2.metadata.index.IndexProvider;
@@ -1385,21 +1384,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
throw new IOException("Cannot lock a non file based repository"); //$NON-NLS-1$
}
- // TODO: Throw an IO Exception if we cannot lock this location
- Location anyLoc = (Location) ServiceHelper.getService(Activator.getContext(), Location.class.getName());
- File repositoryFile = URIUtil.toFile(repositoryLocation);
- Location location = anyLoc.createLocation(null, getLockFile().toURL(), !repositoryFile.canWrite());
- location.set(getLockFile().toURL(), false);
- return location;
- }
-
- private File getLockFile() throws IOException {
- URI repositoryLocation = getLocation();
- if (!URIUtil.isFileURI(repositoryLocation)) {
- throw new IOException("Cannot lock a non file based repository"); //$NON-NLS-1$
- }
- URI result = URIUtil.append(repositoryLocation, ".artifactlock"); //$NON-NLS-1$
- return URIUtil.toFile(result);
+ return Activator.getInstance().getLockLocation(repositoryLocation);
}
/**
@@ -1496,4 +1481,5 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
}
lockLocation = null;
}
+
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
index 3ba5983e1..bbb92f57a 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
@@ -17,7 +17,8 @@ import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
-import org.eclipse.equinox.internal.p2.core.helpers.*;
+import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
+import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.internal.p2.persistence.XMLParser;
import org.eclipse.equinox.internal.p2.persistence.XMLWriter;
@@ -173,19 +174,7 @@ public class SimpleArtifactRepositoryIO {
if (!URIUtil.isFileURI(repositoryLocation)) {
throw new IOException("Cannot lock a non file based repository"); //$NON-NLS-1$
}
- File repositoryFile = URIUtil.toFile(repositoryLocation);
- Location anyLoc = (Location) ServiceHelper.getService(Activator.getContext(), Location.class.getName());
- Location location = anyLoc.createLocation(null, getLockFile(repositoryLocation).toURL(), !repositoryFile.canWrite());
- location.set(getLockFile(repositoryLocation).toURL(), false);
- return location;
- }
-
- private File getLockFile(URI repositoryLocation) throws IOException {
- if (!URIUtil.isFileURI(repositoryLocation)) {
- throw new IOException("Cannot lock a non file based repository"); //$NON-NLS-1$
- }
- URI result = URIUtil.append(repositoryLocation, ".artifactlock"); //$NON-NLS-1$
- return URIUtil.toFile(result);
+ return Activator.getInstance().getLockLocation(repositoryLocation);
}
private interface XMLConstants extends org.eclipse.equinox.internal.p2.persistence.XMLConstants {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactLockingTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactLockingTest.java
index 6856f312c..9aab0ae81 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactLockingTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactLockingTest.java
@@ -31,7 +31,7 @@ public class ArtifactLockingTest extends AbstractProvisioningTest {
boolean canContinue = false;
- public void _testCancelLoad() throws InterruptedException, ProvisionException {
+ public void testCancelLoad() throws InterruptedException, ProvisionException {
this.canContinue = false;
final IProgressMonitor progressMonitor = new NullProgressMonitor();
new Thread(new Runnable() {
@@ -68,7 +68,7 @@ public class ArtifactLockingTest extends AbstractProvisioningTest {
}
- public void _testWaitForLoad() throws InterruptedException, ProvisionException {
+ public void testWaitForLoad() throws InterruptedException, ProvisionException {
this.canContinue = false;
new Thread(new Runnable() {
public void run() {
@@ -107,7 +107,7 @@ public class ArtifactLockingTest extends AbstractProvisioningTest {
* that the block terminates.
* @throws InterruptedException
*/
- public void _testCancel() throws InterruptedException {
+ public void testCancel() throws InterruptedException {
final IProgressMonitor progressMonitor = new NullProgressMonitor();
this.keepRunning = true;
@@ -223,7 +223,7 @@ public class ArtifactLockingTest extends AbstractProvisioningTest {
* parallel, but rather, the second one waits for the first to complete.
* @throws InterruptedException
*/
- public void _testMultipleExecuteBatch() throws InterruptedException {
+ public void testMultipleExecuteBatch() throws InterruptedException {
this.lockAcquired = false;
Thread t1 = new Thread(new Runnable() {
public void run() {

Back to the top