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

Unified Diff: pkg/analysis_server/lib/src/server/driver.dart

Issue 1063153004: Convert analyzer and analysis_server to use the plugin package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/server/driver.dart
diff --git a/pkg/analysis_server/lib/src/server/driver.dart b/pkg/analysis_server/lib/src/server/driver.dart
index 36ba37b944c1c8a8776473e0291f3e8a661b9522..9a467e4b2d48f93b7d8eb54558e7f28107ada535 100644
--- a/pkg/analysis_server/lib/src/server/driver.dart
+++ b/pkg/analysis_server/lib/src/server/driver.dart
@@ -17,14 +17,14 @@ import 'package:analysis_server/starter.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/instrumentation/file_instrumentation.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
-import 'package:analyzer/plugin/plugin.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/incremental_logger.dart';
import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/sdk_io.dart';
-import 'package:analyzer/src/plugin/plugin_impl.dart';
import 'package:args/args.dart';
+import 'package:plugin/manager.dart';
+import 'package:plugin/plugin.dart';
/**
* Initializes incremental logger.
@@ -51,6 +51,130 @@ void _initIncrementalLogger(String spec) {
}
}
+/// Commandline argument parser. (Copied from analyzer/lib/options.dart)
+/// TODO(pquitslund): replaces with a simple [ArgParser] instance
+/// when the args package supports ignoring unrecognized
+/// options/flags (https://github.com/dart-lang/args/issues/9).
+class CommandLineParser {
+ final List<String> _knownFlags;
+ final bool _alwaysIgnoreUnrecognized;
+ final ArgParser _parser;
+
+ /// Creates a new command line parser
+ CommandLineParser({bool alwaysIgnoreUnrecognized: false})
+ : _knownFlags = <String>[],
+ _alwaysIgnoreUnrecognized = alwaysIgnoreUnrecognized,
+ _parser = new ArgParser(allowTrailingOptions: true);
+
+ ArgParser get parser => _parser;
+
+ /// Defines a flag.
+ /// See [ArgParser.addFlag()].
+ void addFlag(String name, {String abbr, String help, bool defaultsTo: false,
+ bool negatable: true, void callback(bool value), bool hide: false}) {
+ _knownFlags.add(name);
+ _parser.addFlag(name,
+ abbr: abbr,
+ help: help,
+ defaultsTo: defaultsTo,
+ negatable: negatable,
+ callback: callback,
+ hide: hide);
+ }
+
+ /// Defines a value-taking option.
+ /// See [ArgParser.addOption()].
+ void addOption(String name, {String abbr, String help, List<String> allowed,
+ Map<String, String> allowedHelp, String defaultsTo, void callback(value),
+ bool allowMultiple: false}) {
+ _knownFlags.add(name);
+ _parser.addOption(name,
+ abbr: abbr,
+ help: help,
+ allowed: allowed,
+ allowedHelp: allowedHelp,
+ defaultsTo: defaultsTo,
+ callback: callback,
+ allowMultiple: allowMultiple);
+ }
+
+ /// Generates a string displaying usage information for the defined options.
+ /// See [ArgParser.usage].
+ String getUsage() => _parser.usage;
+
+ /// Parses [args], a list of command-line arguments, matches them against the
+ /// flags and options defined by this parser, and returns the result. The
+ /// values of any defined variables are captured in the given map.
+ /// See [ArgParser].
+ ArgResults parse(
+ List<String> args, Map<String, String> definedVariables) => _parser
+ .parse(_filterUnknowns(parseDefinedVariables(args, definedVariables)));
+
+ List<String> parseDefinedVariables(
+ List<String> args, Map<String, String> definedVariables) {
+ int count = args.length;
+ List<String> remainingArgs = <String>[];
+ for (int i = 0; i < count; i++) {
+ String arg = args[i];
+ if (arg == '--') {
+ while (i < count) {
+ remainingArgs.add(args[i++]);
+ }
+ } else if (arg.startsWith("-D")) {
+ definedVariables[arg.substring(2)] = args[++i];
+ } else {
+ remainingArgs.add(arg);
+ }
+ }
+ return remainingArgs;
+ }
+
+ List<String> _filterUnknowns(List<String> args) {
+
+ // Only filter args if the ignore flag is specified, or if
+ // _alwaysIgnoreUnrecognized was set to true
+ if (_alwaysIgnoreUnrecognized ||
+ args.contains('--ignore-unrecognized-flags')) {
+
+ // Filter all unrecognized flags and options.
+ List<String> filtered = <String>[];
+ for (int i = 0; i < args.length; ++i) {
+ String arg = args[i];
+ if (arg.startsWith('--') && arg.length > 2) {
+ String option = arg.substring(2);
+ // strip the last '=value'
+ int equalsOffset = option.lastIndexOf('=');
+ if (equalsOffset != -1) {
+ option = option.substring(0, equalsOffset);
+ }
+ // check the option
+ if (!_knownFlags.contains(option)) {
+ //"eat" params by advancing to the next flag/option
+ i = _getNextFlagIndex(args, i);
+ } else {
+ filtered.add(arg);
+ }
+ } else {
+ filtered.add(arg);
+ }
+ }
+
+ return filtered;
+ } else {
+ return args;
+ }
+ }
+
+ _getNextFlagIndex(args, i) {
+ for (; i < args.length; ++i) {
+ if (args[i].startsWith('--')) {
+ return i;
+ }
+ }
+ return i;
+ }
+}
+
/**
* The [Driver] class represents a single running instance of the analysis
* server application. It is responsible for parsing command line options
@@ -418,127 +542,3 @@ class Driver implements ServerStarter {
return uuid;
}
}
-
-/// Commandline argument parser. (Copied from analyzer/lib/options.dart)
-/// TODO(pquitslund): replaces with a simple [ArgParser] instance
-/// when the args package supports ignoring unrecognized
-/// options/flags (https://github.com/dart-lang/args/issues/9).
-class CommandLineParser {
- final List<String> _knownFlags;
- final bool _alwaysIgnoreUnrecognized;
- final ArgParser _parser;
-
- /// Creates a new command line parser
- CommandLineParser({bool alwaysIgnoreUnrecognized: false})
- : _knownFlags = <String>[],
- _alwaysIgnoreUnrecognized = alwaysIgnoreUnrecognized,
- _parser = new ArgParser(allowTrailingOptions: true);
-
- ArgParser get parser => _parser;
-
- /// Defines a flag.
- /// See [ArgParser.addFlag()].
- void addFlag(String name, {String abbr, String help, bool defaultsTo: false,
- bool negatable: true, void callback(bool value), bool hide: false}) {
- _knownFlags.add(name);
- _parser.addFlag(name,
- abbr: abbr,
- help: help,
- defaultsTo: defaultsTo,
- negatable: negatable,
- callback: callback,
- hide: hide);
- }
-
- /// Defines a value-taking option.
- /// See [ArgParser.addOption()].
- void addOption(String name, {String abbr, String help, List<String> allowed,
- Map<String, String> allowedHelp, String defaultsTo, void callback(value),
- bool allowMultiple: false}) {
- _knownFlags.add(name);
- _parser.addOption(name,
- abbr: abbr,
- help: help,
- allowed: allowed,
- allowedHelp: allowedHelp,
- defaultsTo: defaultsTo,
- callback: callback,
- allowMultiple: allowMultiple);
- }
-
- /// Generates a string displaying usage information for the defined options.
- /// See [ArgParser.usage].
- String getUsage() => _parser.usage;
-
- /// Parses [args], a list of command-line arguments, matches them against the
- /// flags and options defined by this parser, and returns the result. The
- /// values of any defined variables are captured in the given map.
- /// See [ArgParser].
- ArgResults parse(
- List<String> args, Map<String, String> definedVariables) => _parser
- .parse(_filterUnknowns(parseDefinedVariables(args, definedVariables)));
-
- List<String> parseDefinedVariables(
- List<String> args, Map<String, String> definedVariables) {
- int count = args.length;
- List<String> remainingArgs = <String>[];
- for (int i = 0; i < count; i++) {
- String arg = args[i];
- if (arg == '--') {
- while (i < count) {
- remainingArgs.add(args[i++]);
- }
- } else if (arg.startsWith("-D")) {
- definedVariables[arg.substring(2)] = args[++i];
- } else {
- remainingArgs.add(arg);
- }
- }
- return remainingArgs;
- }
-
- List<String> _filterUnknowns(List<String> args) {
-
- // Only filter args if the ignore flag is specified, or if
- // _alwaysIgnoreUnrecognized was set to true
- if (_alwaysIgnoreUnrecognized ||
- args.contains('--ignore-unrecognized-flags')) {
-
- // Filter all unrecognized flags and options.
- List<String> filtered = <String>[];
- for (int i = 0; i < args.length; ++i) {
- String arg = args[i];
- if (arg.startsWith('--') && arg.length > 2) {
- String option = arg.substring(2);
- // strip the last '=value'
- int equalsOffset = option.lastIndexOf('=');
- if (equalsOffset != -1) {
- option = option.substring(0, equalsOffset);
- }
- // check the option
- if (!_knownFlags.contains(option)) {
- //"eat" params by advancing to the next flag/option
- i = _getNextFlagIndex(args, i);
- } else {
- filtered.add(arg);
- }
- } else {
- filtered.add(arg);
- }
- }
-
- return filtered;
- } else {
- return args;
- }
- }
-
- _getNextFlagIndex(args, i) {
- for (; i < args.length; ++i) {
- if (args[i].startsWith('--')) {
- return i;
- }
- }
- return i;
- }
-}
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/server_plugin.dart ('k') | pkg/analysis_server/lib/src/socket_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698