From 89291b56570d97235aec4ed680fbbdd38ae96d44 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 This also reverts the temporary changes of PublishProductToolImpl made in https://github.com/eclipse-tycho/tycho/pull/2929, which are obsolete now that the new P2 version has support for names of update-sites built in. --- p2-maven-plugin/pom.xml | 20 +-- .../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 | 14 +- .../AbstractMetadataRepository2.java | 6 + .../ImmutableInMemoryMetadataRepository.java | 11 +- .../p2/repository/QueryableCollection.java | 75 ----------- .../p2/tools/publisher/ExpandedProduct.java | 20 +-- .../publisher/PublishProductToolImpl.java | 120 +----------------- .../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 +- tycho-gpg-plugin/pom.xml | 7 +- .../gpg/SignRepositoryArtifactsMojo.java | 9 +- 22 files changed, 84 insertions(+), 331 deletions(-) delete mode 100644 tycho-core/src/main/java/org/eclipse/tycho/p2/repository/QueryableCollection.java diff --git a/p2-maven-plugin/pom.xml b/p2-maven-plugin/pom.xml index 60069ee441..cc8f085e6a 100644 --- a/p2-maven-plugin/pom.xml +++ b/p2-maven-plugin/pom.xml @@ -28,7 +28,7 @@ org.eclipse.platform org.eclipse.equinox.p2.core - 2.10.100 + 2.10.200 org.eclipse.platform @@ -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 @@ -144,12 +144,12 @@ org.eclipse.platform org.eclipse.equinox.p2.director.app - 1.3.100 + 1.3.200 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 bd139449b8..a892798fcd 100644 --- a/pom.xml +++ b/pom.xml @@ -297,7 +297,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 799ef8f4e6..751f87d9b3 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 4a53c82945..55144a3744 100644 --- a/tycho-build/pom.xml +++ b/tycho-build/pom.xml @@ -48,7 +48,7 @@ org.eclipse.platform org.eclipse.equinox.p2.core - 2.10.100 + 2.10.200 @@ -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/p2/tools/publisher/PublishProductToolImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublishProductToolImpl.java index 6e6a8c0d63..7ae086009b 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublishProductToolImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublishProductToolImpl.java @@ -16,38 +16,21 @@ import static org.eclipse.tycho.p2.tools.publisher.DependencySeedUtil.createSeed; import java.io.File; -import java.lang.reflect.Field; -import java.net.URI; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; import org.eclipse.core.runtime.AssertionFailedException; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.p2.metadata.TouchpointInstruction; import org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor; import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.Version; import org.eclipse.equinox.p2.publisher.AdviceFileAdvice; -import org.eclipse.equinox.p2.publisher.IPublisherAction; import org.eclipse.equinox.p2.publisher.IPublisherAdvice; -import org.eclipse.equinox.p2.publisher.eclipse.ConfigCUsAction; -import org.eclipse.equinox.p2.publisher.eclipse.IConfigAdvice; import org.eclipse.equinox.p2.publisher.eclipse.ProductAction; -import org.eclipse.equinox.p2.publisher.eclipse.ProductFileAdvice; -import org.eclipse.equinox.p2.repository.IRepository; -import org.eclipse.equinox.p2.repository.IRepositoryReference; import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; -import org.eclipse.equinox.p2.repository.spi.RepositoryReference; import org.eclipse.tycho.ArtifactKey; import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.BuildFailureException; @@ -58,7 +41,6 @@ import org.eclipse.tycho.p2.repository.PublishingRepository; import org.eclipse.tycho.p2.tools.publisher.facade.PublishProductTool; import org.eclipse.tycho.targetplatform.P2TargetPlatform; -import org.xml.sax.Attributes; /** * Tool for transforming product definition source files into p2 metadata and artifacts. Includes @@ -95,58 +77,7 @@ public List publishProduct(File productFile, File launcherBinari IPublisherAdvice[] advice = getProductSpecificAdviceFileAdvice(productFile, expandedProduct); - ProductAction action = new ProductAction(null, expandedProduct, flavor, launcherBinaries) { - //TODO: Remove this anonymous extension once https://github.com/eclipse-equinox/p2/pull/353 is available - @Override - protected IPublisherAction createConfigCUsAction() { - return new ConfigCUsAction(info, flavor, id, version) { - private static final Collection PROPERTIES_TO_SKIP = Set.of("osgi.frameworkClassPath", - "osgi.framework", "osgi.bundles", "eof", "eclipse.p2.profile", "eclipse.p2.data.area", - "org.eclipse.update.reconcile", "org.eclipse.equinox.simpleconfigurator.configUrl"); - - @Override - protected String[] getConfigurationStrings(Collection configAdvice) { - String configurationData = ""; //$NON-NLS-1$ - String unconfigurationData = ""; //$NON-NLS-1$ - Set properties = new HashSet<>(); - for (IConfigAdvice advice : configAdvice) { - for (Entry aProperty : advice.getProperties().entrySet()) { - String key = aProperty.getKey(); - if (!PROPERTIES_TO_SKIP.contains(key) && !properties.contains(key)) { - properties.add(key); - Map parameters = new LinkedHashMap<>(); - parameters.put("propName", key); //$NON-NLS-1$ - parameters.put("propValue", aProperty.getValue()); //$NON-NLS-1$ - configurationData += TouchpointInstruction.encodeAction("setProgramProperty", //$NON-NLS-1$ - parameters); - parameters.put("propValue", ""); //$NON-NLS-1$//$NON-NLS-2$ - unconfigurationData += TouchpointInstruction.encodeAction("setProgramProperty", //$NON-NLS-1$ - parameters); - } - } - if (advice instanceof ProductFileAdvice) { - for (IRepositoryReference repo : ((ProductFileAdvice) advice).getUpdateRepositories()) { - Map parameters = new LinkedHashMap<>(); - parameters.put("type", Integer.toString(repo.getType())); //$NON-NLS-1$ - parameters.put("location", repo.getLocation().toString()); //$NON-NLS-1$ - if (repo.getNickname() != null) { - parameters.put("name", repo.getNickname()); //$NON-NLS-1$ - } - parameters.put("enabled", Boolean.toString( //$NON-NLS-1$ - (repo.getOptions() & IRepository.ENABLED) == IRepository.ENABLED)); - configurationData += TouchpointInstruction.encodeAction("addRepository", //$NON-NLS-1$ - parameters); - parameters.remove("enabled"); //$NON-NLS-1$ - unconfigurationData += TouchpointInstruction.encodeAction("removeRepository", //$NON-NLS-1$ - parameters); - } - } - } - return new String[] { configurationData, unconfigurationData }; - } - }; - } - }; + ProductAction action = new ProductAction(null, expandedProduct, flavor, launcherBinaries); IMetadataRepository metadataRepository = publishingRepository.getMetadataRepository(); IArtifactRepository artifactRepository = publishingRepository .getArtifactRepositoryForWriting(new ProductBinariesWriteSession(expandedProduct.getId())); @@ -195,54 +126,7 @@ private static void addRootFeatures(ExpandedProduct product, List repositories = getRepositoryEntries(); - URI uri = URIUtil.fromString(attributes.getValue("location")); - String name = attributes.getValue("name"); - boolean enabled = Boolean.parseBoolean(attributes.getValue("enabled")); - int options = enabled ? IRepository.ENABLED : IRepository.NONE; - // First add a metadata repository - repositories.add(new RepositoryReference(uri, name, IRepository.TYPE_METADATA, options)); - // Now a colocated artifact repository - repositories.add(new RepositoryReference(uri, name, IRepository.TYPE_ARTIFACT, options)); - } catch (URISyntaxException e) { - // ignore malformed URI's. These should have already been caught by the UI - } - } - }; + return new ProductFile(productFile.getAbsolutePath()); } catch (Exception e) { throw new BuildFailureException( "Cannot parse product file " + productFile.getAbsolutePath() + ": " + e.getMessage(), e); //$NON-NLS-1$ 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 82c410df41..3aa30cbe26 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 @@ -43,6 +43,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; @@ -55,6 +56,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; @@ -103,7 +105,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; @@ -330,7 +331,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 e31a9f60a8..7e51c61b86 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) { @@ -276,7 +271,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) { @@ -286,7 +281,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; } @@ -294,8 +289,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); @@ -313,53 +307,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 23dcb4ff6f..3f939e95ca 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 @@ -444,8 +444,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/pom.xml b/tycho-gpg-plugin/pom.xml index 4d88959fa6..9f354b0ecd 100644 --- a/tycho-gpg-plugin/pom.xml +++ b/tycho-gpg-plugin/pom.xml @@ -49,12 +49,17 @@ org.eclipse.platform org.eclipse.equinox.p2.artifact.repository - 1.5.100 + 1.5.200 org.eclipse.platform org.eclipse.equinox.p2.repository + + org.eclipse.platform + org.eclipse.equinox.p2.metadata + 2.8.0 + org.eclipse.tycho tycho-core 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);