587
|
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.ant.data;
|
|
19 |
|
|
20 |
import org.apache.tools.ant.Project;
|
|
21 |
import org.dom4j.Element;
|
|
22 |
import org.dom4j.Node;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Meta object for an Ant property.
|
|
26 |
*/
|
|
27 |
public class PropertyMeta extends AntObjectMeta {
|
|
28 |
public static final String DEFAULT_EDITABLE = "optional";
|
|
29 |
public static final String STRING_TYPE = "string";
|
|
30 |
public static final String INTEGER_TYPE = "integer";
|
|
31 |
public static final String BOOLEAN_TYPE = "boolean";
|
|
32 |
public static final String DEFAULT_TYPE = STRING_TYPE;
|
|
33 |
|
628
|
34 |
public PropertyMeta(AntObjectMeta parent, Node propNode) {
|
587
|
35 |
super(parent, propNode);
|
|
36 |
}
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Returns the default value of the property.
|
|
40 |
*
|
|
41 |
* @return A default value.
|
|
42 |
*/
|
|
43 |
public String getDefaultValue() {
|
|
44 |
String value = getAttr("value");
|
|
45 |
if (value.length() == 0) {
|
|
46 |
value = getAttr("location");
|
|
47 |
}
|
|
48 |
return value;
|
|
49 |
}
|
|
50 |
|
|
51 |
public String getType() {
|
|
52 |
return getComment().getTagValue("type", PropertyMeta.DEFAULT_TYPE);
|
|
53 |
}
|
|
54 |
|
|
55 |
public String getEditable() {
|
|
56 |
return getComment().getTagValue("editable", PropertyMeta.DEFAULT_EDITABLE);
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Attempts to get the actual value of this current property.
|
|
61 |
*
|
|
62 |
* @return The property's current value.
|
|
63 |
*/
|
|
64 |
public String getValue() {
|
|
65 |
String value = null;
|
|
66 |
Project project = getRuntimeProject();
|
|
67 |
if (project != null) {
|
|
68 |
value = project.getProperty(getName());
|
|
69 |
}
|
|
70 |
return value;
|
|
71 |
}
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Handling of scope is overridden here to make properties declared at the
|
|
75 |
* project root to be public and those nested inside targets, etc to be
|
|
76 |
* private by default. This is only if there is no scope defined in the
|
|
77 |
* comment for the property.
|
|
78 |
*/
|
|
79 |
@Override
|
|
80 |
public String getScope() {
|
628
|
81 |
String scope = super.getScope();
|
|
82 |
Element parent = getNode().getParent();
|
|
83 |
if (getComment().getTagValue("scope").length() == 0 && !parent.getName().equals("project")) {
|
|
84 |
scope = "private";
|
587
|
85 |
}
|
|
86 |
return scope;
|
|
87 |
}
|
|
88 |
}
|