OLD | NEW |
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.runner; | 5 package com.google.dart.runner; |
6 | 6 |
7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
9 import com.google.common.io.CharStreams; | 9 import com.google.common.io.CharStreams; |
10 import com.google.common.io.Files; | 10 import com.google.common.io.Files; |
11 import com.google.dart.compiler.Backend; | 11 import com.google.dart.compiler.Backend; |
12 import com.google.dart.compiler.CommandLineOptions; | 12 import com.google.dart.compiler.CommandLineOptions; |
13 import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions; | 13 import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions; |
14 import com.google.dart.compiler.CompilerConfiguration; | 14 import com.google.dart.compiler.CompilerConfiguration; |
15 import com.google.dart.compiler.DartArtifactProvider; | 15 import com.google.dart.compiler.DartArtifactProvider; |
16 import com.google.dart.compiler.DartCompilationError; | 16 import com.google.dart.compiler.DartCompilationError; |
17 import com.google.dart.compiler.DartCompiler; | 17 import com.google.dart.compiler.DartCompiler; |
18 import com.google.dart.compiler.DartCompilerListener; | 18 import com.google.dart.compiler.DartCompilerListener; |
19 import com.google.dart.compiler.DartSource; | |
20 import com.google.dart.compiler.DefaultCompilerConfiguration; | 19 import com.google.dart.compiler.DefaultCompilerConfiguration; |
21 import com.google.dart.compiler.DefaultDartCompilerListener; | 20 import com.google.dart.compiler.DefaultDartCompilerListener; |
22 import com.google.dart.compiler.DefaultErrorFormatter; | 21 import com.google.dart.compiler.DefaultErrorFormatter; |
23 import com.google.dart.compiler.LibrarySource; | 22 import com.google.dart.compiler.LibrarySource; |
24 import com.google.dart.compiler.Source; | 23 import com.google.dart.compiler.Source; |
25 import com.google.dart.compiler.UnitTestBatchRunner; | 24 import com.google.dart.compiler.UnitTestBatchRunner; |
26 import com.google.dart.compiler.UnitTestBatchRunner.Invocation; | 25 import com.google.dart.compiler.UnitTestBatchRunner.Invocation; |
27 import com.google.dart.compiler.UrlLibrarySource; | 26 import com.google.dart.compiler.UrlLibrarySource; |
28 import com.google.dart.compiler.backend.js.ClosureJsBackend; | 27 import com.google.dart.compiler.backend.js.ClosureJsBackend; |
29 import com.google.dart.compiler.backend.js.JavascriptBackend; | 28 import com.google.dart.compiler.backend.js.JavascriptBackend; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 List<LibrarySource> imports = Lists.newArrayList(); | 117 List<LibrarySource> imports = Lists.newArrayList(); |
119 if (options.getSourceFiles().isEmpty()) { | 118 if (options.getSourceFiles().isEmpty()) { |
120 throw new RunnerError("No script files specified on the command line: " +
Joiner.on(" ").join(args)); | 119 throw new RunnerError("No script files specified on the command line: " +
Joiner.on(" ").join(args)); |
121 } | 120 } |
122 | 121 |
123 String script = options.getSourceFiles().get(0); | 122 String script = options.getSourceFiles().get(0); |
124 ArrayList<String> scriptArguments = new ArrayList<String>(); | 123 ArrayList<String> scriptArguments = new ArrayList<String>(); |
125 | 124 |
126 LibrarySource app = new UrlLibrarySource(new File(script)); | 125 LibrarySource app = new UrlLibrarySource(new File(script)); |
127 | 126 |
128 if (options.shouldExposeCoreImpl()) { | |
129 imports = new ArrayList<LibrarySource>(imports); | |
130 // use a place-holder LibrarySource instance, to be replaced when embedded | |
131 // in the compiler, where the dart uri can be resolved. | |
132 imports.add(new NamedPlaceHolderLibrarySource("dart:coreimpl")); | |
133 } | |
134 | |
135 File outFile = options.getOutputFilename(); | 127 File outFile = options.getOutputFilename(); |
136 | 128 |
137 DefaultDartCompilerListener listener = new DefaultDartCompilerListener() { | 129 DefaultDartCompilerListener listener = new DefaultDartCompilerListener() { |
138 { | 130 { |
139 ((DefaultErrorFormatter) formatter).setOutputStream(stderr); | 131 ((DefaultErrorFormatter) formatter).setOutputStream(stderr); |
140 } | 132 } |
141 @Override | 133 @Override |
142 public void compilationWarning(DartCompilationError event) { | 134 public void compilationWarning(DartCompilationError event) { |
143 compilationError(event); | 135 compilationError(event); |
144 } | 136 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 usage.append("\n"); | 187 usage.append("\n"); |
196 | 188 |
197 OutputStream s = new ByteArrayOutputStream(); | 189 OutputStream s = new ByteArrayOutputStream(); |
198 if (cmdLineParser == null) { | 190 if (cmdLineParser == null) { |
199 cmdLineParser = new CmdLineParser(new DartRunnerOptions()); | 191 cmdLineParser = new CmdLineParser(new DartRunnerOptions()); |
200 } | 192 } |
201 usage.append(s); | 193 usage.append(s); |
202 throw new RunnerError(usage.toString()); | 194 throw new RunnerError(usage.toString()); |
203 } | 195 } |
204 | 196 |
205 private static class NamedPlaceHolderLibrarySource implements LibrarySource { | |
206 private final String name; | |
207 | |
208 public NamedPlaceHolderLibrarySource(String name) { | |
209 this.name = name; | |
210 } | |
211 | |
212 @Override | |
213 public boolean exists() { | |
214 throw new AssertionError(); | |
215 } | |
216 | |
217 @Override | |
218 public long getLastModified() { | |
219 throw new AssertionError(); | |
220 } | |
221 | |
222 @Override | |
223 public String getName() { | |
224 return name; | |
225 } | |
226 | |
227 @Override | |
228 public Reader getSourceReader() { | |
229 throw new AssertionError(); | |
230 } | |
231 | |
232 @Override | |
233 public URI getUri() { | |
234 throw new AssertionError(); | |
235 } | |
236 | |
237 @Override | |
238 public LibrarySource getImportFor(String relPath) { | |
239 throw new AssertionError(); | |
240 } | |
241 | |
242 @Override | |
243 public DartSource getSourceFor(String relPath) { | |
244 throw new AssertionError(); | |
245 } | |
246 } | |
247 | |
248 private static class RunnerDartArtifactProvider extends DartArtifactProvider { | 197 private static class RunnerDartArtifactProvider extends DartArtifactProvider { |
249 private final Map<String, StringWriter> artifacts = new ConcurrentHashMap<St
ring, StringWriter>(); | 198 private final Map<String, StringWriter> artifacts = new ConcurrentHashMap<St
ring, StringWriter>(); |
250 | 199 |
251 @Override | 200 @Override |
252 public Reader getArtifactReader(Source source, String part, String ext) { | 201 public Reader getArtifactReader(Source source, String part, String ext) { |
253 String key = getKey(source, part, ext); | 202 String key = getKey(source, part, ext); |
254 StringWriter w = artifacts.get(key); | 203 StringWriter w = artifacts.get(key); |
255 if (w == null) { | 204 if (w == null) { |
256 return null; | 205 return null; |
257 } | 206 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension()); | 350 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension()); |
402 String js = CharStreams.toString(r); | 351 String js = CharStreams.toString(r); |
403 r.close(); | 352 r.close(); |
404 return new CompilationResult(js, mapping); | 353 return new CompilationResult(js, mapping); |
405 } catch (IOException e) { | 354 } catch (IOException e) { |
406 // This can't happen; it's just a StringWriter. | 355 // This can't happen; it's just a StringWriter. |
407 throw new AssertionError(e); | 356 throw new AssertionError(e); |
408 } | 357 } |
409 } | 358 } |
410 } | 359 } |
OLD | NEW |