From bdaec79d589ee764c662fbe2b9fc877056db5f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 6 Dec 2023 12:49:11 +0200 Subject: [PATCH] Adapt to changes in p2 internals Some smaller cleanups while at it too. --- .../tycho/p2maven/InstallableUnitSlicer.java | 2 +- .../AbstractSlicerResolutionStrategy.java | 29 +++++++------------ .../p2tools/MirrorApplicationServiceImpl.java | 5 +--- .../tycho/p2tools/TychoMirrorApplication.java | 2 +- .../copiedfromp2/MirrorApplication.java | 21 ++++++-------- 5 files changed, 23 insertions(+), 36 deletions(-) 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/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..f2c74192d2 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 @@ -42,7 +42,6 @@ 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; @@ -96,22 +95,18 @@ protected final IQueryable slice(Map propertie } QueryableCollection baseIUCollection = new QueryableCollection(availableIUs); - Slicer slicer = newSlicer(new IQueryable() { + 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(), @@ -175,8 +170,7 @@ protected IInstallableUnit createUnitProviding(String name, Collection matches = propertiesMatch.getMatches(); Map properties = new HashMap<>(); Object p = matches.getParameters()[1]; - if (p instanceof IExpression) { - IExpression expression = (IExpression) p; + if (p instanceof IExpression expression) { IExpression operand = ExpressionUtil.getOperand(expression); IExpression[] operands = ExpressionUtil.getOperands(operand); for (IExpression eq : operands) { @@ -222,8 +216,7 @@ private static IRequirement createStrictRequirementTo(IInstallableUnit unit) { int min = 1; int max = Integer.MAX_VALUE; boolean greedy = true; - IRequirement requirement = MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, unit.getId(), - strictRange, unit.getFilter(), min, max, greedy); - return requirement; + return MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, unit.getId(), strictRange, + unit.getFilter(), min, max, greedy); } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java index a715ef23a1..fe7cf9b8c3 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java @@ -217,10 +217,7 @@ public void recreateArtifactRepository(DestinationRepositoryDescriptor destinati artifactsXz.delete(); } descriptor.setLocation(location.toURI()); - //TODO this is to trigger loading of the osgi services and we can not pass the agent directly see - // https://github.com/eclipse-equinox/p2/issues/151 - agent.getService(IArtifactRepositoryManager.class); - RecreateRepositoryApplication application = new RecreateRepositoryApplication(); + RecreateRepositoryApplication application = new RecreateRepositoryApplication(agent); application.setArtifactRepository(descriptor.getRepoLocation()); try { application.run(new NullProgressMonitor()); 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..7c371baf18 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 @@ -162,7 +162,7 @@ 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(); 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..6983b42940 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 @@ -280,7 +280,7 @@ protected Mirroring getMirroring(Collection ius, IProgressMoni * Collect all artifacts from the IUs that should be mirrored * * @param ius - * the IUs that are selected for mirroring + * the IUs that are selected for mirroring * @return a (modifiable) list of {@link IArtifactKey}s that must be mirrored */ protected List collectArtifactKeys(Collection ius, IProgressMonitor monitor) @@ -315,21 +315,20 @@ private void mirrorMetadata(Collection units, IProgressMonitor * Collect all IUS from the slice that should be mirrored * * @param slice - * the slice for mirroring + * the slice for mirroring * @return a (modifiable) set of {@link IInstallableUnit}s that must be mirrored * @throws ProvisionException */ protected Set collectUnits(IQueryable slice, IProgressMonitor monitor) throws ProvisionException { IQueryResult allIUs = slice.query(QueryUtil.createIUAnyQuery(), monitor); - Set units = allIUs.toSet(); - return units; + return allIUs.toSet(); } /* - * Ensure all mandatory parameters have been set. Throw an exception if there are any missing. We - * don't require the user to specify the artifact repository here, we will default to the ones - * already registered in the manager. (callers are free to add more if they wish) + * Ensure all mandatory parameters have been set. Throw an exception if there are any missing. + * We don't require the user to specify the artifact repository here, we will default to the + * ones already registered in the manager. (callers are free to add more if they wish) */ private void validate() throws ProvisionException { if (sourceRepositories.isEmpty()) @@ -362,7 +361,7 @@ private void initializeIUs() throws ProvisionException { while (queryResult.hasNext()) sourceIUs.add(queryResult.next()); /* old metadata mirroring app did not throw an exception here */ - if (sourceIUs.size() == 0 && destinationMetadataRepository != null && metadataOrArtifacts == null) + if (sourceIUs.isEmpty() && destinationMetadataRepository != null && metadataOrArtifacts == null) throw new ProvisionException(Messages.MirrorApplication_no_IUs); } } @@ -443,8 +442,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); @@ -460,10 +458,9 @@ private IQueryable slice(IProgressMonitor monitor) throws Prov } protected Slicer createSlicer(SlicingOptions options) { - PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), options.getFilter(), + return new PermissiveSlicer(getCompositeMetadataRepository(), options.getFilter(), options.includeOptionalDependencies(), options.isEverythingGreedy(), options.forceFilterTo(), options.considerStrictDependencyOnly(), options.followOnlyFilteredRequirements()); - return slicer; } public void setEnvironments(List environments) {