587
|
1 |
/*
|
628
|
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 |
*/
|
587
|
17 |
package com.nokia.helium.imaker;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.util.List;
|
|
22 |
|
628
|
23 |
import org.apache.log4j.Logger;
|
587
|
24 |
|
|
25 |
import com.nokia.helium.core.plexus.CommandBase;
|
|
26 |
import com.nokia.helium.core.plexus.StreamRecorder;
|
|
27 |
|
|
28 |
/**
|
628
|
29 |
* This class implements a wrapper around iMaker. It helps to introspect: <li>variables <li>targets
|
|
30 |
* <li>configurations
|
|
31 |
*
|
587
|
32 |
*/
|
|
33 |
public class IMaker extends CommandBase<IMakerException> {
|
|
34 |
private static final String TEMP_ROMBUILD_DIR = "epoc32/rombuild/temp";
|
|
35 |
private final Logger log = Logger.getLogger(getClass());
|
|
36 |
private File epocroot;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Create an iMaker wrapper class with a specific epocroot.
|
628
|
40 |
*
|
587
|
41 |
* @param epocroot
|
|
42 |
*/
|
|
43 |
public IMaker(File epocroot) {
|
|
44 |
this.epocroot = epocroot;
|
628
|
45 |
|
587
|
46 |
}
|
628
|
47 |
|
587
|
48 |
/**
|
|
49 |
* Creates a temp working dir for the rom image creation.
|
628
|
50 |
*
|
587
|
51 |
* @return
|
|
52 |
* @throws IOException
|
|
53 |
*/
|
|
54 |
public File createWorkDir() throws IMakerException {
|
|
55 |
try {
|
|
56 |
File tempRootDir = new File(getEpocroot(), TEMP_ROMBUILD_DIR);
|
|
57 |
tempRootDir.mkdirs();
|
|
58 |
File tempDir = File.createTempFile("helium-imaker", "", tempRootDir);
|
|
59 |
tempDir.delete();
|
|
60 |
tempDir.mkdirs();
|
|
61 |
return tempDir;
|
628
|
62 |
}
|
|
63 |
catch (IOException e) {
|
587
|
64 |
throw new IMakerException(e.getMessage(), e);
|
|
65 |
}
|
|
66 |
}
|
628
|
67 |
|
587
|
68 |
/**
|
|
69 |
* Epocroot location.
|
628
|
70 |
*
|
587
|
71 |
* @return the epocroot location
|
|
72 |
*/
|
|
73 |
public File getEpocroot() {
|
|
74 |
return epocroot;
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Get the iMaker version.
|
628
|
79 |
*
|
587
|
80 |
* @return the current iMaker version.
|
|
81 |
* @throws IMakerException is thrown in case of an iMaker execution error.
|
|
82 |
*/
|
|
83 |
public String getVersion() throws IMakerException {
|
|
84 |
log.debug("getVersion");
|
|
85 |
String[] args = new String[1];
|
|
86 |
args[0] = "version";
|
|
87 |
StreamRecorder rec = new StreamRecorder();
|
|
88 |
execute(args, rec);
|
|
89 |
return rec.getBuffer().toString().trim();
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Get the value of a particular variable from iMaker configuration.
|
628
|
94 |
*
|
587
|
95 |
* @param name the variable name
|
|
96 |
* @return the value or null if the variable does not exist.
|
|
97 |
* @throws IMakerException
|
|
98 |
*/
|
|
99 |
public String getVariable(String name) throws IMakerException {
|
|
100 |
log.debug("getVariable: " + name);
|
|
101 |
String[] args = new String[1];
|
|
102 |
args[0] = "print-" + name;
|
|
103 |
PrintVarSteamConsumer consumer = new PrintVarSteamConsumer(name);
|
|
104 |
execute(args, consumer);
|
|
105 |
return consumer.getValue();
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Get the value of a particular variable from iMaker configuration for a particular
|
|
110 |
* configuration.
|
628
|
111 |
*
|
587
|
112 |
* @param name the variable name
|
|
113 |
* @return the value or null if the variable does not exist.
|
|
114 |
* @throws IMakerException
|
|
115 |
*/
|
|
116 |
public String getVariable(String name, File configuration) throws IMakerException {
|
|
117 |
log.debug("getVariable: " + name + " - " + configuration);
|
|
118 |
String[] args = new String[3];
|
|
119 |
args[0] = "-f";
|
|
120 |
args[1] = configuration.getAbsolutePath();
|
|
121 |
args[2] = "print-" + name;
|
|
122 |
PrintVarSteamConsumer consumer = new PrintVarSteamConsumer(name);
|
|
123 |
execute(args, consumer);
|
|
124 |
return consumer.getValue();
|
|
125 |
}
|
|
126 |
|
|
127 |
/**
|
|
128 |
* Get the list of available iMaker configurations.
|
628
|
129 |
*
|
587
|
130 |
* @return a list of configurations
|
|
131 |
* @throws IMakerException
|
|
132 |
*/
|
|
133 |
public List<String> getConfigurations() throws IMakerException {
|
|
134 |
log.debug("getConfigurations");
|
|
135 |
String[] args = new String[1];
|
|
136 |
args[0] = "help-config";
|
|
137 |
HelpConfigStreamConsumer consumer = new HelpConfigStreamConsumer();
|
|
138 |
execute(args, consumer);
|
|
139 |
return consumer.getConfigurations();
|
|
140 |
}
|
628
|
141 |
|
587
|
142 |
/**
|
628
|
143 |
* Get the a list of target supported by a specific configuration.
|
|
144 |
*
|
587
|
145 |
* @param configuration the configuration to use
|
|
146 |
* @return the list of targets.
|
|
147 |
* @throws IMakerException
|
|
148 |
*/
|
|
149 |
public List<String> getTargets(String configuration) throws IMakerException {
|
|
150 |
log.debug("getConfigurations");
|
|
151 |
String[] args = new String[3];
|
|
152 |
args[0] = "-f";
|
|
153 |
args[1] = configuration;
|
|
154 |
args[2] = "help-target-*-list";
|
|
155 |
HelpTargetListStreamConsumer consumer = new HelpTargetListStreamConsumer();
|
|
156 |
execute(args, consumer);
|
|
157 |
return consumer.getTargets();
|
|
158 |
}
|
|
159 |
|
|
160 |
/**
|
|
161 |
* Get the target list for the configuration.
|
628
|
162 |
*
|
587
|
163 |
* @param configuration a File object representing the configuration location.
|
|
164 |
* @return a list of targets.
|
|
165 |
* @throws IMakerException
|
|
166 |
*/
|
|
167 |
public List<String> getTargets(File configuration) throws IMakerException {
|
|
168 |
return getTargets(configuration.getAbsolutePath());
|
|
169 |
}
|
628
|
170 |
|
587
|
171 |
/**
|
|
172 |
* {@inheritDoc}
|
|
173 |
*/
|
|
174 |
@Override
|
|
175 |
protected String getExecutable() {
|
|
176 |
return "imaker";
|
|
177 |
}
|
|
178 |
|
|
179 |
/**
|
|
180 |
* {@inheritDoc}
|
|
181 |
*/
|
|
182 |
@Override
|
|
183 |
public File getWorkingDir() {
|
|
184 |
return getEpocroot();
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* {@inheritDoc}
|
|
189 |
*/
|
|
190 |
@Override
|
628
|
191 |
protected void throwException(String message, Throwable t) throws IMakerException {
|
|
192 |
throw new IMakerException(message, t);
|
587
|
193 |
}
|
628
|
194 |
|
587
|
195 |
}
|