mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:13:04 +00:00
Add hook to command-line analyzer similar to server
R=pquitslund@google.com Review URL: https://codereview.chromium.org/1646413003 .
This commit is contained in:
parent
74f5dc2d7a
commit
3fa4b0fadb
|
@ -3,14 +3,10 @@
|
|||
// 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 'package:analyzer_cli/src/driver.dart';
|
||||
import 'package:analyzer_cli/starter.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
/// The entry point for the analyzer.
|
||||
/// The entry point for the command-line analyzer.
|
||||
void main(List<String> args) {
|
||||
var starter = new Driver();
|
||||
CommandLineStarter starter = new CommandLineStarter();
|
||||
starter.start(args);
|
||||
|
||||
}
|
||||
|
|
16
pkg/analyzer_cli/lib/plugin/analysis/resolver_provider.dart
Normal file
16
pkg/analyzer_cli/lib/plugin/analysis/resolver_provider.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
library analyzer_cli.plugin.analysis.resolver_provider;
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
||||
/**
|
||||
* A function that will return a [UriResolver] that can be used to resolve a
|
||||
* specific kind of URI within the analysis context rooted at the given folder.
|
||||
* This is currently being used to provide a package URI resolver that will be
|
||||
* used by the server (see [ServerStarter.packageResolverProvider]).
|
||||
*/
|
||||
typedef UriResolver ResolverProvider(Folder folder);
|
|
@ -30,9 +30,11 @@ import 'package:analyzer/src/generated/utilities_general.dart'
|
|||
show PerformanceTag;
|
||||
import 'package:analyzer/src/services/lint.dart';
|
||||
import 'package:analyzer/src/task/options.dart';
|
||||
import 'package:analyzer_cli/plugin/analysis/resolver_provider.dart';
|
||||
import 'package:analyzer_cli/src/analyzer_impl.dart';
|
||||
import 'package:analyzer_cli/src/options.dart';
|
||||
import 'package:analyzer_cli/src/perf_report.dart';
|
||||
import 'package:analyzer_cli/starter.dart';
|
||||
import 'package:linter/src/plugin/linter_plugin.dart';
|
||||
import 'package:package_config/discovery.dart' as pkgDiscovery;
|
||||
import 'package:package_config/packages.dart' show Packages;
|
||||
|
@ -61,7 +63,7 @@ bool containsLintRuleEntry(Map<String, YamlNode> options) {
|
|||
|
||||
typedef ErrorSeverity _BatchRunnerHandler(List<String> args);
|
||||
|
||||
class Driver {
|
||||
class Driver implements CommandLineStarter {
|
||||
static final PerformanceTag _analyzeAllTag =
|
||||
new PerformanceTag("Driver._analyzeAll");
|
||||
|
||||
|
@ -79,17 +81,20 @@ class Driver {
|
|||
/// creation.
|
||||
CommandLineOptions _previousOptions;
|
||||
|
||||
@override
|
||||
ResolverProvider packageResolverProvider;
|
||||
|
||||
/// This Driver's current analysis context.
|
||||
///
|
||||
/// *Visible for testing.*
|
||||
AnalysisContext get context => _context;
|
||||
|
||||
/// Set the [plugins] that are defined outside the `analyzer_cli` package.
|
||||
@override
|
||||
void set userDefinedPlugins(List<Plugin> plugins) {
|
||||
_userDefinedPlugins = plugins == null ? <Plugin>[] : plugins;
|
||||
}
|
||||
|
||||
/// Use the given command-line [args] to start this analysis driver.
|
||||
@override
|
||||
void start(List<String> args) {
|
||||
int startTime = new DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
|
@ -309,6 +314,21 @@ class Driver {
|
|||
Map<String, List<fileSystem.Folder>> packageMap;
|
||||
UriResolver packageUriResolver;
|
||||
|
||||
// Create a custom package resolver if one has been specified.
|
||||
if (packageResolverProvider != null) {
|
||||
fileSystem.Folder folder =
|
||||
PhysicalResourceProvider.INSTANCE.getResource('.');
|
||||
UriResolver resolver = packageResolverProvider(folder);
|
||||
if (resolver != null) {
|
||||
// TODO(brianwilkerson) This doesn't support either embedder files or sdk extensions.
|
||||
List<UriResolver> resolvers = <UriResolver>[
|
||||
new DartUriResolver(sdk),
|
||||
resolver,
|
||||
new FileUriResolver()
|
||||
];
|
||||
return new SourceFactory(resolvers);
|
||||
}
|
||||
}
|
||||
// Process options, caching package resolution details.
|
||||
if (options.packageConfigPath != null) {
|
||||
String packageConfigPath = options.packageConfigPath;
|
||||
|
|
40
pkg/analyzer_cli/lib/starter.dart
Normal file
40
pkg/analyzer_cli/lib/starter.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
library analyzer_cli.starter;
|
||||
|
||||
import 'package:analyzer_cli/plugin/analysis/resolver_provider.dart';
|
||||
import 'package:analyzer_cli/src/driver.dart';
|
||||
import 'package:plugin/plugin.dart';
|
||||
|
||||
/**
|
||||
* An object that can be used to start a command-line analysis. This class
|
||||
* exists so that clients can configure a command-line analyzer before starting
|
||||
* it.
|
||||
*
|
||||
* Clients may not extend, implement or mix-in this class.
|
||||
*/
|
||||
abstract class CommandLineStarter {
|
||||
/**
|
||||
* Initialize a newly created starter to start up a command-line analysis.
|
||||
*/
|
||||
factory CommandLineStarter() = Driver;
|
||||
|
||||
/**
|
||||
* Set the package resolver provider used to override the way package URI's
|
||||
* are resolved in some contexts. The provider should return `null` if the
|
||||
* default package resolution scheme should be used instead.
|
||||
*/
|
||||
void set packageResolverProvider(ResolverProvider provider);
|
||||
|
||||
/**
|
||||
* Set the [plugins] that are defined outside the analyzer_cli package.
|
||||
*/
|
||||
void set userDefinedPlugins(List<Plugin> plugins);
|
||||
|
||||
/**
|
||||
* Use the given command-line [arguments] to start this analyzer.
|
||||
*/
|
||||
void start(List<String> arguments);
|
||||
}
|
Loading…
Reference in a new issue