Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RepositoryReference a record #3030

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading