0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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 |
|
|
19 |
package com.nokia.s60tools.appdep.plugin;
|
|
20 |
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.IOException;
|
|
23 |
import java.net.URL;
|
|
24 |
|
|
25 |
import org.eclipse.core.runtime.FileLocator;
|
|
26 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
27 |
import org.eclipse.jface.preference.IPreferenceStore;
|
|
28 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
29 |
import org.eclipse.swt.widgets.Control;
|
|
30 |
import org.eclipse.swt.widgets.Shell;
|
|
31 |
import org.eclipse.ui.IWorkbenchPage;
|
|
32 |
import org.eclipse.ui.PlatformUI;
|
|
33 |
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
34 |
import org.osgi.framework.BundleContext;
|
|
35 |
|
|
36 |
import com.nokia.s60tools.appdep.common.ProductInfoRegistry;
|
|
37 |
import com.nokia.s60tools.appdep.core.AppDepCacheIndexManager;
|
|
38 |
import com.nokia.s60tools.appdep.core.AppDepSettings;
|
|
39 |
import com.nokia.s60tools.appdep.core.job.AppDepJobManager;
|
|
40 |
import com.nokia.s60tools.appdep.resources.ImageKeys;
|
|
41 |
import com.nokia.s60tools.appdep.resources.ImageResourceManager;
|
|
42 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
43 |
import com.nokia.s60tools.appdep.util.AppDepConsole;
|
|
44 |
import com.nokia.s60tools.sdk.RVCTToolChainInfo;
|
|
45 |
import com.nokia.s60tools.sdk.SdkEnvInfomationResolveFailureException;
|
|
46 |
import com.nokia.s60tools.sdk.SdkManager;
|
|
47 |
import com.nokia.s60tools.util.console.IConsolePrintUtility;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* The main plugin class to be used in the desktop.
|
|
51 |
*/
|
|
52 |
public class AppDepPlugin extends AbstractUIPlugin {
|
|
53 |
|
|
54 |
/**
|
|
55 |
* The shared instance.
|
|
56 |
*/
|
|
57 |
private static AppDepPlugin plugin;
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Command line tool settings should not be garbage collected
|
|
61 |
* during the plugin's lifetime. Having a reference in here
|
|
62 |
* should enforce that singleton class is not garbage collected.
|
|
63 |
*/
|
|
64 |
private static AppDepSettings settings;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Also <code>AppDepJobManager</code> instance should not be garbage collected
|
|
68 |
* during the plugin's lifetime. Having a reference in here
|
|
69 |
* should enforce that singleton class is not garbage collected.
|
|
70 |
*/
|
|
71 |
private static AppDepJobManager pluginJobManager;
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Also <code>AppDepCacheIndexManager</code> instance should not be garbage collected
|
|
75 |
* during the plugin's lifetime. Having a reference in here
|
|
76 |
* should enforce that singleton class is not garbage collected.
|
|
77 |
*/
|
|
78 |
private static AppDepCacheIndexManager cacheIndexManager;
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Stores preferences
|
|
82 |
*/
|
|
83 |
private static IPreferenceStore prefsStore;
|
|
84 |
|
|
85 |
|
|
86 |
/**
|
|
87 |
* The constructor.
|
|
88 |
*/
|
|
89 |
public AppDepPlugin() {
|
|
90 |
plugin = this;
|
|
91 |
settings = AppDepSettings.getActiveSettings();
|
|
92 |
pluginJobManager = AppDepJobManager.getInstance();
|
|
93 |
cacheIndexManager = AppDepCacheIndexManager.getInstance();
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Gets plug-in install path.
|
|
98 |
* @return plug-in install path
|
|
99 |
* @throws IOException
|
|
100 |
*/
|
|
101 |
private String getPluginInstallPath() throws IOException{
|
|
102 |
// URL to the plugin's root ("/")
|
|
103 |
URL relativeURL = getBundle().getEntry("/"); //$NON-NLS-1$
|
|
104 |
// Converting into local path
|
|
105 |
URL localURL = FileLocator.toFileURL(relativeURL);
|
|
106 |
// Getting install location in correct form
|
|
107 |
File f = new File(localURL.getPath());
|
|
108 |
String pluginInstallLocation = f.getAbsolutePath();
|
|
109 |
|
|
110 |
return pluginInstallLocation;
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Gets images path relative to given plugin install path.
|
|
115 |
* @param pluginInstallPath Plugin installation path.
|
|
116 |
* @return Path were image resources are located.
|
|
117 |
* @throws IOException
|
|
118 |
*/
|
|
119 |
private String getImagesPath(String pluginInstallPath) throws IOException{
|
|
120 |
return pluginInstallPath
|
|
121 |
+ File.separatorChar
|
|
122 |
+ ProductInfoRegistry.getImagesDirectoryName();
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
* This method is called upon plug-in activation
|
|
127 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
|
128 |
*/
|
|
129 |
public void start(BundleContext context) throws Exception {
|
|
130 |
super.start(context);
|
|
131 |
|
|
132 |
//Startup sequence starting message
|
|
133 |
//This debug println has been left into the code in purpose
|
|
134 |
System.out.println("*** AppDep Plugin STARTUP..."); //$NON-NLS-1$
|
|
135 |
|
|
136 |
//Plug-in install location
|
|
137 |
String pluginInstallLocation = getPluginInstallPath();
|
|
138 |
//This debug println has been left into the code in purpose
|
|
139 |
System.out.println("pluginInstallLocation: " + pluginInstallLocation); //$NON-NLS-1$
|
|
140 |
|
|
141 |
//Images path
|
|
142 |
String imagesPath = getImagesPath(pluginInstallLocation);
|
|
143 |
//This debug println has been left into the code in purpose
|
|
144 |
System.out.println("imagesPath: " + imagesPath); //$NON-NLS-1$
|
|
145 |
|
|
146 |
// Loading images required by this plug-in
|
|
147 |
ImageResourceManager.loadImages(imagesPath);
|
|
148 |
|
|
149 |
initializeSettings(pluginInstallLocation);
|
|
150 |
|
|
151 |
// Removing inconsistent partially created
|
|
152 |
// cache files, if such exist
|
|
153 |
settings.cleanupPartiallyCreatedCacheFiles();
|
|
154 |
|
|
155 |
//Startup sequence completed message
|
|
156 |
//This debug println has been left into the code in purpose
|
|
157 |
System.out.println("*** AppDep Plugin STARTED."); //$NON-NLS-1$
|
|
158 |
}
|
|
159 |
|
|
160 |
/**
|
|
161 |
* Initializing tool settings.
|
|
162 |
* @param pluginInstallPath Plugin installation path.
|
|
163 |
*/
|
|
164 |
private void initializeSettings(String pluginInstallPath) {
|
|
165 |
|
|
166 |
//
|
|
167 |
// Settings gained from SDK Support Plug-in
|
|
168 |
//
|
|
169 |
|
|
170 |
// RVCT tools
|
|
171 |
resolveDefaultRvctToolBinaries();
|
|
172 |
//This debug println has been left into the code in purpose
|
|
173 |
System.out.println("RVCT Tool Binaries Directory: " + settings.getRvctToolsDir()); //$NON-NLS-1$
|
|
174 |
System.out.println("RVCT Tool Version: " + settings.getRvctToolsVersion()); //$NON-NLS-1$
|
|
175 |
|
|
176 |
// GCCE tools
|
|
177 |
try {
|
|
178 |
settings.setGcceToolsDir(SdkManager.getCSLArmToolchainInstallPathAndCheckReqTools());
|
|
179 |
settings.setGcceToolsInstalled( true );
|
|
180 |
//This debug println has been left into the code in purpose
|
|
181 |
System.out.println("GCCE Tool Binaries Directory: " + settings.getGcceToolsDir()); //$NON-NLS-1$
|
|
182 |
} catch (SdkEnvInfomationResolveFailureException e1) {
|
|
183 |
e1.printStackTrace();
|
|
184 |
settings.setGcceToolsInstalled( false );
|
|
185 |
AppDepConsole.getInstance().println(Messages.getString("AppDepPlugin.StartupFail_Msg_GCCE_Install_Location_Not_Found") //$NON-NLS-1$
|
|
186 |
+ e1.getMessage(),
|
|
187 |
IConsolePrintUtility.MSG_ERROR);
|
|
188 |
}
|
|
189 |
|
|
190 |
// Checking that at least GCCE or RVCT tools are installed.
|
|
191 |
// If not installed, showing an error message to user and aborting
|
|
192 |
// plugin start by throwing an exception
|
|
193 |
boolean isRequiredToolsInstalled = (settings.isGcceToolsInstalled()
|
|
194 |
|| settings.isRvctToolsInstalled());
|
|
195 |
|
|
196 |
if(! isRequiredToolsInstalled ){
|
|
197 |
String errorMsg = Messages.getString("AppDepPlugin.StartupFail_Msg_Could_Not_Detect_Required_Toolchains") //$NON-NLS-1$
|
|
198 |
+ Messages.getString("AppDepPlugin.StartupFail_Msg_Required_Tools_Tip") //$NON-NLS-1$
|
|
199 |
+ Messages.getString("AppDepPlugin.StartupFail_Msg_Install_Required_Tools_Tip_Cont") //$NON-NLS-1$
|
|
200 |
+ "\n\n" //$NON-NLS-1$
|
|
201 |
+ Messages.getString("AppDepPlugin.StartupFail_Msg_Timeout_Network_Check"); //$NON-NLS-1$
|
|
202 |
Shell sh = this.getWorkbench().getDisplay().getActiveShell();
|
|
203 |
|
|
204 |
String[] dlgButtonArr = { Messages.getString("AppDepPlugin.OK_Button_Label") }; //$NON-NLS-1$
|
|
205 |
MessageDialog dlg = new MessageDialog(sh,
|
|
206 |
ProductInfoRegistry.getProductName(),
|
|
207 |
ImageResourceManager.getImage(ImageKeys.IMG_APP_ICON),
|
|
208 |
errorMsg,
|
|
209 |
MessageDialog.ERROR,
|
|
210 |
dlgButtonArr,
|
|
211 |
0
|
|
212 |
);
|
|
213 |
dlg.create();
|
|
214 |
dlg.open();
|
|
215 |
throw new RuntimeException(errorMsg);
|
|
216 |
}
|
|
217 |
|
|
218 |
//
|
|
219 |
// Setting location for external binaries
|
|
220 |
//
|
|
221 |
String externalProgramsPath = pluginInstallPath
|
|
222 |
+ File.separatorChar
|
|
223 |
+ ProductInfoRegistry.getWin32BinariesRelativePath();
|
|
224 |
//External programs are to be found from this path
|
|
225 |
//This debug println has been left into the code in purpose
|
|
226 |
System.out.println("externalProgramsPath: " + externalProgramsPath); //$NON-NLS-1$
|
|
227 |
settings.setExternalProgramsPathName(externalProgramsPath);
|
|
228 |
|
|
229 |
// Resources path
|
|
230 |
String resourcesPath = pluginInstallPath
|
|
231 |
+ File.separatorChar
|
|
232 |
+ ProductInfoRegistry.getAppDepResourcesDirectory();
|
|
233 |
//This debug println has been left into the code in purpose
|
|
234 |
System.out.println("resourcesPath: " + resourcesPath); //$NON-NLS-1$
|
|
235 |
settings.setResourcesPath(resourcesPath);
|
|
236 |
|
|
237 |
// Resolving XSL filename
|
|
238 |
String xslFileName =
|
|
239 |
ProductInfoRegistry.getAppDepExportXSLFileName();
|
|
240 |
settings.setXSLFileName(xslFileName);
|
|
241 |
String isUsedByXSLFileName =
|
|
242 |
ProductInfoRegistry.getAppDepIsUsedByXSLFileName();
|
|
243 |
settings.setIsUsedByXSLFileName(isUsedByXSLFileName);
|
|
244 |
}
|
|
245 |
|
|
246 |
/**
|
|
247 |
* Resolves which RVCT Tool Binaries should be used by default.
|
|
248 |
* The selection of the used RVCT toolchain is made based on
|
|
249 |
* the following criteria:
|
|
250 |
* - If there is several possibilities.
|
|
251 |
* Using the binaries with newest timestamp.
|
|
252 |
* - If only one possibility was available, using it. If none reporting
|
|
253 |
* it to Console output.
|
|
254 |
*/
|
|
255 |
private void resolveDefaultRvctToolBinaries() {
|
|
256 |
|
|
257 |
//Get all toolchains
|
|
258 |
RVCTToolChainInfo[] rvctTools = SdkManager.getInstalledRVCTTools();
|
|
259 |
|
|
260 |
if(rvctTools.length > 1){
|
|
261 |
|
|
262 |
// Environment variable is not defined or
|
|
263 |
// there was no match => Using the newest binaries.
|
|
264 |
useTheNewestAvailableRvctToolbinaries(rvctTools);
|
|
265 |
}
|
|
266 |
else if(rvctTools.length == 1){
|
|
267 |
// There is only one possibility
|
|
268 |
useTheFirstAvailableToolchain(rvctTools);
|
|
269 |
}
|
|
270 |
else{
|
|
271 |
settings.setRvctToolsInstalled( false );
|
|
272 |
|
|
273 |
AppDepConsole.getInstance().println(Messages.getString("AppDepPlugin.StartupFail_Msg_RVCT_Install_Location_Not_Found"), //$NON-NLS-1$
|
|
274 |
IConsolePrintUtility.MSG_ERROR);
|
|
275 |
}
|
|
276 |
}
|
|
277 |
|
|
278 |
/**
|
|
279 |
* Sets first encountered toolchain as used toolchain.
|
|
280 |
* @param rvctTools RVCT toolchain info object array.
|
|
281 |
*/
|
|
282 |
private void useTheFirstAvailableToolchain(RVCTToolChainInfo[] rvctTools) {
|
|
283 |
String rvctToolBinariesDirectory = rvctTools[0].getRvctToolBinariesDirectory();
|
|
284 |
settings.setRvctToolsDir(rvctToolBinariesDirectory);
|
|
285 |
settings.setRvctToolsVersion(rvctTools[0].getRvctToolsVersion());
|
|
286 |
settings.setRvctToolsInstalled( true );
|
|
287 |
}
|
|
288 |
|
|
289 |
/**
|
|
290 |
* Called when there is more than one available toolchain binaries.
|
|
291 |
* Resolves which one is the newest, and sets it as default.
|
|
292 |
* @param rvctTools Array to RVCT tool info structure.
|
|
293 |
*/
|
|
294 |
private void useTheNewestAvailableRvctToolbinaries(RVCTToolChainInfo[] rvctTools) {
|
|
295 |
String binDirStored = null;
|
|
296 |
String versionInfoStored = null;
|
|
297 |
long lastModifiedStored = 0;
|
|
298 |
for (int i = 0; i < rvctTools.length; i++) {
|
|
299 |
String binDirTmp = rvctTools[i].getRvctToolBinariesDirectory();
|
|
300 |
String elfProg = binDirTmp
|
|
301 |
+ File.separatorChar
|
|
302 |
+ AppDepSettings.RVCT_FROM_ELF_EXECUTABLE;
|
|
303 |
File elfFile = new File(elfProg);
|
|
304 |
if(elfFile.exists()){
|
|
305 |
long modified = elfFile.lastModified();
|
|
306 |
if(modified > lastModifiedStored){
|
|
307 |
lastModifiedStored = modified;
|
|
308 |
binDirStored = binDirTmp;
|
|
309 |
versionInfoStored = rvctTools[i].getRvctToolsVersion();
|
|
310 |
}
|
|
311 |
}
|
|
312 |
}
|
|
313 |
if(binDirStored != null){
|
|
314 |
settings.setRvctToolsDir(binDirStored);
|
|
315 |
settings.setRvctToolsVersion(versionInfoStored);
|
|
316 |
settings.setRvctToolsInstalled( true );
|
|
317 |
}
|
|
318 |
else{
|
|
319 |
useTheFirstAvailableToolchain(rvctTools);
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
/**
|
|
324 |
* This method is called when the plug-in is stopped
|
|
325 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
|
326 |
*/
|
|
327 |
public void stop(BundleContext context) throws Exception {
|
|
328 |
|
|
329 |
//Starting plugin shutdown sequence
|
|
330 |
//This debug println has been left into the code in purpose
|
|
331 |
System.out.println("AppDep Plugin SHUTDOWN..."); //$NON-NLS-1$
|
|
332 |
|
|
333 |
// Shutting down registered ongoing background jobs
|
|
334 |
pluginJobManager.shutdown();
|
|
335 |
|
|
336 |
// Informing also cache index manager about the shutdown
|
|
337 |
cacheIndexManager.shutdown();
|
|
338 |
|
|
339 |
// Removing inconsistent partially created
|
|
340 |
// cache files, if such exist
|
|
341 |
settings.cleanupPartiallyCreatedCacheFiles();
|
|
342 |
|
|
343 |
plugin = null;
|
|
344 |
super.stop(context);
|
|
345 |
}
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Returns the shared instance.
|
|
349 |
*/
|
|
350 |
public static AppDepPlugin getDefault() {
|
|
351 |
return plugin;
|
|
352 |
}
|
|
353 |
|
|
354 |
/**
|
|
355 |
* Returns an image descriptor for the image file at the given
|
|
356 |
* plug-in relative path.
|
|
357 |
* @param path the path
|
|
358 |
* @return the image descriptor
|
|
359 |
*/
|
|
360 |
public static ImageDescriptor getImageDescriptor(String path) {
|
|
361 |
return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.s60tools.appdep.plugin", path); //$NON-NLS-1$
|
|
362 |
}
|
|
363 |
|
|
364 |
/**
|
|
365 |
* This must be called from UI thread. If called
|
|
366 |
* from non-UI thread this returns <code>null</code>.
|
|
367 |
* @return Currently active workbench page.
|
|
368 |
*/
|
|
369 |
public static IWorkbenchPage getCurrentlyActivePage(){
|
|
370 |
return getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
|
371 |
}
|
|
372 |
|
|
373 |
/**
|
|
374 |
* This must be called from UI thread. If called
|
|
375 |
* from non-UI thread this returns <code>null</code>.
|
|
376 |
* @return The shell of the currently active workbench window..
|
|
377 |
*/
|
|
378 |
public static Shell getCurrentlyActiveWbWindowShell(){
|
|
379 |
IWorkbenchPage page = getCurrentlyActivePage();
|
|
380 |
if(page != null){
|
|
381 |
return page.getWorkbenchWindow().getShell();
|
|
382 |
}
|
|
383 |
return null;
|
|
384 |
}
|
|
385 |
|
|
386 |
/**
|
|
387 |
* Returns the PreferenceStore where plugin preferences are stored
|
|
388 |
* @return the PreferenceStore where plugin preferences are stored
|
|
389 |
*/
|
|
390 |
public static IPreferenceStore getPrefsStore(){
|
|
391 |
if (prefsStore == null){
|
|
392 |
prefsStore = getDefault().getPreferenceStore();
|
|
393 |
}
|
|
394 |
|
|
395 |
return prefsStore;
|
|
396 |
}
|
|
397 |
|
|
398 |
/**
|
|
399 |
* Bounds given context sensitive help ID into given UI control.
|
|
400 |
* @param composite UI control to which bind given context-sensitive help ID.
|
|
401 |
* @param contextHelpID Context-sensitive help ID.
|
|
402 |
*/
|
|
403 |
public static void setContextSensitiveHelpID(
|
|
404 |
Control composite, String contextHelpID) {
|
|
405 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, contextHelpID);
|
|
406 |
}
|
|
407 |
|
|
408 |
}
|