@Override public NativeEnvironmentRepository build(NativeEnvironmentProperties environmentProperties) { NativeEnvironmentRepository repository = new NativeEnvironmentRepository(environment, environmentProperties); if(properties.getDefaultLabel() != null) { repository.setDefaultLabel(properties.getDefaultLabel()); } return repository; } }
private String[] getArgs(String application, String profile, String label) { List<String> list = new ArrayList<String>(); String config = application; if (!config.startsWith("application")) { config = "application," + config; } list.add("--spring.config.name=" + config); list.add("--spring.cloud.bootstrap.enabled=false"); list.add("--encrypt.failOnError=" + this.failOnError); list.add("--spring.config.location=" + StringUtils.arrayToCommaDelimitedString( getLocations(application, profile, label).getLocations())); return list.toArray(new String[0]); }
private Set<Path> getFileRepo() { if (this.scmRepository != null) { try { Resource resource = this.resourceLoader.getResource(this.scmRepository.getUri()); if (resource instanceof FileSystemResource) { return Collections.singleton(Paths.get(resource.getURI())); } } catch (IOException e) { log.error("Cannot resolve URI for path: " + this.scmRepository.getUri()); } } if (this.nativeEnvironmentRepository != null) { Set<Path> paths = new LinkedHashSet<>(); for (String path : this.nativeEnvironmentRepository.getSearchLocations()) { Resource resource = this.resourceLoader.getResource(path); if (resource.exists()) { try { paths.add(Paths.get(resource.getURI())); } catch (Exception e) { log.error("Cannot resolve URI for path: " + path); } } } return paths; } return null; }
@Override public synchronized Environment findOne(String application, String profile, String label) { NativeEnvironmentRepository delegate = new NativeEnvironmentRepository(getEnvironment(), new NativeEnvironmentProperties()); Locations locations = getLocations(application, profile, label); delegate.setSearchLocations(locations.getLocations()); Environment result = delegate.findOne(application, profile, ""); result.setVersion(locations.getVersion()); result.setLabel(label); return this.cleaner.clean(result, getWorkingDirectory().toURI().toString(), getUri()); }
@Override public PropertySource<?> locate(org.springframework.core.env.Environment environment) { final ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment; final NativeEnvironmentRepository springEnv = new NativeEnvironmentRepository(configurableEnvironment); final List<File> propertiesPath = getConfigDirs(); //https://github.com/spring-cloud/spring-cloud-config/issues/338 springEnv.setSearchLocations(toSearchLocations(propertiesPath)); CompositePropertySource composite = new CompositePropertySource(FileSystemLocator.class.getSimpleName()); addToPropertySource(returnPropertiesForName(springEnv, appCoordinates.getApplicationNameWithCountry()), composite); addToPropertySource(returnPropertiesForName(springEnv, appCoordinates.getApplicationNameWithoutCountry()), composite); addToPropertySource(returnPropertiesForName(springEnv, ConfigLocations.BASE_FILENAME_FOR_GLOBAL_CONFIG), composite); return composite; }
@Override public Environment findOne(String config, String profile, String label) { SpringApplicationBuilder builder = new SpringApplicationBuilder( PropertyPlaceholderAutoConfiguration.class); ConfigurableEnvironment environment = getEnvironment(profile); builder.environment(environment); builder.web(WebApplicationType.NONE).bannerMode(Mode.OFF); if (!logger.isDebugEnabled()) { // Make the mini-application startup less verbose builder.logStartupInfo(false); } String[] args = getArgs(config, profile, label); // Explicitly set the listeners (to exclude logging listener which would change // log levels in the caller) builder.application() .setListeners(Arrays.asList(new ConfigFileApplicationListener())); ConfigurableApplicationContext context = builder.run(args); environment.getPropertySources().remove("profiles"); try { return clean(new PassthruEnvironmentRepository(environment).findOne(config, profile, label)); } finally { context.close(); } }
private Environment returnPropertiesForName(NativeEnvironmentRepository springEnv, String forName) { return springEnv.findOne(forName, appCoordinates.getEnvironment(), null); }
public void setSearchLocations(String... locations) { this.searchLocations = locations; if (locations != null) { for (int i = 0; i < locations.length; i++) { String location = locations[i]; if (isDirectory(location) && !location.endsWith("/")) { location = location + "/"; } locations[i] = location; } } }
value = value + "/"; if (isDirectory(value)) { output.add(value); if (StringUtils.hasText(label)) { String labelled = location + label.trim() + "/"; if (isDirectory(labelled)) { output.add(labelled);
for (String pattern : getLocations(result.getName(), profile, result.getLabel()).getLocations()) { if (!pattern.contains(":")) {
private Set<Path> getFileRepo() { if (this.scmRepository != null) { try { Resource resource = this.resourceLoader.getResource(this.scmRepository.getUri()); if (resource instanceof FileSystemResource) { return Collections.singleton(Paths.get(resource.getURI())); } } catch (IOException e) { log.error("Cannot resolve URI for path: " + this.scmRepository.getUri()); } } if (this.nativeEnvironmentRepository != null) { Set<Path> paths = new LinkedHashSet<>(); for (String path : this.nativeEnvironmentRepository.getSearchLocations()) { Resource resource = this.resourceLoader.getResource(path); if (resource.exists()) { try { paths.add(Paths.get(resource.getURI())); } catch (Exception e) { log.error("Cannot resolve URI for path: " + path); } } } return paths; } return null; }