core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/sdk/ui/NewPluginChecker.java
author timkelly
Wed, 12 May 2010 17:44:08 -0500
changeset 1352 2953a4d4c5d9
parent 883 260ef22f2f0d
child 1434 79471fd1fd69
permissions -rw-r--r--
Add SDKCorePlugin.SUPPORTS_SBSV1_BUILDER to enable/disable SBSv1 builder support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     1
/*
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     3
* All rights reserved.
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     8
*
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    11
*
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    12
* Contributors:
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    13
*
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    14
* Description: 
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    15
*
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    16
*/
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    17
package com.nokia.carbide.cpp.internal.sdk.ui;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    18
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    19
import com.nokia.carbide.cpp.internal.sdk.core.model.DynamicFeatureInstaller;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    20
import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    21
import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    22
import com.nokia.carbide.cpp.sdk.ui.SDKUIPlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    23
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    24
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    25
import org.eclipse.core.resources.ResourcesPlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    26
import org.eclipse.core.runtime.*;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    27
import org.eclipse.core.runtime.jobs.Job;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    28
import org.eclipse.swt.widgets.Shell;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    29
import org.eclipse.ui.IWorkbench;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    30
import org.eclipse.ui.IWorkbenchWindow;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    31
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    32
import java.io.File;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    33
import java.util.List;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    34
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    35
@SuppressWarnings("restriction")
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    36
public class NewPluginChecker {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    37
883
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    38
	private static final String SDK_FEATURE_SUBDIR = "epoc32/kit";  //$NON-NLS-1$
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    39
	
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    40
	public static void checkForNewlyInstalledPlugins(final IWorkbench workbench){
643
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    41
		
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    42
		if (WorkbenchUtils.isJUnitRunning()){
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    43
			return;
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    44
		}
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    45
		
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    46
		final List<ISymbianSDK> sdkList = SDKCorePlugin.getSDKManager().getSDKList();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    47
		Job job = new Job("Checking installed SDKs for plugins") { 
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    48
			@Override
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    49
			protected IStatus run(IProgressMonitor monitor) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    50
				boolean installed = false;
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    51
				boolean oneSDKWasScanned = false;
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    52
				for (ISymbianSDK sdk : sdkList) {
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    53
					
871
009f5d356768 fixed bug #10641.
wpaul
parents: 643
diff changeset
    54
					if (sdk.isPreviouslyScanned() == false) {
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    55
						oneSDKWasScanned = true;
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    56
						// XML was parsed, now try to run the feature installer
871
009f5d356768 fixed bug #10641.
wpaul
parents: 643
diff changeset
    57
						sdk.setPreviouslyScanned(true);
009f5d356768 fixed bug #10641.
wpaul
parents: 643
diff changeset
    58
						File featureDir = new File(sdk.getEPOCROOT() + SDK_FEATURE_SUBDIR);
883
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    59
						try {
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    60
							DynamicFeatureInstaller installer = new DynamicFeatureInstaller(featureDir, null);
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    61
							if (installer.install()) {
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    62
								installed = true;
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    63
							}
883
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    64
						} catch (Exception e) {
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    65
							// Boog 8383: We should fail silently, since this will not break anything and may SDKs will not have any documentation
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    66
							// Otherwise, these errors will be logged every time this check is done (workspace is opened)
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    67
							// Originally, this was used to install MBS build support, but now is only used for SDK documentation
260ef22f2f0d better fix for bug #10641.
wpaul
parents: 871
diff changeset
    68
	//						ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SDKCorePlugin.PLUGIN_ID, IStatus.ERROR, "Unable to install plug-ins dynamically.", e));
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    69
						}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    70
					}
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    71
					
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    72
				}
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    73
				
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    74
				if (oneSDKWasScanned) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    75
					SDKCorePlugin.getSDKManager().updateCarbideSDKCache();
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    76
				}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    77
				if (installed) {
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    78
					// plugins from some SDK were installed
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    79
					doEclipseRestartDialog(workbench);
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    80
				}
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    81
				
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    82
				return Status.OK_STATUS;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    83
			}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    84
		};
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    85
		job.schedule();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    86
	}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    87
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    88
	public static void doEclipseRestartDialog(final IWorkbench workbench) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    89
		if (WorkbenchUtils.isJUnitRunning()){
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    90
			// Don't show the restart dialog if JUnit is running
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    91
			return;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    92
		}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    93
		workbench.getDisplay().asyncExec(new Runnable() {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    94
			public void run() {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    95
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    96
				if (window != null) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    97
					Shell shell = window.getShell();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    98
					// Possible Enhancement: Set the SDKs that have new features so they can be displayed to the user
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    99
					RestartIDEDialog.show(shell,
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   100
							Messages.getString("NewPluginChecker.New_Plugins_Installed") + //$NON-NLS-1$
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   101
					Messages.getString("NewPluginChecker.Restart_Msg")); //$NON-NLS-1$
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   102
				} else {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   103
					ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.WARNING, SDKUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("NewPluginChecker.Restart_Error"), null)); //$NON-NLS-1$
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   104
				}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   105
			}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   106
		});
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   107
	}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   108
}