• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.internal.codegen;
18 
19 import static java.lang.annotation.ElementType.FIELD;
20 import static java.lang.annotation.ElementType.METHOD;
21 import static java.lang.annotation.ElementType.PARAMETER;
22 import static java.lang.annotation.RetentionPolicy.RUNTIME;
23 
24 import com.google.common.collect.ImmutableSet;
25 import dagger.Module;
26 import dagger.Provides;
27 import dagger.spi.BindingGraphPlugin;
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.Target;
30 import java.util.Optional;
31 import java.util.ServiceLoader;
32 import javax.inject.Qualifier;
33 import javax.inject.Singleton;
34 
35 /** Contains the bindings for {@link BindingGraphValidator} from external SPI providers. */
36 @Module
37 abstract class SpiModule {
SpiModule()38   private SpiModule() {}
39 
40   @Provides
41   @Singleton
externalPlugins( @estingPlugins Optional<ImmutableSet<BindingGraphPlugin>> testingPlugins)42   static ImmutableSet<BindingGraphPlugin> externalPlugins(
43       @TestingPlugins Optional<ImmutableSet<BindingGraphPlugin>> testingPlugins) {
44     return testingPlugins.orElseGet(
45         () ->
46             ImmutableSet.copyOf(
47                 ServiceLoader.load(
48                     BindingGraphPlugin.class, BindingGraphValidator.class.getClassLoader())));
49   }
50 
51   @Qualifier
52   @Retention(RUNTIME)
53   @Target({FIELD, PARAMETER, METHOD})
54   @interface TestingPlugins {}
55 }
56