Skip to content

Commit

Permalink
Adapt to changes in p2 internals
Browse files Browse the repository at this point in the history
Some smaller cleanups while at it too.
  • Loading branch information
akurtakov committed Dec 6, 2023
1 parent 619c16a commit bdaec79
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IQueryResult<IInstallableUnit> computeDependencies(Collection<IInstallabl
IQueryable<IInstallableUnit> avaiableIUs) throws CoreException {
NullProgressMonitor monitor = new NullProgressMonitor();
PermissiveSlicer slicer = new TychoSlicer(avaiableIUs);
IQueryable<IInstallableUnit> slice = slicer.slice(rootIus.toArray(IInstallableUnit[]::new), monitor);
IQueryable<IInstallableUnit> slice = slicer.slice(rootIus, monitor);
IStatus sliceStatus = slicer.getStatus();
if (sliceStatus.matches(IStatus.ERROR)) {
throw new CoreException(sliceStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,22 +95,18 @@ protected final IQueryable<IInstallableUnit> slice(Map<String, String> propertie
}

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

@Override
public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {

IQueryResult<IInstallableUnit> queryResult = baseIUCollection.query(query, monitor);
if (queryResult.isEmpty()) {
IQueryable<IInstallableUnit> additionalUnitStore = data.getAdditionalUnitStore();
if (additionalUnitStore != null) {
return additionalUnitStore.query(query, monitor);
}
IQueryResult<IInstallableUnit> queryResult = baseIUCollection.query(query, monitor1);
if (queryResult.isEmpty()) {
IQueryable<IInstallableUnit> additionalUnitStore = data.getAdditionalUnitStore();
if (additionalUnitStore != null) {
return additionalUnitStore.query(query, monitor1);
}
return queryResult;
}
return queryResult;
}, properties);
IQueryable<IInstallableUnit> slice = slicer.slice(seedIUs.toArray(EMPTY_IU_ARRAY), monitor);
IQueryable<IInstallableUnit> slice = slicer.slice(seedIUs, monitor);
MultiStatus slicerStatus = slicer.getStatus();
if (slice == null || isSlicerError(slicerStatus)) {
throw new ResolverException(StatusTool.toLogMessage(slicerStatus), properties.toString(),
Expand Down Expand Up @@ -175,8 +170,7 @@ protected IInstallableUnit createUnitProviding(String name, Collection<IRequirem
IMatchExpression<IInstallableUnit> matches = propertiesMatch.getMatches();
Map<String, Object> 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) {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private boolean matchesSelectionContext(IMatchExpression<IInstallableUnit> filte
}

@Override
public IQueryable<IInstallableUnit> slice(IInstallableUnit[] ius, IProgressMonitor monitor) {
public IQueryable<IInstallableUnit> slice(Collection<IInstallableUnit> ius, IProgressMonitor monitor) {
IQueryable<IInstallableUnit> slice = super.slice(ius, monitor);
if (includeAllSource && targetPlatform != null) {
Set<IInstallableUnit> collected = slice.query(QueryUtil.ALL_UNITS, null).toSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected Mirroring getMirroring(Collection<IInstallableUnit> 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<IArtifactKey> collectArtifactKeys(Collection<IInstallableUnit> ius, IProgressMonitor monitor)
Expand Down Expand Up @@ -315,21 +315,20 @@ private void mirrorMetadata(Collection<IInstallableUnit> 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<IInstallableUnit> collectUnits(IQueryable<IInstallableUnit> slice, IProgressMonitor monitor)
throws ProvisionException {
IQueryResult<IInstallableUnit> allIUs = slice.query(QueryUtil.createIUAnyQuery(), monitor);
Set<IInstallableUnit> 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())
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -443,8 +442,7 @@ private IQueryable<IInstallableUnit> slice(IProgressMonitor monitor) throws Prov
return performResolution(monitor);

Slicer slicer = createSlicer(slicingOptions);
IQueryable<IInstallableUnit> slice = slicer.slice(sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]),
monitor);
IQueryable<IInstallableUnit> slice = slicer.slice(sourceIUs, monitor);

if (slice != null && slicingOptions.latestVersionOnly()) {
IQueryResult<IInstallableUnit> queryResult = slice.query(QueryUtil.createLatestIUQuery(), monitor);
Expand All @@ -460,10 +458,9 @@ private IQueryable<IInstallableUnit> 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<TargetEnvironment> environments) {
Expand Down

0 comments on commit bdaec79

Please sign in to comment.