[
https://issues.apache.org/jira/browse/MRESOLVER-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17609042#comment-17609042
]
ASF GitHub Bot commented on MRESOLVER-266:
------------------------------------------
michael-o commented on code in PR #196:
URL: https://github.com/apache/maven-resolver/pull/196#discussion_r979298783
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/DefaultSyncContextFactory.java:
##########
@@ -66,24 +101,69 @@ public DefaultSyncContextFactory()
@Override
public void initService( final ServiceLocator locator )
{
- NamedLockFactorySelector selector = Objects.requireNonNull(
- locator.getService( NamedLockFactorySelector.class ) );
- this.namedLockFactoryAdapter = new NamedLockFactoryAdapter(
- selector.getSelectedNameMapper(),
- selector.getSelectedNamedLockFactory()
- );
+ HashMap<String, NameMapper> mappers = new HashMap<>();
+ mappers.put( StaticNameMapper.NAME, new StaticNameMapper() );
+ mappers.put( GAVNameMapper.NAME, new GAVNameMapper() );
+ mappers.put( DiscriminatingNameMapper.NAME, new
DiscriminatingNameMapper( new GAVNameMapper() ) );
+ mappers.put( FileGAVNameMapper.NAME, new FileGAVNameMapper() );
+ this.nameMappers = mappers;
+
+ HashMap<String, NamedLockFactory> factories = new HashMap<>();
+ factories.put( NoopNamedLockFactory.NAME, new NoopNamedLockFactory() );
+ factories.put( LocalReadWriteLockNamedLockFactory.NAME, new
LocalReadWriteLockNamedLockFactory() );
+ factories.put( LocalSemaphoreNamedLockFactory.NAME, new
LocalSemaphoreNamedLockFactory() );
+ factories.put( FileLockNamedLockFactory.NAME, new
FileLockNamedLockFactory() );
+ this.namedLockFactories = factories;
}
@Override
public SyncContext newInstance( final RepositorySystemSession session,
final boolean shared )
{
requireNonNull( session, "session cannot be null" );
- return namedLockFactoryAdapter.newInstance( session, shared );
+ NamedLockFactoryAdapter adapter =
+ (NamedLockFactoryAdapter) session.getData().computeIfAbsent(
+ ADAPTER_KEY,
+ () -> createAdapter( session )
+ );
+ return adapter.newInstance( session, shared );
+ }
+
+ private NamedLockFactoryAdapter createAdapter( final
RepositorySystemSession session )
+ {
+ String nameMapperName = ConfigUtils.getString( session,
DEFAULT_NAME_MAPPER, NAME_MAPPER_KEY );
+ String namedLockFactoryName = ConfigUtils.getString( session,
DEFAULT_FACTORY, FACTORY_KEY );
+ NameMapper nameMapper = nameMappers.get( nameMapperName );
+ if ( nameMapper == null )
+ {
+ throw new IllegalArgumentException( "Unknown NameMapper name: " +
namedLockFactoryName
Review Comment:
This is wrong. It must be `nameMapperName`. Just copy and paste.
> Simplify adapter creation and align configuration for it
> --------------------------------------------------------
>
> Key: MRESOLVER-266
> URL: https://issues.apache.org/jira/browse/MRESOLVER-266
> Project: Maven Resolver
> Issue Type: Task
> Components: Resolver
> Reporter: Tamás Cservenák
> Assignee: Tamás Cservenák
> Priority: Major
> Fix For: resolver-next
>
>
> Rework how named lock factory adapter is created, it is the ONLY bit reaching
> directly to Java System Properties instead to rely on session config
> properties. This makes it impossible to control from Maven for example (as it
> is "too late").
> Proposed changes:
> * adapter should be created based on session config properties, not Java
> system properties
> * adapter should be stored within session
> * adapter creation should be vastly simplified (currently we have 4 involved
> class: selectors and default sync context)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)