Skip to content

Commit

Permalink
Make the slicing options of the mirror-target-platform mojo configurable
Browse files Browse the repository at this point in the history
Currently the mirror-target-platform mirrors everything it could gather,
that could probably be to much, one maybe even want to configure even
more things like optional dependencies.

This now adds a new <options> parameter that allows to fine tune the
slicing options used for mirror the target.
Apply suggestions from code review

Co-authored-by: Titouan Vervack <[email protected]>
  • Loading branch information
laeubi and tivervac committed Feb 16, 2024
1 parent 86bf842 commit 5a1eef3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
Expand All @@ -39,6 +40,7 @@
@Component(role = InstallableUnitSlicer.class)
public class InstallableUnitSlicer {

private static final SlicingOptions DEFAULT_SLICING_OPTIONS = new SlicingOptions();
@Requirement
private Logger log;

Expand All @@ -51,13 +53,18 @@ public class InstallableUnitSlicer {
* @param rootIus the root units that are inspected for the slice
* @param avaiableIUs the {@link IQueryable} of all units that could be used for
* the slice
* @param options the options used for the slicing
* @return the result of the slicing
* @throws CoreException if there is any error
*/
public IQueryResult<IInstallableUnit> computeDependencies(Collection<IInstallableUnit> rootIus,
IQueryable<IInstallableUnit> avaiableIUs) throws CoreException {
IQueryable<IInstallableUnit> avaiableIUs, SlicingOptions options)
throws CoreException {
options = Objects.requireNonNullElse(options, DEFAULT_SLICING_OPTIONS);
NullProgressMonitor monitor = new NullProgressMonitor();
PermissiveSlicer slicer = new TychoSlicer(avaiableIUs);
PermissiveSlicer slicer = new PermissiveSlicer(avaiableIUs, options.getFilter(),
options.isIncludeOptionalDependencies(), options.isEverythingGreedy(), options.isForceFilterTo(),
options.isConsiderStrictDependencyOnly(), options.isFollowOnlyFilteredRequirements());
IQueryable<IInstallableUnit> slice = slicer.slice(rootIus, monitor);
IStatus sliceStatus = slicer.getStatus();
if (sliceStatus.matches(IStatus.ERROR)) {
Expand All @@ -66,6 +73,9 @@ public IQueryResult<IInstallableUnit> computeDependencies(Collection<IInstallabl
if (!sliceStatus.isOK()) {
log.debug("There are warnings from the slicer: " + sliceStatus);
}
if (options.isLatestVersionOnly()) {
return slice.query(QueryUtil.createLatestIUQuery(), monitor);
}
return slice.query(QueryUtil.createIUAnyQuery(), monitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,64 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;
package org.eclipse.tycho.p2maven;

import java.util.Hashtable;
import java.util.Map;

/**
* Holds the slicing options for a permissive slicer, the defaults are:
* <ul>
* <li>includeOptionalDependencies = true</li>
* <li>everythingGreedy = true</li>
* <li>forceFilterTo = true</li>
* <li>considerStrictDependencyOnly = false</li>
* <li>followOnlyFilteredRequirements = false</li>
* <li>filter = null</li>
* <li>latestVersion = true</li>
* </ul>
* This effectively means that everything that can be included will be included
* in the slice.
*/
public class SlicingOptions {
private boolean includeOptionalDependencies = true;
private boolean everythingGreedy = true;
private boolean forceFilterTo = true;
private boolean considerStrictDependencyOnly = false;
private boolean followOnlyFilteredRequirements = false;
private boolean latestVersion = false;
private boolean resolve = false;

private boolean latestVersion = true;

private Map<String, String> filter = null;

public boolean includeOptionalDependencies() {
public boolean isIncludeOptionalDependencies() {
return includeOptionalDependencies;
}

public void includeOptionalDependencies(boolean optional) {
public void setIncludeOptionalDependencies(boolean optional) {
this.includeOptionalDependencies = optional;
}

public boolean isEverythingGreedy() {
return everythingGreedy;
}

public void everythingGreedy(boolean greedy) {
public void setEverythingGreedy(boolean greedy) {
this.everythingGreedy = greedy;
}

public boolean forceFilterTo() {
public boolean isForceFilterTo() {
return forceFilterTo;
}

public void forceFilterTo(boolean forcedTo) {
public void setForceFilterTo(boolean forcedTo) {
this.forceFilterTo = forcedTo;
}

public boolean considerStrictDependencyOnly() {
public boolean isConsiderStrictDependencyOnly() {
return considerStrictDependencyOnly;
}

public void considerStrictDependencyOnly(boolean strict) {
public void setConsiderStrictDependencyOnly(boolean strict) {
this.considerStrictDependencyOnly = strict;
}

Expand All @@ -69,27 +82,19 @@ public void setFilter(Map<String, String> filter) {
this.filter = filter;
}

public void followOnlyFilteredRequirements(boolean onlyFiltered) {
public void setFollowOnlyFilteredRequirements(boolean onlyFiltered) {
this.followOnlyFilteredRequirements = onlyFiltered;
}

public boolean followOnlyFilteredRequirements() {
public boolean isFollowOnlyFilteredRequirements() {
return followOnlyFilteredRequirements;
}

public boolean latestVersionOnly() {
public boolean isLatestVersionOnly() {
return latestVersion;
}

public void latestVersionOnly(boolean latest) {
public void setLatestVersionOnly(boolean latest) {
this.latestVersion = latest;
}

public void installTimeLikeResolution(boolean resolve) {
this.resolve = resolve;
}

public boolean getInstallTimeLikeResolution() {
return resolve;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.eclipse.tycho.p2.tools.mirroring.facade.MirrorApplicationService;
import org.eclipse.tycho.p2maven.InstallableUnitSlicer;
import org.eclipse.tycho.p2maven.ListCompositeArtifactRepository;
import org.eclipse.tycho.p2maven.SlicingOptions;
import org.eclipse.tycho.repository.registry.facade.ReactorRepositoryManager;

/**
Expand All @@ -74,6 +75,35 @@ public class MirrorTargetPlatformMojo extends AbstractMojo {
@Parameter(defaultValue = "true")
private boolean includeCategories = true;

/**
* Allows configuration of additional slicing options for example like this:
*
* <pre>
* &lt;options&gt;
* &lt;!-- should optional dependencies be included (true) or ignored (false), defaults to true --&gt;
* &lt;includeOptionalDependencies&gt;true/false&lt;/includeOptionalDependencies&gt;
* &lt;!-- should requirements be considered always greedy (true) - i.e., install even if there are no usages - or only if specified (false), defaults to true --&gt;
* &lt;everythingGreedy&gt;true/false&lt;/everythingGreedy&gt;
* &lt;!-- should only strict dependencies be considered (true) or all dependencies (false), defaults to false --&gt;
* &lt;!-- a strict dependency is one with a strict version range (e.g. [1.2,1.2]) and usually maps to items included in a feature, default is false --&gt;
* &lt;considerStrictDependencyOnly&gt;true/false&lt;/considerStrictDependencyOnly&gt;
* &lt;!-- should only items that have a filter be considered (true) or all of them (false), default is false --&gt;
* &lt;followOnlyFilteredRequirements&gt;true/false&lt;/followOnlyFilteredRequirements&gt;
* &lt;!-- if no filter context is defined and a filter is encountered (e.g., os = win32 on a requirement), the filter will always match (true) or fail (false), default is true --&gt;
* &lt;forceFilterTo&gt;true/false&lt;/forceFilterTo&gt;
* &lt;!-- should only the latest version (true) or all versions (false) be included, default is true --&gt;
* &lt;latestVersion&gt;true/false&lt;/latestVersion&gt;
* &lt;!-- defines the filter context, if not given, filtering is disabled and the value of forceFilterTo is used --&gt;
* &lt;filter&gt;
* &lt;key&gt;value&lt;/key&gt;
* ...
* &lt;/filter&gt;
* &lt;/options&gt;
* </pre>
*/
@Parameter
private SlicingOptions options;

@Component
private TargetPlatformService platformService;

Expand Down Expand Up @@ -123,7 +153,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
label = project.getId();
}
rootIus.add(createCategory(label, query));
mirrorUnits = installableUnitSlicer.computeDependencies(rootIus, metadataRepository);
mirrorUnits = installableUnitSlicer.computeDependencies(rootIus, metadataRepository, options);
} catch (CoreException e) {
throw new MojoFailureException("Failed to compute dependencies to mirror", e);
}
Expand Down

0 comments on commit 5a1eef3

Please sign in to comment.