From b46100f41b9a39f5eafa0dbf919c949063c2ee90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 12 May 2024 07:33:50 +0200 Subject: [PATCH] Use RepositoryTracker for KnownRepositories to be consistent with Update Currently if the user choose 'Check for Updates' the handler uses the ProvisioningUI (that uses RepositoryTracker internally) to choose the initial items to offer. The UpdateChecker (aka automatically search for updates) on the other hand uses a (potentially) different set of items. This now adds a new method that allow to pass the repository flags to be used when search for an update and delegate it on the callers side to use the Provisioning UI. --- .../equinox/p2/core/IProvisioningAgent.java | 23 ++++++++ .../repository/LocalMetadataRepository.java | 3 +- .../scheduler/AutomaticUpdateScheduler.java | 9 ++- .../.settings/.api_filters | 12 ++++ .../META-INF/MANIFEST.MF | 1 + .../p2/updatechecker/UpdateChecker.java | 34 +++++++---- .../p2/updatechecker/IUpdateChecker.java | 56 +++++++++++-------- 7 files changed, 102 insertions(+), 36 deletions(-) create mode 100644 bundles/org.eclipse.equinox.p2.updatechecker/.settings/.api_filters diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java index fd41a00989..0d06a7128f 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java @@ -142,4 +142,27 @@ default String getProperty(String key, String defaultValue) { return property; } + /** + * Returns an agent bound property as a boolean, the default implementation + * delegates to {@link IProvisioningAgent#getBooleanProperty(String, boolean)} + * with false as the default. + * + * @since 2.11 + */ + default boolean getBooleanProperty(String key) { + return getBooleanProperty(key, false); + } + + /** + * Returns an agent bound property as a boolean, the default implementation + * delegates to {@link IProvisioningAgent#getProperty(String)} with the given + * default as a String and parses the result as by + * {@link Boolean#parseBoolean(String)}. + * + * @since 2.11 + */ + default boolean getBooleanProperty(String key, boolean defaultValue) { + return Boolean.parseBoolean(getProperty(key, Boolean.toString(defaultValue))); + } + } \ No newline at end of file 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 a8f67bc2fe..28a2830a27 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 @@ -191,8 +191,7 @@ public void publishRepositoryReferences() { return; } List repositoriesSnapshot = createRepositoriesSnapshot(); - boolean referenceAsSystem = Boolean - .parseBoolean(agent.getProperty("p2.metadata.repository.reference.system", "true")); //$NON-NLS-1$ //$NON-NLS-2$ + boolean referenceAsSystem = agent.getBooleanProperty("p2.metadata.repository.reference.system", true); //$NON-NLS-1$ for (IRepositoryReference reference : repositoriesSnapshot) { RepositoryEvent event = RepositoryEvent.newDiscoveryEvent(reference.getLocation(), reference.getNickname(), reference.getType(), reference.isEnabled(), referenceAsSystem); diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java index 6d56f31c99..e89cd114d2 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java @@ -31,6 +31,7 @@ import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.query.IQuery; +import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.IStartup; import org.eclipse.ui.PlatformUI; @@ -175,7 +176,13 @@ public void checkingForUpdates() { StatusManager.getManager().handle(status, StatusManager.LOG); return; } - checker.addUpdateCheck(IProfileRegistry.SELF, getProfileQuery(), delay, poll, listener); + checker.addUpdateCheck(IProfileRegistry.SELF, getProfileQuery(), delay, poll, () -> { + if (pagent.getBooleanProperty("p2.ui.sdk.scheduler.update.useProvisioningUI", true)) { //$NON-NLS-1$ + return AutomaticUpdatePlugin.getDefault().getAutomaticUpdater().getProvisioningUI() + .getRepositoryTracker().getMetadataRepositoryFlags(); + } + return IRepositoryManager.REPOSITORIES_ALL; + }, listener); } diff --git a/bundles/org.eclipse.equinox.p2.updatechecker/.settings/.api_filters b/bundles/org.eclipse.equinox.p2.updatechecker/.settings/.api_filters new file mode 100644 index 0000000000..05bc4ef84b --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.updatechecker/.settings/.api_filters @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bundles/org.eclipse.equinox.p2.updatechecker/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.updatechecker/META-INF/MANIFEST.MF index 8d1f719779..a4fcefe3f4 100644 --- a/bundles/org.eclipse.equinox.p2.updatechecker/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.updatechecker/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Import-Package: org.eclipse.equinox.internal.p2.core.helpers, org.eclipse.equinox.p2.core.spi;version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.engine;version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.metadata;version="[2.0.0,3.0.0)", + org.eclipse.equinox.p2.operations;version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.planner;version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.query;version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.repository;version="[2.0.0,3.0.0)", diff --git a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java index a7203231c5..75fdbb4566 100644 --- a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java +++ b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/p2/updatechecker/UpdateChecker.java @@ -18,6 +18,7 @@ import java.net.URI; import java.text.SimpleDateFormat; import java.util.*; +import java.util.function.IntSupplier; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; @@ -57,12 +58,16 @@ private class UpdateCheckThread extends Thread { IUpdateListener listener; String profileId; IQuery query; + private IntSupplier repositoryFlags; - UpdateCheckThread(String profileId, IQuery query, long delay, long poll, IUpdateListener listener) { + UpdateCheckThread(String profileId, IQuery query, long delay, long poll, + IntSupplier repositoryFlags, + IUpdateListener listener) { this.poll = poll; this.delay = delay; this.profileId = profileId; this.query = query; + this.repositoryFlags = repositoryFlags; this.listener = listener; } @@ -75,7 +80,8 @@ public void run() { while (!done) { listener.checkingForUpdates(); trace("Checking for updates for " + profileId + " at " + getTimeStamp()); //$NON-NLS-1$ //$NON-NLS-2$ - Collection iusWithUpdates = checkForUpdates(profileId, query); + Collection iusWithUpdates = checkForUpdates(profileId, query, + repositoryFlags.getAsInt()); if (iusWithUpdates.size() > 0) { trace("Notifying listener of available updates"); //$NON-NLS-1$ UpdateEvent event = new UpdateEvent(profileId, iusWithUpdates); @@ -104,10 +110,17 @@ public UpdateChecker(IProvisioningAgent agent) { @Override public void addUpdateCheck(String profileId, IQuery query, long delay, long poll, IUpdateListener listener) { - if (checkers.containsKey(listener)) + addUpdateCheck(profileId, query, delay, poll, () -> IRepositoryManager.REPOSITORIES_ALL, listener); + } + + @Override + public void addUpdateCheck(String profileId, IQuery query, long delay, long poll, + IntSupplier repositoryFlags, IUpdateListener listener) { + if (checkers.containsKey(listener)) { return; + } trace("Adding update checker for " + profileId + " at " + getTimeStamp()); //$NON-NLS-1$ //$NON-NLS-2$ - UpdateCheckThread thread = new UpdateCheckThread(profileId, query, delay, poll, listener); + UpdateCheckThread thread = new UpdateCheckThread(profileId, query, delay, poll, repositoryFlags, listener); checkers.put(listener, thread); thread.start(); } @@ -121,18 +134,17 @@ public void removeUpdateCheck(IUpdateListener listener) { * Return the array of ius in the profile that have updates * available. */ - Collection checkForUpdates(String profileId, IQuery query) { + Collection checkForUpdates(String profileId, IQuery query, + int repositoryFlags) { IProfile profile = getProfileRegistry().getProfile(profileId); ArrayList iusWithUpdates = new ArrayList<>(); if (profile == null) return Collections.emptyList(); ProvisioningContext context = new ProvisioningContext(agent); - context.setMetadataRepositories(getAvailableRepositories()); + context.setMetadataRepositories(getAvailableRepositories(repositoryFlags)); if (query == null) query = QueryUtil.createIUAnyQuery(); - Iterator iter = profile.query(query, null).iterator(); - while (iter.hasNext()) { - IInstallableUnit iu = iter.next(); + for (IInstallableUnit iu : profile.query(query, null)) { IQueryResult replacements = getPlanner().updatesFor(iu, context, null); if (!replacements.isEmpty()) iusWithUpdates.add(iu); @@ -143,9 +155,9 @@ Collection checkForUpdates(String profileId, IQuery available = new ArrayList<>(); for (URI repositorie : repositories) { try { diff --git a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/provisional/p2/updatechecker/IUpdateChecker.java b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/provisional/p2/updatechecker/IUpdateChecker.java index 299273909a..096dc33254 100644 --- a/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/provisional/p2/updatechecker/IUpdateChecker.java +++ b/bundles/org.eclipse.equinox.p2.updatechecker/src/org/eclipse/equinox/internal/provisional/p2/updatechecker/IUpdateChecker.java @@ -7,12 +7,13 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.updatechecker; +import java.util.function.IntSupplier; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.query.IQuery; @@ -22,40 +23,51 @@ * whether to retrieve the updates, inform the user, etc. */ public interface IUpdateChecker { - public static final String SERVICE_NAME = IUpdateChecker.class.getName(); - public static long ONE_TIME_CHECK = -1L; + String SERVICE_NAME = IUpdateChecker.class.getName(); + long ONE_TIME_CHECK = -1L; /** - * Adds an update listener that will be notified when updates are available for all - * installable units that satisfy the given query. The listener will remain - * registered until removed using the {@link #removeUpdateCheck(IUpdateListener)} - * method. Adding a listener that is identical to a listener that is already registered - * has no effect. + * Adds an update listener that will be notified when updates are available for + * all installable units that satisfy the given query. The listener will remain + * registered until removed using the + * {@link #removeUpdateCheck(IUpdateListener)} method. Adding a listener that is + * identical to a listener that is already registered has no effect. *

