OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express |
11 * or implied. See the License for the specific language governing permissions a nd limitations under | 11 * or implied. See the License for the specific language governing permissions a nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.ui; | 14 package com.google.dart.tools.ui; |
15 | 15 |
16 import com.google.dart.engine.sdk.DirectoryBasedDartSdk; | |
16 import com.google.dart.engine.utilities.instrumentation.Instrumentation; | 17 import com.google.dart.engine.utilities.instrumentation.Instrumentation; |
17 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; | 18 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; |
18 import com.google.dart.tools.core.CmdLineOptions; | 19 import com.google.dart.tools.core.CmdLineOptions; |
19 import com.google.dart.tools.core.DartCore; | 20 import com.google.dart.tools.core.DartCore; |
20 import com.google.dart.tools.core.DartCoreDebug; | 21 import com.google.dart.tools.core.DartCoreDebug; |
21 import com.google.dart.tools.core.instrumentation.InstrumentationLogger; | 22 import com.google.dart.tools.core.instrumentation.InstrumentationLogger; |
23 import com.google.dart.tools.core.model.DartSdk; | |
22 import com.google.dart.tools.core.model.DartSdkManager; | 24 import com.google.dart.tools.core.model.DartSdkManager; |
23 import com.google.dart.tools.ui.feedback.FeedbackUtils; | 25 import com.google.dart.tools.ui.feedback.FeedbackUtils; |
24 import com.google.dart.tools.ui.internal.text.editor.AutoSaveHelper; | 26 import com.google.dart.tools.ui.internal.text.editor.AutoSaveHelper; |
25 | 27 |
26 import org.eclipse.core.runtime.jobs.Job; | 28 import org.eclipse.core.runtime.jobs.Job; |
29 import org.eclipse.jface.dialogs.MessageDialogWithToggle; | |
30 import org.eclipse.jface.preference.IPreferenceStore; | |
31 import org.eclipse.swt.widgets.Display; | |
32 import org.eclipse.swt.widgets.Shell; | |
27 import org.eclipse.ui.IStartup; | 33 import org.eclipse.ui.IStartup; |
34 import org.eclipse.ui.PlatformUI; | |
35 import org.eclipse.ui.editors.text.EditorsUI; | |
28 | 36 |
29 import java.io.File; | 37 import java.io.File; |
38 import java.io.IOException; | |
30 | 39 |
31 /** | 40 /** |
32 * This early startup class is called after the main workbench window opens, and is used to warm up | 41 * This early startup class is called after the main workbench window opens, and is used to warm up |
33 * various bits of compiler infrastructure. | 42 * various bits of compiler infrastructure. |
34 */ | 43 */ |
35 public class DartUIStartup implements IStartup { | 44 public class DartUIStartup implements IStartup { |
36 | 45 |
37 private static final String DART_INSTRUMENTATION_FLAGS_FILE_NAME = "dart_instr umentation_flags.txt"; | 46 private static final String DART_INSTRUMENTATION_FLAGS_FILE_NAME = "dart_instr umentation_flags.txt"; |
38 | 47 |
39 public static void cancelStartup() { | 48 public static void cancelStartup() { |
(...skipping 17 matching lines...) Expand all Loading... | |
57 CmdLineFileProcessor.process(CmdLineOptions.getOptions()); | 66 CmdLineFileProcessor.process(CmdLineOptions.getOptions()); |
58 instrumentation.metric("OpenInitialFilesAndFolders", "Complete"); | 67 instrumentation.metric("OpenInitialFilesAndFolders", "Complete"); |
59 | 68 |
60 AutoSaveHelper.start(); | 69 AutoSaveHelper.start(); |
61 instrumentation.metric("AutoSaveHelperStart", "Complete"); | 70 instrumentation.metric("AutoSaveHelperStart", "Complete"); |
62 | 71 |
63 if (CmdLineOptions.getOptions().getMeasurePerformance()) { | 72 if (CmdLineOptions.getOptions().getMeasurePerformance()) { |
64 Job perfJob = new PerfJob(); | 73 Job perfJob = new PerfJob(); |
65 perfJob.schedule(); | 74 perfJob.schedule(); |
66 } | 75 } |
76 | |
77 warnIfSdkAndDartSdkEnvVarDoNotMatch(); | |
78 | |
67 } catch (Throwable throwable) { | 79 } catch (Throwable throwable) { |
68 // Catch any runtime exceptions that occur during warm up and log them. | 80 // Catch any runtime exceptions that occur during warm up and log them. |
69 DartToolsPlugin.log("Exception occured during editor warmup", throwable); | 81 DartToolsPlugin.log("Exception occured during editor warmup", throwable); |
70 } finally { | 82 } finally { |
71 instrumentation.log(); | 83 instrumentation.log(); |
72 } | 84 } |
73 } | 85 } |
74 | 86 |
75 /** | 87 /** |
76 * Determine if the {@value #DART_INSTRUMENTATION_FLAGS_FILE_NAME} file exists in the user's dart | 88 * Determine if the {@value #DART_INSTRUMENTATION_FLAGS_FILE_NAME} file exists in the user's dart |
(...skipping 24 matching lines...) Expand all Loading... | |
101 instrumentation.metric("BuildDate", DartCore.getBuildDate()); | 113 instrumentation.metric("BuildDate", DartCore.getBuildDate()); |
102 instrumentation.metric("BuildID", DartCore.getBuildId()); | 114 instrumentation.metric("BuildID", DartCore.getBuildId()); |
103 instrumentation.metric("Version", DartCore.getVersion()); | 115 instrumentation.metric("Version", DartCore.getVersion()); |
104 instrumentation.metric("SDKVersion", DartSdkManager.getManager().getSdk(). getSdkVersion()); | 116 instrumentation.metric("SDKVersion", DartSdkManager.getManager().getSdk(). getSdkVersion()); |
105 instrumentation.metric("OSVersion", FeedbackUtils.getOSName()); | 117 instrumentation.metric("OSVersion", FeedbackUtils.getOSName()); |
106 instrumentation.metric("IsInstrumentationFlagFilePresent", IsInstrumentati onFlagFilePresent()); | 118 instrumentation.metric("IsInstrumentationFlagFilePresent", IsInstrumentati onFlagFilePresent()); |
107 } finally { | 119 } finally { |
108 instrumentation.log(); | 120 instrumentation.log(); |
109 } | 121 } |
110 } | 122 } |
123 | |
124 /** | |
125 * If the DART_SDK environment variable is defined, then compare it with the c urrent SDK path and | |
126 * warn the user if they don't match. | |
127 */ | |
128 private void warnIfSdkAndDartSdkEnvVarDoNotMatch() { | |
129 final String doNotWarnKey = "do_not_warn_if_DART_SDK_does_not_match"; | |
130 | |
131 // Skip this check if tests are running or user told us to ignore this probl em | |
132 if (CmdLineOptions.getOptions().getRunTests()) { | |
133 return; | |
134 } | |
135 IPreferenceStore store = EditorsUI.getPreferenceStore(); | |
136 if (store.getBoolean(doNotWarnKey)) { | |
137 return; | |
138 } | |
139 | |
140 // Get the DART_SDK | |
141 File dartSdkDir; | |
142 try { | |
143 String dartSdkPath = System.getenv(DirectoryBasedDartSdk.DART_SDK_ENVIRONM ENT_VARIABLE_NAME); | |
144 if (dartSdkPath == null) { | |
145 return; | |
146 } | |
147 dartSdkDir = new File(dartSdkPath).getCanonicalFile(); | |
148 } catch (Exception e) { | |
149 DartCore.logInformation("Failed to determine DART_SDK", e); | |
150 return; | |
151 } | |
152 | |
153 // Compare with the Editor's SDK | |
154 final String msg; | |
155 if (!dartSdkDir.exists()) { | |
156 msg = Messages.format(DartUIMessages.DartSdkInvalid_doesNotExist, dartSdkD ir.getPath()); | |
157 } else { | |
158 DartSdk editorSdk = DartSdkManager.getManager().getSdk(); | |
159 File editorSdkDir; | |
160 try { | |
161 editorSdkDir = editorSdk.getDirectory().getCanonicalFile(); | |
162 } catch (IOException e) { | |
163 DartCore.logInformation("Failed to determine Editor SDK directory", e); | |
164 return; | |
165 } | |
166 if (!editorSdkDir.equals(dartSdkDir)) { | |
167 msg = Messages.format( | |
168 DartUIMessages.DartSdkInvalid_notEqual, | |
169 new String[] {dartSdkDir.getPath(), editorSdkDir.getPath()}); | |
170 } else { | |
171 return; | |
172 } | |
173 } | |
174 | |
175 Display.getDefault().asyncExec(new Runnable() { | |
lukechurch
2013/11/15 03:19:02
We should instrument the fact that we've discovere
| |
176 @Override | |
177 public void run() { | |
178 Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSh ell(); | |
179 MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openWarni ng( | |
180 shell, | |
181 DartUIMessages.DartSdkInvalid_title, | |
182 msg, | |
183 DartUIMessages.DartSdkInvalid_dontShowAgain, | |
184 false, | |
185 null, | |
186 null); | |
187 EditorsUI.getPreferenceStore().setValue(doNotWarnKey, toggleDialog.getTo ggleState()); | |
188 } | |
189 }); | |
190 } | |
111 } | 191 } |
OLD | NEW |