org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty Java Examples
The following examples show how to use
org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty.
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: CfgPropsDialog.java From nb-springboot with Apache License 2.0 | 6 votes |
private void filterProps(String filter) { DefaultListModel<ConfigurationMetadataProperty> dlmCfgProps = new DefaultListModel<>(); for (ConfigurationMetadataProperty item : sortedProps) { if (filter == null || item.getId().contains(filter)) { if (Utils.isErrorDeprecated(item)) { if (bDeprErrorShow) { dlmCfgProps.addElement(item); } } else { dlmCfgProps.addElement(item); } } } lCfgProps.setModel(dlmCfgProps); if (!dlmCfgProps.isEmpty()) { lCfgProps.setSelectedIndex(0); } }
Example #2
Source File: CfgPropsDialog.java From nb-springboot with Apache License 2.0 | 6 votes |
@Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof ConfigurationMetadataProperty) { ConfigurationMetadataProperty prop = (ConfigurationMetadataProperty) value; if (prop.isDeprecated()) { setText(String.format("<html><s>%s", prop.getId())); if (Utils.isErrorDeprecated(prop)) { setForeground(UIManager.getColor("nb.errorForeground")); } } else { setText(prop.getId()); } } return this; }
Example #3
Source File: AppRegistryController.java From spring-cloud-dashboard with Apache License 2.0 | 6 votes |
/** * Retrieve detailed information about a particular application. * @param type application type * @param name application name * @return detailed application information */ @RequestMapping(value = "/{type}/{name}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public DetailedAppRegistrationResource info( @PathVariable("type") String type, @PathVariable("name") String name) { AppRegistration registration = appRegistry.find(name, type); if (registration == null) { throw new NoSuchAppRegistrationException(name, type); } DetailedAppRegistrationResource result = new DetailedAppRegistrationResource(assembler.toResource(registration)); Resource resource = registration.getResource(); List<ConfigurationMetadataProperty> properties = metadataResolver.listProperties(resource); for (ConfigurationMetadataProperty property : properties) { result.addOption(property); } return result; }
Example #4
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Return metadata about configuration properties that are documented via <a href= * "https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html"> * Spring Boot configuration metadata</a> and visible in an app. * * @param app a Spring Cloud Stream app; typically a Boot uberjar, but directories are * supported as well */ @Override public List<ConfigurationMetadataProperty> listProperties(Resource app, boolean exhaustive) { try { if (app != null) { if (isDockerSchema(app.getURI())) { return resolvePropertiesFromContainerImage(app.getURI()); } else { Archive archive = resolveAsArchive(app); return listProperties(archive, exhaustive); } } } catch (Exception e) { logger.warn("Failed to retrieve properties for resource:" + app, e); return Collections.emptyList(); } return Collections.emptyList(); }
Example #5
Source File: ProposalsCollectorSupportUtils.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
void addValueHintsProposals(final String dsl, AppRegistration appRegistration, final List<CompletionProposal> collector, final String propertyName, final ValueHintProvider[] valueHintProviders){ final Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration); if (metadataResource != null) { final URLClassLoader classLoader = metadataResolver.createAppClassLoader(metadataResource); this.doWithClassLoader(classLoader, () -> { CompletionProposal.Factory proposals = CompletionProposal.expanding(dsl); List<ConfigurationMetadataProperty> whiteList = metadataResolver.listProperties(metadataResource); for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource, true)) { if (CompletionUtils.isMatchingProperty(propertyName, property, whiteList)) { for (ValueHintProvider valueHintProvider : valueHintProviders) { for (ValueHint valueHint : valueHintProvider.generateValueHints(property, classLoader)) { collector.add(proposals.withSuffix(String.valueOf(valueHint.getValue()), valueHint.getShortDescription())); } } } } return null; }); } }
Example #6
Source File: CfgPropsDialog.java From nb-springboot with Apache License 2.0 | 6 votes |
@Override public int compare(ConfigurationMetadataProperty p1, ConfigurationMetadataProperty p2) { if (!sortDeprLast) { return p1.getId().compareTo(p2.getId()); } else { boolean d1 = p1.isDeprecated(); boolean d2 = p2.isDeprecated(); if (d1 && !d2) { return 1; } else if (d2 && !d1) { return -1; } else { return p1.getId().compareTo(p2.getId()); } } }
Example #7
Source File: PropertyDocumentation.java From joinfaces with Apache License 2.0 | 6 votes |
private void printProperty(PrintWriter writer, ConfigurationMetadataProperty property) { writer.print(property.getId()); writer.print('='); Object defaultValue = property.getDefaultValue(); if (defaultValue != null) { if (defaultValue.getClass().isArray()) { defaultValue = Arrays.stream((Object[]) defaultValue) .map(String::valueOf) .collect(Collectors.joining(",")); } writer.print(defaultValue); } if (property.getShortDescription() != null) { writer.print(" # "); writer.print(property.getShortDescription()); } writer.println(); }
Example #8
Source File: LauncherInitializationService.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@EventListener @Transactional public void initialize(ApplicationReadyEvent event) { List<ConfigurationMetadataProperty> metadataProperties = this.resolver.resolve(); this.taskPlatforms.forEach(platform -> { platform.getLaunchers().forEach(launcher -> { List<ConfigurationMetadataPropertyEntity> options = createMetadataPropertyEntities(metadataProperties, launcher.getType()); launcher.setOptions(options); this.launcherRepository.save(launcher); logger.info(String.format( "Added '%s' platform account '%s' into Task Launcher repository.", platform.getName(), launcher.getName())); }); }); }
Example #9
Source File: DeployerInitializationService.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@EventListener @Transactional public void initialize(ApplicationReadyEvent event) { List<ConfigurationMetadataProperty> metadataProperties = this.resolver.resolve(); this.platforms.forEach(platform -> { platform.getDeployers().forEach(deployer -> { List<ConfigurationMetadataPropertyEntity> options = createMetadataPropertyEntities(metadataProperties, deployer.getType()); deployer.setOptions(options); this.deployerRepository.save(deployer); logger.info(String.format( "Added '%s' platform account '%s' into deployer repository.", platform.getName(), deployer.getName())); }); }); }
Example #10
Source File: DeployerConfigurationMetadataResolverTests.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@Test public void testIncludeGroupExcludeProperty() { this.contextRunner .withPropertyValues( "spring.cloud.skipper.server.deployer-properties.group-includes=spring.cloud.deployer.local.port-range", "spring.cloud.skipper.server.deployer-properties.property-excludes=spring.cloud.deployer.local.port-range.low" ) .run((context) -> { SkipperServerProperties skipperServerProperties = context.getBean(SkipperServerProperties.class); DeployerConfigurationMetadataResolver resolver = new DeployerConfigurationMetadataResolver( skipperServerProperties.getDeployerProperties()); resolver.setApplicationContext(context); List<ConfigurationMetadataProperty> data = resolver.resolve(); assertThat(data.size()).isEqualTo(1); }); }
Example #11
Source File: AppRegistryController.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
private DetailedAppRegistrationResource getInfo(ApplicationType type, String name, String version, Boolean allProperties) { AppRegistration registration = appRegistryService.find(name, type, version); if (registration == null) { throw new NoSuchAppRegistrationException(name, type, version); } DetailedAppRegistrationResource result = new DetailedAppRegistrationResource( assembler.toModel(registration)); List<ConfigurationMetadataProperty> properties = metadataResolver .listProperties(appRegistryService.getAppMetadataResource(registration), allProperties); for (ConfigurationMetadataProperty property : properties) { result.addOption(property); } return result; }
Example #12
Source File: CfgPropsCompletionQuery.java From nb-springboot with Apache License 2.0 | 5 votes |
private String extractMapKeyType(ConfigurationMetadataProperty propMeta) { Matcher matcher = PATTERN_MAPKEY_DATATYPE.matcher(propMeta.getType()); if (matcher.matches()) { final String dataType = matcher.group(1); logger.log(FINER, "Map key data type: {0}", dataType); return dataType; } return ""; }
Example #13
Source File: CfgPropCompletionItem.java From nb-springboot with Apache License 2.0 | 5 votes |
public CfgPropCompletionItem(ConfigurationMetadataProperty configurationMeta, int propStartOffset, int caretOffset, boolean sortDeprLast) { this.overwrite = false; this.configurationMeta = configurationMeta; if (configurationMeta.getType() != null) { type = simpleHtmlEscape(shortenJavaType(configurationMeta.getType())); } else { type = null; } this.propStartOffset = propStartOffset; this.caretOffset = caretOffset; this.sortDeprLast = sortDeprLast; }
Example #14
Source File: BootApplicationConfigurationMetadataResolverTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void otherPropertiesShouldOnlyBeVisibleInExtensiveCall() { List<ConfigurationMetadataProperty> properties = resolver .listProperties(new ClassPathResource("apps/filter-processor", getClass())); assertThat(properties, not(hasItem(configPropertyIdentifiedAs("some.prefix.hidden.by.default.secret")))); properties = resolver.listProperties(new ClassPathResource("apps/filter-processor", getClass()), true); assertThat(properties, hasItem(configPropertyIdentifiedAs("some.prefix.hidden.by.default.secret"))); }
Example #15
Source File: DeployerConfigurationMetadataResolverTests.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@Test public void testIncludeProperty() { this.contextRunner .withPropertyValues( "spring.cloud.skipper.server.deployer-properties.property-includes=spring.cloud.deployer.local.port-range.low" ) .run((context) -> { SkipperServerProperties skipperServerProperties = context.getBean(SkipperServerProperties.class); DeployerConfigurationMetadataResolver resolver = new DeployerConfigurationMetadataResolver( skipperServerProperties.getDeployerProperties()); resolver.setApplicationContext(context); List<ConfigurationMetadataProperty> data = resolver.resolve(); assertThat(data.size()).isEqualTo(1); }); }
Example #16
Source File: PropertyDocumentation.java From joinfaces with Apache License 2.0 | 5 votes |
@TaskAction public void generatePropertyDocumentation() throws IOException { ConfigurationMetadataRepository configurationMetadataRepository; configurationMetadataRepository = ConfigurationMetadataRepositoryJsonBuilder.create() .withJsonResource(new FileInputStream(getInputFile().getAsFile().get())) .build(); try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(getOutputFile().getAsFile().get(), "UTF-8")) { writer.println("[source,properties,indent=0,subs=\"verbatim,attributes,macros\"]"); writer.println("----"); configurationMetadataRepository.getAllGroups().values().stream() .sorted(Comparator.comparing(ConfigurationMetadataGroup::getId)) .forEach(group -> { writer.printf("## %s\n", group.getId()); group.getSources().values() .stream() .map(ConfigurationMetadataSource::getShortDescription) .filter(s -> s != null && !s.isEmpty()) .forEach(d -> writer.printf("# %s\n", d)); group.getProperties().values().stream() .sorted(Comparator.comparing(ConfigurationMetadataProperty::getId)) .forEach(property -> printProperty(writer, property)); writer.println(); writer.flush(); }); writer.println("----"); } }
Example #17
Source File: WhitelistProperties.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
private void assertNoAmbiguity(List<ConfigurationMetadataProperty> longForms) { if (longForms.size() > 1) { Set<String> ids = new HashSet<>(longForms.size()); for (ConfigurationMetadataProperty pty : longForms) { ids.add(pty.getId()); } throw new IllegalArgumentException(String.format("Ambiguous short form property '%s' could mean any of %s", longForms.iterator().next().getName(), ids)); } }
Example #18
Source File: BootApplicationConfigurationMetadataResolverTests.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
@Test public void shouldReturnEverythingWhenNoDescriptors() { List<ConfigurationMetadataProperty> properties = resolver.listProperties(new ClassPathResource("apps/no-whitelist", getClass())); List<ConfigurationMetadataProperty> full = resolver.listProperties(new ClassPathResource("apps/no-whitelist", getClass()), true); assertThat( properties.size(), greaterThan(0)); assertThat(properties.size(), is(full.size())); }
Example #19
Source File: CfgPropsCompletionQuery.java From nb-springboot with Apache License 2.0 | 5 votes |
private String extractMapValueType(ConfigurationMetadataProperty propMeta) { Matcher matcher = PATTERN_MAPVALUE_DATATYPE.matcher(propMeta.getType()); if (matcher.matches()) { final String dataType = matcher.group(1); logger.log(FINER, "Map value data type: {0}", dataType); return dataType; } return ""; }
Example #20
Source File: ProposalsCollectorSupportUtils.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
boolean addAlreadyTypedValueHintsProposals(final String text, AppRegistration appRegistration, final List<CompletionProposal> collector, final String propertyName, final ValueHintProvider[] valueHintProviders, final String alreadyTyped){ final Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration); boolean result = false; if (metadataResource == null) { result = false; } else { final URLClassLoader classLoader = metadataResolver.createAppClassLoader(metadataResource); result = this.doWithClassLoader(classLoader, () -> { CompletionProposal.Factory proposals = CompletionProposal.expanding(text); List<ConfigurationMetadataProperty> allProps = metadataResolver.listProperties(metadataResource, true); List<ConfigurationMetadataProperty> whiteListedProps = metadataResolver.listProperties(metadataResource); for (ConfigurationMetadataProperty property : allProps) { if (CompletionUtils.isMatchingProperty(propertyName, property, whiteListedProps)) { for (ValueHintProvider valueHintProvider : valueHintProviders) { List<ValueHint> valueHints = valueHintProvider.generateValueHints(property, classLoader); if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) { collector.clear(); } for (ValueHint valueHint : valueHints) { String candidate = String.valueOf(valueHint.getValue()); if (!candidate.equals(alreadyTyped) && candidate.startsWith(alreadyTyped)) { collector.add(proposals.withSuffix(candidate.substring(alreadyTyped.length()), valueHint.getShortDescription())); } } if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) { return true; } } } } return false; }); } return result; }
Example #21
Source File: SpringBootServiceImpl.java From nb-springboot with Apache License 2.0 | 5 votes |
@Override public List<ConfigurationMetadataProperty> queryPropertyMetadata(String filter) { if (cpExec == null) { init(); } List<ConfigurationMetadataProperty> ret = new LinkedList<>(); if (cachedProperties != null) { for (String propName : getPropertyNames()) { if (filter == null || propName.contains(filter)) { ret.add(cachedProperties.get(propName)); } } } return ret; }
Example #22
Source File: Utils.java From nb-springboot with Apache License 2.0 | 5 votes |
/** * Builds an HTML formatted string with details on a Spring Boot configuration property extracted from its * {@code ItemMetadata}. * * @param cfgMeta the configuration property metadata object * @return the HTML formatted configuration property details */ public static String cfgPropDetailsHtml(ConfigurationMetadataProperty cfgMeta) { StringBuilder sb = new StringBuilder(); // deprecation (optional) Deprecation deprecation = cfgMeta.getDeprecation(); if (deprecation != null) { sb.append("<b>"); if (isErrorDeprecated(cfgMeta)) { sb.append("REMOVED"); } else { sb.append("Deprecated"); } sb.append("</b>"); // deprecation reason if present String reason = deprecation.getReason(); if (reason != null) { sb.append(": ").append(simpleHtmlEscape(reason)); } sb.append("<br/>"); String replacement = deprecation.getReplacement(); if (replacement != null) { sb.append("<i>Replaced by:</i> <tt>").append(replacement).append("</tt><br/>"); } } // description (optional) final String description = cfgMeta.getDescription(); if (description != null) { sb.append(description).append("<br/>"); } // type sb.append("<tt>").append(simpleHtmlEscape(shortenJavaType(cfgMeta.getType()))).append("</tt>"); return sb.toString(); }
Example #23
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
private String asciidocFor(ConfigurationMetadataProperty property, ClassLoader classLoader) { return String.format("$$%s$$:: $$%s$$ *($$%s$$, default: `$$%s$$`%s)*", property.getId(), niceDescription(property), niceType(property), niceDefault(property), maybeHints(property, classLoader)); }
Example #24
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
private CharSequence maybeHints(ConfigurationMetadataProperty property, ClassLoader classLoader) { String type = property.getType().replace('$', '.'); if (ClassUtils.isPresent(type, classLoader)) { Class<?> clazz = ClassUtils.resolveClassName(type, classLoader); if (clazz.isEnum()) { return ", possible values: `" + StringUtils.arrayToDelimitedString(clazz.getEnumConstants(), "`,`") + "`"; } } return ""; }
Example #25
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
private String niceDefault(ConfigurationMetadataProperty property) { if (property.getDefaultValue() == null) { return "<none>"; } else if ("".equals(property.getDefaultValue())) { return "<empty string>"; } else { return stringify(property.getDefaultValue()); } }
Example #26
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
private String niceType(ConfigurationMetadataProperty property) { String type = property.getType(); if (type == null) { return "<unknown>"; } int lastDot = type.lastIndexOf('.'); int lastDollar = type.lastIndexOf('$'); boolean hasGenerics = type.contains("<"); return hasGenerics ? type : type.substring(Math.max(lastDot, lastDollar) + 1); }
Example #27
Source File: BootApplicationConfigurationMetadataResolverTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void appSpecificWhitelistedPropsShouldBeVisible() { List<ConfigurationMetadataProperty> properties = resolver .listProperties(new ClassPathResource("apps/filter-processor", getClass())); assertThat(properties, hasItem(configPropertyIdentifiedAs("filter.expression"))); assertThat(properties, hasItem(configPropertyIdentifiedAs("some.other.property.whitelisted.prefix.expresso2"))); }
Example #28
Source File: DeployerConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Resolve all configuration metadata properties prefixed with {@code spring.cloud.deployer.} * * @return the list */ public List<ConfigurationMetadataProperty> resolve() { List<ConfigurationMetadataProperty> metadataProperties = new ArrayList<>(); ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create(); try { Resource[] resources = applicationContext.getResources(CONFIGURATION_METADATA_PATTERN); for (Resource resource : resources) { builder.withJsonResource(resource.getInputStream()); } } catch (IOException e) { throw new SkipperException("Unable to read configuration metadata", e); } ConfigurationMetadataRepository metadataRepository = builder.build(); Map<String, ConfigurationMetadataGroup> groups = metadataRepository.getAllGroups(); // 1. go through all groups and their properties // 2. filter 'spring.cloud.deployer.' properties // 3. pass in only group includes, empty passes through all // 4. pass in group excludes // 5. same logic for properties for includes and excludes // 6. what's left is white/black listed props groups.values().stream() .filter(g -> g.getId().startsWith(KEY_PREFIX)) .filter(groupEmptyOrAnyMatch(deployerProperties.getGroupIncludes())) .filter(groupNoneMatch(deployerProperties.getGroupExcludes())) .forEach(g -> { g.getProperties().values().stream() .filter(propertyEmptyOrAnyMatch(deployerProperties.getPropertyIncludes())) .filter(propertyNoneMatch(deployerProperties.getPropertyExcludes())) .forEach(p -> { metadataProperties.add(p); }); }); return metadataProperties; }
Example #29
Source File: BootApplicationConfigurationMetadataResolverTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void appDockerResourceEmptyLabels() { when(containerImageMetadataResolver.getImageLabels("test/test:latest")).thenReturn(new HashMap<>()); List<ConfigurationMetadataProperty> properties = resolver .listProperties(new DockerResource("test/test:latest")); assertThat(properties.size(), is(0)); }
Example #30
Source File: BootApplicationConfigurationMetadataResolverTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void appDockerResource() throws IOException { byte[] bytes = StreamUtils.copyToByteArray(new ClassPathResource( "apps/no-whitelist/META-INF/spring-configuration-metadata.json", getClass()).getInputStream()); when(containerImageMetadataResolver.getImageLabels("test/test:latest")) .thenReturn(Collections.singletonMap("org.springframework.cloud.dataflow.spring-configuration-metadata.json", StringEscapeUtils.escapeJson(new String(bytes)))); List<ConfigurationMetadataProperty> properties = resolver.listProperties(new DockerResource("test/test:latest")); assertThat(properties.size(), is(3)); }