Skip to content

Commit

Permalink
Make RepositoryReference a record
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell authored and laeubi committed Nov 14, 2023
1 parent 57ba377 commit 842572c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,13 @@
*******************************************************************************/
package org.eclipse.tycho.p2.tools;

public class RepositoryReference {
private final String name;
private final String location;
private final boolean enable;
import java.net.URI;

public RepositoryReference(String name, String location, boolean enable) {
super();
this.name = name;
this.location = location;
this.enable = enable;
}

public String getName() {
return name;
}
public record RepositoryReference(String name, String location, boolean enable) {

public String getLocation() {
return location;
public URI locationURINormalized() {
// P2 does the same before loading the repo and thus IRepository.getLocation() returns the normalized URL.
// In order to avoid stripping of slashes from URI instances do it now before URIs are created.
return URI.create(location.endsWith("/") ? location.substring(0, location.length() - 1) : location);
}

public boolean isEnable() {
return enable;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,12 @@ protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit,
private static Stream<org.eclipse.equinox.p2.repository.spi.RepositoryReference> toSpiRepositoryReferences(
RepositoryReference rr) {
return Stream.of(IRepository.TYPE_METADATA, IRepository.TYPE_ARTIFACT).map(type -> {
URI location = getNormalizedLocation(rr);
int options = rr.isEnable() ? IRepository.ENABLED : IRepository.NONE;
return new org.eclipse.equinox.p2.repository.spi.RepositoryReference(location, rr.getName(), type, options);
URI location = rr.locationURINormalized();
int options = rr.enable() ? IRepository.ENABLED : IRepository.NONE;
return new org.eclipse.equinox.p2.repository.spi.RepositoryReference(location, rr.name(), type, options);
});
}

private static URI getNormalizedLocation(RepositoryReference r) {
// P2 does the same before loading the repo and thus IRepository.getLocation() returns the normalized URL.
// In order to avoid stripping of slashes from URI instances do it now before URIs are created.
String location = r.getLocation();
return URI.create(location.endsWith("/") ? location.substring(0, location.length() - 1) : location);
}

@Override
protected void finalizeRepositories() {
IMetadataRepository repository = getDestinationMetadataRepository();
Expand Down Expand Up @@ -251,8 +244,8 @@ protected Set<IInstallableUnit> collectUnits(IQueryable<IInstallableUnit> slice,

if (addOnlyProvidingRepoReferences) {
Set<URI> removableReferences = destination.getFilterableRepositoryReferences().stream()
.map(TychoMirrorApplication::getNormalizedLocation).collect(Collectors.toSet());
destination.getRepositoryReferences().stream().map(TychoMirrorApplication::getNormalizedLocation)
.map(RepositoryReference::locationURINormalized).collect(Collectors.toSet());
destination.getRepositoryReferences().stream().map(RepositoryReference::locationURINormalized)
.forEach(removableReferences::remove); // keep reference if explicitly added to the repository
if (!removableReferences.isEmpty()) {
// Assume that for all units that correspond to artifacts the metadata either has a co-located artifact repository or a references to to one that contains it.
Expand Down

0 comments on commit 842572c

Please sign in to comment.