2011/08/05 - Jakarta Cactus has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.cactus.eclipse.runner.containers.jetty;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.net.URL;
26
27 import org.apache.cactus.eclipse.runner.containers.IContainerManager;
28 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
29 import org.apache.cactus.eclipse.runner.ui.CactusPreferences;
30 import org.apache.cactus.eclipse.webapp.internal.WarBuilder;
31 import org.apache.cactus.eclipse.webapp.internal.Webapp;
32 import org.apache.cactus.eclipse.webapp.internal.ui.WebappPlugin;
33 import org.apache.tools.ant.Project;
34 import org.apache.tools.ant.taskdefs.Copy;
35 import org.apache.tools.ant.types.FileSet;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.Path;
38 import org.eclipse.core.runtime.Platform;
39 import org.eclipse.jdt.core.IJavaProject;
40
41
42
43
44
45
46 public class JettyContainerManager implements IContainerManager
47 {
48
49
50
51
52 private static final String JETTY_WEBAPP_PATH = "jetty.webapp";
53
54
55
56
57 private static final String JSPREDIRECTOR_PATH =
58 new String("lib/confs/jspRedirector.jsp");
59
60
61
62
63 private File jettyWebappDir =
64 new File(
65 CactusPreferences.getTempDir()
66 + File.separator
67 + JETTY_WEBAPP_PATH);
68
69
70
71 public void prepare(IJavaProject theJavaProject)
72 {
73 try
74 {
75 cactifyWebapp(theJavaProject);
76 }
77 catch (CoreException e)
78 {
79 CactusPlugin.log("Failed"+e.getMessage());
80 }
81 }
82
83
84
85
86 public void tearDown()
87 {
88
89 }
90
91
92
93
94
95 private void cactifyWebapp(IJavaProject theJavaProject)
96 throws CoreException
97 {
98 WarBuilder.delete(jettyWebappDir);
99 jettyWebappDir.mkdir();
100 copyCactusWebappResources(jettyWebappDir);
101 Webapp webapp = WebappPlugin.getWebapp(theJavaProject);
102 webapp.init();
103 File webappDir = webapp.getAbsoluteDir();
104 if (webappDir != null && webappDir.exists())
105 {
106 copyContents(webappDir, jettyWebappDir);
107 }
108 }
109
110
111
112
113
114
115
116 private void copyCactusWebappResources(File theDir) throws CoreException
117 {
118 Project antProject = new Project();
119 antProject.init();
120 Copy copy = new Copy();
121 copy.setProject(antProject);
122 copy.setTodir(theDir);
123 CactusPlugin thePlugin = CactusPlugin.getDefault();
124 URL jspRedirectorURL = null;
125 try {
126 jspRedirectorURL = Platform.asLocalURL(thePlugin.getBundle().getEntry(JSPREDIRECTOR_PATH));
127 } catch (IOException e1) {
128
129 }
130 if (jspRedirectorURL == null)
131 {
132 throw CactusPlugin.createCoreException(
133 "CactusLaunch.message.prepare.error.plugin.file",
134 " : " + JSPREDIRECTOR_PATH,
135 null);
136 }
137 try{
138 jspRedirectorURL = Platform.asLocalURL(jspRedirectorURL);
139 } catch(IOException e) {
140 throw CactusPlugin.createCoreException(
141 "CactusLaunch.message.prepare.error.plugin.file",
142 " : " + e.getMessage(),
143 null);
144 }
145
146 File jspRedirector = new File(jspRedirectorURL.getPath());
147 FileSet fileSet = new FileSet();
148 fileSet.setFile(jspRedirector);
149 copy.addFileset(fileSet);
150 copy.execute();
151 }
152
153
154
155
156
157
158 private void copyContents(File theSourceDir, File theTargetDir)
159 {
160 Project antProject = new Project();
161 antProject.init();
162 Copy copy = new Copy();
163 copy.setProject(antProject);
164 copy.setTodir(theTargetDir);
165 FileSet fileSet = new FileSet();
166 fileSet.setDir(theSourceDir);
167 copy.addFileset(fileSet);
168 copy.execute();
169 }
170
171
172
173
174 public static String getJettyWebappPath()
175 {
176 return JETTY_WEBAPP_PATH;
177 }
178 }