588
|
1 |
/*
|
628
|
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 |
*/
|
588
|
17 |
|
|
18 |
package com.nokia.helium.core.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.Task;
|
588
|
24 |
|
|
25 |
import com.nokia.helium.core.ant.MappedVariable;
|
|
26 |
import com.nokia.helium.core.ant.VariableMap;
|
|
27 |
import com.nokia.helium.core.ant.types.VariableSet;
|
|
28 |
|
|
29 |
/**
|
628
|
30 |
* To retrive a variable value from a collection of variable set based on name, which contains
|
|
31 |
* property-value in pair.
|
|
32 |
*
|
588
|
33 |
* <pre>
|
|
34 |
* Example:
|
|
35 |
*
|
|
36 |
* <hlm:argSet id="test.variableSet">
|
|
37 |
* <variable name="v1" value="the_value_1"/>
|
|
38 |
* <variable name="v2" value="the_value_2"/>
|
|
39 |
* <variable name="v3" value="the_value_3"/>
|
|
40 |
* </hlm:argSet>
|
|
41 |
*
|
|
42 |
* <hlm:getVariableValue name="v3" property="v1.value">
|
|
43 |
* <hlm:argSet refid="test.variableSet"/>
|
|
44 |
* </hlm:getVariableValue>
|
|
45 |
* </pre>
|
628
|
46 |
*
|
588
|
47 |
* @ant.task name="getVariableValue"
|
|
48 |
*/
|
|
49 |
public class GetValueFromVariableSetTask extends Task {
|
|
50 |
private String name;
|
|
51 |
private String property;
|
|
52 |
private boolean failOnError = true;
|
628
|
53 |
|
|
54 |
private Vector<VariableMap> variableMaps = new Vector<VariableMap>();
|
|
55 |
|
588
|
56 |
public void setName(String name) {
|
|
57 |
this.name = name;
|
|
58 |
}
|
|
59 |
|
|
60 |
/**
|
628
|
61 |
* Helper function to set failonerror attribute for the task.
|
|
62 |
*
|
|
63 |
* @param failStatus, if true will fail the build if no variable is found for matching name.
|
588
|
64 |
*/
|
|
65 |
public void setFailOnError(boolean failStatus) {
|
|
66 |
failOnError = failStatus;
|
|
67 |
}
|
|
68 |
|
|
69 |
/**
|
|
70 |
* Helper function to store the name of the property where the value to be stored
|
628
|
71 |
*
|
588
|
72 |
* @param property name of the property where the result to be stored
|
|
73 |
*/
|
|
74 |
public void setProperty(String property) {
|
|
75 |
this.property = property;
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
628
|
79 |
* Helper function to create the VariableIFImpl object.
|
|
80 |
*
|
588
|
81 |
* @return created VariableIFImpl instance
|
|
82 |
*/
|
|
83 |
public VariableSet createVariableIFImpl() {
|
|
84 |
VariableSet var = new VariableSet();
|
|
85 |
add(var);
|
|
86 |
return var;
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Helper function to add the newly created variable set. Called by ant.
|
628
|
91 |
*
|
588
|
92 |
* @param vs variable set to be added.
|
|
93 |
*/
|
|
94 |
public void add(VariableMap vs) {
|
|
95 |
variableMaps.add(vs);
|
|
96 |
}
|
|
97 |
|
|
98 |
public VariableMap getVariableInterface() {
|
|
99 |
if (variableMaps.isEmpty()) {
|
|
100 |
throw new BuildException("variable interface cannot be null");
|
|
101 |
}
|
628
|
102 |
if (variableMaps.size() > 1) {
|
588
|
103 |
throw new BuildException("maximum one variable interface can be set");
|
|
104 |
}
|
|
105 |
return variableMaps.elementAt(0);
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Task to get the name / value pair
|
628
|
110 |
*
|
588
|
111 |
* @return return the name / value pair for the variable set.
|
|
112 |
*/
|
|
113 |
public void execute() {
|
628
|
114 |
if (name == null) {
|
588
|
115 |
throw new BuildException("'name' attribute has not been defined.");
|
628
|
116 |
}
|
|
117 |
if (property == null) {
|
|
118 |
throw new BuildException("'property' attribute has not been defined.");
|
|
119 |
}
|
588
|
120 |
VariableMap variableMap = getVariableInterface();
|
|
121 |
for (MappedVariable var : variableMap.getVariables()) {
|
|
122 |
if (var.getName().equals(name)) {
|
|
123 |
getProject().setProperty(property, var.getValue());
|
|
124 |
return;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
if (failOnError) {
|
|
128 |
throw new BuildException("Could not find '" + name + "' variable.");
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|