@RequestMapping("/{name}/{profiles}/{label:.*}") public Environment labelled(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { if (name != null && name.contains("(_)")) { // "(_)" is uncommon in a git repo name, but "/" cannot be matched // by Spring MVC name = name.replace("(_)", "/"); } if (label != null && label.contains("(_)")) { // "(_)" is uncommon in a git branch name, but "/" cannot be matched // by Spring MVC label = label.replace("(_)", "/"); } Environment environment = this.repository.findOne(name, profiles, label); if(!acceptEmpty && (environment == null || environment.getPropertySources().isEmpty())){ throw new EnvironmentNotFoundException("Profile Not found"); } return environment; }
synchronized byte[] binary(String name, String profile, String label, String path) throws IOException { if (name != null && name.contains("(_)")) { // "(_)" is uncommon in a git repo name, but "/" cannot be matched // by Spring MVC name = name.replace("(_)", "/"); } if (label != null && label.contains("(_)")) { // "(_)" is uncommon in a git branch name, but "/" cannot be matched // by Spring MVC label = label.replace("(_)", "/"); } // TODO: is this line needed for side effects? prepareEnvironment(this.environmentRepository.findOne(name, profile, label)); try (InputStream is = this.resourceRepository.findOne(name, profile, label, path) .getInputStream()) { return StreamUtils.copyToByteArray(is); } }
@Override public Environment findOne(String name, String profiles, String label) { Environment environment = this.delegate.findOne(name, profiles, label); if (this.environmentEncryptor != null) { environment = this.environmentEncryptor.decrypt(environment); } if (!this.overrides.isEmpty()) { environment.addFirst(new PropertySource("overrides", this.overrides)); } return environment; }
synchronized String retrieve(String name, String profile, String label, String path, boolean resolvePlaceholders) throws IOException { if (name != null && name.contains("(_)")) { // "(_)" is uncommon in a git repo name, but "/" cannot be matched // by Spring MVC name = name.replace("(_)", "/"); } if (label != null && label.contains("(_)")) { // "(_)" is uncommon in a git branch name, but "/" cannot be matched // by Spring MVC label = label.replace("(_)", "/"); } // ensure InputStream will be closed to prevent file locks on Windows try (InputStream is = this.resourceRepository.findOne(name, profile, label, path) .getInputStream()) { String text = StreamUtils.copyToString(is, Charset.forName("UTF-8")); if (resolvePlaceholders) { Environment environment = this.environmentRepository.findOne(name, profile, label); text = resolvePlaceholders(prepareEnvironment(environment), text); } return text; } }
@Override public Environment findOne(String application, String profile, String label) { Environment env = new Environment(application, new String[]{profile}, label, null, null); if(environmentRepositories.size() == 1) { Environment envRepo = environmentRepositories.get(0).findOne(application, profile, label); env.addAll(envRepo.getPropertySources()); env.setVersion(envRepo.getVersion()); env.setState(envRepo.getState()); } else { for (EnvironmentRepository repo : environmentRepositories) { env.addAll(repo.findOne(application, profile, label).getPropertySources()); } } return env; } }
Environment environment = this.environmentRepository.findOne(application, profiles, repository.getLabel());
@Override public org.springframework.core.env.PropertySource<?> locate(Environment environment) { CompositePropertySource composite = new CompositePropertySource("configService"); for (PropertySource source : repository.findOne(name, profiles, label) .getPropertySources()) { @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) source.getSource(); composite.addPropertySource(new MapPropertySource(source.getName(), map)); } return composite; }