Skip to content

Commit

Permalink
[MRESOLVER-298] Make javax.inject optional again (#235)
Browse files Browse the repository at this point in the history
javax.inject is and should be optional (used only when Guice and/or Sisu is being used), but in case SL is being used no javax.inject should be needed.

This rule was violated in 1.9.0 commit 5566bd5 where `javax.inject.Provider` was used in conjuction with SL as well.

This fix introduces `NameMappers` helper static class that constructs name mappers, and javax.inject.Provider classes are used ONLY when in Guice/Sisu, are NOT used with conjunction of SL.

---

https://issues.apache.org/jira/browse/MRESOLVER-298
  • Loading branch information
cstamas committed Jan 12, 2023
1 parent e665213 commit 1010f0f
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource;
import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor;
import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;
import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl;
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory;
Expand Down Expand Up @@ -236,15 +237,15 @@ protected void configure()
.to( org.eclipse.aether.internal.impl.synccontext.legacy.DefaultSyncContextFactory.class )
.in( Singleton.class );

bind( NameMapper.class ).annotatedWith( Names.named( StaticNameMapperProvider.NAME ) )
bind( NameMapper.class ).annotatedWith( Names.named( NameMappers.STATIC_NAME ) )
.toProvider( StaticNameMapperProvider.class ).in( Singleton.class );
bind( NameMapper.class ).annotatedWith( Names.named( GAVNameMapperProvider.NAME ) )
bind( NameMapper.class ).annotatedWith( Names.named( NameMappers.GAV_NAME ) )
.toProvider( GAVNameMapperProvider.class ).in( Singleton.class );
bind( NameMapper.class ).annotatedWith( Names.named( DiscriminatingNameMapperProvider.NAME ) )
bind( NameMapper.class ).annotatedWith( Names.named( NameMappers.DISCRIMINATING_NAME ) )
.toProvider( DiscriminatingNameMapperProvider.class ).in( Singleton.class );
bind( NameMapper.class ).annotatedWith( Names.named( FileGAVNameMapperProvider.NAME ) )
bind( NameMapper.class ).annotatedWith( Names.named( NameMappers.FILE_GAV_NAME ) )
.toProvider( FileGAVNameMapperProvider.class ).in( Singleton.class );
bind( NameMapper.class ).annotatedWith( Names.named( FileHashingGAVNameMapperProvider.NAME ) )
bind( NameMapper.class ).annotatedWith( Names.named( NameMappers.FILE_HGAV_NAME ) )
.toProvider( FileHashingGAVNameMapperProvider.class ).in( Singleton.class );

bind( NamedLockFactory.class ).annotatedWith( Names.named( NoopNamedLockFactory.NAME ) )
Expand Down Expand Up @@ -349,18 +350,18 @@ Map<String, ChecksumAlgorithmFactory> provideChecksumTypes(
@Provides
@Singleton
Map<String, NameMapper> provideNameMappers(
@Named( StaticNameMapperProvider.NAME ) NameMapper staticNameMapper,
@Named( GAVNameMapperProvider.NAME ) NameMapper gavNameMapper,
@Named( DiscriminatingNameMapperProvider.NAME ) NameMapper discriminatingNameMapper,
@Named( FileGAVNameMapperProvider.NAME ) NameMapper fileGavNameMapper,
@Named( FileHashingGAVNameMapperProvider.NAME ) NameMapper fileHashingGavNameMapper )
@Named( NameMappers.STATIC_NAME ) NameMapper staticNameMapper,
@Named( NameMappers.GAV_NAME ) NameMapper gavNameMapper,
@Named( NameMappers.DISCRIMINATING_NAME ) NameMapper discriminatingNameMapper,
@Named( NameMappers.FILE_GAV_NAME ) NameMapper fileGavNameMapper,
@Named( NameMappers.FILE_HGAV_NAME ) NameMapper fileHashingGavNameMapper )
{
Map<String, NameMapper> result = new HashMap<>();
result.put( StaticNameMapperProvider.NAME, staticNameMapper );
result.put( GAVNameMapperProvider.NAME, gavNameMapper );
result.put( DiscriminatingNameMapperProvider.NAME, discriminatingNameMapper );
result.put( FileGAVNameMapperProvider.NAME, fileGavNameMapper );
result.put( FileHashingGAVNameMapperProvider.NAME, fileHashingGavNameMapper );
result.put( NameMappers.STATIC_NAME, staticNameMapper );
result.put( NameMappers.GAV_NAME, gavNameMapper );
result.put( NameMappers.DISCRIMINATING_NAME, discriminatingNameMapper );
result.put( NameMappers.FILE_GAV_NAME, fileGavNameMapper );
result.put( NameMappers.FILE_HGAV_NAME, fileHashingGavNameMapper );
return Collections.unmodifiableMap( result );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.eclipse.aether.internal.impl.synccontext.named;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* As end-user "mappers" are actually configurations/compositions and are constructed from several NameMapper
* implementations, this helper class constructing them. This class also holds "names" used by service locator and
* Guice/Sisu as well.
*
* @since 1.9.4
*/
public final class NameMappers
{
public static final String STATIC_NAME = "static";

public static final String GAV_NAME = "gav";

public static final String FILE_GAV_NAME = "file-gav";

public static final String FILE_HGAV_NAME = "file-hgav";

public static final String DISCRIMINATING_NAME = "discriminating";

public static NameMapper staticNameMapper()
{
return new StaticNameMapper();
}

public static NameMapper gavNameMapper()
{
return GAVNameMapper.gav();
}

public static NameMapper fileGavNameMapper()
{
return new BasedirNameMapper( GAVNameMapper.fileGav() );
}

public static NameMapper fileHashingGavNameMapper()
{
return new BasedirNameMapper( new HashingNameMapper( GAVNameMapper.gav() ) );
}

public static NameMapper discriminatingNameMapper()
{
return new DiscriminatingNameMapper( GAVNameMapper.gav() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
import org.eclipse.aether.MultiRuntimeException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.RepositorySystemLifecycle;
import org.eclipse.aether.internal.impl.synccontext.named.providers.DiscriminatingNameMapperProvider;
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileGAVNameMapperProvider;
import org.eclipse.aether.internal.impl.synccontext.named.providers.FileHashingGAVNameMapperProvider;
import org.eclipse.aether.internal.impl.synccontext.named.providers.GAVNameMapperProvider;
import org.eclipse.aether.internal.impl.synccontext.named.providers.StaticNameMapperProvider;
import org.eclipse.aether.named.NamedLockFactory;
import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
Expand Down Expand Up @@ -67,7 +62,7 @@ public class NamedLockFactoryAdapterFactoryImpl implements NamedLockFactoryAdapt
{
private static final String DEFAULT_FACTORY_NAME = LocalReadWriteLockNamedLockFactory.NAME;

private static final String DEFAULT_NAME_MAPPER_NAME = GAVNameMapperProvider.NAME;
private static final String DEFAULT_NAME_MAPPER_NAME = NameMappers.GAV_NAME;

private static Map<String, NamedLockFactory> getManuallyCreatedFactories()
{
Expand All @@ -82,11 +77,11 @@ private static Map<String, NamedLockFactory> getManuallyCreatedFactories()
private static Map<String, NameMapper> getManuallyCreatedNameMappers()
{
HashMap<String, NameMapper> mappers = new HashMap<>();
mappers.put( StaticNameMapperProvider.NAME, new StaticNameMapperProvider().get() );
mappers.put( GAVNameMapperProvider.NAME, new GAVNameMapperProvider().get() );
mappers.put( DiscriminatingNameMapperProvider.NAME, new DiscriminatingNameMapperProvider().get() );
mappers.put( FileGAVNameMapperProvider.NAME, new FileGAVNameMapperProvider().get() );
mappers.put( FileHashingGAVNameMapperProvider.NAME, new FileHashingGAVNameMapperProvider().get() );
mappers.put( NameMappers.STATIC_NAME, NameMappers.staticNameMapper() );
mappers.put( NameMappers.GAV_NAME, NameMappers.gavNameMapper() );
mappers.put( NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper() );
mappers.put( NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper() );
mappers.put( NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper() );
return Collections.unmodifiableMap( mappers );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.DiscriminatingNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "discriminating" name mapper provider.
*
* @since 1.9.0
*/
@Singleton
@Named( DiscriminatingNameMapperProvider.NAME )
@Named( NameMappers.DISCRIMINATING_NAME )
public class DiscriminatingNameMapperProvider implements Provider<NameMapper>
{
public static final String NAME = "discriminating";

private final NameMapper mapper;

public DiscriminatingNameMapperProvider()
{
this.mapper = new DiscriminatingNameMapper( GAVNameMapper.gav() );
this.mapper = NameMappers.discriminatingNameMapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.BasedirNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "file-gav" name mapper provider.
*
* @since 1.9.0
*/
@Singleton
@Named( FileGAVNameMapperProvider.NAME )
@Named( NameMappers.FILE_GAV_NAME )
public class FileGAVNameMapperProvider implements Provider<NameMapper>
{
public static final String NAME = "file-gav";

private final NameMapper mapper;

public FileGAVNameMapperProvider()
{
this.mapper = new BasedirNameMapper( GAVNameMapper.fileGav() );
this.mapper = NameMappers.fileGavNameMapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,23 @@
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.BasedirNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.HashingNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "file-hgav" name mapper provider.
*
* @since 1.9.0
*/
@Singleton
@Named( FileHashingGAVNameMapperProvider.NAME )
@Named( NameMappers.FILE_HGAV_NAME )
public class FileHashingGAVNameMapperProvider implements Provider<NameMapper>
{
public static final String NAME = "file-hgav";

private final NameMapper mapper;

public FileHashingGAVNameMapperProvider()
{
this.mapper = new BasedirNameMapper( new HashingNameMapper( GAVNameMapper.gav() ) );
this.mapper = NameMappers.fileHashingGavNameMapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@
import javax.inject.Provider;
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.GAVNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "gav" name mapper provider.
*
* @since 1.9.0
*/
@Singleton
@Named( GAVNameMapperProvider.NAME )
@Named( NameMappers.GAV_NAME )
public class GAVNameMapperProvider implements Provider<NameMapper>
{
public static final String NAME = "gav";

private final NameMapper mapper;

public GAVNameMapperProvider()
{
this.mapper = GAVNameMapper.gav();
this.mapper = NameMappers.gavNameMapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@
import javax.inject.Singleton;

import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.StaticNameMapper;
import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;

/**
* The "static" name mapper provider.
*
* @since 1.9.0
*/
@Singleton
@Named( StaticNameMapperProvider.NAME )
@Named( NameMappers.STATIC_NAME )
public class StaticNameMapperProvider implements Provider<NameMapper>
{
public static final String NAME = "static";

private final NameMapper mapper;

public StaticNameMapperProvider()
{
this.mapper = new StaticNameMapper();
this.mapper = NameMappers.staticNameMapper();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
/**
* As end-user "mappers" are actually configurations, constructed from several NameMapper implementations, this
* package is holding providers that are constructing them, as no NameMapper is a component anymore.
* package have providers exposing name mappers constructed by
* {@link org.eclipse.aether.internal.impl.synccontext.named.NameMappers} helper class. These classes are used
* when Guice/Sisu is used, as they assume {@link javax.inject.Provider} class to be present.
*/
package org.eclipse.aether.internal.impl.synccontext.named.providers;

0 comments on commit 1010f0f

Please sign in to comment.