| Index: pkg/analysis_server/bin/dartdeps.dart
|
| diff --git a/pkg/analysis_server/bin/dartdeps.dart b/pkg/analysis_server/bin/dartdeps.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e67cd1e029dae09954ba4358a48fcfc49b198a8e
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/bin/dartdeps.dart
|
| @@ -0,0 +1,104 @@
|
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'dart:async';
|
| +import 'dart:io';
|
| +
|
| +import 'package:args/args.dart';
|
| +import 'package:analysis_server/src/analysis_manager.dart';
|
| +
|
| +/**
|
| + * Start analysis server as a separate process and use the websocket protocol
|
| + * to analyze the application specified on the command line.
|
| + */
|
| +void main(List<String> args) {
|
| + _DartDependencyAnalyzer analyzer = new _DartDependencyAnalyzer();
|
| + analyzer.start(args);
|
| +}
|
| +
|
| +/**
|
| + * Instances of [_DartDependencyAnalyzer] launch an analysis server and use
|
| + * that server to analyze the dependencies of an application.
|
| + */
|
| +class _DartDependencyAnalyzer {
|
| + /**
|
| + * The name of the application that is used to start the analyzer.
|
| + */
|
| + static const BINARY_NAME = 'dartdeps';
|
| +
|
| + /**
|
| + * The name of the option used to print usage information.
|
| + */
|
| + static const String HELP_OPTION = "help";
|
| +
|
| + /**
|
| + * Parse the command line arguments to determine the application to be
|
| + * analyzed, then launch and manage an analysis server to do the work.
|
| + * If there is a problem with the given arguments, then return a non zero
|
| + * value, otherwise return zero.
|
| + */
|
| + void start(List<String> args) {
|
| + var parser = new ArgParser();
|
| + parser.addFlag(HELP_OPTION, help:
|
| + "print this help message without starting analysis", defaultsTo: false,
|
| + negatable: false);
|
| +
|
| + // Parse arguments
|
| + ArgResults results = parser.parse(args);
|
| + if (results[HELP_OPTION]) {
|
| + printUsage(parser);
|
| + return;
|
| + }
|
| + if (results.rest.length == 0) {
|
| + printUsage(parser);
|
| + exitCode = 1;
|
| + return;
|
| + }
|
| + Directory appDir = new Directory(results.rest[0]);
|
| + if (!appDir.existsSync()) {
|
| + print('Specified application directory does not exist: $appDir');
|
| + print('');
|
| + printUsage(parser);
|
| + exitCode = 1;
|
| + return;
|
| + }
|
| + if (results.rest.length > 1) {
|
| + print('Unexpected arguments after $appDir');
|
| + print('');
|
| + printUsage(parser);
|
| + exitCode = 1;
|
| + return;
|
| + }
|
| +
|
| + // Assume that the analysis server entry point is in the same directory
|
| + StringBuffer path = new StringBuffer();
|
| + path.write(FileSystemEntity.parentOf(Platform.script.toFilePath()));
|
| + path.write(Platform.pathSeparator);
|
| + path.write("server.dart");
|
| +
|
| + // Launch analysis server
|
| + AnalysisManager.start(path.toString()).then(analyze);
|
| + }
|
| +
|
| + void analyze(AnalysisManager mgr) {
|
| + print("Analyzing...");
|
| + new Timer(new Duration(seconds: 5), () {
|
| + if (mgr.stop()) {
|
| + print("stopped");
|
| + } else {
|
| + print("already stopped");
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Print information about how to use the server.
|
| + */
|
| + void printUsage(ArgParser parser) {
|
| + print('Usage: $BINARY_NAME [flags] <application_directory>');
|
| + print('');
|
| + print('Supported flags are:');
|
| + print(parser.getUsage());
|
| + }
|
| +}
|
|
|