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.launcher;
22
23 import java.net.URL;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Vector;
27
28 import org.apache.cactus.eclipse.runner.common.LibraryHelper;
29 import org.apache.cactus.eclipse.runner.ui.CactusMessages;
30 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
31 import org.apache.cactus.eclipse.runner.ui.CactusPreferences;
32 import org.eclipse.ant.core.AntCorePlugin;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IProgressMonitor;
35 import org.eclipse.debug.core.ILaunch;
36 import org.eclipse.debug.core.ILaunchConfiguration;
37 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
38 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
39 import org.eclipse.jdt.core.IClasspathEntry;
40 import org.eclipse.jdt.core.IJavaProject;
41 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
42 import org.eclipse.jdt.junit.ITestRunListener;
43 import org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate;
44 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
45 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
46 import org.eclipse.jdt.launching.JavaRuntime;
47 import org.eclipse.swt.widgets.Display;
48
49
50
51
52
53
54
55
56
57
58
59 public class CactusLaunchConfiguration
60 extends JUnitLaunchConfigurationDelegate
61 implements ITestRunListener
62 {
63
64
65
66
67
68 private boolean launchEnded;
69
70
71
72
73 public static final String ID_CACTUS_APPLICATION =
74 "org.apache.cactus.eclipse.runner.launchconfig";
75
76
77
78
79 protected static final String VM_ARG_SEPARATOR = " ";
80
81 private static final String KEY_NO_STARTUP = "nO STARTUP";
82
83
84
85
86 public void launch(
87 final ILaunchConfiguration theConfiguration,
88 final String theMode,
89 final ILaunch theLaunch,
90 final IProgressMonitor thePM)
91 throws CoreException
92 {
93 final IJavaProject javaProject = getJavaProject(theConfiguration);
94 Vector userClasspath =
95 toMemento(
96 JavaRuntime.computeUnresolvedRuntimeClasspath(javaProject));
97 Vector cactusClasspath = toMemento(getCactusClasspath());
98 List classpath =
99 theConfiguration.getAttribute(
100 IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
101 (List) null);
102 if (classpath == null)
103 {
104 classpath = userClasspath;
105 classpath.addAll(0, cactusClasspath);
106 }
107 else
108 {
109 classpath.addAll(0, userClasspath);
110 classpath.addAll(0, cactusClasspath);
111 }
112 final ILaunchConfigurationWorkingCopy cactusConfig =
113 theConfiguration.getWorkingCopy();
114 cactusConfig.setAttribute(
115 IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
116 classpath);
117 cactusConfig.setAttribute(
118 IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
119 false);
120 String jUnitArgs = getVMArguments(theConfiguration);
121 String cactusVMArgs = getCactusVMArgs(javaProject);
122 String globalArgs = jUnitArgs + VM_ARG_SEPARATOR + cactusVMArgs;
123 cactusConfig.setAttribute(
124 IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
125 globalArgs);
126 this.launchEnded = false;
127
128
129 JUnitPlugin.getDefault().addTestRunListener(this);
130
131
132
133 try {
134 new Thread(new Runnable()
135 {
136 public void run()
137 {
138 try
139 {
140 CactusPlugin.getContainerManager(true).prepare(javaProject);
141 Display.getDefault().asyncExec(new Runnable()
142 {
143 public void run()
144 {
145 try
146 {
147 CactusLaunchConfiguration.super.launch(
148 cactusConfig,
149 theMode,
150 theLaunch,
151 thePM);
152 }
153 catch (CoreException e)
154 {
155 CactusPlugin.displayErrorMessage(
156 CactusMessages.getString(
157 "CactusLaunch.message.containerManager.error"),
158 e.getMessage(),
159 null);
160 return;
161 }
162 catch(Exception ex) {
163 CactusPlugin.log("ATTENTION."+ex.getMessage());
164
165 CactusPlugin.displayErrorMessage(
166 CactusMessages.getString(
167 "CactusLaunch.message.containerManager.error"),
168 ex.getMessage(),
169 null);
170 }
171 }
172 });
173 }
174 catch (CoreException e)
175 {
176 CactusPlugin.displayErrorMessage(
177 CactusMessages.getString(
178 "CactusLaunch.message.containerManager.error"),
179 e.getMessage(),
180 null);
181 return;
182 }
183 catch(Exception ex) {
184 CactusPlugin.log("ATTENTION1."+ex.getMessage());
185 CactusPlugin.displayErrorMessage(
186 CactusMessages.getString(
187 "CactusLaunch.message.containerManager.error"),
188 ex.getMessage(),
189 null);
190 }
191 }
192 }).start();
193 } catch(Exception ex) {
194
195 CactusPlugin.displayErrorMessage(
196 CactusMessages.getString(
197 "CactusLaunch.message.containerManager.error"),
198 ex.getMessage(),
199 null);
200 }
201
202
203
204
205 }
206
207
208
209
210
211 private Vector toMemento(IClasspathEntry[] theEntries)
212 {
213 Vector result = new Vector();
214 for (int i = 0; i < theEntries.length; i++)
215 {
216 try
217 {
218 result.add(
219 JavaRuntime
220 .newArchiveRuntimeClasspathEntry(
221 theEntries[i].getPath())
222 .getMemento());
223 }
224 catch (CoreException e)
225 {
226 CactusPlugin.log(e.getMessage());
227
228 }
229 }
230 return result;
231 }
232
233
234
235
236
237
238 private Vector toMemento(IRuntimeClasspathEntry[] theEntries)
239 {
240 Vector result = new Vector();
241 for (int i = 0; i < theEntries.length; i++)
242 {
243 try
244 {
245 result.add(theEntries[i].getMemento());
246 }
247 catch (CoreException e)
248 {
249
250 }
251 }
252 return result;
253 }
254
255
256
257
258
259
260 protected IClasspathEntry[] getCactusClasspath() throws CoreException
261 {
262 IClasspathEntry[] cactusClasspath =
263 LibraryHelper.getClientSideEntries();
264 URL[] antURLs = AntCorePlugin.getPlugin().getPreferences().getAntURLs();
265 IClasspathEntry[] apacheClasspath = getClasspathEntryArray(antURLs);
266 cactusClasspath =
267 LibraryHelper.concatenateEntries(cactusClasspath, apacheClasspath);
268 return cactusClasspath;
269 }
270
271
272
273
274
275 protected String getCactusVMArgs(IJavaProject theJavaProject)
276 {
277 String cactusVMArgs = "";
278 cactusVMArgs += "-Dcactus.contextURL="
279 + CactusPreferences.getContextURL()
280 + VM_ARG_SEPARATOR;
281 return cactusVMArgs;
282 }
283
284
285
286
287
288 private IClasspathEntry[] getClasspathEntryArray(URL[] theAntURLs)
289 {
290 IClasspathEntry[] result = new IClasspathEntry[theAntURLs.length];
291 for (int i = 0; i < theAntURLs.length; i++)
292 {
293 result[i] =
294 LibraryHelper.getIClasspathEntry(theAntURLs[i].getPath());
295 }
296 return result;
297 }
298
299
300
301
302 public void testRunStarted(int theTestCount)
303 {
304 }
305
306
307
308
309
310 public void testRunEnded(long theElapsedTime)
311 {
312
313
314 if (this.launchEnded)
315 {
316 return;
317 }
318 try
319 {
320 CactusPlugin.getContainerManager(false).tearDown();
321 }
322 catch (CoreException e)
323 {
324 CactusPlugin.displayErrorMessage(
325 CactusMessages.getString(
326 "CactusLaunch.message.containerManager.error"),
327 e.getMessage(),
328 null);
329 return;
330 }
331 catch (Exception ex) {
332 CactusPlugin.log("Exception tearing down:"+ex.getMessage());
333 }
334 this.launchEnded = true;
335 }
336
337
338
339
340
341
342 public void testRunStopped(long theElapsedTime)
343 {
344 testRunEnded(0);
345 }
346
347
348
349
350 public void testStarted(String theTestId, String theTestName)
351 {
352 }
353
354
355
356
357 public void testEnded(String theTestId, String theTestName)
358 {
359 }
360
361
362
363
364 public void testFailed(
365 int theStatus,
366 String theTestId,
367 String theTestName,
368 String theTrace)
369 {
370 }
371
372
373
374
375 public void testTreeEntry(String theEntry)
376 {
377 }
378
379
380
381
382
383 public void testRunTerminated()
384 {
385 testRunEnded(0);
386 }
387
388
389
390
391 public void testReran(
392 String theTestId,
393 String theTestClass,
394 String theTestName,
395 int theStatus,
396 String theTrace)
397 {
398 }
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420 }