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); }