]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/GenBuildThread.java
1. Add function "Refresh" in main UI
[mirror_edk2.git] / Tools / 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
21import org.apache.tools.ant.BuildListener;\r
22import org.apache.tools.ant.Project;\r
23import org.apache.tools.ant.taskdefs.Property;\r
24import org.tianocore.build.GenBuildTask;\r
25import org.tianocore.build.fpd.FpdParserForThread;\r
26import org.tianocore.build.id.FpdModuleIdentification;\r
27import org.tianocore.build.id.ModuleIdentification;\r
02c768ee 28import org.tianocore.common.logger.EdkLog;\r
abce9cbd 29\r
30/**\r
31 Add more comment here. \r
32\r
33 @since GenBuild 1.0\r
34**/\r
35public class GenBuildThread implements Runnable {\r
36\r
37 private ModuleIdentification parentModuleId = null;\r
38\r
39 private ModuleIdentification moduleId = null;\r
40\r
41 private Set<FpdModuleIdentification> dependencies = new LinkedHashSet<FpdModuleIdentification>();\r
42 \r
43 private int status = FpdParserForThread.STATUS_DEPENDENCY_NOT_READY;\r
44\r
45 private Project project = null;\r
46\r
47 public Object semaphore = new Object();\r
48\r
49 private String arch = null;\r
50\r
51 private boolean highPriority = false;\r
52\r
53 private Thread thread;\r
54\r
55 public GenBuildThread() {\r
56 thread = new Thread(this);\r
57 }\r
58\r
59 public boolean start() {\r
60 if (highPriority) {\r
61 thread.setPriority(Thread.MAX_PRIORITY);\r
62 }\r
63 \r
64 status = FpdParserForThread.STATUS_START_RUN;\r
65 thread.start();\r
66 return true;\r
67 }\r
68\r
69 public void run() {\r
70 \r
71 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r
72\r
73 //\r
74 // Prepare pass down properties\r
75 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE\r
76 //\r
77 Vector<Property> properties = new Vector<Property>();\r
78 Property property = new Property();\r
79 property.setName("ARCH");\r
80 property.setValue(arch);\r
81 properties.add(property);\r
82\r
83 property = new Property();\r
84 property.setName("MODULE_GUID");\r
85 property.setValue(moduleId.getGuid());\r
86 properties.add(property);\r
87\r
88 property = new Property();\r
89 property.setName("MODULE_VERSION");\r
90 if (moduleId.getVersion() == null) {\r
91 property.setValue("");\r
92 } else {\r
93 property.setValue(moduleId.getVersion());\r
94 }\r
95 properties.add(property);\r
96\r
97 property = new Property();\r
98 property.setName("PACKAGE_GUID");\r
99 property.setValue(moduleId.getPackage().getGuid());\r
100 properties.add(property);\r
101\r
102 property = new Property();\r
103 property.setName("PACKAGE_VERSION");\r
104 if (moduleId.getPackage().getVersion() == null) {\r
105 property.setValue("");\r
106 } else {\r
107 property.setValue(moduleId.getPackage().getVersion());\r
108 }\r
109 properties.add(property);\r
110\r
111 // property = new Property();\r
112 // property.setName("PLATFORM_FILE");\r
113 // property.setValue(arch);\r
114 // properties.add(property);\r
115\r
116 //\r
117 // Build the Module\r
118 //\r
119 GenBuildTask genBuildTask = new GenBuildTask();\r
120\r
121 Project newProject = new Project();\r
122\r
123 Hashtable passdownProperties = project.getProperties();\r
124 Iterator iter = passdownProperties.keySet().iterator();\r
125 while (iter.hasNext()) {\r
126 String item = (String) iter.next();\r
127 newProject.setProperty(item, (String) passdownProperties.get(item));\r
128 }\r
129\r
130 newProject.setInputHandler(project.getInputHandler());\r
131\r
132 Iterator listenerIter = project.getBuildListeners().iterator();\r
133 while (listenerIter.hasNext()) {\r
134 newProject.addBuildListener((BuildListener) listenerIter.next());\r
135 }\r
136\r
137 project.initSubProject(newProject);\r
138\r
139 genBuildTask.setProject(newProject);\r
140\r
141 genBuildTask.setExternalProperties(properties);\r
142\r
143 genBuildTask.parentId = parentModuleId;\r
144\r
145 genBuildTask.perform();\r
146\r
147 status = FpdParserForThread.STATUS_END_RUN;\r
148 \r
02c768ee 149 EdkLog.log("GenBuildThread", fpdModuleId + " build finished. ");\r
abce9cbd 150 \r
151 //\r
152 // \r
153 //\r
154 synchronized (FpdParserForThread.deamonSemaphore) {\r
155 FpdParserForThread.subCount();\r
156 FpdParserForThread.deamonSemaphore.notifyAll();\r
157 }\r
158 }\r
159\r
160 public void setArch(String arch) {\r
161 this.arch = arch;\r
162 }\r
163\r
164 public void setDependencies(Set<FpdModuleIdentification> dependencies) {\r
165 this.dependencies = dependencies;\r
166 }\r
167\r
168 public void setModuleId(ModuleIdentification moduleId) {\r
169 this.moduleId = moduleId;\r
170 }\r
171\r
172 public void setParentModuleId(ModuleIdentification parentModuleId) {\r
173 this.parentModuleId = parentModuleId;\r
174 }\r
175\r
176 public void setProject(Project project) {\r
177 this.project = project;\r
178 }\r
179\r
180 public void setHighPriority(boolean highPriority) {\r
181 this.highPriority = highPriority;\r
182 }\r
183\r
184\r
185 public Set<FpdModuleIdentification> getDependencies() {\r
186 return dependencies;\r
187 }\r
188\r
189 public ModuleIdentification getModuleId() {\r
190 return moduleId;\r
191 }\r
192\r
193 public int getStatus() {\r
194 //\r
195 // Add code here to judge dependency\r
196 //\r
197 if (status == FpdParserForThread.STATUS_DEPENDENCY_NOT_READY) {\r
198 Iterator<FpdModuleIdentification> iter = dependencies.iterator();\r
199 boolean flag = true;\r
200 while (iter.hasNext()) {\r
201 FpdModuleIdentification item = iter.next();\r
202 if (FpdParserForThread.allThreads.get(item).getStatus() == 1) {\r
203 flag = false;\r
204 break ;\r
205 }\r
206 }\r
207 if (flag) {\r
208 status = FpdParserForThread.STATUS_DEPENDENCY_READY;\r
209 }\r
210 }\r
211 return status;\r
212 }\r
213\r
214 public void setStatus(int status) {\r
215 this.status = status;\r
216 }\r
abce9cbd 217}\r