Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the slicing options of the mirror-target-platform mojo configurable #3515

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2009, 2017 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
*******************************************************************************/
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>
laeubi marked this conversation as resolved.
Show resolved Hide resolved
* <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 = true;

private Map<String, String> filter = null;

public boolean isIncludeOptionalDependencies() {
return includeOptionalDependencies;
}

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

public boolean isEverythingGreedy() {
return everythingGreedy;
}

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

public boolean isForceFilterTo() {
return forceFilterTo;
}

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

public boolean isConsiderStrictDependencyOnly() {
return considerStrictDependencyOnly;
}

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

public Map<String, String> getFilter() {
if (filter == null)
filter = new Hashtable<>();
return filter;
}

public void setFilter(Map<String, String> filter) {
this.filter = filter;
}

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

public boolean isFollowOnlyFilteredRequirements() {
return followOnlyFilteredRequirements;
}

public boolean isLatestVersionOnly() {
return latestVersion;
}

public void setLatestVersionOnly(boolean latest) {
this.latestVersion = latest;
}
}
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
Loading