source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Triggers.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.4 KB
Line 
1/*
2 * Copyright 2001-2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.optional.sitraka;
19
20import java.util.Hashtable;
21import java.util.Vector;
22import org.apache.tools.ant.BuildException;
23
24/**
25 * Trigger information. It will return as a command line argument by calling
26 * the <tt>toString()</tt> method.
27 *
28 */
29public class Triggers {
30
31 protected Vector triggers = new Vector();
32
33 public Triggers() {
34 }
35
36
37 /**
38 * add a method trigger
39 */
40 public void addMethod(Method method) {
41 triggers.addElement(method);
42 }
43
44 // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X
45 public String toString() {
46 StringBuffer buf = new StringBuffer();
47 final int size = triggers.size();
48 for (int i = 0; i < size; i++) {
49 buf.append(triggers.elementAt(i).toString());
50 if (i < size - 1) {
51 buf.append(',');
52 }
53 }
54 return buf.toString();
55 }
56
57
58 /**
59 * A trigger for the coverage report
60 */
61 public static class Method {
62 protected String name;
63 protected String event;
64 protected String action;
65 protected String param;
66
67 /**
68 * The name of the method(s) as a regular expression. The name
69 * is the fully qualified name on the form <tt>package.classname.method</tt>
70 * required.
71 */
72 public void setName(String value) {
73 name = value;
74 }
75
76 /**
77 * the event on the method that will trigger the action. Must be
78 * &quot;enter&quot; or &quot;exit&quot;
79 * required.
80 */
81 public void setEvent(String value) {
82 if (eventMap.get(value) == null) {
83 throw new BuildException("Invalid event, must be one of " + eventMap);
84 }
85 event = value;
86 }
87
88 /**
89 * The action to execute; required. Must be one of &quot;clear&quot;,
90 * &quot;pause&quot;, &quot;resume&quot;, &quot;snapshot&quot;, &quot;suspend&quot;,
91 * or &quot;exit&quot;. They respectively clear recording, pause recording,
92 * resume recording, take a snapshot, suspend the recording and exit the program.
93 */
94 public void setAction(String value) throws BuildException {
95 if (actionMap.get(value) == null) {
96 throw new BuildException("Invalid action, must be one of " + actionMap);
97 }
98 action = value;
99 }
100
101 /**
102 * A alphanumeric custom name for the snapshot; optional.
103 */
104 public void setParam(String value) {
105 param = value;
106 }
107
108 // return <name>:<event>:<action>[:param]
109 public String toString() {
110 StringBuffer buf = new StringBuffer();
111 buf.append(name).append(":"); //@todo name must not be null, check for it
112 buf.append(eventMap.get(event)).append(":");
113 buf.append(actionMap.get(action));
114 if (param != null) {
115 buf.append(":").append(param);
116 }
117 return buf.toString();
118 }
119 }
120
121 /** mapping of actions to cryptic command line mnemonics */
122 private static final Hashtable actionMap = new Hashtable(3);
123
124 /** mapping of events to cryptic command line mnemonics */
125 private static final Hashtable eventMap = new Hashtable(3);
126
127 static {
128 actionMap.put("enter", "E");
129 actionMap.put("exit", "X");
130 // clear|pause|resume|snapshot|suspend|exit
131 eventMap.put("clear", "C");
132 eventMap.put("pause", "P");
133 eventMap.put("resume", "R");
134 eventMap.put("snapshot", "S");
135 eventMap.put("suspend", "A");
136 eventMap.put("exit", "X");
137 }
138
139}
Note: See TracBrowser for help on using the repository browser.