- * Once the listener is registered, it will continue to receive notification of updates - * based on the specified polling frequency. However, if a delay value of {@link #ONE_TIME_CHECK} - * is used, only a single update check will occur for that listener. If this delay value - * is used, the specified polling frequency is ignored. - * - * @param profileId The profile id to check for updates - * @param iusToCheckQuery An installable unit query that matches the units to check for updates - * @param delay The delay in milliseconds before the first query should occur, or {@link #ONE_TIME_CHECK} - * to indicate that a single update check should occur immediately - * @param poll The polling frequency, in milliseconds, between checks for updates - * @param listener The listener to be notified of updates + * Once the listener is registered, it will continue to receive notification of + * updates based on the specified polling frequency. However, if a delay value + * of {@link #ONE_TIME_CHECK} is used, only a single update check will occur for + * that listener. If this delay value is used, the specified polling frequency + * is ignored. + * + * @param profileId The profile id to check for updates + * @param iusToCheckQuery An installable unit query that matches the units to + * check for updates + * @param delay The delay in milliseconds before the first query + * should occur, or {@link #ONE_TIME_CHECK} to indicate + * that a single update check should occur immediately + * @param poll The polling frequency, in milliseconds, between checks + * for updates + * @param repositoryFlagsSupplier the repository flags to be used for the update check + * @param listener The listener to be notified of updates * @see #removeUpdateCheck(IUpdateListener) */ - public abstract void addUpdateCheck(String profileId, IQuery iusToCheckQuery, long delay, long poll, IUpdateListener listener); + default void addUpdateCheck(String profileId, IQuery iusToCheckQuery, long delay, long poll, + IntSupplier repositoryFlagsSupplier, IUpdateListener listener) { + addUpdateCheck(profileId, iusToCheckQuery, delay, poll, listener); + } + + void addUpdateCheck(String profileId, IQuery iusToCheckQuery, long delay, long poll, + IUpdateListener listener); /** * Removes an update listener from the set of listeners registered with this update * checker. If an update check is currently in progress the listener may still receive * events after this method returns. Removing a listener that is not registered has * no effect. - * + * * @param listener The listener to remove * @see #addUpdateCheck(String, IQuery, long, long, IUpdateListener) */ - public abstract void removeUpdateCheck(IUpdateListener listener); + void removeUpdateCheck(IUpdateListener listener); } \ No newline at end of file