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

Unified Diff: lib/output_config.dart

Issue 269823003: Parameterize uri resolution and parsing of options, use package:path (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: Created 6 years, 7 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: lib/output_config.dart
diff --git a/lib/output_config.dart b/lib/output_config.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9f763763c6ac06ba1569960e3a665518e76074fd
--- /dev/null
+++ b/lib/output_config.dart
@@ -0,0 +1,44 @@
+// 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.
+
+part of protoc;
+
+/// Configures where output of the protoc compiler should be placed and how to
+/// import one generated file from another.
+abstract class OutputConfiguration {
+
+ /// Returns [filePath] with it's extension replaced with '.pb.dart'.
+ String replacePathExtension(String filePath) =>
+ '${path.withoutExtension(filePath)}.pb.dart';
+
+ /// Returns [file] with it's extension replaced with '.pb.dart'.
+ Uri replaceUriExtension(Uri file) =>
+ path.url.toUri(replacePathExtension(path.url.fromUri(file)));
+
+ /// Resolves an import URI. Both [source] and [target] are .proto files,
+ /// where [target] is imported from [source]. The result URI can be used to
+ /// import [target]'s .pb.dart output from [source]'s .pb.dart output.
+ Uri resolveImport(Uri target, Uri source);
+
+ /// Returns the path, under the output folder, where the code will be
+ /// generated for [inputPath]. The input is expected to be a .proto file,
+ /// while the output is expected to be a .pb.dart file.
+ Uri outputPathFor(Uri inputPath);
+}
+
+/// Default [OutputConfiguration] that uses the same path as the input
+/// file for the output file (just replaces the extension), and that uses
+/// relative paths to resolve imports.
+class DefaultOutputConfiguration extends OutputConfiguration {
+
+ Uri outputPathFor(Uri input) => replaceUriExtension(input);
+
+ Uri resolveImport(Uri target, Uri source) {
+ var builder = path.url;
+ var targetPath = builder.fromUri(target);
+ var sourceDir = builder.dirname(builder.fromUri(source));
+ return builder.toUri(replacePathExtension(
+ builder.relative(targetPath, from: sourceDir)));
+ }
+}
« no previous file with comments | « lib/options.dart ('k') | lib/protobuf_field.dart » ('j') | lib/protobuf_field.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698