Skip to content

Commit

Permalink
Assemble repository for all environments at once
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Sep 24, 2023
1 parent 3118388 commit 94499e6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.BuildDirectory;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.resolver.shared.DependencySeed;
import org.eclipse.tycho.core.shared.StatusTool;
import org.eclipse.tycho.p2.repository.GAV;
Expand Down Expand Up @@ -164,28 +163,24 @@ public void mirrorReactor(RepositoryReferences sources, DestinationRepositoryDes
mirrorApp.setIncludeRequiredFeatures(includeRequiredFeatures);
mirrorApp.setIncludePacked(false); // no way, Tycho do no longer support packed artifacts anyways
mirrorApp.setFilterProvided(filterProvided);
// TODO the p2 mirror tool should support mirroring multiple environments at once
for (TargetEnvironment environment : context.getEnvironments()) {
SlicingOptions options = new SlicingOptions();
options.considerStrictDependencyOnly(!includeAllDependencies);
Map<String, String> filter = options.getFilter();
addFilterForFeatureJARs(filter);
if (filterProperties != null) {
filter.putAll(filterProperties);
}
filter.putAll(environment.toFilterProperties());
mirrorApp.setSlicingOptions(options);

try {
LogListener logListener = new LogListener(logger);
mirrorApp.setLog(logListener);

IStatus returnStatus = mirrorApp.run(null);
checkStatus(returnStatus, false);
logListener.showHelpForLoggedMessages();
} catch (ProvisionException e) {
throw new FacadeException(MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e);
}
mirrorApp.setEnvironments(context.getEnvironments());
SlicingOptions options = new SlicingOptions();
options.considerStrictDependencyOnly(!includeAllDependencies);
Map<String, String> filter = options.getFilter();
addFilterForFeatureJARs(filter);
if (filterProperties != null) {
filter.putAll(filterProperties);
}
mirrorApp.setSlicingOptions(options);
try {
LogListener logListener = new LogListener(logger);
mirrorApp.setLog(logListener);

IStatus returnStatus = mirrorApp.run(null);
checkStatus(returnStatus, false);
logListener.showHelpForLoggedMessages();
} catch (ProvisionException e) {
throw new FacadeException(MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e);
}
recreateArtifactRepository(destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -29,6 +30,7 @@
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.director.Slicer;
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
Expand Down Expand Up @@ -82,13 +84,19 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit,

@Override
protected Slicer createSlicer(SlicingOptions options) {
Map<String, String> context = options.getFilter();
boolean includeOptionalDependencies = options.includeOptionalDependencies();
boolean onlyFilteredRequirements = options.followOnlyFilteredRequirements();
boolean considerFilter = context != null && context.size() > 1;
List<IInstallableUnit> selectionContexts = environments.stream().map(env -> {
Map<String, String> context = new HashMap<>(options.getFilter());
context.putAll(env.toFilterProperties());
return context;
}).map(InstallableUnit::contextIU).toList();
boolean considerFilter = selectionContexts.stream().anyMatch(c -> c.getProperties().size() > 1);
boolean evalFilterTo = options.forceFilterTo();

IMetadataRepository repository = getCompositeMetadataRepository();
return new PermissiveSlicer(repository, context, includeOptionalDependencies, options.isEverythingGreedy(),
options.forceFilterTo(), options.considerStrictDependencyOnly(), onlyFilteredRequirements) {
return new PermissiveSlicer(repository, Map.of(), includeOptionalDependencies, options.isEverythingGreedy(),
evalFilterTo, options.considerStrictDependencyOnly(), onlyFilteredRequirements) {
@Override
protected boolean isApplicable(IInstallableUnit iu, IRequirement req) {
if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu)
Expand All @@ -103,12 +111,22 @@ protected boolean isApplicable(IInstallableUnit iu, IRequirement req) {
if (onlyFilteredRequirements && filter == null) {
return false;
}
return !considerFilter || filter == null || filter.isMatch(selectionContext);
return !considerFilter || filter == null
|| selectionContexts.stream().anyMatch(filter::isMatch);
}
}
return super.isApplicable(req);
}

@Override
protected boolean isApplicable(IInstallableUnit iu) {
if (considerFilter) {
IMatchExpression<IInstallableUnit> filter = iu.getFilter();
return filter == null || selectionContexts.stream().anyMatch(filter::isMatch);
}
return iu.getFilter() == null || evalFilterTo;
}

@Override
protected boolean isApplicable(IRequirement req) {
throw new UnsupportedOperationException("should never be called!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -52,13 +53,15 @@
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tycho.TargetEnvironment;

public class MirrorApplication extends AbstractApplication implements IApplication, IExecutableExtension {
private static final String DEFAULT_COMPARATOR = ArtifactChecksumComparator.COMPARATOR_ID + ".sha-256"; //$NON-NLS-1$
private static final String LOG_ROOT = "p2.mirror"; //$NON-NLS-1$
private static final String MIRROR_MODE = "metadataOrArtifacts"; //$NON-NLS-1$

protected SlicingOptions slicingOptions = new SlicingOptions();
protected List<TargetEnvironment> environments = new ArrayList<>();

private URI baseline;
private String comparatorID;
Expand Down Expand Up @@ -396,23 +399,32 @@ private IArtifactMirrorLog getLog(File location, String root) {
return new FileMirrorLog(absolutePath, 0, root);
}

@SuppressWarnings("unchecked")
private static final IQueryable<IInstallableUnit>[] EMPTY = new IQueryable[0];

private IQueryable<IInstallableUnit> performResolution(IProgressMonitor monitor) throws ProvisionException {
IProfileRegistry registry = getProfileRegistry();
String profileId = "MirrorApplication-" + System.currentTimeMillis(); //$NON-NLS-1$
IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter());
IPlanner planner = agent.getService(IPlanner.class);
if (planner == null)
throw new IllegalStateException();
IProfileChangeRequest pcr = planner.createChangeRequest(profile);
pcr.addAll(sourceIUs);
IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor);
registry.removeProfile(profileId);
@SuppressWarnings("unchecked")
IQueryable<IInstallableUnit>[] arr = new IQueryable[plan.getInstallerPlan() == null ? 1 : 2];
arr[0] = plan.getAdditions();
if (plan.getInstallerPlan() != null)
arr[1] = plan.getInstallerPlan().getAdditions();
return new CompoundQueryable<>(arr);
List<IQueryable<IInstallableUnit>> queryables = new ArrayList<>();
for (TargetEnvironment environment : environments) {
Map<String, String> filter = new HashMap<>(slicingOptions.getFilter());
filter.putAll(environment.toFilterProperties());
IProfile profile = registry.addProfile(profileId, filter);
IPlanner planner = agent.getService(IPlanner.class);
if (planner == null) {
throw new IllegalStateException();
}
IProfileChangeRequest pcr = planner.createChangeRequest(profile);
pcr.addAll(sourceIUs);
IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor);
registry.removeProfile(profileId);
queryables.add(plan.getAdditions());
IProvisioningPlan installerPlan = plan.getInstallerPlan();
if (installerPlan != null) {
queryables.add(installerPlan.getAdditions());
}
}
return new CompoundQueryable<>(queryables.toArray(EMPTY));
}

private IProfileRegistry getProfileRegistry() throws ProvisionException {
Expand Down Expand Up @@ -452,6 +464,10 @@ protected Slicer createSlicer(SlicingOptions options) {
return slicer;
}

public void setEnvironments(List<TargetEnvironment> environments) {
this.environments = environments;
}

public void setSlicingOptions(SlicingOptions options) {
slicingOptions = options;
}
Expand Down

0 comments on commit 94499e6

Please sign in to comment.