Skip to content

Commit

Permalink
Make this logic enabled by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 20, 2023
1 parent ebbfd07 commit 4a0dbda
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ public final class ConfigurationProperties {
*/
public static final boolean DEFAULT_IMPLICIT_PRIORITIES = false;

/**
* A flag indicating whether the created ordered components should be cached or not.
*
* @see #DEFAULT_CACHED_PRIORITIES
* @since TBD
*/
public static final String CACHED_PRIORITIES = PREFIX_PRIORITY + "cached";

/**
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
*
* @since TBD
*/
public static final boolean DEFAULT_CACHED_PRIORITIES = true;

/**
* A flag indicating whether interaction with the user is allowed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,22 @@ final class PrioritizedComponents<T> {
@SuppressWarnings("unchecked")
public static <C> PrioritizedComponents<C> reuseOrCreate(
RepositorySystemSession session, Map<String, C> components, Function<C, Float> priorityFunction) {
String key = PrioritizedComponents.class.getName() + ".pc" + Integer.toHexString(components.hashCode());
return (PrioritizedComponents<C>) session.getData().computeIfAbsent(key, () -> {
PrioritizedComponents<C> newInstance = new PrioritizedComponents<>(session);
components.values().forEach(c -> newInstance.add(c, priorityFunction.apply(c)));
return newInstance;
});
boolean cached = ConfigUtils.getBoolean(
session, ConfigurationProperties.DEFAULT_CACHED_PRIORITIES, ConfigurationProperties.CACHED_PRIORITIES);
if (cached) {
String key = PrioritizedComponents.class.getName() + ".pc" + Integer.toHexString(components.hashCode());
return (PrioritizedComponents<C>)
session.getData().computeIfAbsent(key, () -> create(session, components, priorityFunction));
} else {
return create(session, components, priorityFunction);
}
}

private static <C> PrioritizedComponents<C> create(
RepositorySystemSession session, Map<String, C> components, Function<C, Float> priorityFunction) {
PrioritizedComponents<C> newInstance = new PrioritizedComponents<>(session);
components.values().forEach(c -> newInstance.add(c, priorityFunction.apply(c)));
return newInstance;
}

private static final String FACTORY_SUFFIX = "Factory";
Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Option | Type | Description | Default Value | Supports Repo ID Suffix
`aether.metadataResolver.threads` | int | Number of threads to use in parallel for resolving metadata. | `4` | no
`aether.offline.protocols` | String | Comma-separated list of protocols which are supposed to be resolved offline. | - | no
`aether.offline.hosts` | String | Comma-separated list of hosts which are supposed to be resolved offline. | - | no
`aether.priority.cached` | boolean | Whether the created ordered list of components should be cached (in session) or not. | `true` | no
`aether.priority.<class>` | float | The priority to use for a certain extension class. `class` can either be the fully qualified name or the simple name stands for fully qualified class name. If the class name ends with `Factory` that suffix could optionally be left out. | - | no
`aether.priority.implicit` | boolean | Flag indicating whether the priorities of pluggable extensions are implicitly given by their iteration order such that the first extension has the highest priority. If set, an extension's built-in priority as well as any corresponding `aether.priority.<class>` configuration properties are ignored when searching for a suitable implementation among the available extensions. This priority mode is meant for cases where the application will present/inject extensions in the desired search order. | `false` | no
`aether.remoteRepositoryFilter.groupId` | boolean | Enable `groupId` remote repository filter. | `false` | no
Expand Down

0 comments on commit 4a0dbda

Please sign in to comment.