587
|
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 |
*/
|
587
|
17 |
|
|
18 |
package com.nokia.helium.diamonds;
|
|
19 |
|
628
|
20 |
import java.util.HashMap;
|
|
21 |
import java.util.Map;
|
|
22 |
import com.nokia.helium.core.ant.types.Stage;
|
|
23 |
import com.nokia.helium.core.ant.types.TargetMessageTrigger;
|
|
24 |
import org.apache.tools.ant.Project;
|
|
25 |
import java.util.Hashtable;
|
587
|
26 |
import org.apache.log4j.Logger;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Loads the configuration information from the xml file.
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public final class DiamondsConfig {
|
|
33 |
|
628
|
34 |
private static HashMap<String, Stage> stages = new HashMap<String, Stage>();
|
587
|
35 |
|
628
|
36 |
private static Logger log = Logger.getLogger(DiamondsConfig.class);
|
587
|
37 |
|
628
|
38 |
private static String initialiserTargetName;
|
|
39 |
|
|
40 |
private static Project project;
|
|
41 |
|
|
42 |
private static final String DIAMONDS_HOST_PROPERTY = "diamonds.host";
|
|
43 |
private static final String DIAMONDS_PORT_PROPERTY = "diamonds.port";
|
|
44 |
private static final String DIAMONDS_PATH_PROPERTY = "diamonds.path";
|
|
45 |
private static final String DIAMONDS_TSTAMP_PROPERTY = "diamonds.tstamp.format";
|
|
46 |
private static final String DIAMONDS_MAIL_PROPERTY = "diamonds.mail";
|
|
47 |
private static final String DIAMONDS_LDAP_PROPERTY = "diamonds.ldap.server";
|
|
48 |
private static final String DIAMONDS_SMTP_PROPERTY = "diamonds.smtp.server";
|
|
49 |
private static final String DIAMONDS_INITIALIZER_TARGET_PROPERTY = "diamonds.initializer.targetname";
|
|
50 |
private static final String DIAMONDS_CATEGORY_PROPERTY = "diamonds.category";
|
|
51 |
|
|
52 |
|
|
53 |
private static final String[] PROPERTY_NAMES = {DIAMONDS_HOST_PROPERTY, DIAMONDS_PORT_PROPERTY, DIAMONDS_PATH_PROPERTY,
|
|
54 |
DIAMONDS_TSTAMP_PROPERTY, DIAMONDS_MAIL_PROPERTY,
|
|
55 |
DIAMONDS_LDAP_PROPERTY, DIAMONDS_SMTP_PROPERTY,
|
|
56 |
DIAMONDS_INITIALIZER_TARGET_PROPERTY, DIAMONDS_CATEGORY_PROPERTY};
|
587
|
57 |
|
628
|
58 |
private static HashMap<String, TargetMessageTrigger> targetMessageList = new HashMap<String, TargetMessageTrigger>();
|
587
|
59 |
|
|
60 |
private DiamondsConfig() {
|
|
61 |
}
|
628
|
62 |
|
|
63 |
|
|
64 |
@SuppressWarnings("unchecked")
|
|
65 |
private static void initializeMessage(Project prj) {
|
|
66 |
Hashtable<String, Object> references = prj.getReferences();
|
|
67 |
for (String key : references.keySet()) {
|
|
68 |
Object object = references.get(key);
|
|
69 |
log.debug("key: " + key);
|
|
70 |
if (object instanceof TargetMessageTrigger) {
|
|
71 |
log.debug("found message map:" + object);
|
|
72 |
log.debug("found key: " + key);
|
|
73 |
TargetMessageTrigger message = (TargetMessageTrigger)object;
|
|
74 |
targetMessageList.put(message.getTargetName(), (TargetMessageTrigger)object);
|
|
75 |
}
|
587
|
76 |
}
|
628
|
77 |
}
|
|
78 |
|
|
79 |
@SuppressWarnings("unchecked")
|
|
80 |
public static void initialize(Project prj) throws DiamondsException {
|
|
81 |
project = prj;
|
|
82 |
log.debug("Diamonds config initialization: project: " + project);
|
|
83 |
initializeMessage(prj);
|
|
84 |
for (String property : PROPERTY_NAMES ) {
|
|
85 |
validateProperty(property);
|
587
|
86 |
}
|
628
|
87 |
Hashtable<String, Object> references = prj.getReferences();
|
|
88 |
for (String key : references.keySet()) {
|
|
89 |
Object object = references.get(key);
|
|
90 |
if (object instanceof Stage) {
|
|
91 |
log.debug("stage found: " + key);
|
|
92 |
Stage stageMap = (Stage)object;
|
|
93 |
stageMap.setStageName(key);
|
|
94 |
stages.put(key, (Stage)object);
|
|
95 |
}
|
|
96 |
}
|
587
|
97 |
}
|
|
98 |
|
628
|
99 |
private static void validateProperty(String propertyName) throws DiamondsException {
|
|
100 |
String propertyValue = project.getProperty(propertyName);
|
|
101 |
if (propertyValue == null) {
|
|
102 |
throw new DiamondsException("required property: " + propertyName + " not defined");
|
587
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Helper function to get the stages
|
|
108 |
*
|
|
109 |
* @return the stages from config in memory
|
|
110 |
*/
|
628
|
111 |
static Map<String, Stage> getStages() {
|
587
|
112 |
return stages;
|
|
113 |
}
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Helper function to get the targets
|
|
117 |
*
|
|
118 |
* @return the targets from config in memory
|
|
119 |
*/
|
628
|
120 |
static HashMap<String, TargetMessageTrigger> getTargetsMap() {
|
|
121 |
return targetMessageList;
|
587
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Returns true if stages exists in config
|
|
126 |
*
|
|
127 |
* @return the existance of stages in config
|
|
128 |
*/
|
|
129 |
public static boolean isStagesInConfig() {
|
628
|
130 |
return !stages.isEmpty();
|
587
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Returns true if targets exists in config
|
|
135 |
*
|
|
136 |
* @return the targets from config in memory
|
|
137 |
*/
|
|
138 |
public static boolean isTargetsInConfig() {
|
628
|
139 |
return !targetMessageList.isEmpty();
|
|
140 |
}
|
|
141 |
|
|
142 |
public static String getHost() {
|
|
143 |
return project.getProperty(DIAMONDS_HOST_PROPERTY);
|
|
144 |
}
|
|
145 |
|
|
146 |
public static String getPort() {
|
|
147 |
return project.getProperty(DIAMONDS_PORT_PROPERTY);
|
|
148 |
}
|
|
149 |
|
|
150 |
public static String getPath() {
|
|
151 |
return project.getProperty(DIAMONDS_PATH_PROPERTY);
|
|
152 |
}
|
|
153 |
|
|
154 |
public static String getTimeFormat() {
|
|
155 |
return project.getProperty(DIAMONDS_TSTAMP_PROPERTY);
|
587
|
156 |
}
|
|
157 |
|
628
|
158 |
public static String getMailInfo() {
|
|
159 |
return project.getProperty(DIAMONDS_MAIL_PROPERTY);
|
|
160 |
}
|
|
161 |
|
|
162 |
public static String getLDAPServer() {
|
|
163 |
return project.getProperty(DIAMONDS_LDAP_PROPERTY);
|
587
|
164 |
}
|
|
165 |
|
628
|
166 |
public static String getSMTPServer() {
|
|
167 |
return project.getProperty(DIAMONDS_SMTP_PROPERTY);
|
|
168 |
}
|
|
169 |
|
|
170 |
public static String getBuildIdProperty() {
|
|
171 |
return "diamonds.build.id";
|
|
172 |
}
|
|
173 |
|
|
174 |
public static String getBuildId() {
|
|
175 |
return project.getProperty(getBuildIdProperty());
|
587
|
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Gets the initialiserTargetName
|
|
180 |
*
|
628
|
181 |
* @return the initialiserTargetName
|
587
|
182 |
*/
|
628
|
183 |
public static String getInitializerTargetProperty() {
|
|
184 |
return DIAMONDS_INITIALIZER_TARGET_PROPERTY;
|
587
|
185 |
}
|
628
|
186 |
|
|
187 |
public static String getCategory() {
|
|
188 |
return project.getProperty(DIAMONDS_CATEGORY_PROPERTY);
|
587
|
189 |
}
|
|
190 |
|
|
191 |
} |