Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java43
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java45
2 files changed, 78 insertions, 10 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
index a8936f302..e1fb37a64 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
@@ -45,6 +45,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
// keep a list of the repositories that we have successfully loaded
private List<ChildInfo> loadedRepos = new ArrayList<ChildInfo>();
private IArtifactRepositoryManager manager;
+ private boolean disableSave;
/**
* Create a Composite repository in memory.
@@ -79,7 +80,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
return manager;
}
- /*
+ /**
* This is only called by the parser when loading a repository.
*/
CompositeArtifactRepository(IArtifactRepositoryManager manager, CompositeRepositoryState state) {
@@ -89,7 +90,10 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
addChild(state.getChildren()[i], false);
}
- CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties) {
+ /**
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ protected CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties) {
super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
this.manager = manager;
save();
@@ -393,7 +397,15 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
return applicable.toArray(new IArtifactRequest[applicable.size()]);
}
- private void save() {
+ /**
+ * This method is only protected for testing purposes
+ *
+ * @nooverride This method is not intended to be re-implemented or extended by clients.
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ protected void save() {
+ if (disableSave)
+ return;
if (!isModifiable())
return;
boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$
@@ -551,4 +563,29 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
CompoundQueryable<IArtifactDescriptor> queryable = new CompoundQueryable<IArtifactDescriptor>(repos);
return queryable;
}
+
+ public IStatus executeBatch(Runnable runnable) {
+ IStatus result = null;
+ synchronized (this) {
+ try {
+ disableSave = true;
+ runnable.run();
+ } catch (Throwable e) {
+ result = new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
+ } finally {
+ disableSave = false;
+ try {
+ save();
+ } catch (Exception e) {
+ if (result != null)
+ result = new MultiStatus(Activator.ID, IStatus.ERROR, new IStatus[] {result}, e.getMessage(), e);
+ else
+ result = new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
+ }
+ }
+ }
+ if (result == null)
+ result = Status.OK_STATUS;
+ return 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 127c7851b..4f9a0c33c 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
@@ -216,6 +216,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
private MirrorSelector mirrors;
+ private boolean disableSave = false;
+
static void delete(File toDelete) {
if (toDelete.isDirectory()) {
File[] children = toDelete.listFiles();
@@ -437,11 +439,13 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
simple = createInternalDescriptor(descriptor);
if (simple.getRepositoryProperty(SimpleArtifactDescriptor.ARTIFACT_REFERENCE) == null) {
File file = getArtifactFile(descriptor);
- if (file == null)
- return false;
- delete(file);
- if (file.exists())
- return false;
+ if (file != null) {
+ // If the file != null remove it, otherwise just remove
+ // the descriptor
+ delete(file);
+ if (file.exists())
+ return false;
+ }
}
boolean result = artifactDescriptors.remove(descriptor);
if (result)
@@ -900,11 +904,13 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
}
public void save() {
- boolean compress = "true".equalsIgnoreCase(properties.get(PROP_COMPRESSED)); //$NON-NLS-1$
+ if (disableSave)
+ return;
+ boolean compress = "true".equalsIgnoreCase((String) properties.get(PROP_COMPRESSED)); //$NON-NLS-1$
save(compress);
}
- public void save(boolean compress) {
+ private void save(boolean compress) {
assertModifiable();
OutputStream os = null;
try {
@@ -990,4 +996,29 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMonitor monitor) {
return query.perform(artifactMap.keySet().iterator());
}
+
+ public IStatus executeBatch(Runnable runnable) {
+ IStatus result = null;
+ synchronized (this) {
+ try {
+ disableSave = true;
+ runnable.run();
+ } catch (Throwable e) {
+ result = new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
+ } finally {
+ disableSave = false;
+ try {
+ save();
+ } catch (Exception e) {
+ if (result != null)
+ result = new MultiStatus(Activator.ID, IStatus.ERROR, new IStatus[] {result}, e.getMessage(), e);
+ else
+ result = new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
+ }
+ }
+ }
+ if (result == null)
+ result = Status.OK_STATUS;
+ return result;
+ }
}

Back to the top