1818
1919import java .util .ArrayList ;
2020import java .util .Collections ;
21- import java .util .EnumSet ;
2221import java .util .List ;
2322
2423import org .apache .commons .logging .Log ;
3130import org .springframework .util .StringUtils ;
3231
3332public class ZookeeperConfigDataLoader implements ConfigDataLoader <ZookeeperConfigDataResource > {
34- private static final EnumSet <ConfigData .Option > ALL_OPTIONS = EnumSet .allOf (ConfigData .Option .class );
3533
3634 private final Log log ;
3735
@@ -50,35 +48,24 @@ public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataResou
5048 ZookeeperPropertySource propertySource = new ZookeeperPropertySource (resource .getContext (),
5149 curator );
5250 List <ZookeeperPropertySource > propertySources = Collections .singletonList (propertySource );
53- if (ALL_OPTIONS .size () == 1 ) {
54- // boot 2.4.2 and prior
55- return new ConfigData (propertySources );
56- }
57- else if (ALL_OPTIONS .size () == 2 ) {
58- // boot 2.4.3 and 2.4.4
59- return new ConfigData (propertySources , ConfigData .Option .IGNORE_IMPORTS , ConfigData .Option .IGNORE_PROFILES );
60- }
61- else if (ALL_OPTIONS .size () > 2 ) {
62- // boot 2.4.5+
63- return new ConfigData (propertySources , source -> {
64- List <ConfigData .Option > options = new ArrayList <>();
65- options .add (ConfigData .Option .IGNORE_IMPORTS );
66- options .add (ConfigData .Option .IGNORE_PROFILES );
67- if (StringUtils .hasText (resource .getProfile ())) {
68- options .add (ConfigData .Option .PROFILE_SPECIFIC );
69- }
70- return ConfigData .Options .of (options .toArray (new ConfigData .Option [0 ]));
71- });
7251
73- }
52+ return new ConfigData (propertySources , source -> {
53+ List <ConfigData .Option > options = new ArrayList <>();
54+ options .add (ConfigData .Option .IGNORE_IMPORTS );
55+ options .add (ConfigData .Option .IGNORE_PROFILES );
56+ if (StringUtils .hasText (resource .getProfile ())) {
57+ options .add (ConfigData .Option .PROFILE_SPECIFIC );
58+ }
59+ return ConfigData .Options .of (options .toArray (new ConfigData .Option [0 ]));
60+ });
61+
7462 }
7563 catch (Exception e ) {
7664 if (log .isDebugEnabled ()) {
7765 log .debug ("Error getting properties from zookeeper: " + resource , e );
7866 }
7967 throw new ConfigDataResourceNotFoundException (resource , e );
8068 }
81- return null ;
8269 }
8370
8471}
0 commit comments