1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.googlecode.t7mp.steps;
17
18 import java.io.File;
19 import java.io.FileWriter;
20 import java.io.Writer;
21
22 import org.apache.velocity.Template;
23 import org.apache.velocity.VelocityContext;
24 import org.apache.velocity.app.Velocity;
25 import org.apache.velocity.runtime.RuntimeServices;
26 import org.apache.velocity.runtime.log.LogChute;
27 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
28
29 import com.googlecode.t7mp.T7Configuration;
30 import com.googlecode.t7mp.TomcatSetupException;
31
32 public class BuildCatalinaPropertiesFileStep implements Step {
33
34 @Override
35 public void execute(Context context) {
36 final T7Configuration configuration = context.getConfiguration();
37 try {
38 Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new LogNothingLogChute());
39 Velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
40 Velocity.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
41 Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
42 Velocity.init();
43 Template template = Velocity.getTemplate("com/googlecode/t7mp/conf/catalina.properties");
44 VelocityContext velocityContext = new VelocityContext();
45 velocityContext.put("tomcatHttpPort", configuration.getTomcatHttpPort() + "");
46 velocityContext.put("tomcatShutdownPort", configuration.getTomcatShutdownPort() + "");
47 velocityContext.put("tomcatShutdownCommand", configuration.getTomcatShutdownCommand());
48 velocityContext.put("tomcatHostName", configuration.getTomcatHostName());
49 Writer writer = new FileWriter(new File(configuration.getCatalinaBase(), "/conf/catalina.properties"));
50 template.merge(velocityContext, writer);
51 writer.flush();
52 writer.close();
53 } catch (Exception e) {
54 throw new TomcatSetupException(e.getMessage(), e);
55 }
56 }
57
58
59
60
61
62
63 static class LogNothingLogChute implements LogChute {
64
65 @Override
66 public void init(RuntimeServices rs) throws Exception {
67
68 }
69
70 @Override
71 public void log(int level, String message) {
72
73 }
74
75 @Override
76 public void log(int level, String message, Throwable t) {
77
78 }
79
80 @Override
81 public boolean isLevelEnabled(int level) {
82 return false;
83 }
84
85 }
86
87 }