1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.eclipse.runner.containers.ant;
22
23 import org.apache.cactus.eclipse.runner.ui.CactusMessages;
24 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
25 import org.apache.tools.ant.Task;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.swt.widgets.Display;
28
29 /**
30 * This Ant task is used for running tests between container startup and
31 * shutdown.
32 *
33 * @version $Id: EclipseRunTests.java 238816 2004-02-29 16:36:46Z vmassol $
34 */
35 public class EclipseRunTests extends Task implements Runnable
36 {
37 /**
38 * Indicates that tests are finished, meaning that the task can terminate.
39 */
40 private volatile boolean isFinished = false;
41
42 /**
43 * Launches the Junit tests in Eclipse
44 */
45 public void execute()
46 {
47 Display.getDefault().asyncExec(this);
48 while (!isFinished)
49 {
50 try
51 {
52 Thread.sleep(100);
53 }
54 catch (InterruptedException e)
55 {
56 // Do nothing
57 }
58 }
59 }
60
61 /**
62 * This method notifies the instance that tests are finished and that
63 * it can terminate.
64 */
65 public void finish()
66 {
67 isFinished = true;
68 }
69
70 /**
71 * Launches Cactus tests.
72 */
73 public void run()
74 {
75 try
76 {
77 AntContainerManager antManager =
78 (AntContainerManager) CactusPlugin.getContainerManager(false);
79 antManager.setEclipseRunner(this);
80 antManager.preparationDone();
81 }
82 catch (CoreException e)
83 {
84 CactusPlugin.displayErrorMessage(
85 CactusMessages.getString(
86 "CactusLaunch.message.containerManager.error"),
87 e.getMessage(), null);
88 return;
89 }
90 }
91 }