2 This file is for single module thread definition.
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
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.
13 package org
.tianocore
.build
;
15 import java
.util
.Hashtable
;
16 import java
.util
.Iterator
;
17 import java
.util
.LinkedHashSet
;
19 import java
.util
.Vector
;
21 import org
.apache
.tools
.ant
.BuildListener
;
22 import org
.apache
.tools
.ant
.Project
;
23 import org
.apache
.tools
.ant
.taskdefs
.Property
;
24 import org
.tianocore
.build
.GenBuildTask
;
25 import org
.tianocore
.build
.fpd
.FpdParserForThread
;
26 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
27 import org
.tianocore
.build
.id
.ModuleIdentification
;
28 import org
.tianocore
.common
.logger
.EdkLog
;
31 Add more comment here.
35 public class GenBuildThread
implements Runnable
{
37 private ModuleIdentification parentModuleId
= null;
39 private ModuleIdentification moduleId
= null;
41 private Set
<FpdModuleIdentification
> dependencies
= new LinkedHashSet
<FpdModuleIdentification
>();
43 private int status
= FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
;
45 private Project project
= null;
47 public Object semaphore
= new Object();
49 private String arch
= null;
51 private boolean highPriority
= false;
53 private Thread thread
;
55 public GenBuildThread() {
56 thread
= new Thread(this);
59 public boolean start() {
61 thread
.setPriority(Thread
.MAX_PRIORITY
);
64 status
= FpdParserForThread
.STATUS_START_RUN
;
71 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
74 // Prepare pass down properties
75 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE
77 Vector
<Property
> properties
= new Vector
<Property
>();
78 Property property
= new Property();
79 property
.setName("ARCH");
80 property
.setValue(arch
);
81 properties
.add(property
);
83 property
= new Property();
84 property
.setName("MODULE_GUID");
85 property
.setValue(moduleId
.getGuid());
86 properties
.add(property
);
88 property
= new Property();
89 property
.setName("MODULE_VERSION");
90 if (moduleId
.getVersion() == null) {
91 property
.setValue("");
93 property
.setValue(moduleId
.getVersion());
95 properties
.add(property
);
97 property
= new Property();
98 property
.setName("PACKAGE_GUID");
99 property
.setValue(moduleId
.getPackage().getGuid());
100 properties
.add(property
);
102 property
= new Property();
103 property
.setName("PACKAGE_VERSION");
104 if (moduleId
.getPackage().getVersion() == null) {
105 property
.setValue("");
107 property
.setValue(moduleId
.getPackage().getVersion());
109 properties
.add(property
);
111 // property = new Property();
112 // property.setName("PLATFORM_FILE");
113 // property.setValue(arch);
114 // properties.add(property);
119 GenBuildTask genBuildTask
= new GenBuildTask();
121 Project newProject
= new Project();
123 Hashtable passdownProperties
= project
.getProperties();
124 Iterator iter
= passdownProperties
.keySet().iterator();
125 while (iter
.hasNext()) {
126 String item
= (String
) iter
.next();
127 newProject
.setProperty(item
, (String
) passdownProperties
.get(item
));
130 newProject
.setInputHandler(project
.getInputHandler());
132 Iterator listenerIter
= project
.getBuildListeners().iterator();
133 while (listenerIter
.hasNext()) {
134 newProject
.addBuildListener((BuildListener
) listenerIter
.next());
137 project
.initSubProject(newProject
);
139 genBuildTask
.setProject(newProject
);
141 genBuildTask
.setExternalProperties(properties
);
143 genBuildTask
.parentId
= parentModuleId
;
145 genBuildTask
.perform();
147 status
= FpdParserForThread
.STATUS_END_RUN
;
149 EdkLog
.log("GenBuildThread", fpdModuleId
+ " build finished. ");
154 synchronized (FpdParserForThread
.deamonSemaphore
) {
155 FpdParserForThread
.subCount();
156 FpdParserForThread
.deamonSemaphore
.notifyAll();
160 public void setArch(String arch
) {
164 public void setDependencies(Set
<FpdModuleIdentification
> dependencies
) {
165 this.dependencies
= dependencies
;
168 public void setModuleId(ModuleIdentification moduleId
) {
169 this.moduleId
= moduleId
;
172 public void setParentModuleId(ModuleIdentification parentModuleId
) {
173 this.parentModuleId
= parentModuleId
;
176 public void setProject(Project project
) {
177 this.project
= project
;
180 public void setHighPriority(boolean highPriority
) {
181 this.highPriority
= highPriority
;
185 public Set
<FpdModuleIdentification
> getDependencies() {
189 public ModuleIdentification
getModuleId() {
193 public int getStatus() {
195 // Add code here to judge dependency
197 if (status
== FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
) {
198 Iterator
<FpdModuleIdentification
> iter
= dependencies
.iterator();
200 while (iter
.hasNext()) {
201 FpdModuleIdentification item
= iter
.next();
202 if (FpdParserForThread
.allThreads
.get(item
).getStatus() == 1) {
208 status
= FpdParserForThread
.STATUS_DEPENDENCY_READY
;
214 public void setStatus(int status
) {
215 this.status
= status
;