@Inject public GitElasticsearchClient(@ConfigProperty(name = "ELASTICSEARCH_HOST", defaultValue = "http://elasticsearch") String elasticsearchHost, @ConfigProperty(name = "ELASTICSEARCH_SERVICE_PORT") String elasticsearchPort, @ConfigProperty(name = "GIT_COLLECTOR_USERNAME") String username, @ConfigProperty(name = "GIT_COLLECTOR_PASSWORD") String password) { super(elasticsearchHost, elasticsearchPort, username, password); }
protected <T> T getUntypedPropertyValue(InjectionPoint injectionPoint, Type ipCls) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } return readEntry(configProperty.name(), configProperty.defaultValue(), ipCls, configProperty.converter(), configProperty.parameterizedBy(), configProperty.projectStageAware(), configProperty.evaluateVariables()); }
@Override protected Object getDefaultValue(final Field field) { final ConfigProperty configProperty = field.getAnnotation(ConfigProperty.class); if (configProperty != null && this.configPropertyName.equals(configProperty.name())) { return configProperty.defaultValue(); } return super.getDefaultValue(field); }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Integer> produceIntegerListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Integer> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Integer.parseInt(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Integer property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
/** * Verifies the name of the {@link ConfigProperty}. If the field type matches and the {@link ConfigProperty}'s name * matches, the method returns <code>true</code>. If the {@link ConfigProperty} has a default value set, the value * will be used in case the injection value is <code>null</code>. */ @Override protected boolean isMatching(final Field field) { if (!this.isAutoConvertible(field, super.getValue()) && !super.isMatching(field)) { return false; } final ConfigProperty configProperty = field.getAnnotation(ConfigProperty.class); if (configProperty != null && this.configPropertyName.equals(configProperty.name())) { return true; } return false; }
public void collectDynamicTypes(@Observes ProcessBean<?> processBean) { for (final InjectionPoint ip : processBean.getBean().getInjectionPoints()) { final ConfigProperty annotation = ip.getAnnotated().getAnnotation(ConfigProperty.class); if (annotation == null || annotation.converter() == ConfigResolver.Converter.class) { continue; } dynamicConfigTypes.add(ip.getType()); } }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Long> produceLongListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Long> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Long.parseLong(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
/** * <p>Inspects the given InjectionPoint and search for a {@link ConfigProperty} * annotation or an Annotation with a {@link ConfigProperty} meta-Annotation. * The name and defaultValue information will be used to resolve the * configured value.</p> * * @param injectionPoint current injection point * @return the configured value for the given InjectionPoint */ protected String getStringPropertyValue(InjectionPoint injectionPoint) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } String configuredValue; String defaultValue = configProperty.defaultValue(); configuredValue = getPropertyValue(configProperty.name(), defaultValue); return configuredValue; }
private <T> T getPropertyWithException(InjectionPoint ip, Type ipCls) { try { return getUntypedPropertyValue(ip, ipCls); } catch (RuntimeException rte) { ConfigProperty configProperty = getAnnotation(ip, ConfigProperty.class); throw new RuntimeException("Error while converting property '" + configProperty.name() + "' happening in bean " + ip.getBean(), rte); } } }
@Inject public HubotNotifier(@ConfigProperty(name = "HUBOT_USERNAME") String username, @ConfigProperty(name = "HUBOT_PASSWORD") String password, @ConfigProperty(name = "HUBOT_BUILD_ROOM", defaultValue = DEFAULT_ROOM_EXPRESSION) String roomExpression) { this.username = username; this.password = password; this.roomExpression = roomExpression; }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Float> produceFloatListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Float> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Float.parseFloat(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Float property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
protected <T> T getUntypedPropertyValue(InjectionPoint injectionPoint, Type ipCls) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } return readEntry(configProperty.name(), configProperty.defaultValue(), ipCls, configProperty.converter(), configProperty.parameterizedBy(), configProperty.projectStageAware(), configProperty.evaluateVariables()); }
protected void processEndpointClass(final RoundEnvironment roundEnv, final Element element, StringBuilder buffer, boolean first) { final ConfigProperty property = element.getAnnotation(ConfigProperty.class); if (property != null) { String defaultValue = property.defaultValue(); if ("org.apache.deltaspike.NullValueMarker".equals(defaultValue)) { defaultValue = null; String name = property.name();
@Inject public GitUserHelper(@ConfigProperty(name = "JENKINS_GOGS_USER") String gitUser, @ConfigProperty(name = "JENKINS_GOGS_PASSWORD") String gitPassword, KubernetesClient kubernetesClient) { this.gitUser = gitUser; this.gitPassword = gitPassword; this.kubernetesClient = kubernetesClient; }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Map<String,String> produceStringStringMapConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] pairs = StringUtils.split(propertyValue, "|"); Map<String,String> map = new LinkedHashMap<>(); if (pairs != null) { for (String pair : pairs) { String[] keyValue = StringUtils.split(pair, ";"); if (keyValue != null && (keyValue.length == 1 || keyValue.length == 2)) { map.put(keyValue[0], keyValue.length == 1 ? "" : keyValue[1]); } else { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Map<String,String> property '" + configProperty.name() + "' pair: " + pair + " of " + propertyValue + " happening in bean " + injectionPoint.getBean()); } } } return map; }
final Class<? extends ConfigResolver.Converter> converter = annotation.converter(); final String defaultValue = annotation.defaultValue(); ConfigResolver.TypedResolver<?> typedResolver = delegate.asResolver( prefix + annotation.name(), list || set ? ConfigProperty.NULL : defaultValue, returnType, converter, annotation.parameterizedBy(), annotation.projectStageAware(), annotation.evaluateVariables());
@Inject public ProcessManagerService(@ConfigProperty(name = "JUBE_PROCESS_DIR", defaultValue = "./processes") String storageLocation, @ConfigProperty(name = "JUBE_REMOTE_MAVEN_REPOS", defaultValue = DEFAULT_MAVEN_REPOS) String remoteRepositoryUrls, @ConfigProperty(name = "JUBE_PORT_START", defaultValue = "" + AvailablePortFinder.MIN_PORT_NUMBER) int minPort) throws MalformedObjectNameException, IOException { this(new File(storageLocation), remoteRepositoryUrls, minPort); }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Double> produceDoubleListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Double> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Double.parseDouble(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Double property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
@Inject public ProjectFileSystem(RepositoryCache repositoryCache, @ConfigProperty(name = "PROJECT_FOLDER", defaultValue = "/tmp/fabric8-forge") String rootProjectFolder, @ConfigProperty(name = "GIT_REMOTE_BRANCH_NAME", defaultValue = "origin") String remote, @ConfigProperty(name = "JENKINSFILE_LIBRARY_GIT_REPOSITORY") String jenkinsfileLibraryGitUrl, @ConfigProperty(name = "JENKINSFILE_LIBRARY_GIT_TAG") String jenkinsfileLibraryGitTag) { this.repositoryCache = repositoryCache; this.rootProjectFolder = rootProjectFolder; this.remote = remote; this.jenkinsfileLibraryGitUrl = jenkinsfileLibraryGitUrl; this.jenkinsfileLibraryGitTag = jenkinsfileLibraryGitTag; LOG.info("Using jenkins workflow library: " + this.jenkinsfileLibraryGitUrl); LOG.info("Using jenkins workflow library version: " + this.jenkinsfileLibraryGitTag); }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Long produceLongConfiguration(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } try { return Long.parseLong(configuredValue); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + configuredValue + " happening in bean " + injectionPoint.getBean() , nfe); } }