@Override public boolean matches(Predicate<String> activeProfiles) { for (Profiles candidate : this.parsed) { if (candidate.matches(activeProfiles)) { return true; } } return false; }
private Profiles defaultProfile() { return Profiles.of(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) { return true; } } return false; } return true; }
private static Predicate<Profiles> isMatch(Predicate<String> activeProfile) { return profiles -> profiles.matches(activeProfile); }
private static Profiles not(Profiles profiles) { return activeProfile -> !profiles.matches(activeProfile); }
@Test public void sensibleToString() { assertEquals("spring & framework or java | kotlin", Profiles.of("spring & framework", "java | kotlin").toString()); }
@Test public void ofMultipleElementsWithInverted() { Profiles profiles = Profiles.of("!spring", "framework"); assertFalse(profiles.matches(activeProfiles("spring"))); assertTrue(profiles.matches(activeProfiles("spring", "framework"))); assertTrue(profiles.matches(activeProfiles("framework"))); assertTrue(profiles.matches(activeProfiles("java"))); }
@Override public boolean acceptsProfiles(Profiles profiles) { Assert.notNull(profiles, "Profiles must not be null"); return profiles.matches(this::isProfileActive); }
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(Profiles.of((String[]) value))) { return true; } } return false; } return true; }
@Override public boolean matches(Predicate<String> activeProfiles) { for (Profiles candidate : this.parsed) { if (candidate.matches(activeProfiles)) { return true; } } return false; }
@Test public void ofOrExpressionWithoutSpaces() { Profiles profiles = Profiles.of("(spring|framework)"); assertOrExpression(profiles); }
private static Predicate<Profiles> isMatch(Predicate<String> activeProfile) { return profiles -> profiles.matches(activeProfile); }
@Test public void ofOrExpression() { Profiles profiles = Profiles.of("(spring | framework)"); assertOrExpression(profiles); }