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.ant;
22
23 import java.net.URL;
24 import java.util.Vector;
25
26 import org.apache.cactus.eclipse.runner.containers.ContainerInfo;
27 import org.apache.cactus.eclipse.runner.containers.Credential;
28 import org.apache.cactus.eclipse.runner.containers.IContainerProvider;
29 import org.apache.cactus.eclipse.runner.ui.CactusMessages;
30 import org.eclipse.core.runtime.CoreException;
31 import org.eclipse.core.runtime.IProgressMonitor;
32 import org.eclipse.core.runtime.SubProgressMonitor;
33 import org.eclipse.debug.core.ILaunch;
34 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
35 import org.eclipse.debug.core.ILaunchManager;
36
37
38
39
40
41
42
43 public class AntContainerProvider implements IContainerProvider
44 {
45
46
47
48 private AntContainerManager manager;
49
50
51
52
53 private Vector antArguments = new Vector();
54
55
56
57
58 private EclipseRunTests eclipseRunner;
59
60
61
62
63 private String home;
64
65
66
67
68 private String targetMask;
69
70
71
72
73 private ILaunch startLaunch;
74
75
76
77
78
79
80 public AntContainerProvider(AntContainerManager theManager,
81 String theTargetMask, String theHome)
82 {
83 this.targetMask = theTargetMask;
84 this.home = theHome;
85 this.manager = theManager;
86 }
87
88
89
90
91 public void deploy(String theContextPath, URL theDeployableObject,
92 Credential theCredentials, IProgressMonitor thePM)
93 throws CoreException
94 {
95 thePM.subTask(CactusMessages.getString("CactusLaunch.message.deploy"));
96 String warPath = theDeployableObject.getPath();
97 antArguments.add("-Dcactus.war=" + warPath);
98 antArguments.add("-Dcactus.context=" + theContextPath);
99 }
100
101
102
103
104 public void start(ContainerInfo theContainerInfo, IProgressMonitor thePM)
105 throws CoreException
106 {
107 thePM.subTask(CactusMessages.getString("CactusLaunch.message.start"));
108 String target = getTarget("cactus.run.");
109 antArguments.add(
110 "-Dcactus.test.task=" + EclipseRunTests.class.getName());
111 antArguments.add("-Dcactus.home." + this.targetMask + "=" + home);
112 String[] arguments =
113 (String[]) antArguments.toArray(new String[antArguments.size()]);
114 ILaunchConfigurationWorkingCopy antCopy =
115 this.manager.createAntLaunchConfiguration(arguments, target);
116 this.startLaunch = antCopy.launch(
117 ILaunchManager.RUN_MODE,
118 new SubProgressMonitor(thePM, 8));
119 }
120
121
122
123
124 public void stop(ContainerInfo theContainerInfo, IProgressMonitor thePM)
125 throws CoreException
126 {
127 thePM.subTask(CactusMessages.getString("CactusLaunch.message.stop"));
128 if (eclipseRunner != null)
129 {
130 eclipseRunner.finish();
131 try
132 {
133 thePM.worked(30);
134 while (this.startLaunch == null
135 || !this.startLaunch.isTerminated())
136 {
137 Thread.sleep(300);
138 thePM.worked(7);
139 }
140 }
141 catch (InterruptedException e)
142 {
143
144 }
145 }
146 }
147
148
149
150
151 public void undeploy(String theContextPath, Credential theCredentials,
152 IProgressMonitor thePM) throws CoreException
153 {
154 thePM.subTask(
155 CactusMessages.getString("CactusLaunch.message.undeploy"));
156 String antTarget = getTarget("cactus.clean.");
157 String[] arguments =
158 (String[]) antArguments.toArray(new String[antArguments.size()]);
159 ILaunchConfigurationWorkingCopy antCopy =
160 this.manager.createAntLaunchConfiguration(arguments, antTarget);
161 antCopy.launch(
162 ILaunchManager.RUN_MODE,
163 new SubProgressMonitor(thePM, 50));
164 }
165
166
167
168
169
170 public void setEclipseRunner(EclipseRunTests theEclipseRunner)
171 {
172 this.eclipseRunner = theEclipseRunner;
173 }
174
175
176
177
178
179
180
181 private String getTarget(String thePrefix)
182 {
183 return thePrefix + this.targetMask;
184 }
185 }