Skip to content

Commit

Permalink
resolves the issue with config-driven-services and additional ctor in…
Browse files Browse the repository at this point in the history
…jection points (#6612)
  • Loading branch information
trentjeff authored Apr 13, 2023
1 parent 9c0c0de commit 1e25876
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed 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.
*/

package io.helidon.examples.nima.pico;

import org.junit.jupiter.api.Test;

class GreetEndpointTest {

@Test
void testIt() {
PicoMain.main(new String[] {});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public Optional<Object> resolve(InjectionPointInfo ipInfo,
.addContractImplemented(configBeanType().getName())
.build();
if (!dep.matchesContracts(criteria)) {
return Optional.empty();
return Optional.empty(); // we are being injected with neither a config bean nor a service that matches ourselves
}

// if we are here then we are asking for a config bean for ourselves, or a slave/managed instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ private static void accumulate(DependencyInfo dep,
.orElse(null);
Object target = (resolved instanceof Optional)
? ((Optional<?>) resolved).orElse(null) : resolved;
DefaultPicoInjectionPlan.Builder planBuilder = DefaultPicoInjectionPlan.builder()
.serviceProvider(self)
.injectionPointInfo(ipInfo)
.injectionPointQualifiedServiceProviders(toIpQualified(target))
.unqualifiedProviders(toIpUnqualified(target))
.wasResolved(resolved != null);
if (target != null) {
DefaultPicoInjectionPlan.Builder planBuilder = DefaultPicoInjectionPlan.builder()
.serviceProvider(self)
.injectionPointInfo(ipInfo)
.injectionPointQualifiedServiceProviders(toIpQualified(target))
.unqualifiedProviders(toIpUnqualified(target))
.wasResolved(resolved != null);

if (ipInfo.optionalWrapped()) {
planBuilder.resolved((target instanceof Optional && ((Optional<?>) target).isEmpty())
? Optional.empty() : Optional.of(target));
Expand All @@ -125,9 +126,11 @@ private static void accumulate(DependencyInfo dep,
}
planBuilder.resolved(target);
}

PicoInjectionPlan plan = planBuilder.build();
Object prev = result.put(id, plan);
assert (prev == null) : ipInfo;
}
Object prev = result.put(id, planBuilder.build());
assert (prev == null) : ipInfo;
}
});
}
Expand All @@ -143,8 +146,8 @@ private static void accumulate(DependencyInfo dep,
List<ServiceProvider<?>> serviceProviders =
(tmpServiceProviders != null && !tmpServiceProviders.isEmpty())
? tmpServiceProviders.stream()
.filter(sp -> !isSelf(self, sp))
.collect(Collectors.toList())
.filter(sp -> !isSelf(self, sp))
.collect(Collectors.toList())
: tmpServiceProviders;

dep.injectionPointDependencies()
Expand All @@ -163,7 +166,7 @@ private static void accumulate(DependencyInfo dep,
throw DefaultServices.resolutionBasedInjectionError(
ipInfo.dependencyToServiceInfo());
}
DefaultPicoInjectionPlan plan = DefaultPicoInjectionPlan.builder()
PicoInjectionPlan plan = DefaultPicoInjectionPlan.builder()
.injectionPointInfo(ipInfo)
.injectionPointQualifiedServiceProviders(serviceProviders)
.serviceProvider(self)
Expand Down

0 comments on commit 1e25876

Please sign in to comment.