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; | |
17 import com.google.dart.compiler.DartCompiler; | 16 import com.google.dart.compiler.DartCompiler; |
18 import com.google.dart.compiler.DartCompilerListener; | 17 import com.google.dart.compiler.DartCompilerListener; |
19 import com.google.dart.compiler.DefaultCompilerConfiguration; | 18 import com.google.dart.compiler.DefaultCompilerConfiguration; |
20 import com.google.dart.compiler.DefaultDartCompilerListener; | 19 import com.google.dart.compiler.DefaultDartCompilerListener; |
21 import com.google.dart.compiler.DefaultErrorFormatter; | 20 import com.google.dart.compiler.DefaultErrorFormatter; |
22 import com.google.dart.compiler.LibrarySource; | 21 import com.google.dart.compiler.LibrarySource; |
23 import com.google.dart.compiler.Source; | 22 import com.google.dart.compiler.Source; |
24 import com.google.dart.compiler.UnitTestBatchRunner; | 23 import com.google.dart.compiler.UnitTestBatchRunner; |
25 import com.google.dart.compiler.UnitTestBatchRunner.Invocation; | 24 import com.google.dart.compiler.UnitTestBatchRunner.Invocation; |
26 import com.google.dart.compiler.UrlLibrarySource; | 25 import com.google.dart.compiler.UrlLibrarySource; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 System.exit(1); | 67 System.exit(1); |
69 } | 68 } |
70 | 69 |
71 assert parsedOptions != null; | 70 assert parsedOptions != null; |
72 return parsedOptions; | 71 return parsedOptions; |
73 } | 72 } |
74 | 73 |
75 public static void main(String[] args) { | 74 public static void main(String[] args) { |
76 try { | 75 try { |
77 boolean runBatch = false; | 76 boolean runBatch = false; |
78 final List<LibrarySource> imports = Collections.emptyList(); | |
79 DartRunnerOptions options = processCommandLineOptions(args); | 77 DartRunnerOptions options = processCommandLineOptions(args); |
80 if (options.shouldBatch()) { | 78 if (options.shouldBatch()) { |
81 runBatch = true; | 79 runBatch = true; |
82 if (args.length > 1) { | 80 if (args.length > 1) { |
83 System.err | 81 System.err |
84 .println("(Extra arguments specified with -batch ignored.)"); | 82 .println("(Extra arguments specified with -batch ignored.)"); |
85 } | 83 } |
86 } | 84 } |
87 if (runBatch) { | 85 if (runBatch) { |
88 UnitTestBatchRunner.runAsBatch(args, new Invocation() { | 86 UnitTestBatchRunner.runAsBatch(args, new Invocation() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 | 119 |
122 String script = options.getSourceFiles().get(0); | 120 String script = options.getSourceFiles().get(0); |
123 ArrayList<String> scriptArguments = new ArrayList<String>(); | 121 ArrayList<String> scriptArguments = new ArrayList<String>(); |
124 | 122 |
125 LibrarySource app = new UrlLibrarySource(new File(script)); | 123 LibrarySource app = new UrlLibrarySource(new File(script)); |
126 | 124 |
127 File outFile = options.getOutputFilename(); | 125 File outFile = options.getOutputFilename(); |
128 | 126 |
129 DefaultDartCompilerListener listener = new DefaultDartCompilerListener() { | 127 DefaultDartCompilerListener listener = new DefaultDartCompilerListener() { |
130 { | 128 { |
131 ((DefaultErrorFormatter) formatter).setOutputStream(stderr); | 129 ((DefaultErrorFormatter) formatter).setOutputStream(stderr); |
zundel
2011/10/27 16:19:54
this is pretty ugly, could you make an overload co
| |
132 } | 130 } |
133 @Override | |
134 public void compilationWarning(DartCompilationError event) { | |
135 compilationError(event); | |
136 } | |
137 }; | 131 }; |
138 | 132 |
139 CompilationResult compiled; | 133 CompilationResult compiled; |
140 compiled = compileApp(app, imports, options, listener); | 134 compiled = compileApp(app, imports, options, listener); |
141 | 135 |
142 if (listener.getProblemCount() != 0) { | 136 if (listener.getErrorCount() != 0) { |
143 throw new RunnerError("Compilation failed."); | 137 throw new RunnerError("Compilation failed."); |
144 } | 138 } |
145 | 139 |
146 if (outFile != null) { | 140 if (outFile != null) { |
147 File dir = outFile.getParentFile(); | 141 File dir = outFile.getParentFile(); |
148 if (dir != null) { | 142 if (dir != null) { |
149 if (!dir.exists()) { | 143 if (!dir.exists()) { |
150 throw new RunnerError("Cannot create: " + outFile.getName() | 144 throw new RunnerError("Cannot create: " + outFile.getName() |
151 + ". " + dir + " does not exist"); | 145 + ". " + dir + " does not exist"); |
152 } | 146 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension()); | 344 Reader r = provider.getArtifactReader(app, "", backend.getAppExtension()); |
351 String js = CharStreams.toString(r); | 345 String js = CharStreams.toString(r); |
352 r.close(); | 346 r.close(); |
353 return new CompilationResult(js, mapping); | 347 return new CompilationResult(js, mapping); |
354 } catch (IOException e) { | 348 } catch (IOException e) { |
355 // This can't happen; it's just a StringWriter. | 349 // This can't happen; it's just a StringWriter. |
356 throw new AssertionError(e); | 350 throw new AssertionError(e); |
357 } | 351 } |
358 } | 352 } |
359 } | 353 } |
OLD | NEW |