Skip to content

Commit

Permalink
Speed up assembly of repositories / products
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 22, 2024
1 parent c18717a commit b7109c5
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,18 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.IRunnableWithProgress;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;

public class ImmutableInMemoryMetadataRepository implements IMetadataRepository {
public class ImmutableInMemoryMetadataRepository extends QueryableArray implements IMetadataRepository {

private final IQueryable<IInstallableUnit> units;

public ImmutableInMemoryMetadataRepository(Set<IInstallableUnit> units) {
this.units = new QueryableArray(units);
}

@Override
public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
return units.query(query, monitor);
public ImmutableInMemoryMetadataRepository(Set<IInstallableUnit> units, boolean copy) {
super(units, copy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.RequiredPropertiesMatch;
Expand All @@ -47,6 +46,7 @@
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.core.shared.StatusTool;
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;

abstract class AbstractSlicerResolutionStrategy extends AbstractResolutionStrategy {
Expand Down Expand Up @@ -94,9 +94,9 @@ protected final IQueryable<IInstallableUnit> slice(Map<String, String> propertie
seedIUs.add(createUnitRequiring("tycho-ee", null, data.getEEResolutionHints().getMandatoryRequires()));
}

IQueryable<IInstallableUnit> baseIUCollection = new QueryableArray(availableIUs);
IQueryable<IInstallableUnit> baseIUCollection = new QueryableArray(availableIUs, false);
Slicer slicer = newSlicer((query, monitor1) -> {

//
IQueryResult<IInstallableUnit> queryResult = baseIUCollection.query(query, monitor1);
if (queryResult.isEmpty()) {
IQueryable<IInstallableUnit> additionalUnitStore = data.getAdditionalUnitStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
Expand All @@ -31,6 +30,7 @@
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.p2.publisher.FeatureDependenciesAction;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;

public class DependencyCollector extends AbstractResolutionStrategy {

Expand All @@ -51,7 +51,7 @@ public Collection<IInstallableUnit> resolve(Map<String, String> properties, IPro

result.addAll(data.getRootIUs());

IQueryable<IInstallableUnit> availableUIsQueryable = new QueryableArray(data.getAvailableIUs());
IQueryable<IInstallableUnit> availableUIsQueryable = new QueryableArray(data.getAvailableIUs(), false);
for (IInstallableUnit iu : data.getRootIUs()) {
collectIncludedIUs(availableUIsQueryable, result, errors, iu, true, monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class FinalTargetPlatformImpl extends TargetPlatformBaseImpl {

private IArtifactRepository artifactRepository;
private IMetadataRepository metadataRepository;

public FinalTargetPlatformImpl(LinkedHashSet<IInstallableUnit> installableUnits,
ExecutionEnvironmentResolutionHints executionEnvironment, IRawArtifactFileProvider jointArtifacts,
Expand All @@ -39,6 +40,7 @@ public FinalTargetPlatformImpl(LinkedHashSet<IInstallableUnit> installableUnits,
super(installableUnits, executionEnvironment, jointArtifacts, localArtifactRepository, reactorProjectLookup,
mavenArtifactLookup, shadowed);
this.artifactRepository = artifactRepository;
this.metadataRepository = new ImmutableInMemoryMetadataRepository(installableUnits, false);
}

@Override
Expand All @@ -48,7 +50,7 @@ public void reportUsedLocalIUs(Collection<IInstallableUnit> usedUnits) {

@Override
public IMetadataRepository getMetadataRepository() {
return new ImmutableInMemoryMetadataRepository(installableUnits);
return metadataRepository;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.apache.felix.resolver.util.CopyOnWriteSet;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IProvidedCapability;
Expand Down Expand Up @@ -75,6 +74,7 @@
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

Expand Down Expand Up @@ -329,7 +329,7 @@ public List<IRequirement> getAdditionalRequirements() {
public P2ResolutionResult resolveInstallableUnit(TargetPlatform context, String id, String versionRange) {

P2TargetPlatform targetPlatform = getTargetFromContext(context);
IQueryable<IInstallableUnit> queriable = new QueryableArray(targetPlatform.getInstallableUnits());
IQueryable<IInstallableUnit> queriable = new QueryableArray(targetPlatform.getInstallableUnits(), false);

VersionRange range = new VersionRange(versionRange);
IRequirement requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, id, range, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
Expand All @@ -49,6 +48,7 @@
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
import org.eclipse.tycho.p2.resolver.WrappedArtifact;
import org.eclipse.tycho.p2maven.InstallableUnitGenerator;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;

class PomInstallableUnitStore implements IQueryable<IInstallableUnit> {

Expand Down Expand Up @@ -200,7 +200,7 @@ private IQueryable<IInstallableUnit> getPomIUs() {
}
});
}
collection = new QueryableArray(installableUnitLookUp.keySet());
collection = new QueryableArray(installableUnitLookUp.keySet(), false);
}
return collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.Explanation;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.director.SimplePlanner;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
Expand All @@ -39,6 +38,7 @@
import org.eclipse.tycho.core.shared.StatusTool;
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2tools.copiedfromp2.Projector;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;
import org.eclipse.tycho.p2tools.copiedfromp2.Slicer;

public class ProjectorResolutionStrategy extends AbstractSlicerResolutionStrategy {
Expand Down Expand Up @@ -109,7 +109,7 @@ protected Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu)
};
projector.encode(createUnitRequiring("tycho", seedUnits, seedRequires),
EMPTY_IU_ARRAY /* alreadyExistingRoots */,
new QueryableArray(List.of()) /* installedIUs */, seedUnits /* newRoots */, monitor);
new QueryableArray(List.of(), false) /* installedIUs */, seedUnits /* newRoots */, monitor);
IStatus s = projector.invokeSolver(monitor);
if (s.getSeverity() == IStatus.ERROR) {
Set<Explanation> explanation = getExplanation(projector); // suppress "Cannot complete the request. Generating details."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
Expand Down Expand Up @@ -114,6 +113,7 @@
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;
import org.eclipse.tycho.p2maven.ListCompositeArtifactRepository;
import org.eclipse.tycho.p2maven.advices.MavenPropertiesAdvice;
import org.eclipse.tycho.p2tools.copiedfromp2.QueryableArray;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;
import org.eclipse.tycho.targetplatform.TargetDefinition;
import org.eclipse.tycho.targetplatform.TargetDefinitionContent;
Expand Down Expand Up @@ -334,7 +334,7 @@ private List<MavenArtifactKey> getMissingJunitBundles(ReactorProject project, Se
Collection<ProjectClasspathEntry> entries = eclipseProject.getClasspathEntries();
for (ProjectClasspathEntry entry : entries) {
if (entry instanceof JUnitClasspathContainerEntry junit) {
IQueryable<IInstallableUnit> queriable = new QueryableArray(externalUIs);
IQueryable<IInstallableUnit> queriable = new QueryableArray(externalUIs, false);
Collection<JUnitBundle> artifacts = junit.getArtifacts();
for (JUnitBundle bundle : artifacts) {
MavenArtifactKey maven = ClasspathReader.toMaven(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Iterator;
import java.util.List;

import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.internal.p2.metadata.TranslationSupport;
import org.eclipse.equinox.internal.p2.metadata.index.CapabilityIndex;
Expand All @@ -29,17 +28,21 @@
import org.eclipse.equinox.p2.metadata.index.IIndex;

public class QueryableArray extends IndexProvider<IInstallableUnit> {
private final List<IInstallableUnit> dataSet;
private final Collection<IInstallableUnit> dataSet;
private IIndex<IInstallableUnit> capabilityIndex;
private IIndex<IInstallableUnit> idIndex;
private TranslationSupport translationSupport;

public QueryableArray(IInstallableUnit[] ius) {
dataSet = CollectionUtils.unmodifiableList(ius);
this(List.of(ius), false);
}

public QueryableArray(Collection<IInstallableUnit> ius) {
dataSet = List.copyOf(ius);
this(ius, true);
}

public QueryableArray(Collection<IInstallableUnit> ius, boolean copy) {
dataSet = copy ? List.copyOf(ius) : ius;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.internal.p2.director.Messages;
import org.eclipse.equinox.internal.p2.director.QueryableArray;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnitPatch;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
Expand Down Expand Up @@ -105,11 +104,11 @@ public IQueryable<IInstallableUnit> slice(Collection<IInstallableUnit> ius, IPro
if (result.getSeverity() == IStatus.ERROR) {
return null;
}
return new QueryableArray(considered);
return new QueryableArray(considered, false);
}

private void computeNonGreedyIUs() {
IQueryable<IInstallableUnit> queryable = new QueryableArray(considered);
IQueryable<IInstallableUnit> queryable = new QueryableArray(considered, false);
for (IInstallableUnit iu : queryable.query(QueryUtil.ALL_UNITS, new NullProgressMonitor())) {
iu = iu.unresolved();
Collection<IRequirement> reqs = getRequirements(iu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void initSubject() throws Exception {

LinkedHashSet<IInstallableUnit> installableUnits = new LinkedHashSet<>();
installableUnits.add(InstallableUnitUtil.createFeatureIU("org.eclipse.example.original_feature", "1.0.0"));
IMetadataRepository context = new ImmutableInMemoryMetadataRepository(installableUnits);
IMetadataRepository context = new ImmutableInMemoryMetadataRepository(installableUnits, true);

// TODO these publishers don't produce artifacts, so we could run without file system
outputRepository = new PublishingRepositoryImpl(lookup(IProvisioningAgent.class),
Expand Down

0 comments on commit b7109c5

Please sign in to comment.