From 6cc111153c07b41df5d6f0fad384f1cef25388f0 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 11 Nov 2023 11:37:07 +0100 Subject: [PATCH] Adapt to P2 enhancements in Eclipse 2023-12 And add tests for support of Product Update-site names from the tycho-4.0.x branch. --- p2-maven-plugin/pom.xml | 16 ++-- .../tycho/p2maven/InstallableUnitSlicer.java | 2 +- .../eclipse/tycho/p2maven/ListQueryable.java | 3 +- .../tycho/p2maven/actions/ProductFile2.java | 7 +- pom.xml | 2 +- tycho-api/pom.xml | 4 +- tycho-build/pom.xml | 12 +-- .../AbstractMetadataRepository2.java | 6 ++ .../ImmutableInMemoryMetadataRepository.java | 11 ++- .../p2/repository/QueryableCollection.java | 75 ------------------- .../p2/tools/publisher/ExpandedProduct.java | 20 ++--- .../AbstractSlicerResolutionStrategy.java | 25 +++---- .../tycho/p2resolver/DependencyCollector.java | 4 +- .../tycho/p2resolver/P2ResolverImpl.java | 6 +- .../p2resolver/PomInstallableUnitStore.java | 6 +- .../ProjectorResolutionStrategy.java | 2 +- .../p2resolver/TargetPlatformFactoryImpl.java | 5 +- .../tycho/p2tools/TychoMirrorApplication.java | 64 ++-------------- .../copiedfromp2/MirrorApplication.java | 3 +- .../gpg/SignRepositoryArtifactsMojo.java | 9 +-- .../aProduct.product | 24 ++++++ .../product.update_repository/pom.xml | 64 ++++++++++++++++ .../tycho/test/product/ProductBuildTest.java | 53 +++++++++++++ 23 files changed, 214 insertions(+), 209 deletions(-) delete mode 100644 tycho-core/src/main/java/org/eclipse/tycho/p2/repository/QueryableCollection.java create mode 100644 tycho-its/projects/product.update_repository/aProduct.product create mode 100644 tycho-its/projects/product.update_repository/pom.xml diff --git a/p2-maven-plugin/pom.xml b/p2-maven-plugin/pom.xml index e7d6d48400..91f5ef57d4 100644 --- a/p2-maven-plugin/pom.xml +++ b/p2-maven-plugin/pom.xml @@ -37,22 +37,22 @@ org.eclipse.platform org.eclipse.equinox.p2.publisher - 1.8.100 + 1.9.0 org.eclipse.platform org.eclipse.equinox.p2.director - 2.6.100 + 2.6.200 org.eclipse.platform org.eclipse.equinox.p2.engine - 2.8.100 + 2.9.0 org.eclipse.platform org.eclipse.equinox.p2.metadata - 2.7.100 + 2.8.0 org.eclipse.platform @@ -66,7 +66,7 @@ org.eclipse.platform org.eclipse.equinox.p2.publisher.eclipse - 1.5.100 + 1.5.200 org.eclipse.platform @@ -97,12 +97,12 @@ org.eclipse.platform org.eclipse.equinox.p2.metadata.repository - 1.5.100 + 1.5.200 org.eclipse.platform org.eclipse.equinox.p2.updatesite - 1.3.100 + 1.3.200 @@ -149,7 +149,7 @@ org.eclipse.platform org.eclipse.equinox.p2.repository.tools - 2.4.100 + 2.4.200 diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/InstallableUnitSlicer.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/InstallableUnitSlicer.java index 885964014e..2c9779fd2f 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/InstallableUnitSlicer.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/InstallableUnitSlicer.java @@ -57,7 +57,7 @@ public IQueryResult computeDependencies(Collection avaiableIUs) throws CoreException { NullProgressMonitor monitor = new NullProgressMonitor(); PermissiveSlicer slicer = new TychoSlicer(avaiableIUs); - IQueryable slice = slicer.slice(rootIus.toArray(IInstallableUnit[]::new), monitor); + IQueryable slice = slicer.slice(rootIus, monitor); IStatus sliceStatus = slicer.getStatus(); if (sliceStatus.matches(IStatus.ERROR)) { throw new CoreException(sliceStatus); diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/ListQueryable.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/ListQueryable.java index 46bca84054..c436bece82 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/ListQueryable.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/ListQueryable.java @@ -77,7 +77,8 @@ public Iterator iterator() { return stream().iterator(); } - private Stream stream() { + @Override + public Stream stream() { return resultList.stream().flatMap(r -> StreamSupport .stream(Spliterators.spliteratorUnknownSize(r.iterator(), Spliterator.ORDERED), false)); } diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/actions/ProductFile2.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/actions/ProductFile2.java index 0dd538e50f..350dece93d 100644 --- a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/actions/ProductFile2.java +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/actions/ProductFile2.java @@ -46,12 +46,7 @@ protected void processPlugin(Attributes attributes) { if (os != null || ws != null || arch != null) { entry.setEnvironment(os, ws, arch, null); } - - if (isFragment) { - fragments.add(entry); - } else { - plugins.add(entry); - } + plugins.add(entry); } @Override diff --git a/pom.xml b/pom.xml index 42223d92d0..f1799246d5 100644 --- a/pom.xml +++ b/pom.xml @@ -292,7 +292,7 @@ org.eclipse.platform org.eclipse.equinox.p2.repository - 2.7.100 + 2.8.0 org.eclipse.platform diff --git a/tycho-api/pom.xml b/tycho-api/pom.xml index b53fb52402..c863230358 100644 --- a/tycho-api/pom.xml +++ b/tycho-api/pom.xml @@ -28,12 +28,12 @@ org.eclipse.platform org.eclipse.equinox.p2.metadata - 2.7.100 + 2.8.0 org.eclipse.platform org.eclipse.equinox.p2.publisher - 1.8.100 + 1.9.0 diff --git a/tycho-build/pom.xml b/tycho-build/pom.xml index 6343b36030..3e6cfd139d 100644 --- a/tycho-build/pom.xml +++ b/tycho-build/pom.xml @@ -59,26 +59,26 @@ org.eclipse.platform org.eclipse.equinox.p2.publisher - 1.8.100 + 1.9.0 org.eclipse.platform org.eclipse.equinox.p2.director - 2.6.100 + 2.6.200 org.eclipse.platform org.eclipse.equinox.p2.engine - 2.8.100 + 2.9.0 org.eclipse.platform org.eclipse.equinox.p2.metadata - 2.7.100 + 2.8.0 org.eclipse.platform @@ -95,7 +95,7 @@ org.eclipse.platform org.eclipse.equinox.p2.publisher.eclipse - 1.5.100 + 1.5.200 @@ -124,7 +124,7 @@ org.eclipse.platform org.eclipse.equinox.p2.metadata.repository - 1.5.100 + 1.5.200 org.eclipse.tycho diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/AbstractMetadataRepository2.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/AbstractMetadataRepository2.java index 45fc6cd561..f04db8e2d1 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/AbstractMetadataRepository2.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/AbstractMetadataRepository2.java @@ -63,6 +63,12 @@ public void addReferences(Collection references) // not supported } + @Override + public boolean removeReferences(Collection references) { + // not supported + return false; + } + @Override public Collection getReferences() { // not supported 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 286ac3d312..e9b60b8603 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,21 +24,23 @@ 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; public class ImmutableInMemoryMetadataRepository implements IMetadataRepository { - private final QueryableCollection units; + private final IQueryable units; public ImmutableInMemoryMetadataRepository(Set units) { - this.units = new QueryableCollection(units); + this.units = new QueryableArray(units); } @Override @@ -142,6 +144,11 @@ public void addReferences(Collection references) throw new UnsupportedOperationException(); } + @Override + public boolean removeReferences(Collection references) { + throw new UnsupportedOperationException(); + } + @Override public boolean removeInstallableUnits(Collection installableUnits) { throw new UnsupportedOperationException(); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/QueryableCollection.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/QueryableCollection.java deleted file mode 100644 index 3abcecc6d3..0000000000 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/repository/QueryableCollection.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2012 IBM Corporation and others. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Cloudsmith Inc. - query indexes - * Sonatype, Inc. - adapted for Tycho - *******************************************************************************/ -package org.eclipse.tycho.p2.repository; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -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; -import org.eclipse.equinox.internal.p2.metadata.index.IdIndex; -import org.eclipse.equinox.internal.p2.metadata.index.IndexProvider; -import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.p2.metadata.KeyWithLocale; -import org.eclipse.equinox.p2.metadata.index.IIndex; - -// This class was copied from org.eclipse.equinox.internal.p2.director.QueryableArray -public class QueryableCollection extends IndexProvider { - private final Collection dataSet; - private IIndex capabilityIndex; - private IIndex idIndex; - private TranslationSupport translationSupport; - - public QueryableCollection(Collection ius) { - dataSet = new ArrayList<>(ius); - } - - @Override - public Iterator everything() { - return dataSet.iterator(); - } - - @Override - public synchronized IIndex getIndex(String memberName) { - if (InstallableUnit.MEMBER_PROVIDED_CAPABILITIES.equals(memberName)) { - if (capabilityIndex == null) - capabilityIndex = new CapabilityIndex(dataSet.iterator()); - return capabilityIndex; - } - if (InstallableUnit.MEMBER_ID.equals(memberName)) { - if (idIndex == null) - idIndex = new IdIndex(dataSet.iterator()); - return idIndex; - } - return null; - } - - @Override - public synchronized Object getManagedProperty(Object client, String memberName, Object key) { - if (client instanceof IInstallableUnit iu) { - if (InstallableUnit.MEMBER_TRANSLATED_PROPERTIES.equals(memberName)) { - if (translationSupport == null) { - translationSupport = new TranslationSupport(this); - } - return key instanceof KeyWithLocale keyWithLocale // - ? translationSupport.getIUProperty(iu, keyWithLocale) - : translationSupport.getIUProperty(iu, key.toString()); - } - } - return null; - } -} diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java index 67738ca904..7126972100 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/ExpandedProduct.java @@ -67,26 +67,16 @@ public String getVersion() { } @Override - public List getBundles(boolean includeFragments) { - if (includeFragments == false) { - // currently not needed -> omitted for simplicity - throw new UnsupportedOperationException(); - } + public List getBundles() { if (getProductContentType() == ProductContentType.FEATURES) { // don't expand versions if bundles are not included in the product // TODO why is this method called anyway? - return defaults.getBundles(includeFragments); + return defaults.getBundles(); } return expandedBundles; } - @Override - public List getFragments() { - // currently not needed -> omitted for simplicity - throw new UnsupportedOperationException(); - } - @Override public List getFeatures() { return getFeatures(INCLUDED_FEATURES); @@ -111,7 +101,7 @@ private void expandVersions() { ProductVersionExpansionRun resolver = new ProductVersionExpansionRun(targetPlatform, getLocation()); if (contentType != ProductContentType.FEATURES) { expandedBundles = resolver.resolveReferences("plugin", ArtifactType.TYPE_ECLIPSE_PLUGIN, - defaults.getBundles(true)); + defaults.getBundles()); } if (contentType != ProductContentType.BUNDLES) { expandedFeatures = resolver.resolveReferences("feature", ArtifactType.TYPE_ECLIPSE_FEATURE, @@ -143,9 +133,9 @@ private Map expandVariables(Map originalMap) { // delegating methods @Override - public boolean hasBundles(boolean includeFragments) { + public boolean hasBundles() { // don't need to expand versions for this check - return defaults.hasBundles(includeFragments); + return defaults.hasBundles(); } @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 25631f6cbf..230b437b8b 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,6 +27,7 @@ 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.director.Slicer; import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability; import org.eclipse.equinox.internal.p2.metadata.RequiredCapability; @@ -42,12 +43,10 @@ import org.eclipse.equinox.p2.metadata.expression.IExpression; import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.publisher.actions.JREAction; -import org.eclipse.equinox.p2.query.IQuery; import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.IQueryable; import org.eclipse.tycho.core.shared.MavenLogger; import org.eclipse.tycho.core.shared.StatusTool; -import org.eclipse.tycho.p2.repository.QueryableCollection; import org.eclipse.tycho.p2.resolver.ResolverException; abstract class AbstractSlicerResolutionStrategy extends AbstractResolutionStrategy { @@ -95,23 +94,19 @@ protected final IQueryable slice(Map propertie seedIUs.add(createUnitRequiring("tycho-ee", null, data.getEEResolutionHints().getMandatoryRequires())); } - QueryableCollection baseIUCollection = new QueryableCollection(availableIUs); - Slicer slicer = newSlicer(new IQueryable() { + IQueryable baseIUCollection = new QueryableArray(availableIUs); + Slicer slicer = newSlicer((query, monitor1) -> { - @Override - public IQueryResult query(IQuery query, IProgressMonitor monitor) { - - IQueryResult queryResult = baseIUCollection.query(query, monitor); - if (queryResult.isEmpty()) { - IQueryable additionalUnitStore = data.getAdditionalUnitStore(); - if (additionalUnitStore != null) { - return additionalUnitStore.query(query, monitor); - } + IQueryResult queryResult = baseIUCollection.query(query, monitor1); + if (queryResult.isEmpty()) { + IQueryable additionalUnitStore = data.getAdditionalUnitStore(); + if (additionalUnitStore != null) { + return additionalUnitStore.query(query, monitor1); } - return queryResult; } + return queryResult; }, properties); - IQueryable slice = slicer.slice(seedIUs.toArray(EMPTY_IU_ARRAY), monitor); + IQueryable slice = slicer.slice(seedIUs, monitor); MultiStatus slicerStatus = slicer.getStatus(); if (slice == null || isSlicerError(slicerStatus)) { throw new ResolverException(StatusTool.toLogMessage(slicerStatus), properties.toString(), 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 18057573ee..80f327cd79 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,6 +21,7 @@ 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; @@ -30,7 +31,6 @@ 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.p2.repository.QueryableCollection; public class DependencyCollector extends AbstractResolutionStrategy { @@ -51,7 +51,7 @@ public Collection resolve(Map properties, IPro result.addAll(data.getRootIUs()); - QueryableCollection availableUIsQueryable = new QueryableCollection(data.getAvailableIUs()); + IQueryable availableUIsQueryable = new QueryableArray(data.getAvailableIUs()); for (IInstallableUnit iu : data.getRootIUs()) { collectIncludedIUs(availableUIsQueryable, result, errors, iu, true, monitor); } 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 3a5cb2b1ff..3c95a4380a 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,6 +34,7 @@ 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.internal.p2.director.Slicer; import org.eclipse.equinox.p2.metadata.IArtifactKey; import org.eclipse.equinox.p2.metadata.IInstallableUnit; @@ -72,7 +73,6 @@ import org.eclipse.tycho.core.shared.MavenLogger; import org.eclipse.tycho.core.shared.MultiLineLogger; import org.eclipse.tycho.p2.publisher.AuthoredIUAction; -import org.eclipse.tycho.p2.repository.QueryableCollection; import org.eclipse.tycho.p2.resolver.ResolverException; import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub; import org.eclipse.tycho.targetplatform.P2TargetPlatform; @@ -143,7 +143,7 @@ public Map resolveArtifactDependencies(Ta Collection artifacts) { P2TargetPlatform targetPlatform = getTargetFromContext(context); Collection roots = new ArrayList<>(); - QueryableCollection queriable = new QueryableCollection(targetPlatform.getInstallableUnits()); + IQueryable queriable = new QueryableArray(targetPlatform.getInstallableUnits()); for (ArtifactKey artifactKey : artifacts) { VersionRange range = new VersionRange(artifactKey.getVersion()); IQuery query = ArtifactTypeHelper.createQueryFor(artifactKey.getType(), @@ -327,7 +327,7 @@ public List getAdditionalRequirements() { public P2ResolutionResult resolveInstallableUnit(TargetPlatform context, String id, String versionRange) { P2TargetPlatform targetPlatform = getTargetFromContext(context); - QueryableCollection queriable = new QueryableCollection(targetPlatform.getInstallableUnits()); + IQueryable queriable = new QueryableArray(targetPlatform.getInstallableUnits()); 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 a87e5fd7f8..577da78ab8 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,6 +31,7 @@ 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; @@ -45,7 +46,6 @@ import org.eclipse.tycho.core.maven.MavenArtifactFacade; import org.eclipse.tycho.core.resolver.shared.PomDependencies; import org.eclipse.tycho.p2.metadata.ReactorProjectFacade; -import org.eclipse.tycho.p2.repository.QueryableCollection; import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper; import org.eclipse.tycho.p2.resolver.WrappedArtifact; import org.eclipse.tycho.p2maven.InstallableUnitGenerator; @@ -53,7 +53,7 @@ class PomInstallableUnitStore implements IQueryable { private static final IQueryResult EMPTY_RESULT = new CollectionResult<>(Collections.emptyList()); - private QueryableCollection collection; + private IQueryable collection; private TychoProject tychoProject; private ReactorProject reactorProject; private Map installableUnitLookUp = new HashMap<>(); @@ -200,7 +200,7 @@ private IQueryable getPomIUs() { } }); } - collection = new QueryableCollection(installableUnitLookUp.keySet()); + collection = new QueryableArray(installableUnitLookUp.keySet()); } 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 c63125a946..d48f4cfb34 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 @@ -84,7 +84,7 @@ public Collection resolve(Map properties, IPro new HashSet<>(), false); projector.encode(createUnitRequiring("tycho", seedUnits, seedRequires), EMPTY_IU_ARRAY /* alreadyExistingRoots */, - new QueryableArray(EMPTY_IU_ARRAY) /* installedIUs */, seedUnits /* newRoots */, monitor); + new QueryableArray(List.of()) /* 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 34ac10e159..960c32992d 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,6 +44,7 @@ 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; @@ -56,6 +57,7 @@ import org.eclipse.equinox.p2.publisher.AdviceFileAdvice; 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.query.QueryUtil; import org.eclipse.equinox.p2.repository.IRepository; import org.eclipse.equinox.p2.repository.IRepositoryReference; @@ -104,7 +106,6 @@ import org.eclipse.tycho.p2.repository.MirroringArtifactProvider; import org.eclipse.tycho.p2.repository.ProviderOnlyArtifactRepository; import org.eclipse.tycho.p2.repository.PublishingRepository; -import org.eclipse.tycho.p2.repository.QueryableCollection; import org.eclipse.tycho.p2.repository.RepositoryArtifactProvider; import org.eclipse.tycho.p2.repository.RepositoryBlackboardKey; import org.eclipse.tycho.p2.resolver.BundlePublisher; @@ -333,7 +334,7 @@ private List getMissingJunitBundles(ReactorProject project, Se Collection entries = eclipseProject.getClasspathEntries(); for (ProjectClasspathEntry entry : entries) { if (entry instanceof JUnitClasspathContainerEntry junit) { - QueryableCollection queriable = new QueryableCollection(externalUIs); + IQueryable queriable = new QueryableArray(externalUIs); 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/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java index 9b3320b1c5..1efb1a03bd 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java @@ -18,8 +18,6 @@ import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toList; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -32,7 +30,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; @@ -40,7 +37,6 @@ import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability; import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; import org.eclipse.equinox.internal.p2.metadata.RequiredCapability; -import org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; @@ -51,7 +47,6 @@ import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.query.CollectionResult; -import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.IQueryable; import org.eclipse.equinox.p2.query.QueryUtil; import org.eclipse.equinox.p2.repository.IRepository; @@ -162,13 +157,13 @@ private boolean matchesSelectionContext(IMatchExpression filte } @Override - public IQueryable slice(IInstallableUnit[] ius, IProgressMonitor monitor) { + public IQueryable slice(Collection ius, IProgressMonitor monitor) { IQueryable slice = super.slice(ius, monitor); if (includeAllSource && targetPlatform != null) { Set collected = slice.query(QueryUtil.ALL_UNITS, null).toSet(); Set result = new HashSet<>(collected); var allUnits = targetPlatform.getMetadataRepository().query(QueryUtil.ALL_UNITS, null); - Map> sourceIus = stream(allUnits) + Map> sourceIus = allUnits.stream() .filter(iu -> iu.getId().endsWith(SOURCE_SUFFIX)) .collect(groupingBy(IInstallableUnit::getId)); for (IInstallableUnit iu : collected) { @@ -269,7 +264,7 @@ private List> removeProvidedItems(Collection allElements, } try { URI location = reference.getLocation(); - IRepository repository = loadRepository(repoManager, location, monitor); + IRepository repository = repoManager.loadRepository(location, monitor); referencedRepositories.add(repository); } catch (IllegalArgumentException e) { if (e.getCause() instanceof URISyntaxException uriException) { @@ -279,7 +274,7 @@ private List> removeProvidedItems(Collection allElements, } } } - allElements.removeIf(e -> referencedRepositories.stream().anyMatch(repo -> contains(repo, e))); + allElements.removeIf(e -> referencedRepositories.stream().anyMatch(repo -> repo.contains(e))); return referencedRepositories; } @@ -287,8 +282,7 @@ private void removeNotProvidingReferences(Map> fullReposit List> metadataRepositories, Set removableReferenceURIs) { Map> usedRepositoryItems = new HashMap<>(); for (IRepository repo : metadataRepositories) { - IQueryResult allUnits = repo.query(QueryUtil.ALL_UNITS, null); - Set usedRepoContent = stream(allUnits) + Set usedRepoContent = repo.query(QueryUtil.ALL_UNITS, null).stream() .filter(a -> fullRepositoryContent.getOrDefault(a.getId(), List.of()).contains(a.getVersion())) .collect(Collectors.toSet()); usedRepositoryItems.put(repo.getLocation(), usedRepoContent); @@ -306,53 +300,7 @@ private void removeNotProvidingReferences(Map> fullReposit IMetadataRepository repository = getDestinationMetadataRepository(); List discardedReferences = repository.getReferences().stream() .filter(rr -> !usedRepositoryItems.keySet().contains(rr.getLocation())).toList(); - removeRepositoryReferences(repository, discardedReferences); - } - - //TODO: Just call IMetadataRepository.removeReferences once available: https://github.com/eclipse-equinox/p2/pull/338 - private static void removeRepositoryReferences(IMetadataRepository metadataRepository, - Collection references) { - if (metadataRepository instanceof LocalMetadataRepository localRepo) { - try { - Field repositoriesField = LocalMetadataRepository.class.getDeclaredField("repositories"); - repositoriesField.trySetAccessible(); - Method save = LocalMetadataRepository.class.getDeclaredMethod("save"); - save.trySetAccessible(); - @SuppressWarnings("unchecked") - Set repositories = (Set) repositoriesField.get(localRepo); - repositories.removeAll(references); - save.invoke(localRepo); - } catch (ReflectiveOperationException e) { - throw new IllegalStateException("Failed to clean-up references from assembled repository", e); - } - } - } - - //TODO: just call IRepositoryManager.loadRepository() once available: https://github.com/eclipse-equinox/p2/pull/311 - @SuppressWarnings("unchecked") - private static IRepository loadRepository(IRepositoryManager mgr, URI location, IProgressMonitor monitor) - throws ProvisionException { - if (mgr instanceof IArtifactRepositoryManager artifactRepoManager) { - return (IRepository) artifactRepoManager.loadRepository(location, monitor); - } else if (mgr instanceof IMetadataRepositoryManager metadataMangager) { - return (IRepository) metadataMangager.loadRepository(location, monitor); - } - throw new AssertionError("Unsupported IRepositoryManager type" + mgr.getClass()); - } - - //TODO: just call IRepositoryManager.contains() once available: https://github.com/eclipse-equinox/p2/pull/314 - private static boolean contains(IRepository repository, T element) { - if (repository instanceof IArtifactRepository artifactRepository) { - return artifactRepository.contains((IArtifactKey) element); - } else if (repository instanceof IMetadataRepository metadataRepository) { - return !metadataRepository.query(QueryUtil.createIUQuery((IInstallableUnit) element), null).isEmpty(); - } - throw new AssertionError("Unsupported IRepository type" + repository.getClass()); - } - - //TODO: use query.stream() once available: https://github.com/eclipse-equinox/p2/pull/312 is available - private static Stream stream(IQueryResult result) { - return StreamSupport.stream(result.spliterator(), false); + repository.removeReferences(discardedReferences); } public void setIncludeSources(boolean includeAllSource, TargetPlatform targetPlatform) { diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java index 2e7879dae9..8b866fbbf5 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java @@ -443,8 +443,7 @@ private IQueryable slice(IProgressMonitor monitor) throws Prov return performResolution(monitor); Slicer slicer = createSlicer(slicingOptions); - IQueryable slice = slicer.slice(sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), - monitor); + IQueryable slice = slicer.slice(sourceIUs, monitor); if (slice != null && slicingOptions.latestVersionOnly()) { IQueryResult queryResult = slice.query(QueryUtil.createLatestIUQuery(), monitor); diff --git a/tycho-gpg-plugin/src/main/java/org/eclipse/tycho/gpg/SignRepositoryArtifactsMojo.java b/tycho-gpg-plugin/src/main/java/org/eclipse/tycho/gpg/SignRepositoryArtifactsMojo.java index 0189ad47d5..564ba2ee09 100644 --- a/tycho-gpg-plugin/src/main/java/org/eclipse/tycho/gpg/SignRepositoryArtifactsMojo.java +++ b/tycho-gpg-plugin/src/main/java/org/eclipse/tycho/gpg/SignRepositoryArtifactsMojo.java @@ -14,8 +14,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -188,9 +186,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { } var artifactKeys = artifactRepository.query(ArtifactKeyQuery.ALL_KEYS, null); - var descriptors = StreamSupport.stream(artifactKeys.spliterator(), false) - .map(artifactRepository::getArtifactDescriptors).map(Arrays::asList).flatMap(Collection::stream) - .collect(Collectors.toList()); + var descriptors = artifactKeys.stream().map(artifactRepository::getArtifactDescriptors).map(Arrays::asList) + .flatMap(Collection::stream).toList(); descriptors.parallelStream() .forEach(it -> handle(it, artifactRepository.getArtifactFile(it), signer, keys)); @@ -281,7 +278,7 @@ private void handle(IArtifactDescriptor artifactDescriptor, File artifact, Proxy try { var signatures = signer.generateSignature(artifact); var signerKeys = signatures.all().stream().map(PGPSignature::getKeyID) - .flatMap(id -> signer.getPublicKeys().getKeys(id).stream()).collect(Collectors.toList()); + .flatMap(id -> signer.getPublicKeys().getKeys(id).stream()).toList(); var keyStore = KeyStore.create(existingKeys); keyStore.add(signerKeys); allKeys.add(keyStore); diff --git a/tycho-its/projects/product.update_repository/aProduct.product b/tycho-its/projects/product.update_repository/aProduct.product new file mode 100644 index 0000000000..92dbb32018 --- /dev/null +++ b/tycho-its/projects/product.update_repository/aProduct.product @@ -0,0 +1,24 @@ + + + + + + + + + + -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts + + + + + + + + + + + + + + diff --git a/tycho-its/projects/product.update_repository/pom.xml b/tycho-its/projects/product.update_repository/pom.xml new file mode 100644 index 0000000000..290fd4df2d --- /dev/null +++ b/tycho-its/projects/product.update_repository/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + foo.bar + aProduct + 1.0.0 + eclipse-repository + + UTF-8 + + + + eclipse-latest + p2 + ${target-platform} + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + + materialize-products + + materialize-products + + + + + aProduct + + + + + + archive-products + + archive-products + + + + + aProduct + + + + + + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductBuildTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductBuildTest.java index 59ccaf6096..aad80f804c 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductBuildTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/product/ProductBuildTest.java @@ -9,11 +9,15 @@ *******************************************************************************/ package org.eclipse.tycho.test.product; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -21,6 +25,7 @@ import java.util.stream.Collectors; import org.apache.maven.it.Verifier; +import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.test.AbstractTychoIntegrationTest; import org.junit.Test; @@ -68,4 +73,52 @@ protected void checkPGP(Verifier verifier, String repositoryArtifacts) throws IO } } + + @Test + public void testAdditionOfUpdateRepositories() throws Exception { + Verifier verifier = getVerifier("product.update_repository", true); + verifier.executeGoals(List.of("clean", "verify")); + verifier.verifyErrorFreeLog(); + TargetEnvironment env = TargetEnvironment.getRunningEnvironment(); + Path baseDir = Path.of(verifier.getBasedir()); + Path productPath = baseDir.resolve("target/products/aProduct"); + Path osPlatformPath = productPath.resolve(Path.of(env.getOs(), env.getWs(), env.getArch())); + if (env.getOs().equals("macosx")) { + osPlatformPath = osPlatformPath.resolve("Eclipse.app/Contents/Eclipse"); + } + Path p2EnginePath = osPlatformPath.resolve("p2/org.eclipse.equinox.p2.engine"); + + List expectedReferences = List.of( + new UpdateSiteReference("https://foo.bar.org", null, true), + new UpdateSiteReference("https://foo.bar.org/releases", "Latest release", true), + new UpdateSiteReference("https://foo.bar.org/snapshots", "Latest snapshot", false)); + + assertUpdateRepositoryReferences(expectedReferences, + p2EnginePath.resolve(".settings/org.eclipse.equinox.p2.artifact.repository.prefs")); + assertUpdateRepositoryReferences(expectedReferences, + p2EnginePath.resolve(".settings/org.eclipse.equinox.p2.metadata.repository.prefs")); + + assertUpdateRepositoryReferences(expectedReferences, p2EnginePath.resolve( + "profileRegistry/DefaultProfile.profile/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs")); + assertUpdateRepositoryReferences(expectedReferences, p2EnginePath.resolve( + "profileRegistry/DefaultProfile.profile/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs")); + } + + private record UpdateSiteReference(String uri, String name, boolean enabled) { + } + + private static void assertUpdateRepositoryReferences(List expectedReferences, Path path) + throws IOException { + List prefLines = Files.readAllLines(path); + for (UpdateSiteReference reference : expectedReferences) { + String preferencePrefix = "repositories/" + reference.uri.replace(":", "\\:").replace("/", "_"); + assertThat(prefLines, hasItem(preferencePrefix + "/uri=" + reference.uri.replace(":", "\\:"))); + assertThat(prefLines, hasItem(preferencePrefix + "/enabled=" + reference.enabled)); + if (reference.name != null) { + assertThat(prefLines, hasItem(preferencePrefix + "/nickname=" + reference.name)); + } else { + assertFalse(prefLines.stream().anyMatch(l -> l.startsWith(preferencePrefix + "/nickname="))); + } + } + } }