core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/sdk/ui/NewPluginChecker.java
author timkelly
Mon, 07 Dec 2009 08:45:02 -0600
changeset 643 421b1531a135
parent 231 4885a40e8b9b
child 871 009f5d356768
permissions -rw-r--r--
don't scan SDKs when JUnit is running
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.internal.sdk.core.model.InstallationFailureException;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    21
import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    22
import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    23
import com.nokia.carbide.cpp.sdk.ui.SDKUIPlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    24
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
    25
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    26
import org.eclipse.core.resources.ResourcesPlugin;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    27
import org.eclipse.core.runtime.*;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    28
import org.eclipse.core.runtime.jobs.Job;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    29
import org.eclipse.swt.widgets.Shell;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    30
import org.eclipse.ui.IWorkbench;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    31
import org.eclipse.ui.IWorkbenchWindow;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    32
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    33
import java.io.File;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    34
import java.io.FileNotFoundException;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    35
import java.net.MalformedURLException;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    36
import java.util.List;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    37
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    38
@SuppressWarnings("restriction")
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    39
public class NewPluginChecker {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    40
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    41
	private static final String SDK_FEATURE_SUBDIR = "epoc32/kit/feature";  //$NON-NLS-1$
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    42
	
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    43
	public static void checkForNewlyInstalledPlugins(final IWorkbench workbench){
643
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
		if (WorkbenchUtils.isJUnitRunning()){
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    46
			return;
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    47
		}
421b1531a135 don't scan SDKs when JUnit is running
timkelly
parents: 231
diff changeset
    48
		
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    49
		final List<ISymbianSDK> sdkList = SDKCorePlugin.getSDKManager().getSDKList();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    50
		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
    51
			@Override
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    52
			protected IStatus run(IProgressMonitor monitor) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    53
				boolean installed = false;
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    54
				boolean oneSDKWasScanned = false;
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    55
				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
    56
					
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    57
					if (sdk.isPreviouslyScanned() == false){
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    58
						oneSDKWasScanned = true;
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    59
						// XML was parsed, now try to run the feature installer
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    60
						try {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    61
							sdk.setPreviouslyScanned(true);
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    62
							String eclipsePluginsPath = sdk.getEPOCROOT() + SDK_FEATURE_SUBDIR;
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    63
							DynamicFeatureInstaller installer = new DynamicFeatureInstaller(new File(eclipsePluginsPath), null);
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    64
							if (installer.install()) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    65
								installed = true;
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    66
							}
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    67
	// Boog 8383: We should fail silently, since this will not break anything and may SDKs will not have any documentation
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    68
	// Otherwise, these errors will be logged every time this check is done (workspace is opened)
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    69
	// Originally, this was used to install MBS build support, but now is only used for SDK documentation
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    70
						} catch (MalformedURLException e) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    71
	//						ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SDKCorePlugin.PLUGIN_ID, IStatus.ERROR, "Unable to install plug-ins dynamically.", e));
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    72
						} catch (FileNotFoundException e) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    73
	//						ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SDKCorePlugin.PLUGIN_ID, IStatus.ERROR, "Unable to install plug-ins dynamically.", e));
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    74
						} catch (InstallationFailureException e) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    75
	//						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
    76
						}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    77
					}
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    78
					
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    79
				}
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    80
				
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    81
				if (oneSDKWasScanned) {
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    82
					SDKCorePlugin.getSDKManager().updateCarbideSDKCache();
0
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
				if (installed) {
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    85
					// plugins from some SDK were installed
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    86
					doEclipseRestartDialog(workbench);
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    87
				}
231
4885a40e8b9b fix bug 9032. Only scan SDKs for plugins once for an IDE configuration lifetime.
timkelly
parents: 0
diff changeset
    88
				
0
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    89
				return Status.OK_STATUS;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    90
			}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    91
		};
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    92
		job.schedule();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    93
	}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    94
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    95
	public static void doEclipseRestartDialog(final IWorkbench workbench) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    96
		if (WorkbenchUtils.isJUnitRunning()){
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    97
			// 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
    98
			return;
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
    99
		}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   100
		workbench.getDisplay().asyncExec(new Runnable() {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   101
			public void run() {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   102
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   103
				if (window != null) {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   104
					Shell shell = window.getShell();
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   105
					// 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
   106
					RestartIDEDialog.show(shell,
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   107
							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
   108
					Messages.getString("NewPluginChecker.Restart_Msg")); //$NON-NLS-1$
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   109
				} else {
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   110
					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
   111
				}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   112
			}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   113
		});
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   114
	}
fb279309251b DP tools release version Revision: 200912
Deepak Modgil <Deepak.Modgil@Nokia.com>
parents:
diff changeset
   115
}