From b7109c5ca5bac03e9f678a7737c6660b1d80b38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 22 Jan 2024 11:07:03 +0100 Subject: [PATCH] Speed up assembly of repositories / products --- .../ImmutableInMemoryMetadataRepository.java | 18 ++++-------------- .../AbstractSlicerResolutionStrategy.java | 6 +++--- .../tycho/p2resolver/DependencyCollector.java | 4 ++-- .../p2resolver/FinalTargetPlatformImpl.java | 4 +++- .../tycho/p2resolver/P2ResolverImpl.java | 4 ++-- .../p2resolver/PomInstallableUnitStore.java | 4 ++-- .../ProjectorResolutionStrategy.java | 4 ++-- .../p2resolver/TargetPlatformFactoryImpl.java | 4 ++-- .../p2tools/copiedfromp2/QueryableArray.java | 11 +++++++---- .../tycho/p2tools/copiedfromp2/Slicer.java | 5 ++--- .../tycho/p2resolver/PublisherServiceTest.java | 2 +- 11 files changed, 30 insertions(+), 36 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ImmutableInMemoryMetadataRepository.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ImmutableInMemoryMetadataRepository.java index e9b60b8603..2d506b7876 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ImmutableInMemoryMetadataRepository.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/ImmutableInMemoryMetadataRepository.java @@ -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 units; - - public ImmutableInMemoryMetadataRepository(Set units) { - this.units = new QueryableArray(units); - } - - @Override - public IQueryResult query(IQuery query, IProgressMonitor monitor) { - return units.query(query, monitor); + public ImmutableInMemoryMetadataRepository(Set units, boolean copy) { + super(units, copy); } @Override diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/AbstractSlicerResolutionStrategy.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/AbstractSlicerResolutionStrategy.java index f2d64c9a95..7f38eebcc3 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/AbstractSlicerResolutionStrategy.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/AbstractSlicerResolutionStrategy.java @@ -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; @@ -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 { @@ -94,9 +94,9 @@ protected final IQueryable slice(Map propertie seedIUs.add(createUnitRequiring("tycho-ee", null, data.getEEResolutionHints().getMandatoryRequires())); } - IQueryable baseIUCollection = new QueryableArray(availableIUs); + IQueryable baseIUCollection = new QueryableArray(availableIUs, false); Slicer slicer = newSlicer((query, monitor1) -> { - +// IQueryResult queryResult = baseIUCollection.query(query, monitor1); if (queryResult.isEmpty()) { IQueryable additionalUnitStore = data.getAdditionalUnitStore(); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DependencyCollector.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DependencyCollector.java index 80f327cd79..379ecc873b 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DependencyCollector.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/DependencyCollector.java @@ -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; @@ -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 { @@ -51,7 +51,7 @@ public Collection resolve(Map properties, IPro result.addAll(data.getRootIUs()); - IQueryable availableUIsQueryable = new QueryableArray(data.getAvailableIUs()); + IQueryable availableUIsQueryable = new QueryableArray(data.getAvailableIUs(), false); for (IInstallableUnit iu : data.getRootIUs()) { collectIncludedIUs(availableUIsQueryable, result, errors, iu, true, monitor); } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/FinalTargetPlatformImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/FinalTargetPlatformImpl.java index fd15069b48..caa3cc6c63 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/FinalTargetPlatformImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/FinalTargetPlatformImpl.java @@ -30,6 +30,7 @@ public class FinalTargetPlatformImpl extends TargetPlatformBaseImpl { private IArtifactRepository artifactRepository; + private IMetadataRepository metadataRepository; public FinalTargetPlatformImpl(LinkedHashSet installableUnits, ExecutionEnvironmentResolutionHints executionEnvironment, IRawArtifactFileProvider jointArtifacts, @@ -39,6 +40,7 @@ public FinalTargetPlatformImpl(LinkedHashSet installableUnits, super(installableUnits, executionEnvironment, jointArtifacts, localArtifactRepository, reactorProjectLookup, mavenArtifactLookup, shadowed); this.artifactRepository = artifactRepository; + this.metadataRepository = new ImmutableInMemoryMetadataRepository(installableUnits, false); } @Override @@ -48,7 +50,7 @@ public void reportUsedLocalIUs(Collection usedUnits) { @Override public IMetadataRepository getMetadataRepository() { - return new ImmutableInMemoryMetadataRepository(installableUnits); + return metadataRepository; } @Override diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2ResolverImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2ResolverImpl.java index e02bc5fbd3..21db213c82 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2ResolverImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/P2ResolverImpl.java @@ -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; @@ -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; @@ -329,7 +329,7 @@ public List getAdditionalRequirements() { public P2ResolutionResult resolveInstallableUnit(TargetPlatform context, String id, String versionRange) { P2TargetPlatform targetPlatform = getTargetFromContext(context); - IQueryable queriable = new QueryableArray(targetPlatform.getInstallableUnits()); + IQueryable queriable = new QueryableArray(targetPlatform.getInstallableUnits(), false); VersionRange range = new VersionRange(versionRange); IRequirement requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, id, range, null, diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/PomInstallableUnitStore.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/PomInstallableUnitStore.java index 577da78ab8..833f07ce0c 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/PomInstallableUnitStore.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/PomInstallableUnitStore.java @@ -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; @@ -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 { @@ -200,7 +200,7 @@ private IQueryable getPomIUs() { } }); } - collection = new QueryableArray(installableUnitLookUp.keySet()); + collection = new QueryableArray(installableUnitLookUp.keySet(), false); } return collection; } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/ProjectorResolutionStrategy.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/ProjectorResolutionStrategy.java index 8bc48e5be9..3deb523f2e 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/ProjectorResolutionStrategy.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/ProjectorResolutionStrategy.java @@ -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; @@ -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 { @@ -109,7 +109,7 @@ protected Collection 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 = getExplanation(projector); // suppress "Cannot complete the request. Generating details." diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java index 6f069e6b6a..e31cfbb8e8 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/TargetPlatformFactoryImpl.java @@ -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; @@ -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; @@ -334,7 +334,7 @@ private List getMissingJunitBundles(ReactorProject project, Se Collection entries = eclipseProject.getClasspathEntries(); for (ProjectClasspathEntry entry : entries) { if (entry instanceof JUnitClasspathContainerEntry junit) { - IQueryable queriable = new QueryableArray(externalUIs); + IQueryable queriable = new QueryableArray(externalUIs, false); Collection artifacts = junit.getArtifacts(); for (JUnitBundle bundle : artifacts) { MavenArtifactKey maven = ClasspathReader.toMaven(bundle); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/QueryableArray.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/QueryableArray.java index ea5696f60b..039e6dd7e2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/QueryableArray.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/QueryableArray.java @@ -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; @@ -29,17 +28,21 @@ import org.eclipse.equinox.p2.metadata.index.IIndex; public class QueryableArray extends IndexProvider { - private final List dataSet; + private final Collection dataSet; private IIndex capabilityIndex; private IIndex idIndex; private TranslationSupport translationSupport; public QueryableArray(IInstallableUnit[] ius) { - dataSet = CollectionUtils.unmodifiableList(ius); + this(List.of(ius), false); } public QueryableArray(Collection ius) { - dataSet = List.copyOf(ius); + this(ius, true); + } + + public QueryableArray(Collection ius, boolean copy) { + dataSet = copy ? List.copyOf(ius) : ius; } @Override diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/Slicer.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/Slicer.java index 817dbc9f0e..9aa8c9cf5f 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/Slicer.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/Slicer.java @@ -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; @@ -105,11 +104,11 @@ public IQueryable slice(Collection ius, IPro if (result.getSeverity() == IStatus.ERROR) { return null; } - return new QueryableArray(considered); + return new QueryableArray(considered, false); } private void computeNonGreedyIUs() { - IQueryable queryable = new QueryableArray(considered); + IQueryable queryable = new QueryableArray(considered, false); for (IInstallableUnit iu : queryable.query(QueryUtil.ALL_UNITS, new NullProgressMonitor())) { iu = iu.unresolved(); Collection reqs = getRequirements(iu); diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java index 1a5eaf0315..c6adcc27d2 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/PublisherServiceTest.java @@ -69,7 +69,7 @@ public void initSubject() throws Exception { LinkedHashSet 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),