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.FileNotFoundException;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22
23 import com.googlecode.t7mp.SetupUtil;
24 import com.googlecode.t7mp.TomcatSetupException;
25 import com.googlecode.t7mp.util.CommonsSetupUtil;
26
27
28
29
30
31
32 public class CopyConfigResourceFromClasspath implements Step {
33
34 private static final String MSG_PREFIX = "Could not copy classpathresource ";
35 private static final String MSG_SUFFIX = " to tomcat-conf directory";
36
37 private static final String RESOURCEPATH = "/com/googlecode/t7mp/conf/";
38
39 private SetupUtil setupUtil = new CommonsSetupUtil();
40
41 private final String resource;
42
43 public CopyConfigResourceFromClasspath(String resource) {
44 this.resource = resource;
45 }
46
47 @Override
48 public void execute(Context context) {
49 final File tomcatConfDirectory = new File(context.getConfiguration().getCatalinaBase(), "/conf/");
50 try {
51 FileOutputStream out = new FileOutputStream(new File(tomcatConfDirectory, resource));
52 this.setupUtil.copy(getClass().getResourceAsStream(RESOURCEPATH + resource), out);
53 out.close();
54 } catch (FileNotFoundException e) {
55 throw new TomcatSetupException(MSG_PREFIX + resource + MSG_SUFFIX, e);
56 } catch (IOException e) {
57 throw new TomcatSetupException(MSG_PREFIX + resource + MSG_SUFFIX, e);
58 }
59 }
60 }