Skip to content

Commit

Permalink
[MRESOLVER-419] Preserve component names (#347)
Browse files Browse the repository at this point in the history
Do not inject/convert, inject plain Map instead.

---

https://issues.apache.org/jira/browse/MRESOLVER-419
  • Loading branch information
cstamas authored Oct 20, 2023
1 parent 62d7dc1 commit 9bf157c
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
Expand Down Expand Up @@ -87,7 +87,7 @@ public class DefaultDeployer implements Deployer {

private final UpdateCheckManager updateCheckManager;

private final Collection<MetadataGeneratorFactory> metadataFactories;
private final Map<String, MetadataGeneratorFactory> metadataFactories;

private final SyncContextFactory syncContextFactory;

Expand All @@ -101,7 +101,7 @@ public DefaultDeployer(
RepositoryConnectorProvider repositoryConnectorProvider,
RemoteRepositoryManager remoteRepositoryManager,
UpdateCheckManager updateCheckManager,
Set<MetadataGeneratorFactory> metadataFactories,
Map<String, MetadataGeneratorFactory> metadataFactories,
SyncContextFactory syncContextFactory,
OfflineController offlineController) {
this.fileProcessor = requireNonNull(fileProcessor, "file processor cannot be null");
Expand All @@ -112,7 +112,7 @@ public DefaultDeployer(
this.remoteRepositoryManager =
requireNonNull(remoteRepositoryManager, "remote repository provider cannot be null");
this.updateCheckManager = requireNonNull(updateCheckManager, "update check manager cannot be null");
this.metadataFactories = Collections.unmodifiableCollection(metadataFactories);
this.metadataFactories = Collections.unmodifiableMap(metadataFactories);
this.syncContextFactory = requireNonNull(syncContextFactory, "sync context factory cannot be null");
this.offlineController = requireNonNull(offlineController, "offline controller cannot be null");
}
Expand Down Expand Up @@ -234,7 +234,7 @@ private DeployResult deploy(SyncContext syncContext, RepositorySystemSession ses
private List<? extends MetadataGenerator> getMetadataGenerators(
RepositorySystemSession session, DeployRequest request) {
PrioritizedComponents<MetadataGeneratorFactory> factories =
Utils.sortMetadataGeneratorFactories(session, this.metadataFactories);
Utils.sortMetadataGeneratorFactories(session, this.metadataFactories.values());

List<MetadataGenerator> generators = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
Expand Down Expand Up @@ -68,20 +67,20 @@ public class DefaultInstaller implements Installer {

private final RepositoryEventDispatcher repositoryEventDispatcher;

private final Collection<MetadataGeneratorFactory> metadataFactories;
private final Map<String, MetadataGeneratorFactory> metadataFactories;

private final SyncContextFactory syncContextFactory;

@Inject
public DefaultInstaller(
FileProcessor fileProcessor,
RepositoryEventDispatcher repositoryEventDispatcher,
Set<MetadataGeneratorFactory> metadataFactories,
Map<String, MetadataGeneratorFactory> metadataFactories,
SyncContextFactory syncContextFactory) {
this.fileProcessor = requireNonNull(fileProcessor, "file processor cannot be null");
this.repositoryEventDispatcher =
requireNonNull(repositoryEventDispatcher, "repository event dispatcher cannot be null");
this.metadataFactories = Collections.unmodifiableCollection(metadataFactories);
this.metadataFactories = Collections.unmodifiableMap(metadataFactories);
this.syncContextFactory = requireNonNull(syncContextFactory, "sync context factory cannot be null");
}

Expand Down Expand Up @@ -152,7 +151,7 @@ private InstallResult install(SyncContext syncContext, RepositorySystemSession s
private List<? extends MetadataGenerator> getMetadataGenerators(
RepositorySystemSession session, InstallRequest request) {
PrioritizedComponents<MetadataGeneratorFactory> factories =
Utils.sortMetadataGeneratorFactories(session, this.metadataFactories);
Utils.sortMetadataGeneratorFactories(session, this.metadataFactories.values());

List<MetadataGenerator> generators = new ArrayList<>();

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.LocalRepositoryProvider;
Expand All @@ -47,12 +46,11 @@ public class DefaultLocalRepositoryProvider implements LocalRepositoryProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLocalRepositoryProvider.class);

private final Collection<LocalRepositoryManagerFactory> managerFactories;
private final Map<String, LocalRepositoryManagerFactory> localRepositoryManagerFactories;

@Inject
public DefaultLocalRepositoryProvider(Set<LocalRepositoryManagerFactory> factories) {
requireNonNull(factories, "local repository manager factory cannot be null");
this.managerFactories = Collections.unmodifiableCollection(factories);
public DefaultLocalRepositoryProvider(Map<String, LocalRepositoryManagerFactory> localRepositoryManagerFactories) {
this.localRepositoryManagerFactories = Collections.unmodifiableMap(localRepositoryManagerFactories);
}

@Override
Expand All @@ -61,7 +59,7 @@ public LocalRepositoryManager newLocalRepositoryManager(RepositorySystemSession
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");
PrioritizedComponents<LocalRepositoryManagerFactory> factories = new PrioritizedComponents<>(session);
for (LocalRepositoryManagerFactory factory : this.managerFactories) {
for (LocalRepositoryManagerFactory factory : this.localRepositoryManagerFactories.values()) {
factories.add(factory, factory.getPriority());
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.RemoteRepositoryFilterManager;
Expand All @@ -52,15 +51,15 @@ public class DefaultRepositoryConnectorProvider implements RepositoryConnectorPr

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRepositoryConnectorProvider.class);

private final Collection<RepositoryConnectorFactory> connectorFactories;
private final Map<String, RepositoryConnectorFactory> connectorFactories;

private final RemoteRepositoryFilterManager remoteRepositoryFilterManager;

@Inject
public DefaultRepositoryConnectorProvider(
Set<RepositoryConnectorFactory> connectorFactories,
Map<String, RepositoryConnectorFactory> connectorFactories,
RemoteRepositoryFilterManager remoteRepositoryFilterManager) {
this.connectorFactories = Collections.unmodifiableCollection(connectorFactories);
this.connectorFactories = Collections.unmodifiableMap(connectorFactories);
this.remoteRepositoryFilterManager = requireNonNull(remoteRepositoryFilterManager);
}

Expand All @@ -81,7 +80,7 @@ public RepositoryConnector newRepositoryConnector(RepositorySystemSession sessio
RemoteRepositoryFilter filter = remoteRepositoryFilterManager.getRemoteRepositoryFilter(session);

PrioritizedComponents<RepositoryConnectorFactory> factories = new PrioritizedComponents<>(session);
for (RepositoryConnectorFactory factory : this.connectorFactories) {
for (RepositoryConnectorFactory factory : this.connectorFactories.values()) {
factories.add(factory, factory.getPriority());
}

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

import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryListener;
Expand All @@ -42,18 +41,18 @@ public class DefaultRepositoryEventDispatcher implements RepositoryEventDispatch

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRepositoryEventDispatcher.class);

private final Collection<RepositoryListener> listeners;
private final Map<String, RepositoryListener> listeners;

@Inject
public DefaultRepositoryEventDispatcher(Set<RepositoryListener> listeners) {
this.listeners = Collections.unmodifiableCollection(listeners);
public DefaultRepositoryEventDispatcher(Map<String, RepositoryListener> listeners) {
this.listeners = Collections.unmodifiableMap(listeners);
}

@Override
public void dispatch(RepositoryEvent event) {
requireNonNull(event, "event cannot be null");
if (!listeners.isEmpty()) {
for (RepositoryListener listener : listeners) {
for (RepositoryListener listener : listeners.values()) {
dispatch(event, listener);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import javax.inject.Singleton;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -47,11 +46,11 @@ public final class DefaultRepositoryLayoutProvider implements RepositoryLayoutPr

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRepositoryLayoutProvider.class);

private final Collection<RepositoryLayoutFactory> factories;
private final Map<String, RepositoryLayoutFactory> layoutFactories;

@Inject
public DefaultRepositoryLayoutProvider(Set<RepositoryLayoutFactory> layoutFactories) {
this.factories = Collections.unmodifiableCollection(layoutFactories);
public DefaultRepositoryLayoutProvider(Map<String, RepositoryLayoutFactory> layoutFactories) {
this.layoutFactories = Collections.unmodifiableMap(layoutFactories);
}

@Override
Expand All @@ -61,7 +60,7 @@ public RepositoryLayout newRepositoryLayout(RepositorySystemSession session, Rem
requireNonNull(repository, "remote repository cannot be null");

PrioritizedComponents<RepositoryLayoutFactory> factories = new PrioritizedComponents<>(session);
for (RepositoryLayoutFactory factory : this.factories) {
for (RepositoryLayoutFactory factory : this.layoutFactories.values()) {
factories.add(factory, factory.getPriority());
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.Map;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -47,11 +46,11 @@ public final class DefaultTransporterProvider implements TransporterProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTransporterProvider.class);

private final Collection<TransporterFactory> factories;
private final Map<String, TransporterFactory> transporterFactories;

@Inject
public DefaultTransporterProvider(Set<TransporterFactory> transporterFactories) {
this.factories = Collections.unmodifiableCollection(transporterFactories);
public DefaultTransporterProvider(Map<String, TransporterFactory> transporterFactories) {
this.transporterFactories = Collections.unmodifiableMap(transporterFactories);
}

@Override
Expand All @@ -61,7 +60,7 @@ public Transporter newTransporter(RepositorySystemSession session, RemoteReposit
requireNonNull(repository, "repository cannot be null");

PrioritizedComponents<TransporterFactory> factories = new PrioritizedComponents<>(session);
for (TransporterFactory factory : this.factories) {
for (TransporterFactory factory : this.transporterFactories.values()) {
factories.add(factory, factory.getPriority());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void setup() throws IOException {
connectorProvider,
new StubRemoteRepositoryManager(),
new StaticUpdateCheckManager(true),
Collections.emptySet(),
Collections.emptyMap(),
new StubSyncContextFactory(),
new DefaultOfflineController());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void setup() throws IOException {
installer = new DefaultInstaller(
new TestFileProcessor(),
new StubRepositoryEventDispatcher(),
Collections.emptySet(),
Collections.emptyMap(),
new StubSyncContextFactory());
request = new InstallRequest();
listener = new RecordingRepositoryListener();
Expand Down Expand Up @@ -336,7 +336,7 @@ public long copy(File src, File target, ProgressListener listener) throws IOExce
}
},
new StubRepositoryEventDispatcher(),
Collections.emptySet(),
Collections.emptyMap(),
new StubSyncContextFactory());

request = new InstallRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DefaultRepositoryEventDispatcherTest {

@Test
void testDispatchHandlesAllEventTypes() {
DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(Collections.emptySet());
DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(Collections.emptyMap());

ListenerHandler handler = new ListenerHandler();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class PrefixesRemoteRepositoryFilterSourceTest extends RemoteRepositoryFi
@Override
protected RemoteRepositoryFilterSource getRemoteRepositoryFilterSource(
DefaultRepositorySystemSession session, RemoteRepository remoteRepository) {
DefaultRepositoryLayoutProvider layoutProvider = new DefaultRepositoryLayoutProvider(
Collections.singleton(new Maven2RepositoryLayoutFactory(checksumsSelector())));
DefaultRepositoryLayoutProvider layoutProvider = new DefaultRepositoryLayoutProvider(Collections.singletonMap(
Maven2RepositoryLayoutFactory.NAME, new Maven2RepositoryLayoutFactory(checksumsSelector())));
return new PrefixesRemoteRepositoryFilterSource(layoutProvider);
}

Expand Down
Loading

0 comments on commit 9bf157c

Please sign in to comment.