Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: compiler/java/com/google/dart/compiler/SystemLibrary.java

Issue 9702034: Removes dartc reliance on its own libraries, now can be targeted at any implementation's libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: junit tests fixed Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.compiler; 5 package com.google.dart.compiler;
6 6
7 import java.io.File; 7 import java.io.File;
8 import java.net.URI; 8 import java.net.URI;
9 import java.net.URISyntaxException;
10 9
11 /** 10 /**
12 * A library accessible via the "dart:<libname>.lib" protocol. 11 * A library accessible via the "dart:<libname>" protocol.
13 */ 12 */
14 public class SystemLibrary { 13 public class SystemLibrary {
15 14
16 private final String shortName; 15 private final String shortName;
17 private final String host; 16 private final String host;
18 private final String pathToLib; 17 private final String pathToLib;
19 private final File dirOrZip; 18 private final File dir;
20 19
21 /** 20 /**
22 * Define a new system library such that dart:[shortLibName] will automaticall y be expanded to 21 * Define a new system library such that dart:[shortLibName] will automaticall y be expanded to
23 * dart://[host]/[pathToLib]. For example this call 22 * dart://[host]/[pathToLib]. For example this call
24 * 23 *
25 * <pre> 24 * <pre>
26 * new SystemLibrary("dom.lib", "dom", "dart_dom.lib"); 25 * new SystemLibrary("dom", "dom", "dom.dart");
27 * </pre> 26 * </pre>
28 * 27 *
29 * will define a new system library such that "dart:dom.lib" to automatically be expanded to 28 * will define a new system library such that "dart:dom" to automatically be e xpanded to
30 * "dart://dom/dart_dom.lib". The dirOrZip argument is either the root directo ry or a zip file 29 * "dart://dom/dom.dart".
31 * containing all files for this library.
32 */ 30 */
33 public SystemLibrary(String shortName, String host, String pathToLib, File dir OrZip) { 31 public SystemLibrary(String shortName, String host, String pathToLib) {
34 this.shortName = shortName; 32 this.shortName = shortName;
35 this.host = host; 33 this.host = host;
36 this.pathToLib = pathToLib; 34 this.pathToLib = pathToLib;
37 this.dirOrZip = dirOrZip; 35 this.dir = new File(this.pathToLib).getParentFile();
38 } 36 }
39 37
40 public String getHost() { 38 public String getHost() {
41 return host; 39 return host;
42 } 40 }
43 41
44 public String getPathToLib() { 42 public String getPathToLib() {
45 return pathToLib; 43 return pathToLib;
46 } 44 }
47 45
48 public String getShortName() { 46 public String getShortName() {
49 return shortName; 47 return shortName;
50 } 48 }
51 49
52 public URI translateUri(URI dartUri) { 50 public URI translateUri(URI dartUri) {
53 if (!dirOrZip.exists()) { 51
54 throw new RuntimeException("System library for " + dartUri + " does not ex ist: " + dirOrZip.getPath()); 52 URI dirURI = dir.toURI();
55 } 53 return dirURI.resolve("." + dartUri.getPath());
56 try {
57 URI dirOrZipURI = dirOrZip.toURI();
58 if (dirOrZip.isFile()) {
59 return new URI("jar", "file:" + dirOrZipURI.getPath() + "!" + dartUri.ge tPath(), null);
60 } else {
61 return dirOrZipURI.resolve("." + dartUri.getPath());
62 }
63 } catch (URISyntaxException e) {
64 throw new AssertionError();
65 }
66 } 54 }
67 55
68 public File getFile() { 56 public File getFile() {
69 return this.dirOrZip; 57 return this.dir;
70 } 58 }
71 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698