From 477708039eaaaf83333b236fd90ecca36c98cc15 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 11 Nov 2023 11:39:25 +0100 Subject: [PATCH] Make RepositoryReference a record --- .../tycho/p2/tools/RepositoryReference.java | 27 +++++-------------- .../tycho/p2tools/TychoMirrorApplication.java | 17 ++++-------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/RepositoryReference.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/RepositoryReference.java index c8de3b661d..34d31669fa 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/RepositoryReference.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/RepositoryReference.java @@ -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; - } - } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java index e31a9f60a8..9b3320b1c5 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java @@ -202,19 +202,12 @@ protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, private static Stream 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(); @@ -251,8 +244,8 @@ protected Set collectUnits(IQueryable slice, if (addOnlyProvidingRepoReferences) { Set 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.