Skip to content

Commit

Permalink
Add IMetadataRepository.removeReferences()
Browse files Browse the repository at this point in the history
And clean-up the affected classes at a few occasions.
  • Loading branch information
HannesWell committed Sep 28, 2023
1 parent 0c02412 commit dd1e28a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ private static File getActualLocation(URI location, String extension) {
// return new File(spec + extension);
return spec;
}
if (path.endsWith("/")) //$NON-NLS-1$
path += CompositeMetadataRepositoryFactory.CONTENT_FILENAME;
else
path += "/" + CompositeMetadataRepositoryFactory.CONTENT_FILENAME; //$NON-NLS-1$
return new File(path + extension);
return new File(path, CompositeMetadataRepositoryFactory.CONTENT_FILENAME + extension);
}

public static File getActualLocation(URI location) {
Expand All @@ -262,11 +258,17 @@ public synchronized void addReferences(Collection<? extends IRepositoryReference
throw new UnsupportedOperationException("Cannot add References to a composite repository"); //$NON-NLS-1$
}

@Override
public synchronized boolean removeReferences(Collection<? extends IRepositoryReference> references) {
throw new UnsupportedOperationException("Cannot remove References to a composite repository"); //$NON-NLS-1$
}

@Override
public Collection<IRepositoryReference> getReferences() {
HashSet<IRepositoryReference> allRefs = new HashSet<>();
for (IMetadataRepository child : loadedRepos)
Set<IRepositoryReference> allRefs = new HashSet<>();
for (IMetadataRepository child : loadedRepos) {
allRefs.addAll(child.getReferences());
}
return allRefs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,19 @@ public synchronized void addInstallableUnits(Collection<IInstallableUnit> instal
@Override
public void addReferences(Collection<? extends IRepositoryReference> references) {
assertModifiable();
// only write out the repository if we made changes
if (repositories.addAll(references))
save();
if (repositories.addAll(references)) {
save(); // only write out the repository if we made changes
}
}

@Override
public boolean removeReferences(Collection<? extends IRepositoryReference> references) {
assertModifiable();
if (repositories.removeAll(references)) {
save(); // only write out the repository if we made changes
return true;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public interface IMetadataRepository extends IRepository<IInstallableUnit> {
*/
Collection<IRepositoryReference> getReferences();

/**
* Removes from this repository the given references to other repositories.
*
* @since 2.8
*/
boolean removeReferences(Collection<? extends IRepositoryReference> references);

/**
* Removes all installable units in the given collection from this repository.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public void addReferences(Collection<? extends IRepositoryReference> references)
assertModifiable();
}

@Override
public boolean removeReferences(Collection<? extends IRepositoryReference> references) {
assertModifiable();
return false;
}


@Override
public void removeAll() {
assertModifiable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public synchronized void addReferences(Collection<? extends IRepositoryReference
repositories.addAll(references);
}

@Override
public synchronized boolean removeReferences(Collection<? extends IRepositoryReference> references) {
assertModifiable();
return repositories.removeAll(references);
}

/**
* Returns a collection of {@link RepositoryReference}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void addReferences(Collection<? extends IRepositoryReference> references)
throw new UnsupportedOperationException("Repository not modifiable: " + location); //$NON-NLS-1$
}

@Override
public boolean removeReferences(Collection<? extends IRepositoryReference> references) {
throw new UnsupportedOperationException("Repository not modifiable: " + location); //$NON-NLS-1$
}

@Override
public Collection<IRepositoryReference> getReferences() {
return delegate.getReferences();
Expand Down

0 comments on commit dd1e28a

Please sign in to comment.