From 4a873fb87015b66a136c606180d4991b36494ce1 Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Wed, 18 Sep 2024 08:25:20 +0200 Subject: [PATCH] Ensure that a jar:file: URI is considered local for artifact requests https://github.com/eclipse-platform/eclipse.platform.ui/issues/2265 --- .../META-INF/MANIFEST.MF | 2 +- .../internal/p2/engine/DownloadManager.java | 35 +++++++++++-------- .../p2/engine/ProvisioningContext.java | 19 ++-------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF index 869c08b90..0f224210d 100644 --- a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.engine;singleton:=true -Bundle-Version: 2.10.200.qualifier +Bundle-Version: 2.10.300.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.engine.EngineActivator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java index 48becc562..cfa3ad57c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DownloadManager.java @@ -16,6 +16,7 @@ import java.net.URI; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.engine.phases.Collect; @@ -34,25 +35,29 @@ public class DownloadManager { ArrayList requestsToProcess = new ArrayList<>(); private IProvisioningAgent agent = null; + + /** + * This comparator sorts the repositories such that local repositories are first + */ + private static final Comparator LOCAL_FIRST_COMPARATOR = (arg0, arg1) -> DownloadManager.LOCAL_FIRST_URI_COMPARATOR.compare(arg0.getLocation(), arg1.getLocation()); + /** - * This Comparator sorts the repositories such that local repositories are first. - * TODO: This is copied from the ProvisioningContext class. Can we combine them? - * See https://bugs.eclipse.org/335153. + * A pattern that will recognize a local URI also of the form jar:file:. */ - private static final Comparator LOCAL_FIRST_COMPARATOR = new Comparator<>() { - private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$ - - @Override - public int compare(IArtifactRepository arg0, IArtifactRepository arg1) { - String protocol0 = arg0.getLocation().getScheme(); - String protocol1 = arg1.getLocation().getScheme(); - if (FILE_PROTOCOL.equals(protocol0) && !FILE_PROTOCOL.equals(protocol1)) - return -1; - if (!FILE_PROTOCOL.equals(protocol0) && FILE_PROTOCOL.equals(protocol1)) - return 1; - return 0; + private static final Pattern LOCAL_URI_PATTERN = Pattern.compile("^(file:|jar:file:)", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ + + /** + * This comparator sorts the repository URIs such that local URIs are first. + */ + public static final Comparator LOCAL_FIRST_URI_COMPARATOR = (arg0, arg1) -> { + boolean isLocal0 = LOCAL_URI_PATTERN.matcher(arg0.toString()).find(); + boolean isLocal1 = LOCAL_URI_PATTERN.matcher(arg1.toString()).find(); + if (isLocal0 != isLocal1) { + return isLocal0 ? -1 : 1; } + return 0; }; + private Set ius; public DownloadManager(ProvisioningContext context, IProvisioningAgent agent) { diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java index 998a9b3c0..5560d8f1a 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProvisioningContext.java @@ -20,6 +20,7 @@ import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.engine.DebugHelper; +import org.eclipse.equinox.internal.p2.engine.DownloadManager; import org.eclipse.equinox.internal.p2.repository.Transport; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; @@ -51,8 +52,6 @@ public class ProvisioningContext { private Set failedArtifactRepositories = new HashSet<>(); private Set failedMetadataRepositories = new HashSet<>(); - private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$ - class ArtifactRepositoryQueryable implements IQueryable { List repositories; @@ -71,20 +70,6 @@ public boolean contains(IArtifactRepository element) { } } - /** - * This Comparator sorts the repositories such that local repositories are first - */ - private static final Comparator LOCAL_FIRST_COMPARATOR = (arg0, arg1) -> { - String protocol0 = arg0.getScheme(); - String protocol1 = arg1.getScheme(); - - if (FILE_PROTOCOL.equals(protocol0) && !FILE_PROTOCOL.equals(protocol1)) - return -1; - if (!FILE_PROTOCOL.equals(protocol0) && FILE_PROTOCOL.equals(protocol1)) - return 1; - return 0; - }; - /** * Instructs the provisioning context to follow metadata repository references when * providing queryables for obtaining metadata and artifacts. When this property is set to @@ -183,7 +168,7 @@ public IQueryable getArtifactRepositories(IProgressMonitor private List getLoadedArtifactRepositories(IProgressMonitor monitor) { IArtifactRepositoryManager repoManager = agent.getService(IArtifactRepositoryManager.class); URI[] repositories = artifactRepositories == null ? repoManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL) : artifactRepositories; - Arrays.sort(repositories, LOCAL_FIRST_COMPARATOR); + Arrays.sort(repositories, DownloadManager.LOCAL_FIRST_URI_COMPARATOR); List repos = new ArrayList<>(); SubMonitor sub = SubMonitor.convert(monitor, repositories.length + 1);