Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for mongo client in the whole deployment #15594

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.mongodb.event.ConnectionPoolListener;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
Expand All @@ -41,7 +42,6 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.annotations.Weak;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand Down Expand Up @@ -116,10 +116,10 @@ List<ReflectiveClassBuildItem> addExtensionPointsToNative(CodecProviderBuildItem
}

@BuildStep
public void mongoClientNames(ApplicationArchivesBuildItem applicationArchivesBuildItem,
public void mongoClientNames(BeanArchiveIndexBuildItem indexBuildItem,
BuildProducer<MongoClientNameBuildItem> mongoClientName) {
Set<String> values = new HashSet<>();
IndexView indexView = applicationArchivesBuildItem.getRootArchive().getIndex();
IndexView indexView = indexBuildItem.getIndex();
addMongoClientNameValues(LEGACY_MONGO_CLIENT_ANNOTATION, indexView, values);
addMongoClientNameValues(MONGO_CLIENT_ANNOTATION, indexView, values);
for (String value : values) {
Expand Down Expand Up @@ -163,6 +163,16 @@ MongoConnectionPoolListenerBuildItem setupMetrics(
return null;
}

@BuildStep
void additionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
// add the @MongoClientName class otherwise it won't registered as a qualifier
additionalBeans.produce(
AdditionalBeanBuildItem.builder().addBeanClass(io.quarkus.mongodb.runtime.MongoClientName.class).build());
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MongoClientName.class).build());
// make MongoClients an unremoveable bean
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(MongoClients.class).setUnremovable().build());
}

@Record(STATIC_INIT)
@BuildStep
void build(
Expand All @@ -175,22 +185,13 @@ void build(
CommandListenerBuildItem commandListener,
List<MongoConnectionPoolListenerBuildItem> connectionPoolListenerProvider,
BuildProducer<MongoConnectionNameBuildItem> mongoConnections,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

// add the @MongoClientName class otherwise it won't registered as a qualifier
additionalBeans.produce(
AdditionalBeanBuildItem.builder().addBeanClass(io.quarkus.mongodb.runtime.MongoClientName.class).build());
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MongoClientName.class).build());
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer) {

List<Supplier<ConnectionPoolListener>> poolListenerList = new ArrayList<>(connectionPoolListenerProvider.size());
for (MongoConnectionPoolListenerBuildItem item : connectionPoolListenerProvider) {
poolListenerList.add(item.getConnectionPoolListener());
}

// make MongoClients an unremoveable bean
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(MongoClients.class).setUnremovable().build());

// create MongoClientSupport as a synthetic bean as it's used in AbstractMongoClientProducer
syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem.configure(MongoClientSupport.class)
.scope(Singleton.class)
Expand Down