From 8e71e565de6613e4a37aa787e16e7a425ce3c198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 16 Feb 2024 10:25:23 +0100 Subject: [PATCH 1/3] Import SlicingOptions from P2 --- .../eclipse/tycho/p2maven/SlicingOptions.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/SlicingOptions.java diff --git a/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/SlicingOptions.java b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/SlicingOptions.java new file mode 100644 index 0000000000..3047eaa943 --- /dev/null +++ b/p2-maven-plugin/src/main/java/org/eclipse/tycho/p2maven/SlicingOptions.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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.equinox.p2.internal.repository.tools; + +import java.util.Hashtable; +import java.util.Map; + +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 Map filter = null; + + public boolean includeOptionalDependencies() { + return includeOptionalDependencies; + } + + public void includeOptionalDependencies(boolean optional) { + this.includeOptionalDependencies = optional; + } + + public boolean isEverythingGreedy() { + return everythingGreedy; + } + + public void everythingGreedy(boolean greedy) { + this.everythingGreedy = greedy; + } + + public boolean forceFilterTo() { + return forceFilterTo; + } + + public void forceFilterTo(boolean forcedTo) { + this.forceFilterTo = forcedTo; + } + + public boolean considerStrictDependencyOnly() { + return considerStrictDependencyOnly; + } + + public void considerStrictDependencyOnly(boolean strict) { + this.considerStrictDependencyOnly = strict; + } + + public Map getFilter() { + if (filter == null) + filter = new Hashtable<>(); + return filter; + } + + public void setFilter(Map filter) { + this.filter = filter; + } + + public void followOnlyFilteredRequirements(boolean onlyFiltered) { + this.followOnlyFilteredRequirements = onlyFiltered; + } + + public boolean followOnlyFilteredRequirements() { + return followOnlyFilteredRequirements; + } + + public boolean latestVersionOnly() { + return latestVersion; + } + + public void latestVersionOnly(boolean latest) { + this.latestVersion = latest; + } + + public void installTimeLikeResolution(boolean resolve) { + this.resolve = resolve; + } + + public boolean getInstallTimeLikeResolution() { + return resolve; + } +} From d1956413cd694deef5683be4cf7d5d8db04e3cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 16 Feb 2024 12:08:21 +0100 Subject: [PATCH 2/3] Make the slicing options of the mirror-target-platform mojo configurable 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 parameter that allows to fine tune the slicing options used for mirror the target. --- .../tycho/p2maven/InstallableUnitSlicer.java | 14 ++++- .../eclipse/tycho/p2maven/SlicingOptions.java | 51 ++++++++++--------- .../target/MirrorTargetPlatformMojo.java | 32 +++++++++++- 3 files changed, 71 insertions(+), 26 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 e85c61f199..0dae952a7b 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 @@ -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; @@ -39,6 +40,7 @@ @Component(role = InstallableUnitSlicer.class) public class InstallableUnitSlicer { + private static final SlicingOptions DEFAULT_SLICING_OPTIONS = new SlicingOptions(); @Requirement private Logger log; @@ -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 computeDependencies(Collection rootIus, - IQueryable avaiableIUs) throws CoreException { + IQueryable 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 slice = slicer.slice(rootIus, monitor); IStatus sliceStatus = slicer.getStatus(); if (sliceStatus.matches(IStatus.ERROR)) { @@ -66,6 +73,9 @@ public IQueryResult computeDependencies(Collection + *
  • includeOptionalDependencies = true
  • + *
  • everythingGreedy = true
  • + *
  • forceFilterTo = true
  • + *
  • considerStrictDependencyOnly = false
  • + *
  • followOnlyFilteredRequirements = false
  • + *
  • filter = null
  • + *
  • latestVersion = true
  • + * + * 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 filter = null; - public boolean includeOptionalDependencies() { + public boolean isIncludeOptionalDependencies() { return includeOptionalDependencies; } - public void includeOptionalDependencies(boolean optional) { + public void setIncludeOptionalDependencies(boolean optional) { this.includeOptionalDependencies = optional; } @@ -39,23 +52,23 @@ 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; } @@ -69,27 +82,19 @@ public void setFilter(Map 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; - } } diff --git a/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java b/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java index 0818a39ae5..83b0ee99f8 100644 --- a/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java +++ b/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java @@ -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; /** @@ -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: + * + *
    +     * <options>
    +    *   <!-- should optional dependencies be included (true) or ignored (false), defaults to true -->
    +    *   <includeOptionalDependencies>true/false</includeOptionalDependencies>
    +    *   <!-- should requirements be considered always greedy (true) or only if specified (false), defaults to true -->
    +    *   <everythingGreedy>true/false</everythingGreedy>
    +    *   <!-- should only strict dependencies be consodered (true) or all dependencies (false), defaults to false -->
    +    *   <!-- a strict dependency is onw with a strict version range (e.g. [1.2,1.2]) and usually maps to items included in a feature -->
    +    *   <considerStrictDependencyOnly>true/false</considerStrictDependencyOnly>
    +    *   <!-- should only items that have a filter be considerd (true) or all of them (false), default is false -->
    +    *   <followOnlyFilteredRequirements>true/false</followOnlyFilteredRequirements>
    +    *   <!-- if no filter context is defined and there is a filter, it is forced to be asume to be matched (true) or non matching (false), default is true -->
    +    *   <forceFilterTo>true/false</forceFilterTo>
    +    *   <!-- should only the latest version (true) or all versions (false) be included, default is true -->
    +    *   <latestVersion>true/false</latestVersion>
    +    *   <!-- defines the filter context, if not given, filtering is disabled and the value of forceFilterTo is used -->
    +    *   <filter>
    +    *       <key>value</key>
    +    *            ...
    +    *   </filter>
    +    *  </options>
    +     * 
    + */ + @Parameter + private SlicingOptions options; + @Component private TargetPlatformService platformService; @@ -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); } From 24fcc16518a64316e8a89ae3b9a75e41f8ae10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 16 Feb 2024 15:33:26 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Titouan Vervack --- .../eclipse/tycho/target/MirrorTargetPlatformMojo.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java b/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java index 83b0ee99f8..3e85d86a02 100644 --- a/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java +++ b/target-platform-configuration/src/main/java/org/eclipse/tycho/target/MirrorTargetPlatformMojo.java @@ -82,14 +82,14 @@ public class MirrorTargetPlatformMojo extends AbstractMojo { * <options> * <!-- should optional dependencies be included (true) or ignored (false), defaults to true --> * <includeOptionalDependencies>true/false</includeOptionalDependencies> - * <!-- should requirements be considered always greedy (true) or only if specified (false), defaults to true --> + * <!-- should requirements be considered always greedy (true) - i.e., install even if there are no usages - or only if specified (false), defaults to true --> * <everythingGreedy>true/false</everythingGreedy> - * <!-- should only strict dependencies be consodered (true) or all dependencies (false), defaults to false --> - * <!-- a strict dependency is onw with a strict version range (e.g. [1.2,1.2]) and usually maps to items included in a feature --> + * <!-- should only strict dependencies be considered (true) or all dependencies (false), defaults to false --> + * <!-- 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 --> * <considerStrictDependencyOnly>true/false</considerStrictDependencyOnly> - * <!-- should only items that have a filter be considerd (true) or all of them (false), default is false --> + * <!-- should only items that have a filter be considered (true) or all of them (false), default is false --> * <followOnlyFilteredRequirements>true/false</followOnlyFilteredRequirements> - * <!-- if no filter context is defined and there is a filter, it is forced to be asume to be matched (true) or non matching (false), default is true --> + * <!-- 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 --> * <forceFilterTo>true/false</forceFilterTo> * <!-- should only the latest version (true) or all versions (false) be included, default is true --> * <latestVersion>true/false</latestVersion>