From 53a9d712599227b694570d2919d03103802a83b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 11 May 2024 08:22:00 +0200 Subject: [PATCH] Remember referenced repositories as system repositories instead of user Currently there is a quite surprising behavior, that if a user adds an updatesite that contains a referenced repository, that after an update-check additional repositories are visible. Even worse these are now used additionally to check for updates and if they contain other references these are also added and so on. This can result not only in a long list of sites the user never has added and has no clue where they are coming from but even pulling in unwanted or conflicting updates. This now distinguishes two cases: 1) A repository is discovered by the RepositoryAction it is handled as a user added repository and becomes visible 2) A repository is discovered by a reference in that case it is handled as a system repository and not becomes visible that way the list of user visible repositories stay clean from referenced repositories and unexpected side effects on update checks. --- .../repository/LocalMetadataRepository.java | 2 +- .../helpers/AbstractRepositoryManager.java | 1 + .../p2/repository/RepositoryEvent.java | 33 +++++++++++++------ .../eclipse/actions/RepositoryAction.java | 2 +- 4 files changed, 26 insertions(+), 12 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 aff033c6e5..9e1518b1f0 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 @@ -192,7 +192,7 @@ public void publishRepositoryReferences() { List repositoriesSnapshot = createRepositoriesSnapshot(); for (IRepositoryReference reference : repositoriesSnapshot) { RepositoryEvent event = RepositoryEvent.newDiscoveryEvent(reference.getLocation(), reference.getNickname(), - reference.getType(), reference.isEnabled()); + reference.getType(), reference.isEnabled(), true); bus.publishEvent(event); } } 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 310c14e149..7f70fc53bf 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 @@ -847,6 +847,7 @@ public void notify(EventObject o) { info.location = event.getRepositoryLocation(); info.isEnabled = event.isRepositoryEnabled(); info.nickname = event.getRepositoryNickname(); + info.isSystem = event.isSystem(); addRepository(info, true); } } diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java index 930a127b70..302697a542 100644 --- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java +++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/provisional/p2/repository/RepositoryEvent.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -21,7 +21,7 @@ /** * An event indicating a repository was added, removed, changed, * or discovered. - * + * * @see IProvisioningEventBus * @noextend This class is not intended to be subclassed by clients. */ @@ -29,19 +29,19 @@ public class RepositoryEvent extends EventObject { private static final long serialVersionUID = 3082402920617281765L; /** - * A change kind constant (value 0), indicating a repository was added to the + * A change kind constant (value 0), indicating a repository was added to the * list of repositories known to a repository manager. */ public static final int ADDED = 0; /** - * A change kind constant (value 1), indicating a repository was removed from + * A change kind constant (value 1), indicating a repository was removed from * the list of repositories known to a repository manager. */ public static final int REMOVED = 1; /** - * A change kind constant (value 2), indicating a repository known to a + * A change kind constant (value 2), indicating a repository known to a * repository manager was modified. */ public static final int CHANGED = 2; @@ -67,6 +67,7 @@ public class RepositoryEvent extends EventObject { private final int kind, type; private boolean isEnabled; private String nickname; + private boolean system; /** * Creates and returns a new repository discovery event. @@ -77,15 +78,17 @@ public class RepositoryEvent extends EventObject { * @return A new repository discovery event * @see IRepository#PROP_NICKNAME */ - public static RepositoryEvent newDiscoveryEvent(URI location, String nickname, int repositoryType, boolean enabled) { + public static RepositoryEvent newDiscoveryEvent(URI location, String nickname, int repositoryType, boolean enabled, + boolean system) { RepositoryEvent event = new RepositoryEvent(location, repositoryType, DISCOVERED, enabled); event.nickname = nickname; + event.system = system; return event; } /** * Creates a new repository event. - * + * * @param location the location of the repository that changed. * @param repositoryType the type of repository that was changed * @param kind the kind of change that occurred. @@ -121,9 +124,19 @@ public String getRepositoryNickname() { return nickname; } + /** + * Returns if the repository is a system type see + * {@link IRepository#PROP_SYSTEM}. This method is only applicable for the + * {@link #DISCOVERED} event type. For other event types this method returns + * false. + */ + public boolean isSystem() { + return system; + } + /** * Returns the location of the repository associated with this event. - * + * * @return the location of the repository associated with this event. */ public URI getRepositoryLocation() { @@ -134,7 +147,7 @@ public URI getRepositoryLocation() { * Returns the type of repository associated with this event. Clients * should not assume that the set of possible repository types is closed; * clients should ignore events from repository types they don't know about. - * + * * @return the type of repository associated with this event. * ({@link IRepository#TYPE_METADATA} or {@link IRepository#TYPE_ARTIFACT}). */ @@ -144,7 +157,7 @@ public int getRepositoryType() { /** * Returns whether the affected repository is enabled. - * + * * @return true if the repository is enabled, * and false otherwise. */ diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RepositoryAction.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RepositoryAction.java index 793e782950..22a54d120c 100644 --- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RepositoryAction.java +++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/actions/RepositoryAction.java @@ -149,7 +149,7 @@ protected RepositoryEvent createEvent(Map parameters) throws Cor // default is to be enabled String enablement = (String) parameters.get(ActionConstants.PARM_REPOSITORY_ENABLEMENT); boolean enabled = enablement == null ? true : Boolean.parseBoolean(enablement); - return RepositoryEvent.newDiscoveryEvent(location, name, type, enabled); + return RepositoryEvent.newDiscoveryEvent(location, name, type, enabled, false); } /**