View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
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       * Get the active profile if none has been specified.
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                  //Ignore the error.
77              }
78          }
79          return props;
80      }
81  
82  }