1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.catalog;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.Properties;
22
23 import org.apache.logging.log4j.catalog.api.util.ProfileUtil;
24 import org.springframework.boot.autoconfigure.SpringBootApplication;
25 import org.springframework.boot.builder.SpringApplicationBuilder;
26 import org.springframework.boot.web.support.SpringBootServletInitializer;
27
28
29
30
31 @SpringBootApplication
32 public class AuditCatalogEditor extends SpringBootServletInitializer {
33 private static final String SPRING_PROFILE = "spring.profiles.active";
34
35 public static void main(String[] args) {
36 SpringApplicationBuilder builder = new SpringApplicationBuilder().profiles(getActiveProfile())
37 .sources(AuditCatalogEditor.class);
38 System.setProperty("isEmbedded", "true");
39 builder.run(args);
40 }
41
42
43
44
45 public static String getActiveProfile() {
46 String springProfile = System.getProperty(SPRING_PROFILE);
47 if (springProfile == null) {
48 springProfile = System.getenv(SPRING_PROFILE);
49 }
50 if (springProfile == null) {
51 Properties props = loadProperties();
52 springProfile = props.getProperty(SPRING_PROFILE);
53 if (springProfile == null) {
54 springProfile = "eclipseLink";
55 }
56 }
57 return springProfile;
58 }
59
60 private static Properties loadProperties() {
61 Properties props = new Properties();
62 String env = System.getProperty("env");
63 if (env == null) {
64 env = System.getenv("env");
65 }
66 StringBuilder sb = new StringBuilder("catalog-");
67 if (env != null) {
68 sb.append(env);
69 }
70 sb.append("config.properties");
71 InputStream is = ProfileUtil.class.getClassLoader().getResourceAsStream(sb.toString());
72 if (is != null) {
73 try {
74 props.load(is);
75 } catch (IOException ioe) {
76
77 }
78 }
79 return props;
80 }
81
82 }