587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.helium.imaker.ant.taskdefs;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.util.ArrayList;
|
|
21 |
import java.util.List;
|
|
22 |
|
|
23 |
import org.apache.tools.ant.BuildException;
|
|
24 |
import org.apache.tools.ant.Project;
|
|
25 |
import org.apache.tools.ant.Task;
|
|
26 |
import org.apache.tools.ant.types.DataType;
|
|
27 |
|
|
28 |
import com.nokia.helium.core.plexus.AntStreamConsumer;
|
|
29 |
import com.nokia.helium.imaker.IMaker;
|
|
30 |
import com.nokia.helium.imaker.IMakerException;
|
|
31 |
import com.nokia.helium.imaker.ant.Command;
|
|
32 |
import com.nokia.helium.imaker.ant.Engine;
|
|
33 |
import com.nokia.helium.imaker.ant.IMakerCommandSet;
|
|
34 |
import com.nokia.helium.imaker.ant.engines.JavaEngine;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* The imaker task will allow you to efficiently use iMaker to
|
|
38 |
* build rom images in parallel.
|
|
39 |
*
|
|
40 |
* The task is actually base on two concepts:
|
|
41 |
* <ul>
|
|
42 |
* <li> content configuration: what needs to be built.
|
|
43 |
* <li> acceleration engine: how to build roms in an efficient way.
|
|
44 |
* </ul>
|
|
45 |
*
|
|
46 |
* In the following example the task is configured to use the emake engine
|
|
47 |
* to accelerate the rom image creation and an <code>imakerconfiguration</code> configuration
|
|
48 |
* element to configure the content of the building:
|
|
49 |
*
|
|
50 |
* <pre>
|
|
51 |
* <hlm:emakeEngine id="imaker.ec" />
|
|
52 |
* <hlm:imaker epocroot="${epocroot}"
|
|
53 |
* output="${epocroot}/imaker.log"
|
|
54 |
* engineRefid="imaker.ec"
|
|
55 |
* verbose="true">
|
|
56 |
<hlm:imakerconfiguration>
|
|
57 |
* <makefileset>
|
|
58 |
* <include name="**/product/*ui.mk" />
|
|
59 |
* </makefileset>
|
|
60 |
* <targetset>
|
|
61 |
* <include name="core" />
|
|
62 |
* <include name="langpack_01" />
|
|
63 |
* </targetset>
|
|
64 |
</hlm:imakerconfiguration>
|
|
65 |
* </hlm:imaker>
|
|
66 |
* </pre>
|
|
67 |
* @ant.task name=imaker category=imaker
|
|
68 |
*/
|
|
69 |
public class IMakerTask extends Task {
|
|
70 |
|
|
71 |
private File epocroot;
|
|
72 |
private boolean verbose;
|
|
73 |
private boolean failOnError = true;
|
|
74 |
private List<IMakerCommandSet> commandSets = new ArrayList<IMakerCommandSet>();
|
|
75 |
private String engineRefId;
|
|
76 |
private AntStreamConsumer stdout = new AntStreamConsumer(this);
|
|
77 |
private AntStreamConsumer stderr = new AntStreamConsumer(this, Project.MSG_ERR);
|
|
78 |
private File output;
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Add iMaker Task compatible configuration. The task will
|
|
82 |
* accept any Ant type implementing the IMakerCommandSet
|
|
83 |
* interface like the <code>imakerconfiguration</code> type.
|
|
84 |
*
|
|
85 |
* @param cmdSet an iMaker configuration which will defines
|
|
86 |
* what needs to be built.
|
|
87 |
*
|
|
88 |
* @ant.required
|
|
89 |
*/
|
|
90 |
public void add(IMakerCommandSet cmdSet) {
|
|
91 |
commandSets.add(cmdSet);
|
|
92 |
}
|
|
93 |
|
|
94 |
/**
|
|
95 |
* Defines the reference id of the engine to use.
|
|
96 |
* @ant.not-required Default Java implementation will be used.
|
|
97 |
*/
|
|
98 |
public void setEngineRefId(String engineRefId) {
|
|
99 |
this.engineRefId = engineRefId;
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Retrieve the engine to be used. If the engineRefId
|
|
104 |
* attribute is not defined then the JavaEngine is used
|
|
105 |
* as the default one.
|
|
106 |
* @return An instance of engine.
|
|
107 |
* @throws a BuildException if the engineRefId attribute doesn't define an Engine
|
|
108 |
* object.
|
|
109 |
*/
|
|
110 |
protected Engine getEngine() {
|
|
111 |
if (engineRefId == null) {
|
|
112 |
log("Using default engine (Java threading)");
|
|
113 |
JavaEngine engine = new JavaEngine();
|
|
114 |
engine.setProject(getProject());
|
|
115 |
engine.setTask(this);
|
|
116 |
return engine;
|
|
117 |
} else {
|
618
|
118 |
log("Using engine: " + engineRefId);
|
|
119 |
if (this.getProject().getReference(engineRefId) == null) {
|
|
120 |
throw new BuildException("Could not find engine reference: '" + engineRefId + "'.");
|
|
121 |
}
|
587
|
122 |
try {
|
|
123 |
Engine engine = (Engine)this.getProject().getReference(engineRefId);
|
|
124 |
engine.setTask(this);
|
|
125 |
return engine;
|
|
126 |
} catch (ClassCastException e) {
|
|
127 |
throw new BuildException("Reference '" + engineRefId + "' is not referencing an Engine configuration.");
|
|
128 |
}
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Get current epocroot location (build environment).
|
|
134 |
* @return a File object.
|
|
135 |
*/
|
|
136 |
public File getEpocroot() {
|
|
137 |
File epocroot = this.epocroot;
|
|
138 |
if (epocroot == null) {
|
|
139 |
epocroot = new File(System.getenv("EPOCROOT"));
|
|
140 |
if (epocroot == null) {
|
|
141 |
throw new BuildException("'epocroot' attribute has not been defined.");
|
|
142 |
} else {
|
|
143 |
log("Using EPOCROOT: " + epocroot.getAbsolutePath());
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
if (!epocroot.exists() || !epocroot.isDirectory()) {
|
|
148 |
throw new BuildException("Invalid epocroot directory: " + epocroot);
|
|
149 |
}
|
|
150 |
return epocroot;
|
|
151 |
}
|
|
152 |
|
|
153 |
/**
|
|
154 |
* Defines the EPOCROOT location.
|
|
155 |
* @param epocroot
|
|
156 |
* @ant.not-required Will use EPOCROOT environment variable if not defined.
|
|
157 |
*/
|
|
158 |
public void setEpocroot(File epocroot) {
|
|
159 |
this.epocroot = epocroot;
|
|
160 |
}
|
|
161 |
|
|
162 |
/**
|
|
163 |
* {@inheritDoc}
|
|
164 |
*/
|
|
165 |
@Override
|
|
166 |
public void execute() {
|
|
167 |
try {
|
|
168 |
// Simple way to verify if iMaker is installed under
|
|
169 |
// then environment.
|
|
170 |
IMaker imaker = getIMaker();
|
|
171 |
log("Using iMaker: " + imaker.getVersion());
|
|
172 |
|
|
173 |
// build the content.
|
|
174 |
build();
|
|
175 |
} catch (IMakerException e) {
|
|
176 |
if (shouldFailOnError()) {
|
|
177 |
throw new BuildException(e.getMessage(), e);
|
|
178 |
} else {
|
|
179 |
log(e.getMessage(), Project.MSG_ERR);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Should the task be verbose.
|
|
186 |
* @return Returns true if the task should display all iMaker outputs.
|
|
187 |
*/
|
|
188 |
public boolean isVerbose() {
|
|
189 |
return verbose;
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Defines if the task should log all the output through Ant.
|
|
194 |
* by default only error/warnings are printed.
|
|
195 |
* @param verbose set the verbosity status.
|
|
196 |
* @ant.not-required Default is false.
|
|
197 |
*/
|
|
198 |
public void setVerbose(boolean verbose) {
|
|
199 |
this.verbose = verbose;
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Get the output filename.
|
|
204 |
* @return the output filename.
|
|
205 |
*/
|
|
206 |
public File getOutput() {
|
|
207 |
return output;
|
|
208 |
}
|
|
209 |
|
|
210 |
/**
|
|
211 |
* Defined the output log filename.
|
|
212 |
* @param output
|
|
213 |
* @ant.not-required
|
|
214 |
*/
|
|
215 |
public void setOutput(File output) {
|
|
216 |
this.output = output;
|
|
217 |
}
|
|
218 |
|
|
219 |
/**
|
|
220 |
* Concatenate all the configuration content and
|
|
221 |
* delegate the building to the engine.
|
|
222 |
* @throws IMakerException
|
|
223 |
*/
|
|
224 |
protected void build() throws IMakerException {
|
|
225 |
List<List<Command>> cmds = new ArrayList<List<Command>>();
|
|
226 |
for (IMakerCommandSet cmdSet : commandSets) {
|
|
227 |
if (cmdSet instanceof DataType) {
|
|
228 |
DataType dataType = (DataType)cmdSet;
|
|
229 |
if (dataType.isReference()) {
|
|
230 |
cmdSet = (IMakerCommandSet)dataType.getRefid().getReferencedObject();
|
|
231 |
}
|
|
232 |
}
|
|
233 |
cmds.addAll(cmdSet.getCommands(getIMaker()));
|
|
234 |
}
|
|
235 |
if (cmds.size() > 0) {
|
|
236 |
getEngine().build(cmds);
|
|
237 |
} else {
|
|
238 |
log("Nothing to build.");
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Get a configured IMaker instance. The created object
|
|
244 |
* is configured with output stream redirected to
|
|
245 |
* the task logging. Stderr is always redirected,
|
|
246 |
* stdout is only redirected if the task is configured
|
|
247 |
* to be verbose.
|
|
248 |
*
|
|
249 |
* @return an IMaker instance.
|
|
250 |
*/
|
|
251 |
public IMaker getIMaker() {
|
|
252 |
return getIMaker(verbose, true);
|
|
253 |
}
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Get a configured IMaker instance. The created object
|
|
257 |
* is configured with output stream redirected to
|
|
258 |
* the task logging. Stderr is always redirected,
|
|
259 |
* the stdout will be configured by the verbose parameter.
|
|
260 |
* @param verbose enable stdout redirection to the task logging.
|
|
261 |
* @return an IMaker instance.
|
|
262 |
*/
|
|
263 |
public IMaker getIMaker(boolean verbose, boolean verboseError) {
|
|
264 |
IMaker imaker = new IMaker(getEpocroot());
|
|
265 |
if (verbose) {
|
|
266 |
imaker.addOutputLineHandler(stdout);
|
|
267 |
}
|
|
268 |
if (verboseError) {
|
|
269 |
imaker.addErrorLineHandler(stderr);
|
|
270 |
}
|
|
271 |
return imaker;
|
|
272 |
}
|
|
273 |
|
|
274 |
/**
|
|
275 |
* Defines if the task should fail in case of error.
|
|
276 |
* @ant.not-required Default is true
|
|
277 |
*/
|
|
278 |
public void setFailOnError(boolean failOnError) {
|
|
279 |
this.failOnError = failOnError;
|
|
280 |
}
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Should the task should fail in case of error?
|
|
284 |
* @return true if the task should fail on error.
|
|
285 |
*/
|
|
286 |
public boolean shouldFailOnError() {
|
|
287 |
return this.failOnError;
|
|
288 |
}
|
|
289 |
|
|
290 |
}
|