Skip to content

Commit

Permalink
Ensure that a jar:file: URI is considered local for artifact requests
Browse files Browse the repository at this point in the history
  • Loading branch information
merks committed Sep 18, 2024
1 parent 1e6c36e commit 4a873fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,25 +35,29 @@ public class DownloadManager {
ArrayList<IArtifactRequest> requestsToProcess = new ArrayList<>();
private IProvisioningAgent agent = null;


/**
* This comparator sorts the repositories such that local repositories are first
*/
private static final Comparator<IArtifactRepository> 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<IArtifactRepository> 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<URI> 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<IInstallableUnit> ius;

public DownloadManager(ProvisioningContext context, IProvisioningAgent agent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,8 +52,6 @@ public class ProvisioningContext {
private Set<URI> failedArtifactRepositories = new HashSet<>();
private Set<URI> failedMetadataRepositories = new HashSet<>();

private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$

class ArtifactRepositoryQueryable implements IQueryable<IArtifactRepository> {
List<IArtifactRepository> repositories;

Expand All @@ -71,20 +70,6 @@ public boolean contains(IArtifactRepository element) {
}
}

/**
* This Comparator sorts the repositories such that local repositories are first
*/
private static final Comparator<URI> 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
Expand Down Expand Up @@ -183,7 +168,7 @@ public IQueryable<IArtifactRepository> getArtifactRepositories(IProgressMonitor
private List<IArtifactRepository> 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<IArtifactRepository> repos = new ArrayList<>();
SubMonitor sub = SubMonitor.convert(monitor, repositories.length + 1);
Expand Down

0 comments on commit 4a873fb

Please sign in to comment.