Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/DartUIStartup.java |
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/DartUIStartup.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/DartUIStartup.java |
| index 0d0455888092132396b3dd3f97c741136131032a..af22d2aa0ad1a59a75a7e31b769467165440593a 100644 |
| --- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/DartUIStartup.java |
| +++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/DartUIStartup.java |
| @@ -13,20 +13,29 @@ |
| */ |
| package com.google.dart.tools.ui; |
| +import com.google.dart.engine.sdk.DirectoryBasedDartSdk; |
| import com.google.dart.engine.utilities.instrumentation.Instrumentation; |
| import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; |
| import com.google.dart.tools.core.CmdLineOptions; |
| import com.google.dart.tools.core.DartCore; |
| import com.google.dart.tools.core.DartCoreDebug; |
| import com.google.dart.tools.core.instrumentation.InstrumentationLogger; |
| +import com.google.dart.tools.core.model.DartSdk; |
| import com.google.dart.tools.core.model.DartSdkManager; |
| import com.google.dart.tools.ui.feedback.FeedbackUtils; |
| import com.google.dart.tools.ui.internal.text.editor.AutoSaveHelper; |
| import org.eclipse.core.runtime.jobs.Job; |
| +import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
| +import org.eclipse.jface.preference.IPreferenceStore; |
| +import org.eclipse.swt.widgets.Display; |
| +import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.ui.IStartup; |
| +import org.eclipse.ui.PlatformUI; |
| +import org.eclipse.ui.editors.text.EditorsUI; |
| import java.io.File; |
| +import java.io.IOException; |
| /** |
| * This early startup class is called after the main workbench window opens, and is used to warm up |
| @@ -64,6 +73,9 @@ public class DartUIStartup implements IStartup { |
| Job perfJob = new PerfJob(); |
| perfJob.schedule(); |
| } |
| + |
| + warnIfSdkAndDartSdkEnvVarDoNotMatch(); |
| + |
| } catch (Throwable throwable) { |
| // Catch any runtime exceptions that occur during warm up and log them. |
| DartToolsPlugin.log("Exception occured during editor warmup", throwable); |
| @@ -108,4 +120,72 @@ public class DartUIStartup implements IStartup { |
| instrumentation.log(); |
| } |
| } |
| + |
| + /** |
| + * If the DART_SDK environment variable is defined, then compare it with the current SDK path and |
| + * warn the user if they don't match. |
| + */ |
| + private void warnIfSdkAndDartSdkEnvVarDoNotMatch() { |
| + final String doNotWarnKey = "do_not_warn_if_DART_SDK_does_not_match"; |
| + |
| + // Skip this check if tests are running or user told us to ignore this problem |
| + if (CmdLineOptions.getOptions().getRunTests()) { |
| + return; |
| + } |
| + IPreferenceStore store = EditorsUI.getPreferenceStore(); |
| + if (store.getBoolean(doNotWarnKey)) { |
| + return; |
| + } |
| + |
| + // Get the DART_SDK |
| + File dartSdkDir; |
| + try { |
| + String dartSdkPath = System.getenv(DirectoryBasedDartSdk.DART_SDK_ENVIRONMENT_VARIABLE_NAME); |
| + if (dartSdkPath == null) { |
| + return; |
| + } |
| + dartSdkDir = new File(dartSdkPath).getCanonicalFile(); |
| + } catch (Exception e) { |
| + DartCore.logInformation("Failed to determine DART_SDK", e); |
| + return; |
| + } |
| + |
| + // Compare with the Editor's SDK |
| + final String msg; |
| + if (!dartSdkDir.exists()) { |
| + msg = Messages.format(DartUIMessages.DartSdkInvalid_doesNotExist, dartSdkDir.getPath()); |
| + } else { |
| + DartSdk editorSdk = DartSdkManager.getManager().getSdk(); |
| + File editorSdkDir; |
| + try { |
| + editorSdkDir = editorSdk.getDirectory().getCanonicalFile(); |
| + } catch (IOException e) { |
| + DartCore.logInformation("Failed to determine Editor SDK directory", e); |
| + return; |
| + } |
| + if (!editorSdkDir.equals(dartSdkDir)) { |
| + msg = Messages.format( |
| + DartUIMessages.DartSdkInvalid_notEqual, |
| + new String[] {dartSdkDir.getPath(), editorSdkDir.getPath()}); |
| + } else { |
| + return; |
| + } |
| + } |
| + |
| + Display.getDefault().asyncExec(new Runnable() { |
|
lukechurch
2013/11/15 03:19:02
We should instrument the fact that we've discovere
|
| + @Override |
| + public void run() { |
| + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| + MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openWarning( |
| + shell, |
| + DartUIMessages.DartSdkInvalid_title, |
| + msg, |
| + DartUIMessages.DartSdkInvalid_dontShowAgain, |
| + false, |
| + null, |
| + null); |
| + EditorsUI.getPreferenceStore().setValue(doNotWarnKey, toggleDialog.getToggleState()); |
| + } |
| + }); |
| + } |
| } |