From 03dd58de5d0d61290c12578478cb7ee02ddaaf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 11 May 2024 07:38:06 +0200 Subject: [PATCH 1/2] Use RepositoryEvent.newDiscoveryEvent(..) and pass the nickname Currently even if a reference would define a nickname it is not passed by the repository event resulting in an updatesite to have an empty name. This uses the RepositoryEvent.newDiscoveryEvent(...) method to pass the nickname is present. --- .../p2/metadata/repository/LocalMetadataRepository.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java index 8dddf8a2b..aff033c6e 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java @@ -186,13 +186,14 @@ public void initialize(RepositoryState state) { */ public void publishRepositoryReferences() { IProvisioningEventBus bus = getProvisioningAgent().getService(IProvisioningEventBus.class); - if (bus == null) + if (bus == null) { return; - + } List repositoriesSnapshot = createRepositoriesSnapshot(); for (IRepositoryReference reference : repositoriesSnapshot) { - bus.publishEvent(new RepositoryEvent(reference.getLocation(), reference.getType(), - RepositoryEvent.DISCOVERED, reference.isEnabled())); + RepositoryEvent event = RepositoryEvent.newDiscoveryEvent(reference.getLocation(), reference.getNickname(), + reference.getType(), reference.isEnabled()); + bus.publishEvent(event); } } From 5b8a24528791c4daa54176824f7110d6463ab03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 11 May 2024 08:07:24 +0200 Subject: [PATCH 2/2] AbstractRepositoryManager does not pass the nickname Currently if a discovery event would define a nickname it is not passed by the add repository method resulting in an updatesite to have an empty name. This adds a new method that allows to pass a custom RepositoryInfo so the nickname can be set. --- .../helpers/AbstractRepositoryManager.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java index dd36efc78..310c14e14 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java @@ -160,18 +160,23 @@ private boolean addRepository(URI location, boolean isEnabled, boolean signalAdd RepositoryInfo info = new RepositoryInfo<>(); info.location = location; info.isEnabled = isEnabled; + return addRepository(info, signalAdd); + } + + private boolean addRepository(RepositoryInfo info, boolean signalAdd) { + boolean added = true; synchronized (repositoryLock) { if (repositories == null) restoreRepositories(); - if (contains(location)) + if (contains(info.location)) return false; - added = repositories.put(getKey(location), info) == null; + added = repositories.put(getKey(info.location), info) == null; // save the given repository in the preferences. remember(info, true); } if (added && signalAdd) - broadcastChangeEvent(location, getRepositoryType(), RepositoryEvent.ADDED, isEnabled); + broadcastChangeEvent(info.location, getRepositoryType(), RepositoryEvent.ADDED, info.isEnabled); return added; } @@ -837,8 +842,13 @@ private boolean matchesFlags(RepositoryInfo info, int flags) { public void notify(EventObject o) { if (o instanceof RepositoryEvent) { RepositoryEvent event = (RepositoryEvent) o; - if (event.getKind() == RepositoryEvent.DISCOVERED && event.getRepositoryType() == getRepositoryType()) - addRepository(event.getRepositoryLocation(), event.isRepositoryEnabled(), true); + if (event.getKind() == RepositoryEvent.DISCOVERED && event.getRepositoryType() == getRepositoryType()) { + RepositoryInfo info = new RepositoryInfo<>(); + info.location = event.getRepositoryLocation(); + info.isEnabled = event.isRepositoryEnabled(); + info.nickname = event.getRepositoryNickname(); + addRepository(info, true); + } } }