View Javadoc

1   /**
2    * Copyright (C) 2010-2012 Joerg Bellmann <joerg.bellmann@googlemail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.googlecode.t7mp.steps;
17  
18  import java.util.Map;
19  
20  import com.googlecode.t7mp.PluginLog;
21  
22  public class SetSystemPropertiesStep implements Step {
23  
24      @Override
25      public void execute(Context context) {
26          final String catalinaBasPath = context.getConfiguration().getCatalinaBase().getAbsolutePath();
27          final PluginLog log = context.getLog();
28          System.setProperty("catalina.home", catalinaBasPath);
29          log.debug("set systemproperty key: catalina.home to value " + catalinaBasPath);
30          System.setProperty("catalina.base", catalinaBasPath);
31          log.debug("set systemproperty key: catalina.base to value " + catalinaBasPath);
32          Map<String, String> properties = context.getConfiguration().getSystemProperties();
33          for (String key : properties.keySet()) {
34              String value = replaceCatalinas(properties.get(key));
35              System.setProperty(key, value);
36              log.debug("set systemproperty key: " + key + " to value: " + System.getProperty(key));
37          }
38      }
39  
40      protected String replaceCatalinas(String value) {
41          if (value.startsWith("${catalina.home}")) {
42              value = value.replace("${catalina.home}", System.getProperty("catalina.home"));
43          }
44          if (value.startsWith("${catalina.base}")) {
45              value = value.replace("${catalina.base}", System.getProperty("catalina.base"));
46          }
47          return value;
48      }
49  }