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