|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.carbide.cpp.pi.importer; |
|
19 |
|
20 import java.io.ByteArrayInputStream; |
|
21 import java.util.ArrayList; |
|
22 |
|
23 import org.eclipse.core.resources.IContainer; |
|
24 import org.eclipse.core.resources.IFile; |
|
25 import org.eclipse.core.resources.IProject; |
|
26 import org.eclipse.core.resources.IProjectDescription; |
|
27 import org.eclipse.core.resources.IResource; |
|
28 import org.eclipse.core.resources.IWorkspace; |
|
29 import org.eclipse.core.resources.IWorkspaceRoot; |
|
30 import org.eclipse.core.resources.ResourcesPlugin; |
|
31 import org.eclipse.core.runtime.CoreException; |
|
32 import org.eclipse.core.runtime.Path; |
|
33 import org.eclipse.ui.PlatformUI; |
|
34 import org.eclipse.ui.ide.IDE; |
|
35 |
|
36 import com.nokia.carbide.cpp.internal.pi.analyser.AnalyserDataProcessor; |
|
37 import com.nokia.carbide.cpp.pi.util.GeneralMessages; |
|
38 |
|
39 |
|
40 public class SampleImporter { |
|
41 private static SampleImporter instance; |
|
42 |
|
43 // location of input .dat file |
|
44 private String datFileName; |
|
45 // location of output project |
|
46 private String outputContainerName; |
|
47 // location of output .pi file |
|
48 private String piFileName; |
|
49 // workspace resource .npi file |
|
50 private IFile piFile; |
|
51 // PKG file and their SDK_ID or EPOCROOT |
|
52 public static class PkgObyFile { |
|
53 public String fileAbsolutePath; |
|
54 public String epocRoot; |
|
55 PkgObyFile(String epocRoot, String fileAbsolutePath) { |
|
56 this.fileAbsolutePath = fileAbsolutePath; |
|
57 this.epocRoot = epocRoot; |
|
58 } |
|
59 } |
|
60 private ArrayList<PkgObyFile> pkgObyFileList = new ArrayList<PkgObyFile>(); |
|
61 |
|
62 private boolean importStripTimeStamp = false; // importer is just doing dummy import for stripping time stamp for diffing |
|
63 |
|
64 // ROM related stuff |
|
65 private String romEpocroot; |
|
66 private String romSymbolFile; |
|
67 private String romObyFile; |
|
68 private ArrayList<String> rofsSymbolFileList = new ArrayList<String>(); |
|
69 private ArrayList<String> rofsObyFileList = new ArrayList<String>(); |
|
70 |
|
71 // Custom sample |
|
72 private String custAbsolutePath; |
|
73 private boolean custIsValueBased; |
|
74 private String custDelimitor; |
|
75 |
|
76 // Bup sample |
|
77 private String bupMapProfileId; |
|
78 private String bupMapSymbianSDKId; |
|
79 private boolean bupMapIsBuiltIn; |
|
80 private boolean bupMapIsWorkspace; |
|
81 |
|
82 private SampleImporter() { |
|
83 clear(); |
|
84 // singleton |
|
85 } |
|
86 |
|
87 public static SampleImporter getInstance() { |
|
88 if (instance == null) { |
|
89 instance = new SampleImporter(); |
|
90 } |
|
91 |
|
92 return instance; |
|
93 } |
|
94 |
|
95 public Object clone() throws CloneNotSupportedException { |
|
96 throw new CloneNotSupportedException(); |
|
97 } |
|
98 |
|
99 public String getDatFileName () { |
|
100 return datFileName; |
|
101 } |
|
102 |
|
103 public void setDatFileName (String file) { |
|
104 datFileName = file; |
|
105 } |
|
106 |
|
107 public void clearDatFileName () { |
|
108 setDatFileName(""); //$NON-NLS-1$ |
|
109 } |
|
110 |
|
111 public String getProjectName () { |
|
112 return outputContainerName; |
|
113 } |
|
114 |
|
115 public void setProjectName (String file) { |
|
116 outputContainerName = file; |
|
117 } |
|
118 |
|
119 public void clearProjectName () { |
|
120 setProjectName(""); //$NON-NLS-1$ |
|
121 } |
|
122 |
|
123 public String getPiFileName () { |
|
124 return piFileName; |
|
125 } |
|
126 |
|
127 public void setPiFileName (String file) { |
|
128 piFileName = file; |
|
129 } |
|
130 |
|
131 public void clearPiFileName () { |
|
132 setPiFileName(""); //$NON-NLS-1$ |
|
133 } |
|
134 |
|
135 public IFile getPiFile() { |
|
136 return this.piFile; |
|
137 } |
|
138 |
|
139 public void setPiFile(IFile piFile) { |
|
140 this.piFile = piFile; |
|
141 } |
|
142 |
|
143 public void setStripTimeStampActive () { |
|
144 this.importStripTimeStamp = true; |
|
145 } |
|
146 |
|
147 public void setStripTimeStampDone() { |
|
148 this.importStripTimeStamp = false; |
|
149 } |
|
150 |
|
151 public boolean isStrippingTimeStamp() { |
|
152 return this.importStripTimeStamp; |
|
153 } |
|
154 |
|
155 public PkgObyFile[] getPkgObyFilesList () { |
|
156 ArrayList<PkgObyFile> result = new ArrayList<PkgObyFile>(); |
|
157 // round up all ROM OBY and app PKG |
|
158 if (romObyFile != null && romObyFile.length() > 0) { |
|
159 PkgObyFile romObyEntry = new PkgObyFile(romEpocroot, romObyFile); |
|
160 result.add(romObyEntry); |
|
161 } |
|
162 for (String rofsObyFile : rofsObyFileList) { |
|
163 PkgObyFile rofsObyEntry = new PkgObyFile(romEpocroot, rofsObyFile); |
|
164 result.add(rofsObyEntry); |
|
165 } |
|
166 result.addAll(pkgObyFileList); |
|
167 return result.toArray(new PkgObyFile[result.size()]); |
|
168 } |
|
169 |
|
170 public void addPkgObyFile (String epocroot, String filePath) { |
|
171 pkgObyFileList.add(new PkgObyFile(epocroot, filePath)); |
|
172 } |
|
173 |
|
174 public void clearPkgObyFileList () { |
|
175 pkgObyFileList.clear(); |
|
176 } |
|
177 |
|
178 public String getRomEpocroot () { |
|
179 return romEpocroot; |
|
180 } |
|
181 |
|
182 public void setRomEpocroot (String epocroot) { |
|
183 romEpocroot = epocroot; |
|
184 } |
|
185 |
|
186 public void clearRomEpocroot () { |
|
187 setRomEpocroot(""); //$NON-NLS-1$ |
|
188 } |
|
189 |
|
190 public String getRomSymbolFile () { |
|
191 return romSymbolFile; |
|
192 } |
|
193 |
|
194 public void setRomSymbolFile (String filename) { |
|
195 romSymbolFile = filename; |
|
196 } |
|
197 |
|
198 public void clearRomSymbolFile () { |
|
199 setRomSymbolFile(""); //$NON-NLS-1$ |
|
200 } |
|
201 |
|
202 public String getRomObyFile () { |
|
203 return romObyFile; |
|
204 } |
|
205 |
|
206 public void setRomObyFile (String filename) { |
|
207 romObyFile = filename; |
|
208 } |
|
209 |
|
210 public void clearRomObyFile () { |
|
211 setRomObyFile(""); //$NON-NLS-1$ |
|
212 } |
|
213 |
|
214 public String[] getRofsSymbolFileList () { |
|
215 return rofsSymbolFileList.toArray(new String[rofsSymbolFileList.size()]); |
|
216 } |
|
217 |
|
218 public void addRofsSymbolFile (String filename) { |
|
219 rofsSymbolFileList.add(filename); |
|
220 } |
|
221 |
|
222 public void clearRofsSymbolFileList () { |
|
223 rofsSymbolFileList.clear(); |
|
224 } |
|
225 |
|
226 public String[] getRofsObyFileList () { |
|
227 return rofsObyFileList.toArray(new String[rofsObyFileList.size()]); |
|
228 } |
|
229 |
|
230 public void addRofsObyFile (String filename) { |
|
231 rofsObyFileList.add(filename); |
|
232 } |
|
233 |
|
234 public void clearRofsObyFileList () { |
|
235 rofsObyFileList.clear(); |
|
236 } |
|
237 |
|
238 public String getCustAbsolutePath () { |
|
239 return custAbsolutePath; |
|
240 } |
|
241 |
|
242 public void setCustAbsolutePath (String pathName) { |
|
243 custAbsolutePath = pathName; |
|
244 } |
|
245 |
|
246 public void clearCustAbsolutePath () { |
|
247 setCustAbsolutePath(""); //$NON-NLS-1$ |
|
248 } |
|
249 |
|
250 public boolean getCustIsValueBased () { |
|
251 return custIsValueBased; |
|
252 } |
|
253 |
|
254 public void setCustIsValueBased (boolean value) { |
|
255 custIsValueBased = value; |
|
256 } |
|
257 |
|
258 public void clearCustIsValueBased () { |
|
259 setCustIsValueBased(true); |
|
260 } |
|
261 |
|
262 public String getCustDelimitor () { |
|
263 return custDelimitor; |
|
264 } |
|
265 |
|
266 public void setCustDelimitor (String delimitor) { |
|
267 custDelimitor = delimitor; |
|
268 } |
|
269 |
|
270 public void clearCustDelimitor () { |
|
271 setCustDelimitor(""); //$NON-NLS-1$ |
|
272 } |
|
273 |
|
274 public String getBupMapProfileId() { |
|
275 return bupMapProfileId; |
|
276 } |
|
277 |
|
278 public void setBupMapProfileId(String bupMapProfileId) { |
|
279 this.bupMapProfileId = bupMapProfileId; |
|
280 } |
|
281 |
|
282 public void clearBupMapProfileId() { |
|
283 setBupMapProfileId(""); //$NON-NLS-1$ |
|
284 } |
|
285 |
|
286 public String getBupMapSymbianSDKId() { |
|
287 return bupMapSymbianSDKId; |
|
288 } |
|
289 |
|
290 public void setBupMapSymbianSDKId(String bupMapSymbianSDKId) { |
|
291 this.bupMapSymbianSDKId = bupMapSymbianSDKId != null ? bupMapSymbianSDKId : ""; //$NON-NLS-1$ |
|
292 } |
|
293 |
|
294 public void clearBupMapSymbianSDKId() { |
|
295 setBupMapSymbianSDKId(""); //$NON-NLS-1$ |
|
296 } |
|
297 |
|
298 public boolean isBupMapIsBuiltIn() { |
|
299 return bupMapIsBuiltIn; |
|
300 } |
|
301 |
|
302 public void setBupMapIsBuiltIn(boolean bupMapIsBuiltIn) { |
|
303 this.bupMapIsBuiltIn = bupMapIsBuiltIn; |
|
304 } |
|
305 |
|
306 public void clearBupMapIsBuiltIn() { |
|
307 setBupMapIsBuiltIn(false); |
|
308 } |
|
309 |
|
310 public boolean isBupMapIsWorkspace() { |
|
311 return bupMapIsWorkspace; |
|
312 } |
|
313 |
|
314 public void setBupMapIsWorkspace(boolean bupMapIsWorkspace) { |
|
315 this.bupMapIsWorkspace = bupMapIsWorkspace; |
|
316 } |
|
317 |
|
318 public void clearBupMapIsWorkspace() { |
|
319 setBupMapIsWorkspace(false); |
|
320 } |
|
321 |
|
322 public void clear() { |
|
323 clearDatFileName (); |
|
324 clearProjectName (); |
|
325 clearPiFileName (); |
|
326 clearPkgObyFileList (); |
|
327 clearRomEpocroot (); |
|
328 clearRomSymbolFile (); |
|
329 clearRomObyFile (); |
|
330 clearRofsSymbolFileList (); |
|
331 clearRofsObyFileList (); |
|
332 clearCustAbsolutePath (); |
|
333 clearCustIsValueBased (); |
|
334 clearCustDelimitor (); |
|
335 clearBupMapProfileId (); |
|
336 clearBupMapSymbianSDKId (); |
|
337 clearBupMapIsBuiltIn (); |
|
338 clearBupMapIsWorkspace (); |
|
339 } |
|
340 |
|
341 public boolean validate () { |
|
342 if (getDatFileName().equals("")) { //$NON-NLS-1$ |
|
343 return false; |
|
344 } else if (new java.io.File(getDatFileName()).exists() == false) { |
|
345 return false; |
|
346 } |
|
347 |
|
348 if (getProjectName().equals("")) { //$NON-NLS-1$ |
|
349 return false; |
|
350 } |
|
351 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
352 IResource resource = root.findMember(getProjectName()); |
|
353 if (resource.exists() == false) { |
|
354 return false; |
|
355 } |
|
356 |
|
357 if (getPiFileName().equals("")) { //$NON-NLS-1$ |
|
358 return false; |
|
359 } |
|
360 |
|
361 if (getRomEpocroot().equals("") != false) { //$NON-NLS-1$ |
|
362 if (getRomSymbolFile().equals("") == false) { //$NON-NLS-1$ |
|
363 if (new java.io.File(getRomSymbolFile()).exists() == false) { |
|
364 return false; |
|
365 } |
|
366 } |
|
367 |
|
368 if (getRomObyFile().equals("") == false) { //$NON-NLS-1$ |
|
369 if (new java.io.File(getRomObyFile()).exists() == false) { |
|
370 return false; |
|
371 } |
|
372 } |
|
373 |
|
374 for (String fileName : getRofsObyFileList()) { |
|
375 if (fileName.equals("") == false) { //$NON-NLS-1$ |
|
376 if (new java.io.File(fileName).exists() == false) { |
|
377 return false; |
|
378 } |
|
379 } |
|
380 } |
|
381 } |
|
382 |
|
383 if (pkgObyFileList.size() < 0) { |
|
384 return false; |
|
385 } |
|
386 |
|
387 return true; |
|
388 } |
|
389 |
|
390 public void importSamples(boolean pollTillNpiSaved) { |
|
391 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
392 IResource resource = root.findMember(getProjectName()); |
|
393 |
|
394 IContainer piContainer; |
|
395 if (resource instanceof IContainer) { |
|
396 piContainer = (IContainer) resource; |
|
397 } else { |
|
398 return; |
|
399 } |
|
400 |
|
401 // empty file if there is no symbol file specified, or analyser would crash |
|
402 java.io.File dummySymbol = null; |
|
403 if (getRomSymbolFile() == null || getRomSymbolFile().length() <= 0) { |
|
404 try { |
|
405 dummySymbol = java.io.File.createTempFile("dummySymbol", ".symbol"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
406 setRomSymbolFile(dummySymbol.getAbsolutePath()); |
|
407 } catch (Exception e) { |
|
408 e.printStackTrace(); |
|
409 return; |
|
410 } |
|
411 } |
|
412 |
|
413 try { |
|
414 // import the new project according to wizard |
|
415 piFile = piContainer.getFile(new Path(getPiFileName())); |
|
416 |
|
417 if (piFile.exists()) |
|
418 { |
|
419 piFile.delete(true, null); |
|
420 } |
|
421 } catch (CoreException e) { |
|
422 GeneralMessages.showErrorMessage(com.nokia.carbide.cpp.pi.importer.Messages.getString("SampleImporter.importerInternalError")); //$NON-NLS-1$ |
|
423 GeneralMessages.PiLog(com.nokia.carbide.cpp.pi.importer.Messages.getString("SampleImporter.importerCoreException"), GeneralMessages.ERROR); //$NON-NLS-1$ |
|
424 return; |
|
425 } |
|
426 |
|
427 // import and save the file as npi |
|
428 AnalyserDataProcessor.getInstance().importSaveAndOpen(piFile, pollTillNpiSaved); |
|
429 |
|
430 if (dummySymbol != null) { |
|
431 dummySymbol.delete(); |
|
432 } |
|
433 |
|
434 } |
|
435 |
|
436 // support for removing timestamp to support test |
|
437 public void stripeTimestamp(final String sourceFilePath, final String dstFilePath) { |
|
438 IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
|
439 final IProject piProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject("pifilecompartor_temp"); //$NON-NLS-1$ |
|
440 final IProjectDescription description = workspace.newProjectDescription(piProjectHandle.getName()); |
|
441 SampleImporter sampleImporter = SampleImporter.getInstance(); |
|
442 |
|
443 // strip first file of timestamp by importer like trick |
|
444 sampleImporter.setDatFileName(sourceFilePath); |
|
445 sampleImporter.setPiFileName(dstFilePath); |
|
446 |
|
447 setStripTimeStampActive(); |
|
448 |
|
449 try { |
|
450 if (!piProjectHandle.exists()) { |
|
451 piProjectHandle.create(description, null); |
|
452 piProjectHandle.open(null); |
|
453 } else { |
|
454 piProjectHandle.open(null); |
|
455 } |
|
456 |
|
457 // import the new project according to wizard |
|
458 IFile piFile = piProjectHandle.getFile("temp.npi"); //$NON-NLS-1$ |
|
459 |
|
460 if (piFile.exists()) |
|
461 { |
|
462 piFile.delete(true, null); |
|
463 } |
|
464 // create the .pi on the project so IDE.openEditor works |
|
465 piFile.create(new ByteArrayInputStream("".getBytes()), false, null); //$NON-NLS-1$ |
|
466 |
|
467 IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() , piFile, true); |
|
468 // take out stalled temp.npi window |
|
469 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(true); |
|
470 |
|
471 } catch (CoreException e) { |
|
472 e.printStackTrace(); |
|
473 } |
|
474 setStripTimeStampDone(); |
|
475 } |
|
476 |
|
477 } |