75 import com.nokia.s60tools.analyzetool.engine.UseAtool; |
75 import com.nokia.s60tools.analyzetool.engine.UseAtool; |
76 import com.nokia.s60tools.analyzetool.global.Constants.COMMAND_LINE_ERROR_CODE; |
76 import com.nokia.s60tools.analyzetool.global.Constants.COMMAND_LINE_ERROR_CODE; |
77 |
77 |
78 /** |
78 /** |
79 * Provides commonly used functions. |
79 * Provides commonly used functions. |
80 * |
80 * |
81 * @author kihe |
81 * @author kihe |
82 * |
82 * |
83 */ |
83 */ |
84 public class Util { |
84 public final class Util { |
85 |
85 |
86 /** Contains user selection in the confirmation dialog. */ |
86 /** Contains user selection in the confirmation dialog. */ |
87 private static boolean ret; |
87 private static boolean ret; |
88 |
88 |
89 /** Contains user selection (integer) in the selection dialog. */ |
89 /** Contains user selection (integer) in the selection dialog. */ |
90 private static int retValue; |
90 private static int retValue; |
91 |
91 |
92 /** Contains user selection (String) in the selection dialog. */ |
92 /** Contains user selection (String) in the selection dialog. */ |
93 private static String userSelection = ""; |
93 private static String userSelection = ""; |
94 |
94 |
95 /** Contains StringBuffer size. */ |
95 /** Contains StringBuffer size. */ |
96 private static int bufferSize = 32; |
96 private static int bufferSize = 32; |
97 |
97 |
98 /** |
98 // make constructor private so class doesn't get instantiated |
99 * Checks is module built. |
99 private Util() { |
100 * |
100 // do nothing by design |
101 * @param modules |
101 } |
102 * Project modules |
102 |
103 * @param oneModuleName |
103 /** |
104 * Current module |
104 * Checks is module built. |
105 * @return True if module found and it is build |
105 * |
106 */ |
106 * @param modules |
107 public static boolean chechModuleBuildState( |
107 * Project modules |
108 final AbstractList<MMPInfo> modules, final String oneModuleName) { |
108 * @param oneModuleName |
109 Iterator<MMPInfo> iterModules = modules.iterator(); |
109 * Current module |
110 while (iterModules.hasNext()) { |
110 * @return True if module found and it is build |
111 MMPInfo oneMMPInfo = iterModules.next(); |
111 */ |
112 String target = oneMMPInfo.getTarget(); |
112 public static boolean checkModuleBuildState( |
113 if (target == null) { |
113 final AbstractList<MMPInfo> modules, final String oneModuleName) { |
114 continue; |
114 Iterator<MMPInfo> iterModules = modules.iterator(); |
115 } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) { |
115 while (iterModules.hasNext()) { |
116 return oneMMPInfo.isBuildSuccesfully(); |
116 MMPInfo oneMMPInfo = iterModules.next(); |
117 } |
117 String target = oneMMPInfo.getTarget(); |
118 |
118 if (target == null) { |
119 // target not found try remove {} |
119 continue; |
120 // for example process name is |
120 } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) { |
121 // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]" |
121 return oneMMPInfo.isBuildSuccesfully(); |
122 // but target name is AToolMemoryLeakerDll2.dll |
122 } |
123 CharSequence brace = "{"; |
123 |
124 if (oneModuleName.contains(brace)) { |
124 // target not found try remove {} |
125 // parse braces |
125 // for example process name is |
126 String tmpTargetName = oneModuleName.substring(0, oneModuleName |
126 // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]" |
127 .indexOf('{')); |
127 // but target name is AToolMemoryLeakerDll2.dll |
128 if (tmpTargetName != null |
128 CharSequence brace = "{"; |
129 && oneMMPInfo.getTarget().equalsIgnoreCase( |
129 if (oneModuleName.contains(brace)) { |
130 tmpTargetName)) { |
130 // parse braces |
131 return oneMMPInfo.isBuildSuccesfully(); |
131 String tmpTargetName = oneModuleName.substring(0, oneModuleName |
132 } |
132 .indexOf('{')); |
133 } |
133 if (tmpTargetName != null |
134 } |
134 && oneMMPInfo.getTarget().equalsIgnoreCase( |
135 return false; |
135 tmpTargetName)) { |
136 } |
136 return oneMMPInfo.isBuildSuccesfully(); |
137 |
137 } |
138 /** |
138 } |
139 * Checks is AnalyzeTool libraries installed from the current SDK. |
139 } |
140 * |
140 return false; |
141 * @param cpi |
141 } |
142 * {@link ICarbideProjectInfo} reference |
142 |
143 * @return True if libraries are installed otherwise false. |
143 /** |
144 */ |
144 * Checks is AnalyzeTool libraries installed from the current SDK. |
145 public static boolean checkAtoolLibs(final ICarbideProjectInfo cpi) { |
145 * |
146 // get active platform |
146 * @param cpi |
147 String platform = cpi.getDefaultConfiguration().getPlatformString(); |
147 * {@link ICarbideProjectInfo} reference |
148 |
148 * @return True if libraries are installed otherwise false. |
149 // get epoc root |
149 */ |
150 IPath epocRootPath = EpocEngineHelper.getEpocRootForProject(cpi.getProject()); |
150 public static boolean checkAtoolLibs(final ICarbideProjectInfo cpi) { |
151 |
151 // get active platform |
152 //check that epocroot path found |
152 String platform = cpi.getDefaultConfiguration().getPlatformString(); |
153 if( epocRootPath == null ) { |
153 |
154 return false; |
154 // get epoc root |
155 } |
155 IPath epocRootPath = EpocEngineHelper.getEpocRootForProject(cpi |
156 |
156 .getProject()); |
157 String epocroot = epocRootPath.toOSString(); |
157 |
158 boolean found = true; |
158 // check that epocroot path found |
159 StringBuffer fileBuffer = new StringBuffer(bufferSize); |
159 if (epocRootPath == null) { |
160 fileBuffer.append(Constants.CAN_NOT_FIND_LIBRARIES_MARKER); |
160 return false; |
161 fileBuffer.append(": "); |
161 } |
162 if ((Constants.BUILD_TARGET_WINSCW).equalsIgnoreCase(platform)) { |
162 |
163 for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) { |
163 String epocroot = epocRootPath.toOSString(); |
164 java.io.File file = new java.io.File(epocroot |
164 boolean found = true; |
165 + Constants.atoolLibsWinscw[i]); |
165 StringBuffer fileBuffer = new StringBuffer(bufferSize); |
166 if (!file.exists()) { |
166 fileBuffer.append(Constants.CAN_NOT_FIND_LIBRARIES_MARKER); |
167 found = false; |
167 fileBuffer.append(": "); |
168 fileBuffer.append(epocroot); |
168 if ((Constants.BUILD_TARGET_WINSCW).equalsIgnoreCase(platform)) { |
169 fileBuffer.append(Constants.atoolLibsWinscw[i]); |
169 for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) { |
170 fileBuffer.append(' '); |
170 java.io.File file = new java.io.File(epocroot |
171 } |
171 + Constants.atoolLibsWinscw[i]); |
172 } |
172 if (!file.exists()) { |
173 } else if ((Constants.BUILD_TARGET_ARMV5).equalsIgnoreCase(platform)) { |
173 found = false; |
174 if (AnalyzeToolBuilder.isSBSBuildActivated(cpi)) { |
174 fileBuffer.append(epocroot); |
175 for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) { |
175 fileBuffer.append(Constants.atoolLibsWinscw[i]); |
176 java.io.File file = new java.io.File(epocroot |
176 fileBuffer.append(' '); |
177 + Constants.atoolLibsSbs2[i]); |
177 } |
178 if (!file.exists()) { |
178 } |
179 found = false; |
179 } else if ((Constants.BUILD_TARGET_ARMV5).equalsIgnoreCase(platform)) { |
180 fileBuffer.append(epocroot); |
180 if (AnalyzeToolBuilder.isSBSBuildActivated(cpi)) { |
181 fileBuffer.append(Constants.atoolLibsSbs2[i]); |
181 for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) { |
182 fileBuffer.append(' '); |
182 java.io.File file = new java.io.File(epocroot |
183 } |
183 + Constants.atoolLibsSbs2[i]); |
184 } |
184 if (!file.exists()) { |
185 } else { |
185 found = false; |
186 for (int i = 0; i < Constants.atoolLibs.length; i++) { |
186 fileBuffer.append(epocroot); |
187 java.io.File file = new java.io.File(epocroot |
187 fileBuffer.append(Constants.atoolLibsSbs2[i]); |
188 + Constants.atoolLibs[i]); |
188 fileBuffer.append(' '); |
189 if (!file.exists()) { |
189 } |
190 found = false; |
190 } |
191 fileBuffer.append(epocroot); |
191 } else { |
192 fileBuffer.append(Constants.atoolLibs[i]); |
192 for (int i = 0; i < Constants.atoolLibs.length; i++) { |
193 fileBuffer.append(' '); |
193 java.io.File file = new java.io.File(epocroot |
194 } |
194 + Constants.atoolLibs[i]); |
195 } |
195 if (!file.exists()) { |
196 } |
196 found = false; |
197 } |
197 fileBuffer.append(epocroot); |
198 if (!found) { |
198 fileBuffer.append(Constants.atoolLibs[i]); |
199 createErrorMarker(cpi.getProject(), fileBuffer.toString()); |
199 fileBuffer.append(' '); |
200 } |
200 } |
201 |
201 } |
202 return found; |
202 } |
203 } |
203 } |
204 |
204 if (!found) { |
205 /** |
205 createErrorMarker(cpi.getProject(), fileBuffer.toString()); |
206 * Copies stored memory leak analysis file to given folder. |
206 } |
207 * |
207 |
208 * @param resultFile |
208 return found; |
209 * Existing results file |
209 } |
210 * @param targetPath |
210 |
211 * Where to save xml file |
211 /** |
212 * @return True if copy success otherwise False |
212 * Copies stored memory leak analysis file to given folder. |
213 */ |
213 * |
214 public static boolean copyFileToFolder(final String resultFile, |
214 * @param resultFile |
215 final String targetPath) { |
215 * Existing results file |
216 FileChannel inputChannel = null; |
216 * @param targetPath |
217 FileChannel ouputChannel = null; |
217 * Where to save xml file |
218 FileInputStream inStream = null; |
218 * @return True if copy success otherwise False |
219 FileOutputStream outStream = null; |
219 */ |
220 boolean returnValue = true; |
220 public static boolean copyFileToFolder(final String resultFile, |
221 try { |
221 final String targetPath) { |
222 |
222 FileChannel inputChannel = null; |
223 // get channel to existing file |
223 FileChannel ouputChannel = null; |
224 inStream = new FileInputStream(resultFile); |
224 FileInputStream inStream = null; |
225 inputChannel = inStream.getChannel(); |
225 FileOutputStream outStream = null; |
226 |
226 boolean returnValue = true; |
227 // get channel to new file |
227 try { |
228 outStream = new FileOutputStream(targetPath, false); |
228 |
229 ouputChannel = outStream.getChannel(); |
229 // get channel to existing file |
230 |
230 inStream = new FileInputStream(resultFile); |
231 // get existing file size |
231 inputChannel = inStream.getChannel(); |
232 final long size = inputChannel.size(); |
232 |
233 |
233 // get channel to new file |
234 // position inside the file |
234 outStream = new FileOutputStream(targetPath, false); |
235 long position = 0; |
235 ouputChannel = outStream.getChannel(); |
236 |
236 |
237 // copy file contents if there are data to copy |
237 // get existing file size |
238 while (position < size) { |
238 final long size = inputChannel.size(); |
239 position += ouputChannel.transferFrom(inputChannel, position, |
239 |
240 size - position); |
240 // position inside the file |
241 } |
241 long position = 0; |
242 |
242 |
243 // close opened channels |
243 // copy file contents if there are data to copy |
244 inputChannel.close(); |
244 while (position < size) { |
245 inStream.close(); |
245 position += ouputChannel.transferFrom(inputChannel, position, |
246 ouputChannel.close(); |
246 size - position); |
247 outStream.close(); |
247 } |
248 } catch (FileNotFoundException fnfe) { |
248 |
249 returnValue = false; |
249 // close opened channels |
250 } catch (IOException ioe) { |
250 inputChannel.close(); |
251 returnValue = false; |
251 inStream.close(); |
252 } finally { |
252 ouputChannel.close(); |
253 try { |
253 outStream.close(); |
254 if (inputChannel != null) { |
254 } catch (FileNotFoundException fnfe) { |
255 inputChannel.close(); |
255 returnValue = false; |
256 inputChannel = null; |
256 } catch (IOException ioe) { |
257 } |
257 returnValue = false; |
258 } catch (IOException ioe) { |
258 } finally { |
259 returnValue = false; |
259 try { |
260 } |
260 if (inputChannel != null) { |
261 |
261 inputChannel.close(); |
262 try { |
262 inputChannel = null; |
263 if (inStream != null) { |
263 } |
264 inStream.close(); |
264 } catch (IOException ioe) { |
265 inStream = null; |
265 returnValue = false; |
266 } |
266 } |
267 } catch (IOException ioe) { |
267 |
268 returnValue = false; |
268 try { |
269 } |
269 if (inStream != null) { |
270 |
270 inStream.close(); |
271 try { |
271 inStream = null; |
272 if (ouputChannel != null) { |
272 } |
273 ouputChannel.close(); |
273 } catch (IOException ioe) { |
274 ouputChannel = null; |
274 returnValue = false; |
275 } |
275 } |
276 } catch (IOException ioe) { |
276 |
277 returnValue = false; |
277 try { |
278 } |
278 if (ouputChannel != null) { |
279 |
279 ouputChannel.close(); |
280 try { |
280 ouputChannel = null; |
281 if (outStream != null) { |
281 } |
282 outStream.close(); |
282 } catch (IOException ioe) { |
283 outStream = null; |
283 returnValue = false; |
284 } |
284 } |
285 } catch (IOException ioe) { |
285 |
286 returnValue = false; |
286 try { |
287 } |
287 if (outStream != null) { |
288 |
288 outStream.close(); |
289 } |
289 outStream = null; |
290 |
290 } |
291 return returnValue; |
291 } catch (IOException ioe) { |
292 } |
292 returnValue = false; |
293 |
293 } |
294 /** |
294 |
295 * Creates AnalyzeTool related error marker for the selected project. |
295 } |
296 * |
296 |
297 * @param project |
297 return returnValue; |
298 * Project reference |
298 } |
299 * @param errorText |
299 |
300 * Error information |
300 /** |
301 */ |
301 * Creates AnalyzeTool related error marker for the selected project. |
302 public static void createErrorMarker(final IProject project, |
302 * |
303 final String errorText) { |
303 * @param project |
304 try { |
304 * Project reference |
305 // check project validity |
305 * @param errorText |
306 if (project == null || !project.isOpen()) { |
306 * Error information |
307 return; |
307 */ |
308 } |
308 public static void createErrorMarker(final IProject project, |
309 |
309 final String errorText) { |
310 // create marker for the project |
310 try { |
311 IMarker marker = project |
311 // check project validity |
312 .createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER); |
312 if (project == null || !project.isOpen()) { |
313 if (marker.exists()) { |
313 return; |
314 // set marker attributes |
314 } |
315 marker.setAttribute(IMarker.SEVERITY, IMarker.PRIORITY_HIGH); |
315 |
316 marker.setAttribute(IMarker.TEXT, errorText); |
316 // create marker for the project |
317 marker.setAttribute(IMarker.MESSAGE, errorText); |
317 IMarker marker = project |
318 } |
318 .createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER); |
319 } catch (CoreException ce) { |
319 if (marker.exists()) { |
320 // #ifdef DEBUG |
320 // set marker attributes |
321 ce.printStackTrace(); |
321 marker.setAttribute(IMarker.SEVERITY, IMarker.PRIORITY_HIGH); |
322 // #endif |
322 marker.setAttribute(IMarker.TEXT, errorText); |
323 } |
323 marker.setAttribute(IMarker.MESSAGE, errorText); |
324 } |
324 } |
325 |
325 } catch (CoreException ce) { |
326 /** |
326 // #ifdef DEBUG |
327 * Deletes existing data file. |
327 ce.printStackTrace(); |
328 * |
328 // #endif |
329 * @param project |
329 } |
330 * Project reference |
330 } |
331 */ |
331 |
332 public static void deleteDataFile(final IProject project) { |
332 /** |
333 String bldInfFolder = getBldInfFolder(project, false); |
333 * Deletes existing data file. |
334 String dataFileLocation = bldInfFolder + Constants.FILENAME; |
334 * |
335 java.io.File tmpFile = new java.io.File(dataFileLocation); |
335 * @param project |
336 if (tmpFile.exists()) { |
336 * Project reference |
337 tmpFile.delete(); |
337 */ |
338 } |
338 public static void deleteDataFile(final IProject project) { |
339 |
339 String bldInfFolder = getBldInfFolder(project, false); |
340 String xmlFileLocation = bldInfFolder + Constants.FILENAME_CARBIDE; |
340 String dataFileLocation = bldInfFolder + Constants.FILENAME; |
341 java.io.File tmpXMLFile = new java.io.File(xmlFileLocation); |
341 java.io.File tmpFile = new java.io.File(dataFileLocation); |
342 if (tmpXMLFile.exists()) { |
342 if (tmpFile.exists()) { |
343 tmpXMLFile.delete(); |
343 tmpFile.delete(); |
344 } |
344 } |
345 |
345 |
346 tmpFile = null; |
346 String xmlFileLocation = bldInfFolder + Constants.FILENAME_CARBIDE; |
347 tmpXMLFile = null; |
347 java.io.File tmpXMLFile = new java.io.File(xmlFileLocation); |
348 } |
348 if (tmpXMLFile.exists()) { |
349 |
349 tmpXMLFile.delete(); |
350 |
350 } |
351 /** |
351 |
352 * Open file save dialog. |
352 tmpFile = null; |
353 * |
353 tmpXMLFile = null; |
354 * @param title |
354 } |
355 * Save dialog title |
355 |
356 * @param ext |
356 /** |
357 * Used extension filters |
357 * Open file save dialog. |
358 * |
358 * |
359 * @param shell |
359 * @param title |
360 * Used Shell reference |
360 * Save dialog title |
361 * |
361 * @param ext |
362 * @return User selected path |
362 * Used extension filters |
363 */ |
363 * |
364 public static String fileSaveDialog(final String title, final String[] ext, |
364 * @param shell |
365 final Shell shell) { |
365 * Used Shell reference |
366 FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); |
366 * |
367 fileDialog.setText(title); |
367 * @return User selected path |
368 fileDialog.setFilterExtensions(ext); |
368 */ |
369 return fileDialog.open(); |
369 public static String fileSaveDialog(final String title, final String[] ext, |
370 |
370 final Shell shell) { |
371 } |
371 FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); |
372 |
372 fileDialog.setText(title); |
373 /** |
373 fileDialog.setFilterExtensions(ext); |
374 * Gets atool.exe installation folder which is specified on preferences |
374 return fileDialog.open(); |
375 * page. |
375 |
376 * |
376 } |
377 * @return Atool.exe installation folder |
377 |
378 */ |
378 /** |
379 public static String getAtoolInstallFolder() { |
379 * Gets atool.exe installation folder which is specified on preferences |
380 // get preference store |
380 * page. |
381 IPreferenceStore store = Activator.getPreferences(); |
381 * |
382 |
382 * @return Atool.exe installation folder |
383 // create new string buffer |
383 */ |
384 StringBuffer atoolInstallFolder = new StringBuffer(); |
384 public static String getAtoolInstallFolder() { |
385 |
385 // get preference store |
386 boolean useInternal = store.getBoolean(Constants.USE_INTERNAL); |
386 IPreferenceStore store = Activator.getPreferences(); |
387 |
387 |
388 // append atool.exe installation folder |
388 // create new string buffer |
389 String folder = store.getString(Constants.ATOOL_FOLDER); |
389 StringBuffer atoolInstallFolder = new StringBuffer(); |
390 if (useInternal) { |
390 |
391 atoolInstallFolder.append(getDefaultAtoolLocation()); |
391 boolean useInternal = store.getBoolean(Constants.USE_INTERNAL); |
392 } else if (("").equals(folder)) { |
392 |
393 store.setValue(Constants.USE_INTERNAL, true); |
393 // append atool.exe installation folder |
394 atoolInstallFolder.append(getDefaultAtoolLocation()); |
394 String folder = store.getString(Constants.ATOOL_FOLDER); |
395 } else if (folder.equals(Constants.DEFAULT_ATOOL_FOLDER)) { |
395 if (useInternal) { |
396 java.io.File file = new java.io.File(Constants.DEFAULT_ATOOL_FOLDER); |
396 atoolInstallFolder.append(getDefaultAtoolLocation()); |
397 if (file.exists()) { |
397 } else if (("").equals(folder)) { |
398 atoolInstallFolder.append(Constants.DEFAULT_ATOOL_FOLDER); |
398 store.setValue(Constants.USE_INTERNAL, true); |
399 } else { |
399 atoolInstallFolder.append(getDefaultAtoolLocation()); |
400 store.setValue(Constants.USE_INTERNAL, true); |
400 } else if (folder.equals(Constants.DEFAULT_ATOOL_FOLDER)) { |
401 atoolInstallFolder.append(getDefaultAtoolLocation()); |
401 java.io.File file = new java.io.File(Constants.DEFAULT_ATOOL_FOLDER); |
402 } |
402 if (file.exists()) { |
403 } else { |
403 atoolInstallFolder.append(Constants.DEFAULT_ATOOL_FOLDER); |
404 atoolInstallFolder.append(folder); |
404 } else { |
405 } |
405 store.setValue(Constants.USE_INTERNAL, true); |
406 // append atool.exe to installation path |
406 atoolInstallFolder.append(getDefaultAtoolLocation()); |
407 atoolInstallFolder.append("\\atool.exe"); |
407 } |
408 return atoolInstallFolder.toString(); |
408 } else { |
409 } |
409 atoolInstallFolder.append(folder); |
410 |
410 } |
411 /** |
411 // append atool.exe to installation path |
412 * Returns atool.exe version number Executes atool.exe via Process class and |
412 atoolInstallFolder.append("\\atool.exe"); |
413 * parses atool.exe output to get version number. |
413 return atoolInstallFolder.toString(); |
414 * |
414 } |
415 * @param path |
415 |
416 * Atool.exe path |
416 /** |
417 * @return Atool.exe version number if found otherwise "Not available" |
417 * Returns atool.exe version number Executes atool.exe via Process class and |
418 */ |
418 * parses atool.exe output to get version number. |
419 public static String getAtoolVersionNumber(final String path) { |
419 * |
420 |
420 * @param path |
421 BufferedInputStream br = null; |
421 * Atool.exe path |
422 |
422 * @return Atool.exe version number if found otherwise "Not available" |
423 try { |
423 */ |
424 // used atool.exe location |
424 public static String getAtoolVersionNumber(final String path) { |
425 String usedPath = null; |
425 |
426 |
426 BufferedInputStream br = null; |
427 // if path not given => use default location |
427 |
428 if (path == null) { |
428 try { |
429 usedPath = getDefaultAtoolLocation() + "\\atool.exe"; |
429 // used atool.exe location |
430 } |
430 String usedPath = null; |
431 else if( path.contains("atool.exe") ){ |
431 |
432 usedPath = path; |
432 // if path not given => use default location |
433 } |
433 if (path == null) { |
434 // else use given location |
434 usedPath = getDefaultAtoolLocation() + "\\atool.exe"; |
435 else { |
435 } else if (path.contains("atool.exe")) { |
436 usedPath = path + "\\atool.exe"; |
436 usedPath = path; |
437 } |
437 } |
438 |
438 // else use given location |
439 // command |
439 else { |
440 String[] args = { "cmd", "/c", usedPath, "-v" }; |
440 usedPath = path + "\\atool.exe"; |
441 |
441 } |
442 // execute command |
442 |
443 Process pr = Runtime.getRuntime().exec(args); |
443 // command |
444 |
444 String[] args = { "cmd", "/c", usedPath, "-v" }; |
445 // get atool.exe response to buffer |
445 |
446 br = new BufferedInputStream(pr |
446 // execute command |
447 .getInputStream()); |
447 Process pr = Runtime.getRuntime().exec(args); |
448 |
448 |
449 // wait that all the input is captured |
449 // get atool.exe response to buffer |
450 pr.waitFor(); |
450 br = new BufferedInputStream(pr.getInputStream()); |
451 |
451 |
452 // create new stringbuffer for the input |
452 // wait that all the input is captured |
453 StringBuffer bf = new StringBuffer(""); |
453 pr.waitFor(); |
454 int r = -1; |
454 |
455 |
455 // create new stringbuffer for the input |
456 // read atool.exe response to stringbufffer |
456 StringBuffer bf = new StringBuffer(""); |
457 while ((r = br.read()) != -1) { |
457 int r = -1; |
458 bf.append((char) r); |
458 |
459 } |
459 // read atool.exe response to stringbufffer |
460 |
460 while ((r = br.read()) != -1) { |
461 // because atool.exe response is following format |
461 bf.append((char) r); |
462 // Version: [version number] |
462 } |
463 // Path: [location] |
463 |
464 // Modified: [date and time] |
464 // because atool.exe response is following format |
465 // we only need to get first row of response |
465 // Version: [version number] |
466 String[] array = bf.toString().split("\r\n"); |
466 // Path: [location] |
467 |
467 // Modified: [date and time] |
468 // check array |
468 // we only need to get first row of response |
469 if (array != null && array.length > 0) { |
469 String[] array = bf.toString().split("\r\n"); |
470 |
470 |
471 String version = "Version:"; |
471 // check array |
472 |
472 if (array != null && array.length > 0) { |
473 // get first array |
473 |
474 String versionStr = array[0]; |
474 String version = "Version:"; |
475 |
475 |
476 // if first row contains "version:" |
476 // get first array |
477 if (versionStr.contains(version)) { |
477 String versionStr = array[0]; |
478 |
478 |
479 // get atool.exe version number |
479 // if first row contains "version:" |
480 String atoolVersionNbr = versionStr.substring(version |
480 if (versionStr.contains(version)) { |
481 .length() + 1, versionStr.length()); |
481 |
482 |
482 // get atool.exe version number |
483 if( atoolVersionNbr == null || ("").equals(atoolVersionNbr ) ) { |
483 String atoolVersionNbr = versionStr.substring(version |
484 return Constants.PREFS_ATOOL_VER_NOT_FOUND; |
484 .length() + 1, versionStr.length()); |
485 } |
485 |
486 |
486 if (atoolVersionNbr == null || ("").equals(atoolVersionNbr)) { |
487 return atoolVersionNbr; |
487 return Constants.PREFS_ATOOL_VER_NOT_FOUND; |
488 } |
488 } |
489 } |
489 |
490 br.close(); |
490 return atoolVersionNbr; |
491 } catch (Exception e) { |
491 } |
492 e.printStackTrace(); |
492 } |
493 } finally { |
493 br.close(); |
494 try { |
494 } catch (Exception e) { |
495 if( br != null ) { |
495 e.printStackTrace(); |
496 br.close(); |
496 } finally { |
497 br = null; |
497 try { |
498 } |
498 if (br != null) { |
499 }catch( IOException ioe ) { |
499 br.close(); |
500 ioe.printStackTrace(); |
500 br = null; |
501 } |
501 } |
502 |
502 } catch (IOException ioe) { |
503 } |
503 ioe.printStackTrace(); |
504 return Constants.PREFS_ATOOL_VER_NOT_FOUND; |
504 } |
505 } |
505 |
506 |
506 } |
507 /** |
507 return Constants.PREFS_ATOOL_VER_NOT_FOUND; |
508 * Returns the version number of the AnalyzeTool host-side feature, or "Unknown" if it cannot be determined |
508 } |
509 * @return feature version string |
509 |
510 */ |
510 /** |
511 public static String getAToolFeatureVersionNumber(){ |
511 * Returns dbghelp.dll version information |
512 String version = Constants.UNKNOWN; |
512 * |
513 IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); |
513 * @param path |
|
514 * atool.exe path |
|
515 * @return dbghelp.dll version information |
|
516 */ |
|
517 public static String getDbghelpDllVersionInfo(final String path) { |
|
518 |
|
519 String dbghelpDllVersionInfo = Constants.DBGHELPDLL_IS_UP_TO_DATE; |
|
520 BufferedInputStream bis = null; |
|
521 |
|
522 try { |
|
523 String usedPath = null; |
|
524 |
|
525 if (path == null) { |
|
526 usedPath = getDefaultAtoolLocation() + "\\atool.exe"; |
|
527 } else if (path.contains("atool.exe")) { |
|
528 usedPath = path; |
|
529 } else { |
|
530 usedPath = path + "\\atool.exe"; |
|
531 } |
|
532 |
|
533 String[] args = { "cmd", "/c", usedPath, "-vdbghelp" }; |
|
534 |
|
535 Process pr = Runtime.getRuntime().exec(args); |
|
536 |
|
537 bis = new BufferedInputStream(pr.getInputStream()); |
|
538 |
|
539 pr.waitFor(); |
|
540 |
|
541 StringBuffer sb = new StringBuffer(""); |
|
542 int r = -1; |
|
543 |
|
544 while ((r = bis.read()) != -1) { |
|
545 sb.append((char) r); |
|
546 } |
|
547 |
|
548 if (pr.exitValue() == 1) |
|
549 dbghelpDllVersionInfo = sb.toString(); |
|
550 |
|
551 bis.close(); |
|
552 } catch (Exception e) { |
|
553 e.printStackTrace(); |
|
554 } finally { |
|
555 try { |
|
556 if (bis != null) { |
|
557 bis.close(); |
|
558 bis = null; |
|
559 } |
|
560 } catch (IOException ioe) { |
|
561 ioe.printStackTrace(); |
|
562 } |
|
563 } |
|
564 return dbghelpDllVersionInfo; |
|
565 } |
|
566 |
|
567 /** |
|
568 * Returns the version number of the AnalyzeTool host-side feature, or |
|
569 * "Unknown" if it cannot be determined |
|
570 * |
|
571 * @return feature version string |
|
572 */ |
|
573 public static String getAToolFeatureVersionNumber() { |
|
574 String version = Constants.UNKNOWN; |
|
575 IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); |
514 if (providers != null) { |
576 if (providers != null) { |
515 for (IBundleGroupProvider bundleGroupProvider : providers) { |
577 for (IBundleGroupProvider bundleGroupProvider : providers) { |
516 for (IBundleGroup feature : bundleGroupProvider.getBundleGroups()) { |
578 for (IBundleGroup feature : bundleGroupProvider |
517 if (feature.getIdentifier().equals("com.nokia.carbide.extensions.analyzetool")){ |
579 .getBundleGroups()) { |
|
580 if (feature.getIdentifier().equals( |
|
581 "com.nokia.carbide.extensions.analyzetool")) { |
518 version = feature.getVersion(); |
582 version = feature.getVersion(); |
519 break; |
583 break; |
520 } |
584 } |
521 } |
585 } |
522 } |
586 } |
523 } |
587 } |
524 return version; |
588 return version; |
525 } |
589 } |
526 |
590 |
527 /** |
591 /** |
528 * Gets project bld.inf folder path. |
592 * |
529 * |
593 * Below is code a sample which are related to the AT-682, but it is decided |
530 * @param project |
594 * to let out from current release. |
531 * Project reference |
595 * |
532 * @param createTempFolder |
596 * /** Finds and returns AnalyzeTool core version number. Version number is |
533 * Flag to create atool_temp folder |
597 * read from the analyzetool header file and it can be located under the |
534 * @return Project bld.inf folder path |
598 * epoc32 folder. |
535 */ |
599 * |
536 public static String getBldInfFolder(final IProject project, |
600 * @param project |
537 final boolean createTempFolder) { |
601 * Project reference |
538 // get bld.inf directory |
602 * @return Found version number, otherwise null. |
539 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager() |
603 * |
540 .getProjectInfo(project); |
604 * public static String getAtoolCoreVersion(IProject project) { if( |
541 if (cpi == null) { |
605 * project != null && project.isOpen() ) { |
542 return ""; |
606 * |
543 } |
607 * //get Carbide project info IPath epocRootPath = |
544 |
608 * EpocEngineHelper.getEpocRootForProject(project); if( epocRootPath |
545 String infDir = cpi.getINFWorkingDirectory().toOSString(); |
609 * == null ) { return null; } |
546 |
610 * |
547 // create atool_temp folder if it does not exists |
611 * File file = null; //thru all the possible locations for( int i=0; |
548 if (createTempFolder) { |
612 * i< Constants.AT_CORE_INCLUDE_FILE_WITH_VERSION_NUMBER.length; |
549 UseAtool.createAToolFolderIfNeeded(infDir); |
613 * i++) { //get file path StringBuffer location = new |
550 } |
614 * StringBuffer(); location.append(epocRootPath.toOSString()); |
551 |
615 * location |
552 return infDir + "\\atool_temp\\"; |
616 * .append(Constants.AT_CORE_INCLUDE_FILE_WITH_VERSION_NUMBER[i]); |
553 } |
617 * |
554 |
618 * //check that file exists file = new File(location.toString()); |
555 /** |
619 * if( file.exists() ) { break; } } |
556 * Gets cpp file name and path. |
620 * |
557 * |
621 * //read file content FileInputStream fis = null; BufferedReader |
558 * @param resource |
622 * input = null; try{ // get input fis = new FileInputStream(file); |
559 * One resource file |
623 * input = new BufferedReader(new InputStreamReader(fis,"UTF-8")); |
560 * @return MMP file name and path if resource is mmp file, otherwise null |
624 * |
561 */ |
625 * // get first line of data file String line = null; String version |
562 public static String getCPPFileNameAndPath(final IResource resource) { |
626 * = null; // go thru file while ((line = input.readLine()) != null) |
563 // get file extension |
627 * { if( line.contains(Constants.AT_CORE_VERSION_NUMBER_TAG) ) { |
564 String fileExt = resource.getFileExtension(); |
628 * String[] text = line.split(" "); version = text[1]; } } |
565 String cppFileAndPath = null; |
629 * fis.close(); input.close(); return version; } catch(Exception e) |
566 |
630 * { e.printStackTrace(); } } return null; } |
567 // if file contains extension and it equals to mmp |
631 */ |
568 if (fileExt != null && fileExt.compareTo("cpp") == 0) { |
632 |
569 // get resource location/path |
633 /** |
570 String resourcePath = resource.getLocation().toString(); |
634 * Gets project bld.inf folder path. |
571 |
635 * |
572 // if resource path does not contain atool_temp folder |
636 * @param project |
573 // save resource location |
637 * Project reference |
574 if (resourcePath.indexOf(Constants.ATOOL_TEMP) == -1) { |
638 * @param createTempFolder |
575 cppFileAndPath = resource.getProjectRelativePath().toString(); |
639 * Flag to create atool_temp folder |
576 } |
640 * @return Project bld.inf folder path |
577 |
641 */ |
578 } |
642 public static String getBldInfFolder(final IProject project, |
579 |
643 final boolean createTempFolder) { |
580 // return cpp file name and path |
644 // get bld.inf directory |
581 return cppFileAndPath; |
645 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager() |
582 } |
646 .getProjectInfo(project); |
583 |
647 if (cpi == null) { |
584 /** |
648 return ""; |
585 * Returns atool.exe location inside the plugin. |
649 } |
586 * |
650 |
587 * @return Atool.exe location folder could be found otherwise "" |
651 String infDir = cpi.getINFWorkingDirectory().toOSString(); |
588 */ |
652 |
589 public static String getDefaultAtoolLocation() { |
653 // create atool_temp folder if it does not exists |
590 try { |
654 if (createTempFolder) { |
591 // AnalyzeTool bundle |
655 UseAtool.createAToolFolderIfNeeded(infDir); |
592 Bundle bunble = Platform |
656 } |
593 .getBundle("com.nokia.s60tools.analyzetool.corecomponents"); //$NON-NLS-1$ |
657 |
594 |
658 return infDir + "\\atool_temp\\"; |
595 // if bundle not found return empty path |
659 } |
596 if( bunble == null ) { |
660 |
597 return ""; |
661 /** |
598 } |
662 * Gets cpp file name and path. |
599 // get bundle URL |
663 * |
600 URL bundleURL = bunble.getEntry("/"); |
664 * @param resource |
601 |
665 * One resource file |
602 // get file URL |
666 * @return MMP file name and path if resource is mmp file, otherwise null |
603 URL fileURL = FileLocator.toFileURL(bundleURL); |
667 */ |
604 |
668 public static String getCPPFileNameAndPath(final IResource resource) { |
605 // create new file |
669 // get file extension |
606 File file = new File(fileURL.getPath()); |
670 String fileExt = resource.getFileExtension(); |
607 |
671 String cppFileAndPath = null; |
608 // if file exists return file path + atool.exe folder name |
672 |
609 if (file.exists()) { |
673 // if file contains extension and it equals to mmp |
610 return file.getAbsolutePath(); |
674 if (fileExt != null && fileExt.compareTo("cpp") == 0) { |
611 } |
675 // get resource location/path |
612 return ""; |
676 String resourcePath = resource.getLocation().toString(); |
613 |
677 |
614 } catch (Exception e) { |
678 // if resource path does not contain atool_temp folder |
615 e.printStackTrace(); |
679 // save resource location |
616 return ""; |
680 if (resourcePath.indexOf(Constants.ATOOL_TEMP) == -1) { |
617 } |
681 cppFileAndPath = resource.getProjectRelativePath().toString(); |
618 } |
682 } |
619 |
683 |
620 /** |
684 } |
621 * Gets last slash index for current string. |
685 |
622 * |
686 // return cpp file name and path |
623 * @param line |
687 return cppFileAndPath; |
624 * Line where to find slash index |
688 } |
625 * @return Integer value of slash index |
689 |
626 */ |
690 /** |
627 public static int getLastSlashIndex(final String line) { |
691 * Returns atool.exe location inside the plugin. |
628 // get last slash index |
692 * |
629 char slash = '/'; |
693 * @return Atool.exe location folder could be found otherwise "" |
630 int slashIndex = line.lastIndexOf(slash); |
694 */ |
631 if (slashIndex == -1) { |
695 public static String getDefaultAtoolLocation() { |
632 char backSlash = '\\'; |
696 try { |
633 slashIndex = line.lastIndexOf(backSlash); |
697 // AnalyzeTool bundle |
634 } |
698 Bundle bunble = Platform |
635 |
699 .getBundle("com.nokia.s60tools.analyzetool.corecomponents"); //$NON-NLS-1$ |
636 return slashIndex; |
700 |
637 } |
701 // if bundle not found return empty path |
638 |
702 if (bunble == null) { |
639 /** |
703 return ""; |
640 * Check is atool.exe available. |
704 } |
641 * |
705 // get bundle URL |
642 * @return True if atool.exe found otherwise False |
706 URL bundleURL = bunble.getEntry("/"); |
643 */ |
707 |
644 public static boolean isAtoolAvailable() { |
708 // get file URL |
645 IPreferenceStore store = Activator.getPreferences(); |
709 URL fileURL = FileLocator.toFileURL(bundleURL); |
646 String folderLocation = store.getString(Constants.ATOOL_FOLDER); |
710 |
647 |
711 // create new file |
648 if (folderLocation.length() > 0) { |
712 File file = new File(fileURL.getPath()); |
649 if (!folderLocation.endsWith("\\")) { |
713 |
650 folderLocation += "\\"; |
714 // if file exists return file path + atool.exe folder name |
651 } |
715 if (file.exists()) { |
652 |
716 return file.getAbsolutePath(); |
653 IPath atoolPath = new Path(folderLocation + "atool.exe"); |
717 } |
654 |
718 return ""; |
655 // if folder does not exists |
719 |
656 if (atoolPath.toFile().exists()) { |
720 } catch (Exception e) { |
657 return true; |
721 e.printStackTrace(); |
658 } |
722 return ""; |
659 } |
723 } |
660 |
724 } |
661 return false; |
725 |
662 } |
726 /** |
663 |
727 * Gets last slash index for current string. |
664 /** |
728 * |
665 * Checks is data file available. |
729 * @param line |
666 * |
730 * Line where to find slash index |
667 * @param project |
731 * @return Integer value of slash index |
668 * Project reference |
732 */ |
669 * @return Data file path if it's available otherwise null |
733 public static int getLastSlashIndex(final String line) { |
670 */ |
734 // get last slash index |
671 public static String isDataFileAvailable(final IProject project) { |
735 char slash = '/'; |
672 String bldInfFolder = getBldInfFolder(project, false); |
736 int slashIndex = line.lastIndexOf(slash); |
673 String dataFileLocation = bldInfFolder + Constants.FILENAME; |
737 if (slashIndex == -1) { |
674 java.io.File dataFile = new java.io.File(dataFileLocation); |
738 char backSlash = '\\'; |
675 if (dataFile.exists() && dataFile.length() > 0 ) { |
739 slashIndex = line.lastIndexOf(backSlash); |
676 return dataFileLocation; |
740 } |
677 } |
741 |
678 return null; |
742 return slashIndex; |
679 } |
743 } |
680 |
744 |
681 /** |
745 /** |
682 * Checks is file extension .xml. |
746 * Check is atool.exe available. |
683 * |
747 * |
684 * @param filePath |
748 * @return True if atool.exe found otherwise False |
685 * File location |
749 */ |
686 * @return True if file contains xml extension otherwise false |
750 public static boolean isAtoolAvailable() { |
687 */ |
751 IPreferenceStore store = Activator.getPreferences(); |
688 public static boolean isFileXML(final String filePath) { |
752 String folderLocation = store.getString(Constants.ATOOL_FOLDER); |
689 String fileNameAndExt = null; |
753 |
690 // get index of last backslash |
754 if (folderLocation.length() > 0) { |
691 int index = Util.getLastSlashIndex(filePath); |
755 if (!folderLocation.endsWith("\\")) { |
692 |
756 folderLocation += "\\"; |
693 // if backslash found |
757 } |
694 if (index != -1) { |
758 |
695 |
759 IPath atoolPath = new Path(folderLocation + "atool.exe"); |
696 // get file name |
760 |
697 fileNameAndExt = filePath.substring(index + 1, filePath.length()); |
761 // if folder does not exists |
698 |
762 if (atoolPath.toFile().exists()) { |
699 // if file name contains xml extension |
763 return true; |
700 if (fileNameAndExt.contains(".xml")) { |
764 } |
701 return true; |
765 } |
702 } |
766 |
703 } |
767 return false; |
704 return false; |
768 } |
705 |
769 |
706 } |
770 /** |
707 |
771 * Checks is data file available. |
708 /** |
772 * |
709 * Check if current module is build. |
773 * @param project |
710 * |
774 * Project reference |
711 * @param mmpFile |
775 * @return Data file path if it's available otherwise null |
712 * MMP file name and path |
776 */ |
713 * @return True if module is build otherwise False |
777 public static String isDataFileAvailable(final IProject project) { |
714 */ |
778 String bldInfFolder = getBldInfFolder(project, false); |
715 public static boolean isModuleBuild(final String mmpFile) { |
779 String dataFileLocation = bldInfFolder + Constants.FILENAME; |
716 String path = null; |
780 java.io.File dataFile = new java.io.File(dataFileLocation); |
717 // remove mmp file name for path |
781 if (dataFile.exists() && dataFile.length() > 0) { |
718 int slash = Util.getLastSlashIndex(mmpFile); |
782 return dataFileLocation; |
719 if (slash == -1) { |
783 } |
720 return false; |
784 return null; |
721 } |
785 } |
722 path = mmpFile.substring(0, slash); |
786 |
723 String buildFile = path + "\\atool_temp\\BuildComplete"; |
787 /** |
724 java.io.File file = new java.io.File(buildFile); |
788 * Checks is file extension .xml. |
725 return file.exists(); |
789 * |
726 } |
790 * @param filePath |
727 |
791 * File location |
728 /** |
792 * @return True if file contains xml extension otherwise false |
729 * Checks that belongs given module to selected project. |
793 */ |
730 * |
794 public static boolean isFileXML(final String filePath) { |
731 * @param modules |
795 String fileNameAndExt = null; |
732 * Project modules |
796 // get index of last backslash |
733 * @param oneModuleName |
797 int index = Util.getLastSlashIndex(filePath); |
734 * One module name |
798 |
735 * @return True if module belongs to selected project otherwise false |
799 // if backslash found |
736 */ |
800 if (index != -1) { |
737 public static boolean isModulePartOfProject( |
801 |
738 final AbstractList<MMPInfo> modules, final String oneModuleName) { |
802 // get file name |
739 Iterator<MMPInfo> iterModules = modules.iterator(); |
803 fileNameAndExt = filePath.substring(index + 1, filePath.length()); |
740 while (iterModules.hasNext()) { |
804 |
741 MMPInfo oneMMPInfo = iterModules.next(); |
805 // if file name contains xml extension |
742 String target = oneMMPInfo.getTarget(); |
806 if (fileNameAndExt.contains(".xml")) { |
743 if (target == null) { |
807 return true; |
744 continue; |
808 } |
745 } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) { |
809 } |
746 return true; |
810 return false; |
747 } |
811 |
748 |
812 } |
749 // target not found try remove {} |
813 |
750 // for example process name is |
814 /** |
751 // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]" |
815 * Check if current module is built. |
752 // but target name is AToolMemoryLeakerDll2.dll |
816 * |
753 CharSequence brace = "{"; |
817 * @param mmpFile |
754 if (oneModuleName.contains(brace)) { |
818 * MMP file name and path |
755 // parse braces |
819 * @return True if module is build otherwise False |
756 String tmpTargetName = oneModuleName.substring(0, oneModuleName |
820 */ |
757 .indexOf('{')); |
821 public static boolean isModuleBuilt(final String mmpFile) { |
758 if (tmpTargetName != null |
822 String path = null; |
759 && oneMMPInfo.getTarget().equalsIgnoreCase( |
823 // remove mmp file name for path |
760 tmpTargetName)) { |
824 int slash = Util.getLastSlashIndex(mmpFile); |
761 return true; |
825 if (slash == -1) { |
762 } |
826 return false; |
763 } |
827 } |
764 } |
828 path = mmpFile.substring(0, slash); |
765 return false; |
829 String buildFile = path + "\\atool_temp\\BuildComplete"; |
766 } |
830 java.io.File file = new java.io.File(buildFile); |
767 |
831 return file.exists(); |
768 /** |
832 } |
769 * Gets current project targets info. |
833 |
770 * |
834 /** |
771 * @param project |
835 * Checks that does given module belong to selected project. |
772 * Project reference |
836 * |
773 * |
837 * @param modules |
774 * @return AbstractList<MMPInfo> List of project targets |
838 * Project modules |
775 */ |
839 * @param oneModuleName |
776 public static AbstractList<MMPInfo> loadProjectTargetsInfo( |
840 * One module name |
777 final IProject project) { |
841 * @return True if module belongs to selected project otherwise false |
778 AbstractList<MMPInfo> targets = new ArrayList<MMPInfo>(); |
842 */ |
779 if (project == null || !project.isOpen()) { |
843 public static boolean isModulePartOfProject( |
780 return targets; |
844 final AbstractList<MMPInfo> modules, final String oneModuleName) { |
781 } |
845 Iterator<MMPInfo> iterModules = modules.iterator(); |
782 |
846 while (iterModules.hasNext()) { |
783 // Assumes buildConfig (ICarbideBuildConfiguration) is known |
847 MMPInfo oneMMPInfo = iterModules.next(); |
784 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager() |
848 String target = oneMMPInfo.getTarget(); |
785 .getProjectInfo(project); |
849 if (target == null) { |
786 if (cpi == null) { |
850 continue; |
787 return new ArrayList<MMPInfo>(); |
851 } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) { |
788 } |
852 return true; |
789 |
853 } |
790 ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration(); |
854 |
791 |
855 // target not found try remove {} |
792 for (IPath mmpPath : EpocEngineHelper |
856 // for example process name is |
793 .getMMPFilesForBuildConfiguration(buildConfig)) { |
857 // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]" |
794 Object data = EpocEnginePlugin.runWithMMPData(mmpPath, |
858 // but target name is AToolMemoryLeakerDll2.dll |
795 new DefaultMMPViewConfiguration(buildConfig |
859 CharSequence brace = "{"; |
796 .getCarbideProject().getProject(), buildConfig, |
860 if (oneModuleName.contains(brace)) { |
797 new AcceptedNodesViewFilter()), |
861 // parse braces |
798 new MMPDataRunnableAdapter() { |
862 String tmpTargetName = oneModuleName.substring(0, oneModuleName |
799 public Object run(IMMPData mmpData) { |
863 .indexOf('{')); |
800 // The real return value, getting a single argument |
864 if (tmpTargetName != null |
801 // setting |
865 && oneMMPInfo.getTarget().equalsIgnoreCase( |
802 return mmpData.getSingleArgumentSettings().get( |
866 tmpTargetName)) { |
803 EMMPStatement.TARGET); |
867 return true; |
804 |
868 } |
805 } |
869 } |
806 }); |
870 } |
807 |
871 return false; |
808 // Make sure to test for and cast to proper Object type! |
872 } |
809 int index = Util.getLastSlashIndex(mmpPath.toOSString()); |
873 |
810 String mmpFileName = ""; |
874 /** |
811 if (index != -1) { |
875 * Gets current project targets info. |
812 mmpFileName = mmpPath.toOSString().substring(index + 1, |
876 * |
813 mmpPath.toOSString().length()); |
877 * @param project |
814 } |
878 * Project reference |
815 MMPInfo oneMMPInfo = new MMPInfo(mmpFileName); |
879 * |
816 oneMMPInfo.setLocation(mmpPath.toOSString()); |
880 * @return AbstractList<MMPInfo> List of project targets |
817 |
881 */ |
818 String mmpStatement = (String) data; // Now we should have the |
882 public static AbstractList<MMPInfo> loadProjectTargetsInfo( |
819 // TARGETTYPE |
883 final IProject project) { |
820 oneMMPInfo.setTarget(mmpStatement); |
884 AbstractList<MMPInfo> targets = new ArrayList<MMPInfo>(); |
821 targets.add(oneMMPInfo); |
885 if (project == null || !project.isOpen()) { |
822 } |
886 return targets; |
823 return targets; |
887 } |
824 } |
888 |
825 |
889 // Assumes buildConfig (ICarbideBuildConfiguration) is known |
826 /** |
890 ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager() |
827 * Opens confirmation Dialog. |
891 .getProjectInfo(project); |
828 * |
892 if (cpi == null) { |
829 * @param text |
893 return new ArrayList<MMPInfo>(); |
830 * Dialog info text |
894 } |
831 * @return boolean True if user selects "Yes" False if user selects "No" |
895 |
832 */ |
896 ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration(); |
833 public static boolean openConfirmationDialog(final String text) { |
897 |
834 |
898 for (IPath mmpPath : EpocEngineHelper |
835 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
899 .getMMPFilesForBuildConfiguration(buildConfig)) { |
836 new Runnable() { |
900 Object data = EpocEnginePlugin.runWithMMPData(mmpPath, |
837 public void run() { |
901 new DefaultMMPViewConfiguration(buildConfig |
838 ret = MessageDialog.openQuestion(new Shell(), |
902 .getCarbideProject().getProject(), buildConfig, |
839 Constants.ANALYZE_TOOL_TITLE, text); |
903 new AcceptedNodesViewFilter()), |
840 } |
904 new MMPDataRunnableAdapter() { |
841 }); |
905 public Object run(IMMPData mmpData) { |
842 return ret; |
906 // The real return value, getting a single argument |
843 } |
907 // setting |
844 |
908 return mmpData.getSingleArgumentSettings().get( |
845 /** |
909 EMMPStatement.TARGET); |
846 * Opens confirmation Dialog. |
910 |
847 * |
911 } |
848 * @param text |
912 }); |
849 * Dialog info text |
913 |
850 * @return int User selected index |
914 // Make sure to test for and cast to proper Object type! |
851 */ |
915 int index = Util.getLastSlashIndex(mmpPath.toOSString()); |
852 public static int openConfirmationDialogWithCancel(final String text) { |
916 String mmpFileName = ""; |
853 |
917 if (index != -1) { |
854 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
918 mmpFileName = mmpPath.toOSString().substring(index + 1, |
855 new Runnable() { |
919 mmpPath.toOSString().length()); |
856 public void run() { |
920 } |
857 |
921 MMPInfo oneMMPInfo = new MMPInfo(mmpFileName); |
858 String[] labels = new String[3]; |
922 oneMMPInfo.setLocation(mmpPath.toOSString()); |
859 labels[0] = "Yes"; |
923 |
860 labels[1] = "No"; |
924 String mmpStatement = (String) data; // Now we should have the |
861 labels[2] = "Cancel"; |
925 // TARGETTYPE |
862 MessageDialog mDialog = new MessageDialog(new Shell(), |
926 oneMMPInfo.setTarget(mmpStatement); |
863 Constants.ANALYZE_TOOL_TITLE, null, text, 0, |
927 targets.add(oneMMPInfo); |
864 labels, 0); |
928 } |
865 mDialog.open(); |
929 return targets; |
866 mDialog.create(); |
930 } |
867 retValue = mDialog.getReturnCode(); |
931 |
868 } |
932 /** |
869 }); |
933 * Opens confirmation Dialog. |
870 return retValue; |
934 * |
871 } |
935 * @param text |
872 |
936 * Dialog info text |
873 /** |
937 * @return boolean True if user selects "Yes" False if user selects "No" |
874 * Opens console view. |
938 */ |
875 */ |
939 public static boolean openConfirmationDialog(final String text) { |
876 public static void openConsoleView() { |
940 |
877 // sync with UI thread |
941 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
878 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){ |
942 new Runnable() { |
879 public void run() { |
943 public void run() { |
880 |
944 ret = MessageDialog.openQuestion(new Shell(), |
881 try { |
945 Constants.ANALYZE_TOOL_TITLE, text); |
882 // get active workspace page |
946 } |
883 IWorkbenchPage page = Activator.getDefault().getWorkbench() |
947 }); |
884 .getActiveWorkbenchWindow().getActivePage(); |
948 return ret; |
885 |
949 } |
886 |
950 |
887 // display main view |
951 /** |
888 if (page != null) { |
952 * Opens confirmation Dialog. |
889 IWorkbenchPart part = page.getActivePart(); |
953 * |
890 |
954 * @param text |
891 |
955 * Dialog info text |
892 String activePageID = part.getSite().getId(); |
956 * @return int User selected index |
893 |
957 */ |
894 if( activePageID.equals(Constants.ANALYZE_TOOL_VIEW_ID) || part instanceof org.eclipse.ui.navigator.CommonNavigator) { |
958 public static int openConfirmationDialogWithCancel(final String text) { |
895 page |
959 |
896 .showView(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); |
960 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
897 } |
961 new Runnable() { |
898 |
962 public void run() { |
899 } |
963 |
900 |
964 String[] labels = new String[3]; |
901 } catch (Exception e) { |
965 labels[0] = "Yes"; |
902 e.printStackTrace(); |
966 labels[1] = "No"; |
903 } |
967 labels[2] = "Cancel"; |
904 } |
968 MessageDialog mDialog = new MessageDialog(new Shell(), |
905 }); |
969 Constants.ANALYZE_TOOL_TITLE, null, text, 0, |
906 } |
970 labels, 0); |
907 |
971 mDialog.open(); |
908 /** |
972 mDialog.create(); |
909 * Opens selection dialog. |
973 retValue = mDialog.getReturnCode(); |
910 * |
974 } |
911 * @param shell |
975 }); |
912 * Shell reference |
976 return retValue; |
913 * @param title |
977 } |
914 * Dialog title |
978 |
915 * @param defaultLocation |
979 /** |
916 * Dialog default location |
980 * Opens console view. |
917 * @return User selection |
981 */ |
918 */ |
982 public static void openConsoleView() { |
919 public static String openFileDialog(final Shell shell, final String title, |
983 // sync with UI thread |
920 final String defaultLocation) { |
984 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { |
921 FileDialog fileDialog = new FileDialog(shell); |
|
922 fileDialog.setText(title); |
|
923 // set the file extension filter |
|
924 String[] filterExt = { "*.*", "*.dat", "*.xml" }; |
|
925 fileDialog.setFilterExtensions(filterExt); |
|
926 |
|
927 // fileDialog.setFilterPath( defaultLocation ); |
|
928 return fileDialog.open(); |
|
929 } |
|
930 |
|
931 /** |
|
932 * Opens selection dialog. |
|
933 * |
|
934 * @param title |
|
935 * Dialog title |
|
936 * @param message |
|
937 * Dialog message text |
|
938 * @param input |
|
939 * Dialog input |
|
940 * @return Selected item |
|
941 */ |
|
942 public static String openSelectionDialog(final String title, |
|
943 final String message, final AbstractList<String> input) { |
|
944 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
|
945 new Runnable() { |
|
946 public void run() { |
|
947 userSelection = ""; |
|
948 |
|
949 ListDialog ld = new ListDialog(new Shell()); |
|
950 ld.setAddCancelButton(true); |
|
951 ld.setContentProvider(new ArrayContentProvider()); |
|
952 ld.setLabelProvider(new LabelProvider()); |
|
953 |
|
954 int width = 0; |
|
955 // calculate dialog width |
|
956 for (int i = 0; i < input.size(); i++) { |
|
957 String tempStr = input.get(i); |
|
958 |
|
959 if (tempStr.length() > width) { |
|
960 width = tempStr.length(); |
|
961 } |
|
962 } |
|
963 |
|
964 // set dialog width |
|
965 // ld.setWidthInChars( width + 2 ); |
|
966 ld.setInput(input); |
|
967 ld.setTitle(title); |
|
968 if (message != null) { |
|
969 ld.setMessage(message); |
|
970 } |
|
971 |
|
972 ld.setHelpAvailable(false); |
|
973 ld.open(); |
|
974 |
|
975 Object[] objs = ld.getResult(); |
|
976 if (objs != null) { |
|
977 userSelection = objs[0].toString(); |
|
978 } |
|
979 |
|
980 } |
|
981 }); |
|
982 return userSelection; |
|
983 } |
|
984 |
|
985 /** |
|
986 * Displays error message. |
|
987 * |
|
988 * @param message |
|
989 * Error note content |
|
990 */ |
|
991 public static void showErrorMessage(final String message) { |
|
992 |
|
993 PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable() { |
|
994 public void run() { |
985 public void run() { |
995 MessageDialog |
986 |
996 .openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Constants.DIALOG_TITLE, message); |
987 try { |
|
988 // get active workspace page |
|
989 IWorkbenchPage page = Activator.getDefault().getWorkbench() |
|
990 .getActiveWorkbenchWindow().getActivePage(); |
|
991 |
|
992 // display main view |
|
993 if (page != null) { |
|
994 IWorkbenchPart part = page.getActivePart(); |
|
995 |
|
996 String activePageID = part.getSite().getId(); |
|
997 |
|
998 if (activePageID.equals(Constants.ANALYZE_TOOL_VIEW_ID) |
|
999 || part instanceof org.eclipse.ui.navigator.CommonNavigator) { |
|
1000 page |
|
1001 .showView(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); |
|
1002 } |
|
1003 |
|
1004 } |
|
1005 |
|
1006 } catch (Exception e) { |
|
1007 e.printStackTrace(); |
|
1008 } |
997 } |
1009 } |
998 }); |
1010 }); |
999 |
1011 } |
1000 } |
1012 |
1001 |
1013 /** |
1002 /** |
1014 * Opens selection dialog. |
1003 * Displays information note. |
1015 * |
1004 * |
1016 * @param shell |
1005 * @param message |
1017 * Shell reference |
1006 * Information note content |
1018 * @param title |
1007 */ |
1019 * Dialog title |
1008 public static void showMessage(final String message) { |
1020 * @param defaultLocation |
1009 |
1021 * Dialog default location |
1010 //sync with the UI thread |
1022 * @return User selection |
1011 PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable() { |
1023 */ |
1012 public void run() { |
1024 public static String openFileDialog(final Shell shell, final String title, |
1013 |
1025 final String defaultLocation) { |
1014 MessageDialog |
1026 FileDialog fileDialog = new FileDialog(shell); |
1015 .openInformation(Activator.getDefault().getWorkbench() |
1027 fileDialog.setText(title); |
1016 .getDisplay().getActiveShell(), Constants.DIALOG_TITLE, |
1028 // set the file extension filter |
1017 message); |
1029 String[] filterExt = { "*.*", "*.dat", "*.xml" }; |
1018 } |
1030 fileDialog.setFilterExtensions(filterExt); |
1019 }); |
1031 |
1020 |
1032 // fileDialog.setFilterPath( defaultLocation ); |
1021 } |
1033 return fileDialog.open(); |
1022 |
1034 } |
1023 /** |
1035 |
1024 * Check is atool.exe verbose output checked. |
1036 /** |
1025 * |
1037 * Opens selection dialog. |
1026 * @return True verbose output is checked otherwise False |
1038 * |
1027 */ |
1039 * @param title |
1028 public static boolean verboseAtoolOutput() { |
1040 * Dialog title |
1029 IPreferenceStore store = Activator.getPreferences(); |
1041 * @param message |
1030 return store.getBoolean(Constants.ATOOL_VERBOSE); |
1042 * Dialog message text |
1031 } |
1043 * @param input |
1032 |
1044 * Dialog input |
1033 /** |
1045 * @return Selected item |
1034 * Creates progress dialog and clears atool.exe made changes. |
1046 */ |
1035 * |
1047 public static String openSelectionDialog(final String title, |
1036 * @param newProject |
1048 final String message, final AbstractList<String> input) { |
1037 * Project reference |
1049 Activator.getDefault().getWorkbench().getDisplay().syncExec( |
1038 */ |
1050 new Runnable() { |
1039 public final void clearAtoolChanges(final IProject newProject) { |
1051 public void run() { |
1040 |
1052 userSelection = ""; |
1041 // project reference |
1053 |
1042 final IProject project = newProject; |
1054 ListDialog ld = new ListDialog(new Shell()); |
1043 |
1055 ld.setAddCancelButton(true); |
1044 Job cleanJob = new Job(Constants.PROGRESSDIALOG_CLEAR_CHANGES) { |
1056 ld.setContentProvider(new ArrayContentProvider()); |
1045 @Override |
1057 ld.setLabelProvider(new LabelProvider()); |
1046 protected IStatus run(IProgressMonitor monitor) { |
1058 |
1047 |
1059 int width = 0; |
1048 // update progress monitor state |
1060 // calculate dialog width |
1049 monitor.beginTask(Constants.PROGRESSDIALOG_CLEAR_CHANGES, IProgressMonitor.UNKNOWN); |
1061 for (int i = 0; i < input.size(); i++) { |
1050 |
1062 String tempStr = input.get(i); |
1051 // get project info |
1063 |
1052 ICarbideProjectInfo cpi = CarbideBuilderPlugin |
1064 if (tempStr.length() > width) { |
1053 .getBuildManager().getProjectInfo(project); |
1065 width = tempStr.length(); |
1054 if (cpi == null) { |
1066 } |
1055 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
1067 } |
1056 IStatus.OK, |
1068 |
1057 Constants.PROGRESSDIALOG_CLEAN_COMPLETE, null); |
1069 // set dialog width |
1058 } |
1070 // ld.setWidthInChars( width + 2 ); |
1059 |
1071 ld.setInput(input); |
1060 // new command launcher |
1072 ld.setTitle(title); |
1061 CarbideCommandLauncher cmdLauncher = new CarbideCommandLauncher( |
1073 if (message != null) { |
1062 project, monitor, Constants.atoolParserIds, cpi |
1074 ld.setMessage(message); |
1063 .getINFWorkingDirectory()); |
1075 } |
1064 cmdLauncher.startTimingStats(); |
1076 |
1065 |
1077 ld.setHelpAvailable(false); |
1066 cmdLauncher.showCommand(true); |
1078 ld.open(); |
1067 |
1079 |
1068 cmdLauncher.writeToConsole(cmdLauncher.getTimingStats()); |
1080 Object[] objs = ld.getResult(); |
1069 |
1081 if (objs != null) { |
1070 AbstractList<String> usedArguments = new ArrayList<String>(); |
1082 userSelection = objs[0].toString(); |
1071 usedArguments.add("-c"); |
1083 } |
1072 if (Util.verboseAtoolOutput()) { |
1084 |
1073 usedArguments.add(Constants.ATOOL_SHOW_DEBUG); |
1085 } |
1074 } |
1086 }); |
1075 |
1087 return userSelection; |
1076 String[] arguments = new String[usedArguments.size()]; |
1088 } |
1077 usedArguments.toArray(arguments); |
1089 |
1078 int error = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode(); |
1090 /** |
1079 error = cmdLauncher.executeCommand(new Path(Util |
1091 * Displays error message. |
1080 .getAtoolInstallFolder()), arguments, |
1092 * |
1081 CarbideCPPBuilder.getResolvedEnvVars(cpi |
1093 * @param message |
1082 .getDefaultConfiguration()), cpi |
1094 * Error note content |
1083 .getINFWorkingDirectory()); |
1095 */ |
1084 |
1096 public static void showErrorMessage(final String message) { |
1085 // if command line engine returns some error code => display the error |
1097 |
1086 if( error != Constants.COMMAND_LINE_ERROR_CODE.OK.getCode() ) { |
1098 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
1087 Constants.COMMAND_LINE_ERROR_CODE errorCode = Util.getErrorCode(error); |
1099 public void run() { |
1088 Util.displayCommandLineError(errorCode); |
1100 MessageDialog.openError(PlatformUI.getWorkbench() |
1089 } |
1101 .getActiveWorkbenchWindow().getShell(), |
1090 |
1102 Constants.DIALOG_TITLE, message); |
1091 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
1103 } |
1092 IStatus.OK, Constants.PROGRESSDIALOG_CLEAN_COMPLETE, |
1104 }); |
1093 null); |
1105 |
1094 } |
1106 } |
1095 }; |
1107 |
1096 cleanJob.setUser(true); |
1108 /** |
1097 cleanJob.schedule(); |
1109 * Displays information note. |
1098 } |
1110 * |
1099 |
1111 * @param message |
1100 |
1112 * Information note content |
1101 /** |
1113 */ |
1102 * Compares two atool.exe version numbers and returns |
1114 public static void showMessage(final String message) { |
1103 * higher one. |
1115 |
1104 * @param firstVersion First version number |
1116 // sync with the UI thread |
1105 * @param secondVersion Second version number |
1117 PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { |
1106 * @return 0 if the first one is higher, 1 if the second one is higher otherwise -1 |
1118 public void run() { |
1107 */ |
1119 |
1108 public static int compareVersionNumber(String firstVersion, String secondVersion) |
1120 MessageDialog.openInformation(Activator.getDefault() |
1109 { |
1121 .getWorkbench().getDisplay().getActiveShell(), |
1110 |
1122 Constants.DIALOG_TITLE, message); |
1111 // split version numbers |
1123 } |
1112 String first[] = firstVersion.split("[.]"); |
1124 }); |
1113 String second[] = secondVersion.split("[.]"); |
1125 |
1114 |
1126 } |
1115 // check that version numbers contains valid formatting |
1127 |
1116 if( first == null || second == null || first.length <1 || second.length < 1 || (first.length != second.length) ) { |
1128 /** |
1117 return Constants.VERSION_NUMBERS_INVALID; |
1129 * Check is atool.exe verbose output checked. |
1118 } |
1130 * |
1119 // if version number equals => no need to check which one is higher |
1131 * @return True verbose output is checked otherwise False |
1120 if( firstVersion.equalsIgnoreCase(secondVersion) ) |
1132 */ |
1121 { |
1133 public static boolean verboseAtoolOutput() { |
1122 return Constants.VERSION_NUMBERS_EQUALS; |
1134 IPreferenceStore store = Activator.getPreferences(); |
1123 } |
1135 return store.getBoolean(Constants.ATOOL_VERBOSE); |
1124 // thru splitted version number |
1136 } |
1125 for( int i=0; i<first.length; i++ ) { |
1137 |
1126 try{ |
1138 /** |
1127 int firstNumber = Integer.parseInt( first[i] ); |
1139 * Creates progress dialog and clears atool.exe made changes. |
1128 int secondNumber = Integer.parseInt( second[i] ); |
1140 * |
1129 |
1141 * @param newProject |
1130 // if first and second given number equals => skip to next number |
1142 * Project reference |
1131 if( firstNumber == secondNumber ) { |
1143 */ |
1132 continue; |
1144 public static final void clearAtoolChanges(final IProject newProject) { |
1133 } |
1145 |
1134 else if( firstNumber > secondNumber ) { |
1146 // project reference |
1135 return Constants.VERSION_NUMBERS_FIRST; |
1147 final IProject project = newProject; |
1136 } |
1148 |
1137 else { |
1149 Job cleanJob = new Job(Constants.PROGRESSDIALOG_CLEAR_CHANGES) { |
1138 return Constants.VERSION_NUMBERS_SECOND; |
1150 @Override |
1139 } |
1151 protected IStatus run(IProgressMonitor monitor) { |
1140 |
1152 |
1141 }catch(NumberFormatException nfe) { |
1153 // update progress monitor state |
1142 nfe.printStackTrace(); |
1154 monitor.beginTask(Constants.PROGRESSDIALOG_CLEAR_CHANGES, |
1143 return Constants.VERSION_NUMBERS_INVALID; |
1155 IProgressMonitor.UNKNOWN); |
1144 } |
1156 |
1145 } |
1157 // get project info |
1146 return Constants.VERSION_NUMBERS_INVALID; |
1158 ICarbideProjectInfo cpi = CarbideBuilderPlugin |
1147 } |
1159 .getBuildManager().getProjectInfo(project); |
1148 |
1160 if (cpi == null) { |
1149 |
1161 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
1150 /** |
1162 IStatus.OK, |
1151 * Displays corresponding error message. |
1163 Constants.PROGRESSDIALOG_CLEAN_COMPLETE, null); |
1152 * @param errorCode Error code |
1164 } |
1153 */ |
1165 |
1154 public static final void displayCommandLineError( Constants.COMMAND_LINE_ERROR_CODE errorCode ) { |
1166 // new command launcher |
1155 switch(errorCode) { |
1167 CarbideCommandLauncher cmdLauncher = new CarbideCommandLauncher( |
1156 case EXECUTE_ERROR: |
1168 project, monitor, Constants.atoolParserIds, cpi |
1157 Util.showErrorMessage(Constants.ERROR_ATOOL_NOT_AVAILABLE); |
1169 .getINFWorkingDirectory()); |
1158 break; |
1170 cmdLauncher.startTimingStats(); |
1159 case OK: |
1171 |
1160 // everything is OK, no need to do anything |
1172 cmdLauncher.showCommand(true); |
1161 break; |
1173 |
1162 |
1174 cmdLauncher.writeToConsole(cmdLauncher.getTimingStats()); |
1163 case INVALID_ARGUMENT_ERROR: |
1175 |
1164 Util.showErrorMessage("AnalyzeTool tried to execute command line engine with invalid parameters. \n\nTo avoid this go to AnalyzeTool preference page and select \"Use internal " + |
1176 AbstractList<String> usedArguments = new ArrayList<String>(); |
1165 "command line engine\"."); |
1177 usedArguments.add("-c"); |
1166 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Extension tried to execute command line engine with invalid parameters."); |
1178 if (Util.verboseAtoolOutput()) { |
1167 break; |
1179 usedArguments.add(Constants.ATOOL_SHOW_DEBUG); |
1168 |
1180 } |
1169 case CANNOT_FIND_EPOCROOT: |
1181 |
1170 Util.showErrorMessage("AnalyzeTool can not find epocroot. \nCheck SDK preferences and build project again."); |
1182 String[] arguments = new String[usedArguments.size()]; |
1171 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Can not find epocroot."); |
1183 usedArguments.toArray(arguments); |
1172 break; |
1184 int error = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode(); |
1173 |
1185 error = cmdLauncher.executeCommand(new Path(Util |
1174 case MAKEFILE_ERROR: |
1186 .getAtoolInstallFolder()), arguments, CarbideCPPBuilder |
1175 Util.showErrorMessage("AnalyzeTool command line engine fails to create makefiles.\n\nTry to clean AnalyzeTool changes and build project again." + |
1187 .getResolvedEnvVars(cpi.getDefaultConfiguration()), cpi |
1176 "\nIf problem still occurs contact AnalyzeTool development team."); |
1188 .getINFWorkingDirectory()); |
1177 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Make file error."); |
1189 |
1178 break; |
1190 // if command line engine returns some error code => display the |
1179 |
1191 // error |
1180 case NO_SUPPORTED_MODULES_ERROR: |
1192 if (error != Constants.COMMAND_LINE_ERROR_CODE.OK.getCode()) { |
1181 Util.showErrorMessage("Project contains unsupported modules, this project could not build with AnalyzeTool!"); |
1193 Constants.COMMAND_LINE_ERROR_CODE errorCode = Util |
1182 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - No supported modules error."); |
1194 .getErrorCode(error); |
1183 break; |
1195 Util.displayCommandLineError(errorCode); |
1184 |
1196 } |
1185 case WRONG_DATA_FILE_VERSION: |
1197 |
1186 Util.showErrorMessage("Selected data file contains invalid version number. \nThis usually means that data file " + |
1198 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID, |
1187 "format is changed and AnalyzeTool command line engine can not resolve that. \n\nTry run tests again with the newest version of AnalyzeTool."); |
1199 IStatus.OK, Constants.PROGRESSDIALOG_CLEAN_COMPLETE, |
1188 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Wrong data file version."); |
1200 null); |
1189 break; |
1201 } |
1190 |
1202 }; |
1191 case ANALYZE_ERROR: |
1203 cleanJob.setUser(true); |
1192 Util.showErrorMessage("AnalyzeTool can not analyze the selected data file.\nThis problem usually occurs when selected file contains corrupted AnalyzeTool data. \nTry to run " + |
1204 cleanJob.schedule(); |
1193 "tests again with the newest version of AnalyzeTool."); |
1205 } |
1194 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - General Analyze Error."); |
1206 |
1195 break; |
1207 /** |
1196 |
1208 * Compares two atool.exe version numbers and returns index of the higher |
1197 case SYMBOL_FILE_ERROR: |
1209 * one. |
1198 Util.showErrorMessage("AnalyzeTool can not resolve selected symbol file(s). \n\nGo to AnalyzeTool advanced preference page and check selected symbol file(s)."); |
1210 * |
1199 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Symbol file error."); |
1211 * @param firstVersion |
1200 break; |
1212 * First version number |
1201 |
1213 * @param secondVersion |
1202 case DATA_FILE_EMPTY: |
1214 * Second version number |
1203 Util.showErrorMessage("Can not analyze. \n\nSelected file is empty."); |
1215 * @return 0 if the first one is higher, 1 if the second one is higher, 2 if |
1204 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Selected file is empty."); |
1216 * the versions equals otherwise -1 |
1205 break; |
1217 */ |
1206 |
1218 public static int compareVersionNumber(String firstVersion, |
1207 case DATA_FILE_INVALID: |
1219 String secondVersion) { |
1208 Util.showErrorMessage("Can not analyze. \n\nSelected data file does not contain AnalyzeTool data."); |
1220 |
1209 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Invalid data file."); |
1221 // split version numbers |
1210 break; |
1222 String first[] = firstVersion.split("[.]"); |
1211 |
1223 String second[] = secondVersion.split("[.]"); |
1212 case RELEASABLES_ERROR: |
1224 |
1213 Util.showErrorMessage("AnalyzeTool can not copy needed files, therefore callstack can not be displayed when analyzing data." + |
1225 // check that version numbers contains valid formatting |
1214 "\n\nTry to clean AnalyzeTool made changes and build project again."); |
1226 if (first == null || second == null || first.length < 1 |
1215 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Releasebles error."); |
1227 || second.length < 1 || (first.length != second.length)) { |
1216 break; |
1228 return Constants.VERSION_NUMBERS_INVALID; |
1217 |
1229 } |
1218 case RESTORE_MODULES_ERROR: |
1230 // if version number equals => no need to check which one is higher |
1219 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Restore module error."); |
1231 if (firstVersion.equalsIgnoreCase(secondVersion)) { |
1220 break; |
1232 return Constants.VERSION_NUMBERS_EQUALS; |
1221 |
1233 } |
1222 case CREATING_TEMP_CPP_ERROR: |
1234 // thru splitted version number |
1223 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Creating temp cpp file error."); |
1235 for (int i = 0; i < first.length; i++) { |
1224 break; |
1236 try { |
1225 |
1237 int firstNumber = Integer.parseInt(first[i]); |
1226 case CLEANING_TEMP_ERROR: |
1238 int secondNumber = Integer.parseInt(second[i]); |
1227 Util.showErrorMessage("AnalyzeTool failed to clean project. You may have to clean changes manually."); |
1239 |
1228 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Clean error."); |
1240 // if first and second given number equals => skip to next |
1229 break; |
1241 // number |
1230 |
1242 if (firstNumber == secondNumber) { |
1231 case READ_MAKEFILE_ERROR: |
1243 continue; |
1232 Util.showErrorMessage("AnalyzeTool command line engine can not read project make files. \n\nTry to clean AnalyzeTool" + |
1244 } else if (firstNumber > secondNumber) { |
1233 " made changes and build project again."); |
1245 return Constants.VERSION_NUMBERS_FIRST; |
1234 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Read make file error."); |
1246 } else { |
1235 break; |
1247 return Constants.VERSION_NUMBERS_SECOND; |
1236 |
1248 } |
1237 case MODIFY_MODULES_ERROR: |
1249 |
1238 Util.showErrorMessage("AnalyzeTool command line engine can not modify project modules."); |
1250 } catch (NumberFormatException nfe) { |
1239 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Modify modules error."); |
1251 nfe.printStackTrace(); |
1240 break; |
1252 return Constants.VERSION_NUMBERS_INVALID; |
1241 |
1253 } |
1242 case INVALID_MMP_DEFINED: |
1254 } |
1243 // I think this case is not possible in extension side. |
1255 return Constants.VERSION_NUMBERS_INVALID; |
1244 // because we ask mmp files from Carbide |
1256 } |
1245 // however if this case happens we just log it Carbide error log |
1257 |
1246 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Invalid mmp file."); |
1258 /** |
1247 break; |
1259 * Displays corresponding error message. |
1248 |
1260 * |
1249 case UNKNOWN_ERROR: |
1261 * @param errorCode |
1250 Util.showErrorMessage("Unable to execute action for current project."); |
1262 * Error code |
1251 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - unknown error."); |
1263 */ |
1252 break; |
1264 public static final void displayCommandLineError( |
1253 |
1265 Constants.COMMAND_LINE_ERROR_CODE errorCode) { |
1254 } |
1266 switch (errorCode) { |
1255 } |
1267 case EXECUTE_ERROR: |
1256 |
1268 Util.showErrorMessage(Constants.ERROR_ATOOL_NOT_AVAILABLE); |
1257 /** |
1269 break; |
1258 * Finds correct Enum value for integer value. |
1270 case OK: |
1259 * |
1271 // everything is OK, no need to do anything |
1260 * @param value Value to find from enum values |
1272 break; |
1261 * @return Enum value if found otherwise COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR |
1273 |
1262 */ |
1274 case INVALID_ARGUMENT_ERROR: |
1263 public static COMMAND_LINE_ERROR_CODE getErrorCode(final int value) { |
1275 Util |
1264 for( COMMAND_LINE_ERROR_CODE errorCode : COMMAND_LINE_ERROR_CODE.values() ) { |
1276 .showErrorMessage("AnalyzeTool tried to execute command line engine with invalid parameters. \n\nTo avoid this go to AnalyzeTool preference page and select \"Use internal " |
1265 if( errorCode.getCode() == value ) { |
1277 + "command line engine\"."); |
1266 return errorCode; |
1278 Activator |
1267 } |
1279 .getDefault() |
1268 } |
1280 .logInfo( |
1269 return COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR; |
1281 IStatus.ERROR, |
1270 } |
1282 IStatus.ERROR, |
|
1283 "AnalyzeTool - Extension tried to execute command line engine with invalid parameters."); |
|
1284 break; |
|
1285 |
|
1286 case CANNOT_FIND_EPOCROOT: |
|
1287 Util |
|
1288 .showErrorMessage("AnalyzeTool can not find epocroot. \nCheck SDK preferences and build project again."); |
|
1289 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1290 "AnalyzeTool - Can not find epocroot."); |
|
1291 break; |
|
1292 |
|
1293 case MAKEFILE_ERROR: |
|
1294 Util |
|
1295 .showErrorMessage("AnalyzeTool command line engine fails to create makefiles.\n\nTry to clean AnalyzeTool changes and build project again." |
|
1296 + "\nIf problem still occurs contact AnalyzeTool development team."); |
|
1297 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1298 "AnalyzeTool - Make file error."); |
|
1299 break; |
|
1300 |
|
1301 case NO_SUPPORTED_MODULES_ERROR: |
|
1302 Util |
|
1303 .showErrorMessage("Project contains unsupported modules, this project could not build with AnalyzeTool!"); |
|
1304 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1305 "AnalyzeTool - No supported modules error."); |
|
1306 break; |
|
1307 |
|
1308 case WRONG_DATA_FILE_VERSION: |
|
1309 Util |
|
1310 .showErrorMessage("Selected data file contains invalid version number. \nThis usually means that data file " |
|
1311 + "format is changed and AnalyzeTool command line engine can not resolve that. \n\nTry run tests again with the newest version of AnalyzeTool."); |
|
1312 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1313 "AnalyzeTool - Wrong data file version."); |
|
1314 break; |
|
1315 |
|
1316 case ANALYZE_ERROR: |
|
1317 Util |
|
1318 .showErrorMessage("AnalyzeTool can not analyze the selected data file.\nThis problem usually occurs when selected file contains corrupted AnalyzeTool data. \nTry to run " |
|
1319 + "tests again with the newest version of AnalyzeTool."); |
|
1320 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1321 "AnalyzeTool - General Analyze Error."); |
|
1322 break; |
|
1323 |
|
1324 case SYMBOL_FILE_ERROR: |
|
1325 Util |
|
1326 .showErrorMessage("AnalyzeTool can not resolve selected symbol file(s). \n\nGo to AnalyzeTool advanced preference page and check selected symbol file(s)."); |
|
1327 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1328 "AnalyzeTool - Symbol file error."); |
|
1329 break; |
|
1330 |
|
1331 case DATA_FILE_EMPTY: |
|
1332 Util |
|
1333 .showErrorMessage("Can not analyze. \n\nSelected file is empty."); |
|
1334 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1335 "AnalyzeTool - Selected file is empty."); |
|
1336 break; |
|
1337 |
|
1338 case DATA_FILE_INVALID: |
|
1339 Util |
|
1340 .showErrorMessage("Can not analyze. \n\nSelected data file does not contain AnalyzeTool data."); |
|
1341 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1342 "AnalyzeTool - Invalid data file."); |
|
1343 break; |
|
1344 |
|
1345 case RELEASABLES_ERROR: |
|
1346 Util |
|
1347 .showErrorMessage("AnalyzeTool can not copy needed files, therefore callstack can not be displayed when analyzing data." |
|
1348 + "\n\nTry to clean AnalyzeTool made changes and build project again."); |
|
1349 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1350 "AnalyzeTool - Releasebles error."); |
|
1351 break; |
|
1352 |
|
1353 case RESTORE_MODULES_ERROR: |
|
1354 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1355 "AnalyzeTool - Restore module error."); |
|
1356 break; |
|
1357 |
|
1358 case CREATING_TEMP_CPP_ERROR: |
|
1359 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1360 "AnalyzeTool - Creating temp cpp file error."); |
|
1361 break; |
|
1362 |
|
1363 case CLEANING_TEMP_ERROR: |
|
1364 Util |
|
1365 .showErrorMessage("AnalyzeTool failed to clean project. You may have to clean changes manually."); |
|
1366 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1367 "AnalyzeTool - Clean error."); |
|
1368 break; |
|
1369 |
|
1370 case READ_MAKEFILE_ERROR: |
|
1371 Util |
|
1372 .showErrorMessage("AnalyzeTool command line engine can not read project make files. \n\nTry to clean AnalyzeTool" |
|
1373 + " made changes and build project again."); |
|
1374 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1375 "AnalyzeTool - Read make file error."); |
|
1376 break; |
|
1377 |
|
1378 case MODIFY_MODULES_ERROR: |
|
1379 Util |
|
1380 .showErrorMessage("AnalyzeTool command line engine can not modify project modules."); |
|
1381 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1382 "AnalyzeTool - Modify modules error."); |
|
1383 break; |
|
1384 |
|
1385 case INVALID_MMP_DEFINED: |
|
1386 // I think this case is not possible in extension side. |
|
1387 // because we ask mmp files from Carbide |
|
1388 // however if this case happens we just log it Carbide error log |
|
1389 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1390 "AnalyzeTool - Invalid mmp file."); |
|
1391 break; |
|
1392 |
|
1393 case EMPTY_DATA_FILE: |
|
1394 Util |
|
1395 .showErrorMessage("Can not analyze. \n\nSelected file is empty."); |
|
1396 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1397 "AnalyzeTool - Selected file is empty."); |
|
1398 break; |
|
1399 case UNKNOWN_ERROR: |
|
1400 Util |
|
1401 .showErrorMessage("Unable to execute action for current project."); |
|
1402 Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, |
|
1403 "AnalyzeTool - unknown error."); |
|
1404 break; |
|
1405 |
|
1406 } |
|
1407 } |
|
1408 |
|
1409 /** |
|
1410 * Finds correct Enum value for integer value. |
|
1411 * |
|
1412 * @param value |
|
1413 * Value to find from enum values |
|
1414 * @return Enum value if found otherwise |
|
1415 * COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR |
|
1416 */ |
|
1417 public static COMMAND_LINE_ERROR_CODE getErrorCode(final int value) { |
|
1418 for (COMMAND_LINE_ERROR_CODE errorCode : COMMAND_LINE_ERROR_CODE |
|
1419 .values()) { |
|
1420 if (errorCode.getCode() == value) { |
|
1421 return errorCode; |
|
1422 } |
|
1423 } |
|
1424 return COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR; |
|
1425 } |
1271 } |
1426 } |