org.springframework.core.type.AnnotatedTypeMetadata Java Examples
The following examples show how to use
org.springframework.core.type.AnnotatedTypeMetadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationConfigUtils.java From lams with GNU General Public License v2.0 | 6 votes |
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) { if (metadata.isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); } else if (abd.getMetadata() != metadata && abd.getMetadata().isAnnotated(Lazy.class.getName())) { abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value")); } if (metadata.isAnnotated(Primary.class.getName())) { abd.setPrimary(true); } if (metadata.isAnnotated(DependsOn.class.getName())) { abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); } if (abd instanceof AbstractBeanDefinition) { AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd; if (metadata.isAnnotated(Role.class.getName())) { absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue()); } if (metadata.isAnnotated(Description.class.getName())) { absBd.setDescription(attributesFor(metadata, Description.class).getString("value")); } } }
Example #2
Source File: SetupSteps.java From atlas with Apache License 2.0 | 6 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { try { Configuration configuration = ApplicationProperties.get(); boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false); if (shouldRunSetup) { LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY); return true; } else { LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY); } } catch (AtlasException e) { LOG.error("Unable to read config to determine if setup is needed. Not running setup."); } return false; }
Example #3
Source File: OnPackagingCondition.java From initializr with Apache License 2.0 | 5 votes |
@Override protected boolean matches(ProjectDescription description, ConditionContext context, AnnotatedTypeMetadata metadata) { if (description.getPackaging() == null) { return false; } String packagingId = (String) metadata.getAllAnnotationAttributes(ConditionalOnPackaging.class.getName()) .getFirst("value"); Packaging packaging = Packaging.forId(packagingId); return description.getPackaging().id().equals(packaging.id()); }
Example #4
Source File: PostgresDatabaseCondition.java From OpenCue with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String dbEngine = System.getenv("CUEBOT_DB_ENGINE"); if (dbEngine == null) { return true; } DatabaseEngine selectedDatabaseEngine = DatabaseEngine.valueOf(dbEngine.toUpperCase()); return selectedDatabaseEngine.equals(DatabaseEngine.POSTGRES); }
Example #5
Source File: ShadowSpringBootConditionTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test public void assertMatch() { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty("spring.shardingsphere.rules.shadow.column", "user_id"); ConditionContext context = Mockito.mock(ConditionContext.class); AnnotatedTypeMetadata metadata = Mockito.mock(AnnotatedTypeMetadata.class); when(context.getEnvironment()).thenReturn(mockEnvironment); ShadowSpringBootCondition condition = new ShadowSpringBootCondition(); ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata); assertThat(matchOutcome.isMatch(), is(true)); }
Example #6
Source File: NotEnableOauth2SsoCondition.java From onetwo with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String ssoClass = "org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso"; boolean ssoClientAnnotationExists = ClassUtils.isPresent(ssoClass, null); if(!ssoClientAnnotationExists){ return ConditionOutcome.match("EnableOAuth2Sso not exists!"); } String[] beanNames = context.getBeanFactory().getBeanNamesForAnnotation(EnableOAuth2Sso.class); if(beanNames==null || beanNames.length==0){ return ConditionOutcome.match("not @EnableOAuth2Sso bean found!"); } return ConditionOutcome.noMatch("@EnableOAuth2Sso sso client!"); }
Example #7
Source File: AbstractCondition.java From mongodb-aggregate-query-support with Apache License 2.0 | 5 votes |
protected Object getParameterByIndex(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { Assert.isAssignable(AggregateQueryMethodConditionContext.class, conditionContext.getClass()); AggregateQueryMethodConditionContext ctx = (AggregateQueryMethodConditionContext) conditionContext; List<Object> parameters = ctx.getParameterValues(); int parameterIndex = getParameterIndex(annotatedTypeMetadata); int paramCount = parameters.size(); if (parameterIndex < paramCount) { return parameters.get(parameterIndex); } throw new IllegalArgumentException("Argument index " + parameterIndex + " out of bounds, max count: " + paramCount); }
Example #8
Source File: RedisEnabledCondition.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { if ( !isTestRun( context ) ) { return getConfiguration().getProperty( ConfigurationKey.REDIS_ENABLED ).equalsIgnoreCase( "true" ); } return false; }
Example #9
Source File: MissingSpringCloudRegistryConfigPropertyCondition.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConfigurableEnvironment environment = (ConfigurableEnvironment) context .getEnvironment(); String protocol = environment.getProperty("dubbo.registry.protocol"); if (PROTOCOL.equals(protocol)) { return ConditionOutcome.noMatch( "'spring-cloud' protocol was found from 'dubbo.registry.protocol'"); } String address = environment.getProperty("dubbo.registry.address"); if (StringUtils.startsWithIgnoreCase(address, PROTOCOL)) { return ConditionOutcome.noMatch( "'spring-cloud' protocol was found from 'dubbo.registry.address'"); } Map<String, Object> properties = getSubProperties( environment.getPropertySources(), "dubbo.registries."); boolean found = properties.entrySet().stream().anyMatch(entry -> { String key = entry.getKey(); String value = String.valueOf(entry.getValue()); return (key.endsWith(".address") && value.startsWith(PROTOCOL)) || (key.endsWith(".protocol") && PROTOCOL.equals(value)); }); return found ? ConditionOutcome.noMatch( "'spring-cloud' protocol was found in 'dubbo.registries.*'") : ConditionOutcome.match(); }
Example #10
Source File: OnAwsCloudEnvironmentCondition.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { if (AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment()) { return ConditionOutcome.match(); } return ConditionOutcome.noMatch("not running in aws environment"); }
Example #11
Source File: PropertyExistsCondition.java From logging-log4j-audit with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment env = context.getEnvironment(); MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(ConditionOnPropertyExists.class.getName()); if (attrs != null) { Object value = attrs.get("value"); return value != null && null != env && env.getProperty(value.toString()) != null; } return false; }
Example #12
Source File: HazelcastJetConfigResourceCondition.java From hazelcast-jet-contrib with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { if (System.getProperty(this.configSystemProperty) != null) { return ConditionOutcome.match( startConditionMessage().because("System property '" + this.configSystemProperty + "' is set.")); } return super.getMatchOutcome(context, metadata); }
Example #13
Source File: JuiserSpringSecurityCondition.java From juiser with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage matchMessage = ConditionMessage.empty(); boolean enabled = isSpringSecurityEnabled(context); if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityEnabled.class.getName())) { if (!enabled) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityEnabled.class) .didNotFind("spring security enabled").atAll()); } matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityEnabled.class) .foundExactly("spring security enabled"); } if (metadata.isAnnotated(ConditionalOnJuiserSpringSecurityDisabled.class.getName())) { if (enabled) { return ConditionOutcome.noMatch( ConditionMessage.forCondition(ConditionalOnJuiserSpringSecurityDisabled.class) .didNotFind("spring security disabled").atAll()); } matchMessage = matchMessage.andCondition(ConditionalOnJuiserSpringSecurityDisabled.class) .didNotFind("spring security disabled").atAll(); } return ConditionOutcome.match(matchMessage); }
Example #14
Source File: RxJava2OnClasspathCondition.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return AspectUtil.checkClassIfFound(context, CLASS_TO_CHECK, (e) -> logger.info( "RxJava2 related Aspect extensions are not activated, because RxJava2 is not on the classpath.")) && AspectUtil.checkClassIfFound(context, R4J_RXJAVA, (e) -> logger.info( "RxJava2 related Aspect extensions are not activated because Resilience4j RxJava2 module is not on the classpath.")); }
Example #15
Source File: MissingCondition.java From java-master with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { try { context.getBeanFactory().getBean(RedisTemplate.class); return false; } catch (NoSuchBeanDefinitionException e) { return true; } }
Example #16
Source File: FlexyPoolConfiguration.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("FlexyPoolConfigurationAvailable"); String propertiesFilePath = System.getProperty(PropertyLoader.PROPERTIES_FILE_PATH); if (propertiesFilePath != null && ClassLoaderUtils.getResource(propertiesFilePath) != null) { return ConditionOutcome.match(message.found("FlexyPool configuration file").items(propertiesFilePath)); } if (ClassLoaderUtils.getResource(PropertyLoader.PROPERTIES_FILE_NAME) != null) { return ConditionOutcome.match(message.found("FlexyPool configuration file").items(PropertyLoader.PROPERTIES_FILE_NAME)); } return ConditionOutcome.noMatch(message.didNotFind("FlexyPool configuration file").atAll()); }
Example #17
Source File: KafkaConditionalCommunicate.java From ext-opensource-netty with Mozilla Public License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment env = context.getEnvironment(); return "kafka".equalsIgnoreCase( env.getProperty("netty.server.interal.communicate")); }
Example #18
Source File: RedisDisabledCondition.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata ) { if ( !isTestRun( context ) ) { return !getConfiguration().getProperty( ConfigurationKey.REDIS_ENABLED ).equalsIgnoreCase( "true" ); } return true; }
Example #19
Source File: WicketSettingsCondition.java From wicket-spring-boot with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { String implVersion = null; String wicketVersion = retrieveWicketVersion(implVersion); Map<String, Object> attributes = metadata .getAnnotationAttributes(ConditionalOnWicket.class.getName()); Range range = (Range) attributes.get("range"); int expectedVersion = (int) attributes.get("value"); String[] splittedWicketVersion = wicketVersion.split("\\."); int majorWicketVersion = Integer.valueOf(splittedWicketVersion[0]); return getMatchOutcome(range, majorWicketVersion, expectedVersion); }
Example #20
Source File: OnJdwpDebugCondition.java From super-cloudops with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Object enablePropertyName = metadata.getAnnotationAttributes(ConditionalOnJdwpDebug.class.getName()) .get(NAME_ENABLE_PROPERTY); isTrue(nonNull(enablePropertyName) && isNotBlank(enablePropertyName.toString()), format("%s.%s It shouldn't be empty", ConditionalOnJdwpDebug.class.getSimpleName(), NAME_ENABLE_PROPERTY)); // Obtain environment enable property value. Boolean enable = context.getEnvironment().getProperty(enablePropertyName.toString(), Boolean.class); return isNull(enable) ? isJVMDebugging : enable; }
Example #21
Source File: OnPlatformVersionCondition.java From initializr with Apache License 2.0 | 5 votes |
@Override protected boolean matches(ProjectDescription description, ConditionContext context, AnnotatedTypeMetadata metadata) { Version platformVersion = description.getPlatformVersion(); if (platformVersion == null) { return false; } return Arrays.stream( (String[]) metadata.getAnnotationAttributes(ConditionalOnPlatformVersion.class.getName()).get("value")) .anyMatch((range) -> VersionParser.DEFAULT.parseRange(range).match(platformVersion)); }
Example #22
Source File: OnClassCondition.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnClass.class.getName(), true); String className = String.valueOf(attributes.get(AnnotationUtils.VALUE).get(0)); return ClassUtils.isPresent(className, context.getClassLoader()); }
Example #23
Source File: CustomMetricsCondition.java From cf-java-logging-support with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { try { new CFConfigurationProvider(); } catch (IllegalArgumentException ex) { LOG.error("Custom Metrics reporter will not start since required ENVs are missing: {}", ex.getMessage()); return false; } return true; }
Example #24
Source File: AuthorizationServerTokenServicesConfiguration.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("OAuth JWT KeyStore Condition"); Environment environment = context.getEnvironment(); String keyStore = environment.getProperty("security.oauth2.authorization.jwt.key-store"); if (StringUtils.hasText(keyStore)) { return ConditionOutcome.match(message.foundExactly("provided key store location")); } return ConditionOutcome.noMatch(message.didNotFind("provided key store location").atAll()); }
Example #25
Source File: MySQLAutoconfiguration.java From tutorials with MIT License | 5 votes |
@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("Hibernate"); return Arrays.stream(CLASS_NAMES).filter(className -> ClassUtils.isPresent(className, context.getClassLoader())).map(className -> ConditionOutcome.match(message.found("class").items(Style.NORMAL, className))).findAny() .orElseGet(() -> ConditionOutcome.noMatch(message.didNotFind("class", "classes").items(Style.NORMAL, Arrays.asList(CLASS_NAMES)))); }
Example #26
Source File: OnLanguageCondition.java From initializr with Apache License 2.0 | 5 votes |
@Override protected boolean matches(ProjectDescription description, ConditionContext context, AnnotatedTypeMetadata metadata) { if (description.getLanguage() == null) { return false; } String languageId = (String) metadata.getAllAnnotationAttributes(ConditionalOnLanguage.class.getName()) .getFirst("value"); Language language = Language.forId(languageId, null); return description.getLanguage().id().equals(language.id()); }
Example #27
Source File: ProfileCondition.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (context.getEnvironment() != null) { MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); if (attrs != null) { for (Object value : attrs.get("value")) { if (context.getEnvironment().acceptsProfiles(((String[]) value))) { return true; } } return false; } } return true; }
Example #28
Source File: OnProfileCondition.java From apollo with Apache License 2.0 | 5 votes |
private Set<String> retrieveAnnotatedProfiles(AnnotatedTypeMetadata metadata, String annotationType) { if (!metadata.isAnnotated(annotationType)) { return Collections.emptySet(); } MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(annotationType); if (attributes == null) { return Collections.emptySet(); } Set<String> profiles = Sets.newHashSet(); List<?> values = attributes.get("value"); if (values != null) { for (Object value : values) { if (value instanceof String[]) { Collections.addAll(profiles, (String[]) value); } else { profiles.add((String) value); } } } return profiles; }
Example #29
Source File: CloudCondition.java From solace-java-spring-boot with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata annoMetaData) { Environment env = context.getEnvironment(); String VCAP_APPLICATION = env.getProperty("VCAP_APPLICATION"); if ( VCAP_APPLICATION != null ) { String VCAP_SERVICES = env.getProperty("VCAP_SERVICES"); return VCAP_SERVICES != null && VCAP_SERVICES.contains("\"solace-pubsub\""); } return false; }
Example #30
Source File: FooConfiguration.java From spring-test-examples with Apache License 2.0 | 5 votes |
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { if (context.getEnvironment() != null) { Boolean property = context.getEnvironment().getProperty("foo.create", Boolean.class); return Boolean.TRUE.equals(property); } return false; }