|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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.s60tools.appdep.locatecomponent; |
|
19 |
|
20 import org.eclipse.cdt.core.model.ICProject; |
|
21 import org.eclipse.core.runtime.IProgressMonitor; |
|
22 import org.eclipse.core.runtime.IStatus; |
|
23 import org.eclipse.core.runtime.Platform; |
|
24 import org.eclipse.core.runtime.Status; |
|
25 |
|
26 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
27 import com.nokia.s60tools.appdep.resources.Messages; |
|
28 import com.nokia.s60tools.appdep.util.AppDepConsole; |
|
29 import com.nokia.s60tools.sdk.SdkInformation; |
|
30 import com.nokia.s60tools.util.console.IConsolePrintUtility; |
|
31 import com.nokia.s60tools.util.exceptions.JobCancelledByUserException; |
|
32 import com.nokia.s60tools.util.sourcecode.ProjectUtils; |
|
33 import com.nokia.s60tools.util.sourcecode.SourceFileLocation; |
|
34 |
|
35 /** |
|
36 * Utility methods for handling Carbide/Eclipse projects, uses ProjectUtils class |
|
37 * and captures IStatus messages so that project creation can be used outside {@link CreateProjectJob}. |
|
38 */ |
|
39 public class DEProjectUtils extends ProjectUtils{ |
|
40 |
|
41 /** |
|
42 * Constructor |
|
43 * @param printUtility console for printing warning info, and error messages |
|
44 */ |
|
45 public DEProjectUtils(IConsolePrintUtility printUtility) { |
|
46 super(printUtility); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Creates project pointed by the given bld.inf file. |
|
51 * @param monitor Job progress monitor. |
|
52 * @param bldInfFilePath Absolute path to bld.inf file |
|
53 * @return Project creation status object. |
|
54 */ |
|
55 public CProjectJobStatus createProjectImpl(IProgressMonitor monitor, String bldInfFilePath) { |
|
56 return runImpl(monitor, null, bldInfFilePath); |
|
57 } |
|
58 /** |
|
59 * Creates project pointed by the given source file location. |
|
60 * @param monitor Job progress monitor. |
|
61 * @param location Source file location. |
|
62 * @return Project creation status object. |
|
63 */ |
|
64 public CProjectJobStatus createProjectImpl(IProgressMonitor monitor, SourceFileLocation location) { |
|
65 return runImpl(monitor, location, null); |
|
66 } |
|
67 |
|
68 /** |
|
69 * Creates project pointed by the given bld.inf file and source file location. |
|
70 * @param monitor Job progress monitor. |
|
71 * @param location Source file location. Used as default input info, if defined. |
|
72 * If set to <code>null</code> using bld.inf file instead. |
|
73 * @param bldInfFilePath Absolute path to bld.inf file |
|
74 * @return Project creation status object. |
|
75 */ |
|
76 private CProjectJobStatus runImpl(IProgressMonitor monitor, SourceFileLocation location, String bldInfFilePath) { |
|
77 IStatus status = null; |
|
78 ICProject cProject = null; |
|
79 CProjectJobStatus ret = new CProjectJobStatus(); |
|
80 try { |
|
81 AppDepSettings settings = AppDepSettings.getActiveSettings(); |
|
82 SdkInformation sdkInfo = settings.getCurrentlyUsedSdk(); |
|
83 |
|
84 if(location != null){ |
|
85 cProject = createProject(monitor, location, sdkInfo.getSdkId()); |
|
86 }else{ |
|
87 cProject = createProject(monitor, bldInfFilePath, sdkInfo.getSdkId()); |
|
88 } |
|
89 // Creation went OK, if we end up here. |
|
90 status = Status.OK_STATUS; |
|
91 } catch (JobCancelledByUserException e) { |
|
92 status = Status.CANCEL_STATUS; |
|
93 } catch (Exception e) { |
|
94 e.printStackTrace(); |
|
95 String errMsg = Messages.getString("CreateProjectJob.Err_Msg"); //$NON-NLS-1$ |
|
96 status = new Status( |
|
97 Status.ERROR,Platform.PI_RUNTIME, |
|
98 Status.ERROR,errMsg, e); |
|
99 AppDepConsole.getInstance().println(errMsg, IConsolePrintUtility.MSG_ERROR); |
|
100 |
|
101 }finally{ |
|
102 ret.setCProject(cProject); |
|
103 ret.setStatus(status); |
|
104 } |
|
105 return ret; |
|
106 } |
|
107 } |