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