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 8dddf8a2b4..aff033c6e5 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); } } 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 dd36efc788..310c14e149 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); + } } }