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
;
30 Add more comment here.
34 public class GenBuildThread
implements Runnable
{
36 private ModuleIdentification parentModuleId
= null;
38 private ModuleIdentification moduleId
= null;
40 private Set
<FpdModuleIdentification
> dependencies
= new LinkedHashSet
<FpdModuleIdentification
>();
42 private int status
= FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
;
44 private Project project
= null;
46 public Object semaphore
= new Object();
48 private String arch
= null;
50 private boolean highPriority
= false;
52 private Thread thread
;
54 public GenBuildThread() {
55 thread
= new Thread(this);
58 public boolean start() {
60 thread
.setPriority(Thread
.MAX_PRIORITY
);
63 status
= FpdParserForThread
.STATUS_START_RUN
;
70 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
73 // Prepare pass down properties
74 // ARCH, MODULE_GUID, MODULE_VERSION, PACKAGE_GUID, PACKAGE_VERSION, PLATFORM_FILE
76 Vector
<Property
> properties
= new Vector
<Property
>();
77 Property property
= new Property();
78 property
.setName("ARCH");
79 property
.setValue(arch
);
80 properties
.add(property
);
82 property
= new Property();
83 property
.setName("MODULE_GUID");
84 property
.setValue(moduleId
.getGuid());
85 properties
.add(property
);
87 property
= new Property();
88 property
.setName("MODULE_VERSION");
89 if (moduleId
.getVersion() == null) {
90 property
.setValue("");
92 property
.setValue(moduleId
.getVersion());
94 properties
.add(property
);
96 property
= new Property();
97 property
.setName("PACKAGE_GUID");
98 property
.setValue(moduleId
.getPackage().getGuid());
99 properties
.add(property
);
101 property
= new Property();
102 property
.setName("PACKAGE_VERSION");
103 if (moduleId
.getPackage().getVersion() == null) {
104 property
.setValue("");
106 property
.setValue(moduleId
.getPackage().getVersion());
108 properties
.add(property
);
110 // property = new Property();
111 // property.setName("PLATFORM_FILE");
112 // property.setValue(arch);
113 // properties.add(property);
118 GenBuildTask genBuildTask
= new GenBuildTask();
120 Project newProject
= new Project();
122 Hashtable passdownProperties
= project
.getProperties();
123 Iterator iter
= passdownProperties
.keySet().iterator();
124 while (iter
.hasNext()) {
125 String item
= (String
) iter
.next();
126 newProject
.setProperty(item
, (String
) passdownProperties
.get(item
));
129 newProject
.setInputHandler(project
.getInputHandler());
131 Iterator listenerIter
= project
.getBuildListeners().iterator();
132 while (listenerIter
.hasNext()) {
133 newProject
.addBuildListener((BuildListener
) listenerIter
.next());
136 project
.initSubProject(newProject
);
138 genBuildTask
.setProject(newProject
);
140 genBuildTask
.setExternalProperties(properties
);
142 genBuildTask
.parentId
= parentModuleId
;
144 genBuildTask
.perform();
146 status
= FpdParserForThread
.STATUS_END_RUN
;
148 System
.out
.println(fpdModuleId
+ " build finished. ");
153 synchronized (FpdParserForThread
.deamonSemaphore
) {
154 FpdParserForThread
.subCount();
155 FpdParserForThread
.deamonSemaphore
.notifyAll();
159 public void setArch(String arch
) {
163 public void setDependencies(Set
<FpdModuleIdentification
> dependencies
) {
164 this.dependencies
= dependencies
;
167 public void setModuleId(ModuleIdentification moduleId
) {
168 this.moduleId
= moduleId
;
171 public void setParentModuleId(ModuleIdentification parentModuleId
) {
172 this.parentModuleId
= parentModuleId
;
175 public void setProject(Project project
) {
176 this.project
= project
;
179 public void setHighPriority(boolean highPriority
) {
180 this.highPriority
= highPriority
;
184 public Set
<FpdModuleIdentification
> getDependencies() {
188 public ModuleIdentification
getModuleId() {
192 public int getStatus() {
194 // Add code here to judge dependency
196 if (status
== FpdParserForThread
.STATUS_DEPENDENCY_NOT_READY
) {
197 Iterator
<FpdModuleIdentification
> iter
= dependencies
.iterator();
199 while (iter
.hasNext()) {
200 FpdModuleIdentification item
= iter
.next();
201 if (FpdParserForThread
.allThreads
.get(item
).getStatus() == 1) {
207 status
= FpdParserForThread
.STATUS_DEPENDENCY_READY
;
213 public void setStatus(int status
) {
214 this.status
= status
;