Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.util.Optional;
  2.  
  3. import javax.annotation.PostConstruct;
  4.  
  5. import org.springframework.boot.context.properties.ConfigurationProperties;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.context.annotation.PropertySource;
  8.  
  9. @Configuration("application")
  10. @PropertySource("application.properties")
  11. @ConfigurationProperties(prefix = "git")
  12. public class GitProperties {
  13.  
  14. private String user;
  15. private String pass;
  16. private String remote;
  17. private String branch;
  18. private String directory;
  19. private String active;
  20.  
  21. public boolean active() {
  22. return "true".equals(active);
  23. }
  24.  
  25. @PostConstruct
  26. private void init() {
  27. try {
  28. user = Optional.ofNullable(user).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_USER"));
  29. pass = Optional.ofNullable(pass).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_PASS"));
  30. remote = Optional.ofNullable(remote).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_REMOTE"));
  31. branch = Optional.ofNullable(branch).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_BRANCH"));
  32. directory = Optional.ofNullable(directory).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_DIRECTORY"));
  33. active = Optional.ofNullable(active).filter(s -> !s.isBlank()).orElseGet(() -> System.getenv("GIT_ACTIVE"));
  34. } catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. public String getUser() {
  40. return user;
  41. }
  42.  
  43. public void setUser(String user) {
  44. this.user = user;
  45. }
  46.  
  47. public String getPass() {
  48. return pass;
  49. }
  50.  
  51. public void setPass(String pass) {
  52. this.pass = pass;
  53. }
  54.  
  55. public String getBranch() {
  56. return branch;
  57. }
  58.  
  59. public void setBranch(String branch) {
  60. this.branch = branch;
  61. }
  62.  
  63. public String getDirectory() {
  64. return directory;
  65. }
  66.  
  67. public void setDirectory(String directory) {
  68. this.directory = directory;
  69. }
  70.  
  71. public String getRemote() {
  72. return remote;
  73. }
  74.  
  75. public void setRemote(String remote) {
  76. this.remote = remote;
  77. }
  78.  
  79. public String getActive() {
  80. return active;
  81. }
  82.  
  83. public void setActive(String active) {
  84. this.active = active;
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement