| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Dart project authors. | 2 * Copyright 2012 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 | 14 |
| 15 package com.google.dart.tools.core.model; | 15 package com.google.dart.tools.core.model; |
| 16 | 16 |
| 17 import com.google.dart.engine.context.AnalysisContext; | 17 import com.google.dart.engine.context.AnalysisContext; |
| 18 import com.google.dart.engine.internal.context.AnalysisContextImpl; | 18 import com.google.dart.engine.internal.context.AnalysisContextImpl; |
| 19 import com.google.dart.engine.sdk.DirectoryBasedDartSdk; | 19 import com.google.dart.engine.sdk.DirectoryBasedDartSdk; |
| 20 import com.google.dart.engine.sdk.SdkLibrary; | 20 import com.google.dart.engine.sdk.SdkLibrary; |
| 21 import com.google.dart.engine.source.ContentCache; | 21 import com.google.dart.engine.source.ContentCache; |
| 22 import com.google.dart.engine.source.DartUriResolver; | 22 import com.google.dart.engine.source.DartUriResolver; |
| 23 import com.google.dart.engine.source.FileBasedSource; | 23 import com.google.dart.engine.source.FileBasedSource; |
| 24 import com.google.dart.engine.source.Source; | 24 import com.google.dart.engine.source.Source; |
| 25 import com.google.dart.engine.source.SourceFactory; | 25 import com.google.dart.engine.source.SourceFactory; |
| 26 import com.google.dart.engine.source.UriKind; | 26 import com.google.dart.engine.source.UriKind; |
| 27 import com.google.dart.tools.core.DartCore; | 27 import com.google.dart.tools.core.DartCore; |
| 28 | 28 |
| 29 import org.eclipse.core.runtime.FileLocator; |
| 29 import org.eclipse.core.runtime.IProgressMonitor; | 30 import org.eclipse.core.runtime.IProgressMonitor; |
| 30 import org.eclipse.core.runtime.IStatus; | 31 import org.eclipse.core.runtime.IStatus; |
| 31 import org.eclipse.core.runtime.Platform; | 32 import org.eclipse.core.runtime.Platform; |
| 32 import org.eclipse.core.runtime.Status; | 33 import org.eclipse.core.runtime.Status; |
| 33 import org.eclipse.core.runtime.SubMonitor; | 34 import org.eclipse.core.runtime.SubMonitor; |
| 34 | 35 |
| 35 import java.io.BufferedInputStream; | 36 import java.io.BufferedInputStream; |
| 36 import java.io.BufferedOutputStream; | 37 import java.io.BufferedOutputStream; |
| 37 import java.io.File; | 38 import java.io.File; |
| 38 import java.io.FileInputStream; | 39 import java.io.FileInputStream; |
| 40 import java.io.FileNotFoundException; |
| 39 import java.io.FileOutputStream; | 41 import java.io.FileOutputStream; |
| 42 import java.io.FileReader; |
| 40 import java.io.IOException; | 43 import java.io.IOException; |
| 41 import java.io.InputStream; | 44 import java.io.InputStream; |
| 42 import java.io.OutputStream; | 45 import java.io.OutputStream; |
| 43 import java.net.URI; | 46 import java.net.URI; |
| 47 import java.net.URISyntaxException; |
| 48 import java.net.URL; |
| 44 import java.net.URLConnection; | 49 import java.net.URLConnection; |
| 45 import java.util.ArrayList; | 50 import java.util.ArrayList; |
| 46 import java.util.List; | 51 import java.util.List; |
| 52 import java.util.Properties; |
| 47 import java.util.zip.ZipEntry; | 53 import java.util.zip.ZipEntry; |
| 48 import java.util.zip.ZipInputStream; | 54 import java.util.zip.ZipInputStream; |
| 49 | 55 |
| 50 // http://commondatastorage.googleapis.com/dart-editor-archive-integration/lates
t/dartsdk-macos-32.zip | 56 // http://commondatastorage.googleapis.com/dart-editor-archive-integration/lates
t/dartsdk-macos-32.zip |
| 51 | 57 |
| 52 // TOOD(devoncarew): refactor the download/unzip/copy code into utility methods
(to be | 58 // TOOD(devoncarew): refactor the download/unzip/copy code into utility methods
(to be |
| 53 // shared with the update code). | 59 // shared with the update code). |
| 54 | 60 |
| 55 /** | 61 /** |
| 56 * The clearing house for getting the current SDK and listening for SDK changes. | 62 * The clearing house for getting the current SDK and listening for SDK changes. |
| 57 * | 63 * |
| 58 * @coverage dart.tools.core.model | 64 * @coverage dart.tools.core.model |
| 59 */ | 65 */ |
| 60 public class DartSdkManager { | 66 public class DartSdkManager { |
| 61 | 67 |
| 62 private static final String SDK_GS_PREFIX = "http://commondatastorage.googleap
is.com/dart-archive/channels/dev/release/latest/sdk/dartsdk-"; | 68 /** |
| 69 * Environment variable key for user-specified update URLs. |
| 70 */ |
| 71 public static final String UPDATE_URL_ENV_VAR = "com.dart.tools.update.core.ur
l"; |
| 72 |
| 73 private static final String DEFAULT_UPDATE_URL = "http://dartlang.org/editor/u
pdate/channels/dev/"; |
| 63 | 74 |
| 64 /** | 75 /** |
| 65 * A special instance of {@link com.google.dart.engine.sdk.DartSdk} representi
ng missing SDK. | 76 * A special instance of {@link com.google.dart.engine.sdk.DartSdk} representi
ng missing SDK. |
| 66 */ | 77 */ |
| 67 public static final com.google.dart.engine.sdk.DartSdk NO_SDK = new com.google
.dart.engine.sdk.DartSdk() { | 78 public static final com.google.dart.engine.sdk.DartSdk NO_SDK = new com.google
.dart.engine.sdk.DartSdk() { |
| 68 private final SdkLibrary[] libraries = new SdkLibrary[] {}; | 79 private final SdkLibrary[] libraries = new SdkLibrary[] {}; |
| 69 private final String[] uris = new String[] {DART_CORE}; | 80 private final String[] uris = new String[] {DART_CORE}; |
| 70 private AnalysisContext sdkContext; | 81 private AnalysisContext sdkContext; |
| 71 private FileBasedSource coreSource; | 82 private FileBasedSource coreSource; |
| 72 | 83 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 336 } |
| 326 } | 337 } |
| 327 | 338 |
| 328 dir.delete(); | 339 dir.delete(); |
| 329 } | 340 } |
| 330 | 341 |
| 331 private File downloadFile(IProgressMonitor monitor) throws IOException { | 342 private File downloadFile(IProgressMonitor monitor) throws IOException { |
| 332 File tempFile = File.createTempFile(SDK_DIR_NAME, ".zip"); | 343 File tempFile = File.createTempFile(SDK_DIR_NAME, ".zip"); |
| 333 tempFile.deleteOnExit(); | 344 tempFile.deleteOnExit(); |
| 334 | 345 |
| 335 URI downloadURI = URI.create(SDK_GS_PREFIX + getPlatformCode() + "-" + getPl
atformBititude() | 346 URI downloadURI = URI.create(getSdkUrl()); |
| 336 + "-release.zip"); | |
| 337 | 347 |
| 338 URLConnection connection = downloadURI.toURL().openConnection(); | 348 URLConnection connection = downloadURI.toURL().openConnection(); |
| 339 | 349 |
| 340 int length = connection.getContentLength(); | 350 int length = connection.getContentLength(); |
| 341 | 351 |
| 342 FileOutputStream out = new FileOutputStream(tempFile); | 352 FileOutputStream out = new FileOutputStream(tempFile); |
| 343 | 353 |
| 344 monitor.beginTask("Download SDK", length); | 354 monitor.beginTask("Download SDK", length); |
| 345 | 355 |
| 346 copyStream(connection.getInputStream(), out, monitor, length); | 356 copyStream(connection.getInputStream(), out, monitor, length); |
| 347 | 357 |
| 348 monitor.done(); | 358 monitor.done(); |
| 349 | 359 |
| 350 if (connection.getLastModified() != 0) { | 360 if (connection.getLastModified() != 0) { |
| 351 tempFile.setLastModified(connection.getLastModified()); | 361 tempFile.setLastModified(connection.getLastModified()); |
| 352 } | 362 } |
| 353 | 363 |
| 354 return tempFile; | 364 return tempFile; |
| 355 } | 365 } |
| 356 | 366 |
| 367 private String getSdkUrl() { |
| 368 String url = getUpdateChannelUrl(); |
| 369 if (url == null) { |
| 370 url = DEFAULT_UPDATE_URL; |
| 371 } |
| 372 return url + "latest/sdk/dartsdk-" + getPlatformCode() + "-" + getPlatformBi
titude() |
| 373 + "-release.zip"; |
| 374 } |
| 375 |
| 376 private String getUpdateChannelUrl() { |
| 377 try { |
| 378 URL url = new URL("platform:/plugin/com.google.dart.tools.core/update.prop
erties"); |
| 379 File file = new File(FileLocator.resolve(url).toURI()); |
| 380 if (file.exists()) { |
| 381 Properties properties = new Properties(); |
| 382 properties.load(new FileReader(file)); |
| 383 return properties.getProperty(UPDATE_URL_ENV_VAR); |
| 384 } |
| 385 } catch (FileNotFoundException e) { |
| 386 DartCore.logError(e); |
| 387 } catch (IOException e) { |
| 388 DartCore.logError(e); |
| 389 } catch (URISyntaxException e) { |
| 390 DartCore.logError(e); |
| 391 } |
| 392 return null; |
| 393 } |
| 394 |
| 357 private void initSdk() { | 395 private void initSdk() { |
| 358 if (getDefaultPluginsSdkDirectory().exists()) { | 396 if (getDefaultPluginsSdkDirectory().exists()) { |
| 359 oldSdk = new DartSdk(getDefaultPluginsSdkDirectory()); | 397 oldSdk = new DartSdk(getDefaultPluginsSdkDirectory()); |
| 360 } else if (getDefaultEditorSdkDirectory().exists()) { | 398 } else if (getDefaultEditorSdkDirectory().exists()) { |
| 361 oldSdk = new DartSdk(getDefaultEditorSdkDirectory()); | 399 oldSdk = new DartSdk(getDefaultEditorSdkDirectory()); |
| 362 } else { | 400 } else { |
| 363 oldSdk = NONE; | 401 oldSdk = NONE; |
| 364 } | 402 } |
| 365 } | 403 } |
| 366 | 404 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 initSdk(); | 478 initSdk(); |
| 441 | 479 |
| 442 // send upgrade notifications | 480 // send upgrade notifications |
| 443 notifyListeners(); | 481 notifyListeners(); |
| 444 } finally { | 482 } finally { |
| 445 monitor.done(); | 483 monitor.done(); |
| 446 } | 484 } |
| 447 } | 485 } |
| 448 | 486 |
| 449 } | 487 } |
| OLD | NEW |