KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > emma > emmaTask


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: emmaTask.java,v 1.1.1.1.2.2 2004/07/10 03:34:52 vlad_r Exp $
8  */

9 package com.vladium.emma;
10
11 import com.vladium.emma.IAppConstants;
12 import java.util.ArrayList JavaDoc;
13 import java.util.List JavaDoc;
14
15 import org.apache.tools.ant.BuildException;
16 import org.apache.tools.ant.Project;
17
18 import com.vladium.emma.ant.NestedTask;
19 import com.vladium.emma.ant.SuppressableTask;
20 import com.vladium.emma.data.mergeTask;
21 import com.vladium.emma.instr.instrTask;
22 import com.vladium.emma.report.reportTask;
23
24 // ----------------------------------------------------------------------------
25
/**
26  * @author Vlad Roubtsov, (C) 2003
27  */

28 public
29 final class emmaTask extends SuppressableTask
30 {
31     // public: ................................................................
32

33     // TODO: this and related tasks should be designed for external extensibility
34
// [make non final and use virtual prop getters]
35

36     public emmaTask ()
37     {
38         m_tasks = new ArrayList JavaDoc ();
39     }
40     
41     
42     public synchronized void execute () throws BuildException
43     {
44         log (IAppConstants.APP_VERBOSE_BUILD_ID, Project.MSG_VERBOSE);
45         
46         if (isEnabled ())
47         {
48             while (! m_tasks.isEmpty ())
49             {
50                 final NestedTask task = (NestedTask) m_tasks.remove (0);
51                 
52                 final String JavaDoc name = getTaskName ();
53                 try
54                 {
55                     setTaskName (task.getTaskName ());
56                     
57                     task.execute ();
58                 }
59                 finally
60                 {
61                     setTaskName (name);
62                 }
63             }
64         }
65     }
66
67     
68     public NestedTask createInstr ()
69     {
70         return addTask (new instrTask (this), getNestedTaskName ("instr"));
71     }
72     
73     public NestedTask createMerge ()
74     {
75         return addTask (new mergeTask (this), getNestedTaskName ("merge"));
76     }
77     
78     public NestedTask createReport ()
79     {
80         return addTask (new reportTask (this), getNestedTaskName ("report"));
81     }
82     
83     // protected: .............................................................
84

85
86     protected NestedTask addTask (final NestedTask task, final String JavaDoc pseudoName)
87     {
88         initTask (task, pseudoName);
89         
90         m_tasks.add (task);
91         return task;
92     }
93     
94     protected void initTask (final NestedTask task, final String JavaDoc pseudoName)
95     {
96         task.setTaskName (pseudoName);
97         task.setProject (getProject ());
98         task.setLocation (getLocation ());
99         task.setOwningTarget (getOwningTarget ());
100         
101         task.init ();
102     }
103     
104     protected String JavaDoc getNestedTaskName (final String JavaDoc subname)
105     {
106         return getTaskName ().concat (".").concat (subname);
107     }
108         
109     // package: ...............................................................
110

111     // private: ...............................................................
112

113     
114     private final List JavaDoc /* NestedTask */ m_tasks;
115
116 } // end of class
117
// ----------------------------------------------------------------------------
Popular Tags