1 /* |
1 /* |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 package com.nokia.helium.imaker; |
17 package com.nokia.helium.imaker; |
18 |
18 |
19 import java.io.File; |
19 import java.io.File; |
20 import java.io.IOException; |
20 import java.io.IOException; |
21 import java.util.List; |
21 import java.util.List; |
22 |
22 |
|
23 import org.apache.log4j.Logger; |
23 |
24 |
24 import com.nokia.helium.core.plexus.CommandBase; |
25 import com.nokia.helium.core.plexus.CommandBase; |
25 import com.nokia.helium.core.plexus.StreamRecorder; |
26 import com.nokia.helium.core.plexus.StreamRecorder; |
26 |
27 |
27 import org.apache.log4j.Logger; |
|
28 |
|
29 /** |
28 /** |
30 * This class implements a wrapper around iMaker. |
29 * This class implements a wrapper around iMaker. It helps to introspect: <li>variables <li>targets |
31 * It helps to introspect: |
30 * <li>configurations |
32 * <li> variables |
31 * |
33 * <li> targets |
|
34 * <li> configurations |
|
35 * |
|
36 */ |
32 */ |
37 public class IMaker extends CommandBase<IMakerException> { |
33 public class IMaker extends CommandBase<IMakerException> { |
38 private static final String TEMP_ROMBUILD_DIR = "epoc32/rombuild/temp"; |
34 private static final String TEMP_ROMBUILD_DIR = "epoc32/rombuild/temp"; |
39 private final Logger log = Logger.getLogger(getClass()); |
35 private final Logger log = Logger.getLogger(getClass()); |
40 private File epocroot; |
36 private File epocroot; |
41 |
37 |
42 /** |
38 /** |
43 * Create an iMaker wrapper class with a specific epocroot. |
39 * Create an iMaker wrapper class with a specific epocroot. |
|
40 * |
44 * @param epocroot |
41 * @param epocroot |
45 */ |
42 */ |
46 public IMaker(File epocroot) { |
43 public IMaker(File epocroot) { |
47 this.epocroot = epocroot; |
44 this.epocroot = epocroot; |
48 |
45 |
49 } |
46 } |
50 |
47 |
51 /** |
48 /** |
52 * Creates a temp working dir for the rom image creation. |
49 * Creates a temp working dir for the rom image creation. |
|
50 * |
53 * @return |
51 * @return |
54 * @throws IOException |
52 * @throws IOException |
55 */ |
53 */ |
56 public File createWorkDir() throws IMakerException { |
54 public File createWorkDir() throws IMakerException { |
57 try { |
55 try { |
59 tempRootDir.mkdirs(); |
57 tempRootDir.mkdirs(); |
60 File tempDir = File.createTempFile("helium-imaker", "", tempRootDir); |
58 File tempDir = File.createTempFile("helium-imaker", "", tempRootDir); |
61 tempDir.delete(); |
59 tempDir.delete(); |
62 tempDir.mkdirs(); |
60 tempDir.mkdirs(); |
63 return tempDir; |
61 return tempDir; |
64 } catch (IOException e) { |
62 } |
|
63 catch (IOException e) { |
65 throw new IMakerException(e.getMessage(), e); |
64 throw new IMakerException(e.getMessage(), e); |
66 } |
65 } |
67 } |
66 } |
68 |
67 |
69 /** |
68 /** |
70 * Epocroot location. |
69 * Epocroot location. |
|
70 * |
71 * @return the epocroot location |
71 * @return the epocroot location |
72 */ |
72 */ |
73 public File getEpocroot() { |
73 public File getEpocroot() { |
74 return epocroot; |
74 return epocroot; |
75 } |
75 } |
76 |
76 |
77 /** |
77 /** |
78 * Get the iMaker version. |
78 * Get the iMaker version. |
|
79 * |
79 * @return the current iMaker version. |
80 * @return the current iMaker version. |
80 * @throws IMakerException is thrown in case of an iMaker execution error. |
81 * @throws IMakerException is thrown in case of an iMaker execution error. |
81 */ |
82 */ |
82 public String getVersion() throws IMakerException { |
83 public String getVersion() throws IMakerException { |
83 log.debug("getVersion"); |
84 log.debug("getVersion"); |
88 return rec.getBuffer().toString().trim(); |
89 return rec.getBuffer().toString().trim(); |
89 } |
90 } |
90 |
91 |
91 /** |
92 /** |
92 * Get the value of a particular variable from iMaker configuration. |
93 * Get the value of a particular variable from iMaker configuration. |
|
94 * |
93 * @param name the variable name |
95 * @param name the variable name |
94 * @return the value or null if the variable does not exist. |
96 * @return the value or null if the variable does not exist. |
95 * @throws IMakerException |
97 * @throws IMakerException |
96 */ |
98 */ |
97 public String getVariable(String name) throws IMakerException { |
99 public String getVariable(String name) throws IMakerException { |
104 } |
106 } |
105 |
107 |
106 /** |
108 /** |
107 * Get the value of a particular variable from iMaker configuration for a particular |
109 * Get the value of a particular variable from iMaker configuration for a particular |
108 * configuration. |
110 * configuration. |
|
111 * |
109 * @param name the variable name |
112 * @param name the variable name |
110 * @return the value or null if the variable does not exist. |
113 * @return the value or null if the variable does not exist. |
111 * @throws IMakerException |
114 * @throws IMakerException |
112 */ |
115 */ |
113 public String getVariable(String name, File configuration) throws IMakerException { |
116 public String getVariable(String name, File configuration) throws IMakerException { |
121 return consumer.getValue(); |
124 return consumer.getValue(); |
122 } |
125 } |
123 |
126 |
124 /** |
127 /** |
125 * Get the list of available iMaker configurations. |
128 * Get the list of available iMaker configurations. |
|
129 * |
126 * @return a list of configurations |
130 * @return a list of configurations |
127 * @throws IMakerException |
131 * @throws IMakerException |
128 */ |
132 */ |
129 public List<String> getConfigurations() throws IMakerException { |
133 public List<String> getConfigurations() throws IMakerException { |
130 log.debug("getConfigurations"); |
134 log.debug("getConfigurations"); |
132 args[0] = "help-config"; |
136 args[0] = "help-config"; |
133 HelpConfigStreamConsumer consumer = new HelpConfigStreamConsumer(); |
137 HelpConfigStreamConsumer consumer = new HelpConfigStreamConsumer(); |
134 execute(args, consumer); |
138 execute(args, consumer); |
135 return consumer.getConfigurations(); |
139 return consumer.getConfigurations(); |
136 } |
140 } |
137 |
141 |
138 /** |
142 /** |
139 * Get the a list of target supported by a specific configuration. |
143 * Get the a list of target supported by a specific configuration. |
|
144 * |
140 * @param configuration the configuration to use |
145 * @param configuration the configuration to use |
141 * @return the list of targets. |
146 * @return the list of targets. |
142 * @throws IMakerException |
147 * @throws IMakerException |
143 */ |
148 */ |
144 public List<String> getTargets(String configuration) throws IMakerException { |
149 public List<String> getTargets(String configuration) throws IMakerException { |
152 return consumer.getTargets(); |
157 return consumer.getTargets(); |
153 } |
158 } |
154 |
159 |
155 /** |
160 /** |
156 * Get the target list for the configuration. |
161 * Get the target list for the configuration. |
|
162 * |
157 * @param configuration a File object representing the configuration location. |
163 * @param configuration a File object representing the configuration location. |
158 * @return a list of targets. |
164 * @return a list of targets. |
159 * @throws IMakerException |
165 * @throws IMakerException |
160 */ |
166 */ |
161 public List<String> getTargets(File configuration) throws IMakerException { |
167 public List<String> getTargets(File configuration) throws IMakerException { |
162 return getTargets(configuration.getAbsolutePath()); |
168 return getTargets(configuration.getAbsolutePath()); |
163 } |
169 } |
164 |
170 |
165 /** |
171 /** |
166 * {@inheritDoc} |
172 * {@inheritDoc} |
167 */ |
173 */ |
168 @Override |
174 @Override |
169 protected String getExecutable() { |
175 protected String getExecutable() { |