1. Update to just keep several line JAVA related msg; 2. Remove file PropertyManager...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / GenBuildThread.java
CommitLineData
abce9cbd 1/** @file\r
2 This file is for single module thread definition. \r
3\r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13package org.tianocore.build;\r
14\r
15import java.util.Hashtable;\r
16import java.util.Iterator;\r
17import java.util.LinkedHashSet;\r
18import java.util.Set;\r
19import java.util.Vector;\r
20\r
3067c4b0 21import org.apache.tools.ant.BuildException;\r
abce9cbd 22import org.apache.tools.ant.BuildListener;\r
23import org.apache.tools.ant.Project;\r
24import org.apache.tools.ant.taskdefs.Property;\r
25import org.tianocore.build.GenBuildTask;\r
26import org.tianocore.build.fpd.FpdParserForThread;\r
498e9021 27import org.tianocore.build.global.GenBuildLogger;\r
abce9cbd 28import org.tianocore.build.id.FpdModuleIdentification;\r
29import org.tianocore.build.id.ModuleIdentification;\r
02c768ee 30import org.tianocore.common.logger.EdkLog;\r
abce9cbd 31\r
32/**\r
33 Add more comment here. \r
34\r
35 @since GenBuild 1.0\r
36**/\r
37public class GenBuildThread implements Runnable {\r
38\r
39 private ModuleIdentification parentModuleId = null;\r
40\r
41 private ModuleIdentification moduleId = null;\r
42\r
43 private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();\r
44 \r
45 private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;\r
46\r
47 private Project project = null;\r
48\r
49 public Object semaphore = new Object();\r
50\r
51 private String arch = null;\r
52\r
53 private boolean highPriority = false;\r
54\r
55 private Thread thread;\r
56\r
3067c4b0 57 public GenBuildThread(ModuleIdentification moduleId, String arch) {\r
58 this.moduleId = moduleId;\r
59 this.arch = arch;\r
60 thread = new Thread(FpdParserForThread.tg, this, moduleId + ":" + arch);\r
abce9cbd 61 }\r
62\r
63 public boolean start() {\r
64 if (highPriority) {\r
65 thread.setPriority(Thread.MAX_PRIORITY);\r
66 }\r
3067c4b0 67\r
abce9cbd 68 status = FpdParserForThread.STATUS_START_RUN;\r
498e9021 69\r
abce9cbd 70 thread.start();\r
498e9021 71\r
abce9cbd 72 return true;\r
73 }\r
74\r
75 public void run() {\r
abce9cbd 76\r
3067c4b0 77 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r
78 \r
79 try {\r
80 //\r
81 // Prepare pass down properties\r
82 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE\r
83 //\r
84 Vector<Property> properties = new Vector<Property>();\r
85 Property property = new Property();\r
86 property.setName("ARCH");\r
87 property.setValue(arch);\r
88 properties.add(property);\r
89 \r
90 property = new Property();\r
91 property.setName("MODULE_GUID");\r
92 property.setValue(moduleId.getGuid());\r
93 properties.add(property);\r
94 \r
95 property = new Property();\r
96 property.setName("MODULE_VERSION");\r
97 if (moduleId.getVersion() == null) {\r
98 property.setValue("");\r
99 } else {\r
100 property.setValue(moduleId.getVersion());\r
101 }\r
102 properties.add(property);\r
103 \r
104 property = new Property();\r
105 property.setName("PACKAGE_GUID");\r
106 property.setValue(moduleId.getPackage().getGuid());\r
107 properties.add(property);\r
108 \r
109 property = new Property();\r
110 property.setName("PACKAGE_VERSION");\r
111 if (moduleId.getPackage().getVersion() == null) {\r
112 property.setValue("");\r
113 } else {\r
114 property.setValue(moduleId.getPackage().getVersion());\r
115 }\r
116 properties.add(property);\r
117 \r
118 //\r
119 // Build the Module\r
120 //\r
121 GenBuildTask genBuildTask = new GenBuildTask();\r
122 \r
123 Project newProject = new Project();\r
124 \r
125 Hashtable passdownProperties = project.getProperties();\r
126 Iterator iter = passdownProperties.keySet().iterator();\r
127 while (iter.hasNext()) {\r
128 String item = (String) iter.next();\r
129 newProject.setProperty(item, (String) passdownProperties.get(item));\r
130 }\r
131 \r
132 newProject.setInputHandler(project.getInputHandler());\r
133 \r
134 Iterator listenerIter = project.getBuildListeners().iterator();\r
498e9021 135 GenBuildLogger newLogger = null;\r
3067c4b0 136 while (listenerIter.hasNext()) {\r
498e9021 137 BuildListener item = (BuildListener)listenerIter.next();\r
138 if (item instanceof GenBuildLogger) {\r
139 newLogger = (GenBuildLogger)((GenBuildLogger)item).clone();\r
140 newLogger.setId(fpdModuleId);\r
141 newProject.addBuildListener(newLogger);\r
142 } else {\r
143 newProject.addBuildListener(item);\r
144 }\r
3067c4b0 145 }\r
146 \r
147 project.initSubProject(newProject);\r
498e9021 148 \r
3067c4b0 149 genBuildTask.setProject(newProject);\r
150 \r
151 genBuildTask.setExternalProperties(properties);\r
152 \r
153 genBuildTask.parentId = parentModuleId;\r
498e9021 154\r
d3945b9d 155 genBuildTask.perform();\r
3067c4b0 156 } catch (BuildException be) {\r
2a9060e2 157 \r
158 EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, fpdModuleId + " build error. \n" + be.getMessage());\r
498e9021 159 \r
160 if (FpdParserForThread.errorModule == null) {\r
161 FpdParserForThread.errorModule = fpdModuleId;\r
162 }\r
2eb7d78d 163 \r
3067c4b0 164 synchronized (FpdParserForThread.deamonSemaphore) {\r
498e9021 165 FpdParserForThread.subCount();\r
3067c4b0 166 FpdParserForThread.deamonSemaphore.notifyAll();\r
167 }\r
498e9021 168 \r
3067c4b0 169 return ;\r
abce9cbd 170 }\r
3067c4b0 171 \r
abce9cbd 172 status = FpdParserForThread.STATUS_END_RUN;\r
2eb7d78d 173\r
174 EdkLog.log("GenBuild", EdkLog.EDK_ALWAYS, fpdModuleId + " build finished. ");\r
abce9cbd 175 \r
176 //\r
177 // \r
178 //\r
179 synchronized (FpdParserForThread.deamonSemaphore) {\r
180 FpdParserForThread.subCount();\r
181 FpdParserForThread.deamonSemaphore.notifyAll();\r
182 }\r
183 }\r
184\r
185 public void setArch(String arch) {\r
186 this.arch = arch;\r
187 }\r
188\r
189 public void setDependencies(Set<FpdModuleIdentification> dependencies) {\r
190 this.dependencies = dependencies;\r
191 }\r
192\r
193 public void setModuleId(ModuleIdentification moduleId) {\r
194 this.moduleId = moduleId;\r
195 }\r
196\r
197 public void setParentModuleId(ModuleIdentification parentModuleId) {\r
198 this.parentModuleId = parentModuleId;\r
199 }\r
200\r
201 public void setProject(Project project) {\r
202 this.project = project;\r
203 }\r
204\r
205 public void setHighPriority(boolean highPriority) {\r
206 this.highPriority = highPriority;\r
207 }\r
208\r
209\r
210 public Set<FpdModuleIdentification> getDependencies() {\r
211 return dependencies;\r
212 }\r
213\r
214 public ModuleIdentification getModuleId() {\r
215 return moduleId;\r
216 }\r
217\r
218 public int getStatus() {\r
219 //\r
220 // Add code here to judge dependency\r
221 //\r
222 if (status == FpdParserForThread.STATUS_DEPENDENCY_NOT_READY) {\r
223 Iterator<FpdModuleIdentification> iter = dependencies.iterator();\r
224 boolean flag = true;\r
225 while (iter.hasNext()) {\r
226 FpdModuleIdentification item = iter.next();\r
227 if (FpdParserForThread.allThreads.get(item).getStatus() == 1) {\r
228 flag = false;\r
229 break ;\r
230 }\r
231 }\r
232 if (flag) {\r
233 status = FpdParserForThread.STATUS_DEPENDENCY_READY;\r
234 }\r
235 }\r
236 return status;\r
237 }\r
238\r
239 public void setStatus(int status) {\r
240 this.status = status;\r
241 }\r
abce9cbd 242}\r