588
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.signal.ant.taskdefs;
|
|
19 |
|
628
|
20 |
import java.util.Vector;
|
|
21 |
|
588
|
22 |
import org.apache.tools.ant.BuildException;
|
628
|
23 |
import org.apache.tools.ant.Target;
|
588
|
24 |
import org.apache.tools.ant.Task;
|
628
|
25 |
|
588
|
26 |
import com.nokia.helium.signal.ant.SignalList;
|
|
27 |
import com.nokia.helium.signal.ant.types.SignalNotifierInput;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* This task provide a way to raise a signal.
|
|
31 |
* If the provided result is different from 0 then the mentioned signal
|
|
32 |
* is raised.
|
|
33 |
*
|
|
34 |
* You can emit a signal based from the signal task, its behavior will get defined by the
|
|
35 |
* nested signalInput element. e.g:
|
|
36 |
* <pre>
|
|
37 |
* <target name="raise-signal">
|
|
38 |
* <-- Some computation that sets result property -->
|
|
39 |
* <property name="result" value="1"/>
|
|
40 |
*
|
|
41 |
* <hlm:signal name="compileSignal" result="${result}">
|
|
42 |
* <-- Let's refer to some existing signal input configuration -->
|
|
43 |
* <hlm:signalInput refid="testDeferredSignalInput" />
|
|
44 |
* </hlm:signal>
|
|
45 |
* </target>
|
|
46 |
* </pre>
|
|
47 |
*
|
|
48 |
* The execution of the <code>signal</code> task will behave depending on the <code>compileSignal</code> configuration,
|
|
49 |
* if not defined the build will fail.
|
|
50 |
*
|
|
51 |
* @ant.task name="signal" category="Signaling"
|
|
52 |
*/
|
|
53 |
public class SignalTask extends Task {
|
|
54 |
|
|
55 |
private String name;
|
|
56 |
private String message;
|
|
57 |
private Integer result;
|
|
58 |
|
|
59 |
private Vector<SignalNotifierInput> signalNotifierInputs = new Vector<SignalNotifierInput>();
|
|
60 |
|
|
61 |
public String getMessage() {
|
|
62 |
return message;
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Helper function called by ant to create the new signalinput
|
|
67 |
*/
|
|
68 |
public SignalNotifierInput createSignalNotifierInput() {
|
|
69 |
SignalNotifierInput input = new SignalNotifierInput();
|
|
70 |
add(input);
|
|
71 |
return input;
|
|
72 |
}
|
|
73 |
|
|
74 |
public SignalNotifierInput getSignalNotifierInput() {
|
|
75 |
return (SignalNotifierInput)signalNotifierInputs.elementAt(0);
|
|
76 |
}
|
|
77 |
/**
|
|
78 |
* Helper function to add the created signalinput
|
|
79 |
* @param filter to be added to the filterset
|
|
80 |
*/
|
|
81 |
public void add(SignalNotifierInput input) {
|
|
82 |
signalNotifierInputs.add(input);
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Error message.
|
|
88 |
*
|
|
89 |
* @ant.not-required
|
|
90 |
*/
|
|
91 |
public void setMessage(String message) {
|
|
92 |
this.message = message;
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
public String getName() {
|
|
97 |
return name;
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Signal name to emit.
|
|
102 |
*
|
|
103 |
* @ant.required
|
|
104 |
*/
|
|
105 |
public void setName(String name) {
|
|
106 |
this.name = name;
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* integer value representing the number of errors.
|
|
111 |
*
|
|
112 |
* @ant.required
|
|
113 |
*/
|
|
114 |
public void setResult(int result) {
|
|
115 |
this.result = new Integer(result);
|
|
116 |
}
|
|
117 |
|
|
118 |
@Override
|
|
119 |
public void execute() {
|
628
|
120 |
if (name == null) {
|
588
|
121 |
throw new BuildException("'name' attribute is not defined.");
|
628
|
122 |
}
|
588
|
123 |
if (result == null) {
|
|
124 |
result = new Integer(0);
|
|
125 |
}
|
|
126 |
|
|
127 |
SignalList signalList = new SignalList(getProject());
|
|
128 |
boolean failStatus = result.intValue() != 0;
|
|
129 |
if (failStatus) {
|
|
130 |
// keep same message as earlier.
|
|
131 |
log(name
|
|
132 |
+ ": "
|
|
133 |
+ name
|
|
134 |
+ " signal failed. Expected result was 0, actual result was "
|
|
135 |
+ result);
|
|
136 |
|
|
137 |
if (message == null) {
|
|
138 |
message = "Expected result was 0, actual result was " + result;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
// notify the user
|
|
143 |
String targetName = "signalExceptionTarget";
|
|
144 |
Target target = this.getOwningTarget();
|
|
145 |
if (target != null) {
|
|
146 |
targetName = target.getName();
|
|
147 |
}
|
|
148 |
|
|
149 |
if (signalNotifierInputs.isEmpty()) {
|
|
150 |
Object config = getProject().getReference(name);
|
|
151 |
if (config == null) {
|
|
152 |
throw new BuildException("Could not find signal config for signal name: " + name);
|
|
153 |
}
|
628
|
154 |
signalList.processForSignal(getProject(), this.getSignalNotifierInput(), this.name,
|
|
155 |
this.getOwningTarget().getName(), message, result.intValue() != 0);
|
|
156 |
|
588
|
157 |
if (result.intValue() != 0) {
|
|
158 |
// keep same message as earlier.
|
|
159 |
log(name
|
|
160 |
+ ": "
|
|
161 |
+ name
|
|
162 |
+ " signal failed. Expected result was 0, actual result was "
|
|
163 |
+ result);
|
|
164 |
|
|
165 |
if (message == null) {
|
|
166 |
message = "Expected result was 0, actual result was " + result;
|
|
167 |
}
|
|
168 |
signalList.fail(getName(), this.getOwningTarget().getName(), message);
|
|
169 |
}
|
|
170 |
|
|
171 |
} else {
|
|
172 |
signalList.processForSignal(getProject(), getSignalNotifierInput(), getName(),
|
|
173 |
targetName, message, failStatus);
|
|
174 |
}
|
|
175 |
}
|
|
176 |
|
|
177 |
}
|