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 = true; + + private Map 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 getFilter() { + if (filter == null) + filter = new Hashtable<>(); + return filter; + } + + public void setFilter(Map 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; + } +} 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..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 @@ -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) - 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 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 considered (true) or all of them (false), default is false -->
    +    *   <followOnlyFilteredRequirements>true/false</followOnlyFilteredRequirements>
    +    *   <!-- 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>
    +    *   <!-- 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); }