| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
| 9 import 'package:analysis_server/src/analysis_manager.dart'; | 9 import 'package:analysis_server/src/analysis_manager.dart'; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * Instances of [_DartDependencyAnalyzer] launch an analysis server and use | 26 * Instances of [_DartDependencyAnalyzer] launch an analysis server and use |
| 27 * that server to analyze the dependencies of an application. | 27 * that server to analyze the dependencies of an application. |
| 28 */ | 28 */ |
| 29 class _DartDependencyAnalyzer { | 29 class _DartDependencyAnalyzer { |
| 30 /** | 30 /** |
| 31 * The name of the application that is used to start the analyzer. | 31 * The name of the application that is used to start the analyzer. |
| 32 */ | 32 */ |
| 33 static const BINARY_NAME = 'dartdeps'; | 33 static const BINARY_NAME = 'dartdeps'; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * The name of the option used to specify the Dart SDK. |
| 37 */ |
| 38 static const String DART_SDK_OPTION = 'dart-sdk'; |
| 39 |
| 40 /** |
| 36 * The name of the option used to print usage information. | 41 * The name of the option used to print usage information. |
| 37 */ | 42 */ |
| 38 static const String HELP_OPTION = 'help'; | 43 static const String HELP_OPTION = 'help'; |
| 39 | 44 |
| 40 /** | 45 /** |
| 41 * The name of the option used to specify an already running server. | 46 * The name of the option used to specify an already running server. |
| 42 */ | 47 */ |
| 43 static const String SERVER_OPTION = 'server'; | 48 static const String SERVER_OPTION = 'server'; |
| 44 | 49 |
| 45 /** | 50 /** |
| 46 * The command line arguments. | 51 * The command line arguments. |
| 47 */ | 52 */ |
| 48 final List<String> args; | 53 final List<String> args; |
| 49 | 54 |
| 50 /** | 55 /** |
| 56 * The path to the Dart SDK used during analysis. |
| 57 */ |
| 58 String sdkPath; |
| 59 |
| 60 /** |
| 51 * The manager for the analysis server. | 61 * The manager for the analysis server. |
| 52 */ | 62 */ |
| 53 AnalysisManager manager; | 63 AnalysisManager manager; |
| 54 | 64 |
| 55 _DartDependencyAnalyzer(this.args); | 65 _DartDependencyAnalyzer(this.args); |
| 56 | 66 |
| 57 /** | 67 /** |
| 58 * Parse the command line arguments to determine the application to be | 68 * Parse the command line arguments to determine the application to be |
| 59 * analyzed, then launch and manage an analysis server to do the work. | 69 * analyzed, then launch and manage an analysis server to do the work. |
| 60 */ | 70 */ |
| 61 Future run() { | 71 Future run() { |
| 62 return new Future(start).then(analyze).whenComplete(stop); | 72 return new Future(start).then(analyze).whenComplete(stop); |
| 63 } | 73 } |
| 64 | 74 |
| 65 /** | 75 /** |
| 66 * Parse the command line arguments to determine the application to be | 76 * Parse the command line arguments to determine the application to be |
| 67 * analyzed, then launch an analysis server. | 77 * analyzed, then launch an analysis server. |
| 68 * Return `null` if the command line arguments are invalid. | 78 * Return `null` if the command line arguments are invalid. |
| 69 */ | 79 */ |
| 70 Future<AnalysisManager> start() { | 80 Future<AnalysisManager> start() { |
| 71 var parser = new ArgParser(); | 81 var parser = new ArgParser(); |
| 82 parser.addOption( |
| 83 DART_SDK_OPTION, |
| 84 help: '[sdkPath] path to Dart SDK'); |
| 72 parser.addFlag(HELP_OPTION, | 85 parser.addFlag(HELP_OPTION, |
| 73 help: 'print this help message without starting analysis', | 86 help: 'print this help message without starting analysis', |
| 74 defaultsTo: false, | 87 defaultsTo: false, |
| 75 negatable: false); | 88 negatable: false); |
| 76 parser.addOption( | 89 parser.addOption( |
| 77 SERVER_OPTION, | 90 SERVER_OPTION, |
| 78 help: '[serverUrl] use an analysis server thats already running'); | 91 help: '[serverUrl] use an analysis server thats already running'); |
| 79 | 92 |
| 80 // Parse arguments | 93 // Parse arguments |
| 81 ArgResults results; | 94 ArgResults results; |
| 82 try { | 95 try { |
| 83 results = parser.parse(args); | 96 results = parser.parse(args); |
| 84 } on FormatException catch(e) { | 97 } on FormatException catch(e) { |
| 85 print(e.message); | 98 print(e.message); |
| 86 print(''); | 99 print(''); |
| 87 printUsage(parser); | 100 printUsage(parser); |
| 88 exitCode = 1; | 101 exitCode = 1; |
| 89 return null; | 102 return null; |
| 90 } | 103 } |
| 91 if (results[HELP_OPTION]) { | 104 if (results[HELP_OPTION]) { |
| 92 printUsage(parser); | 105 printUsage(parser); |
| 93 return null; | 106 return null; |
| 94 } | 107 } |
| 108 sdkPath = results[DART_SDK_OPTION]; |
| 109 if (sdkPath is! String) { |
| 110 print('Missing path to Dart SDK'); |
| 111 printUsage(parser); |
| 112 return null; |
| 113 } |
| 114 Directory sdkDir = new Directory(sdkPath); |
| 115 if (!sdkDir.existsSync()) { |
| 116 print('Specified Dart SDK does not exist: $sdkPath'); |
| 117 printUsage(parser); |
| 118 return null; |
| 119 } |
| 95 if (results.rest.length == 0) { | 120 if (results.rest.length == 0) { |
| 96 printUsage(parser); | 121 printUsage(parser); |
| 97 exitCode = 1; | 122 exitCode = 1; |
| 98 return null; | 123 return null; |
| 99 } | 124 } |
| 100 Directory appDir = new Directory(results.rest[0]); | 125 Directory appDir = new Directory(results.rest[0]); |
| 101 if (!appDir.existsSync()) { | 126 if (!appDir.existsSync()) { |
| 102 print('Specified application directory does not exist: $appDir'); | 127 print('Specified application directory does not exist: $appDir'); |
| 103 print(''); | 128 print(''); |
| 104 printUsage(parser); | 129 printUsage(parser); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 /** | 176 /** |
| 152 * Print information about how to use the server. | 177 * Print information about how to use the server. |
| 153 */ | 178 */ |
| 154 void printUsage(ArgParser parser) { | 179 void printUsage(ArgParser parser) { |
| 155 print('Usage: $BINARY_NAME [flags] <application_directory>'); | 180 print('Usage: $BINARY_NAME [flags] <application_directory>'); |
| 156 print(''); | 181 print(''); |
| 157 print('Supported flags are:'); | 182 print('Supported flags are:'); |
| 158 print(parser.getUsage()); | 183 print(parser.getUsage()); |
| 159 } | 184 } |
| 160 } | 185 } |
| OLD | NEW |