Skip to content

Commit 9297b3d

Browse files
authored
Refactor protos to add package and license lines (#696)
Follow official protobuf style guide: 1. License header (if applicable) 2. File overview 3. Syntax 4. Package 5. Imports (sorted) 6. File options 7. Everything else Internally we want a `package` line in every proto, and it's easier to do add `package` lines to protos than to add them as exceptions. License headers added the old files based on creation date. protos in google/protobuf are not updated as they are copied from protoc. The proto file `unittest_nested_any.proto` was added #568. Since it's not copied from protoc I moved it to test/protos. Fixes #692
1 parent 7ac3908 commit 9297b3d

31 files changed

+112
-42
lines changed

protoc_plugin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ TEST_PROTO_LIST = \
2121
google/protobuf/timestamp \
2222
google/protobuf/type \
2323
google/protobuf/unittest_import \
24-
google/protobuf/unittest_nested_any \
2524
google/protobuf/unittest_optimize_for \
2625
google/protobuf/unittest_well_known_types \
2726
google/protobuf/unittest \
@@ -46,6 +45,7 @@ TEST_PROTO_LIST = \
4645
map_field \
4746
mixins \
4847
multiple_files_test \
48+
nested_any \
4949
nested_extension \
5050
nested_message \
5151
non_nested_extension \

protoc_plugin/test/any_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import '../out/protos/using_any.pb.dart';
1313
void main() {
1414
test('pack -> unpack', () {
1515
var any = Any.pack(SearchRequest()..query = 'hest');
16-
expect(any.typeUrl, 'type.googleapis.com/SearchRequest');
16+
expect(any.typeUrl, 'type.googleapis.com/service.SearchRequest');
1717
var any1 = Any.pack(SearchRequest()..query = 'hest1',
1818
typeUrlPrefix: 'example.com');
19-
expect(any1.typeUrl, 'example.com/SearchRequest');
19+
expect(any1.typeUrl, 'example.com/service.SearchRequest');
2020
expect(any1.canUnpackInto(SearchRequest.getDefault()), true);
2121
expect(any1.canUnpackInto(SearchResponse.getDefault()), false);
2222
var searchRequest = any.unpackInto(SearchRequest());
@@ -42,7 +42,7 @@ void main() {
4242
var any = Any.pack(toplevel.T()
4343
..a = 127
4444
..b = 'hest');
45-
expect(any.typeUrl, 'type.googleapis.com/T');
45+
expect(any.typeUrl, 'type.googleapis.com/toplevel.T');
4646
var t2 = any.unpackInto(toplevel.T());
4747
expect(t2.a, 127);
4848
expect(t2.b, 'hest');

protoc_plugin/test/proto3_json_test.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import '../out/protos/google/protobuf/field_mask.pb.dart';
1616
import '../out/protos/google/protobuf/struct.pb.dart';
1717
import '../out/protos/google/protobuf/timestamp.pb.dart';
1818
import '../out/protos/google/protobuf/unittest.pb.dart';
19-
import '../out/protos/google/protobuf/unittest_nested_any.pb.dart';
2019
import '../out/protos/google/protobuf/unittest_well_known_types.pb.dart';
2120
import '../out/protos/google/protobuf/wrappers.pb.dart';
2221
import '../out/protos/map_field.pb.dart';
22+
import '../out/protos/nested_any.pb.dart';
2323
import '../out/protos/oneof.pb.dart';
2424
import 'oneof_test.dart';
2525
import 'test_util.dart';
@@ -281,12 +281,10 @@ void main() {
281281
{
282282
'anyField2': {
283283
'value': '1',
284-
'@type':
285-
'type.googleapis.com/protobuf_unittest_nested_any.AnyMessage1'
284+
'@type': 'type.googleapis.com/nested_any.AnyMessage1'
286285
},
287286
'value': '2',
288-
'@type':
289-
'type.googleapis.com/protobuf_unittest_nested_any.AnyMessage2'
287+
'@type': 'type.googleapis.com/nested_any.AnyMessage2'
290288
});
291289
});
292290

@@ -941,12 +939,10 @@ void main() {
941939
..mergeFromProto3Json({
942940
'anyField2': {
943941
'value': '1',
944-
'@type':
945-
'type.googleapis.com/protobuf_unittest_nested_any.AnyMessage1'
942+
'@type': 'type.googleapis.com/nested_any.AnyMessage1'
946943
},
947944
'value': '2',
948-
'@type':
949-
'type.googleapis.com/protobuf_unittest_nested_any.AnyMessage2'
945+
'@type': 'type.googleapis.com/nested_any.AnyMessage2'
950946
}, typeRegistry: TypeRegistry([AnyMessage1(), AnyMessage2()]));
951947

952948
expect(

protoc_plugin/test/protos/ExtensionEnumNameConflict.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
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.
4+
15
syntax = "proto2";
26

37
package protobuf_unittest;

protoc_plugin/test/protos/ExtensionNameConflict.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
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.
4+
15
syntax = "proto2";
26

37
package protobuf_unittest;

protoc_plugin/test/protos/bytes.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
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.
4+
15
syntax = "proto2";
26

7+
package bytes;
8+
39
message BytesEntity {
410
optional bytes value = 1;
511
repeated bytes values = 2;

protoc_plugin/test/protos/custom_option.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
syntax = "proto2";
66

7+
package custom_option;
8+
79
import "descriptor.proto";
810

911
extend google.protobuf.MessageOptions {

protoc_plugin/test/protos/dart_name.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
syntax = "proto2";
66

7-
import "dart_options.proto";
8-
97
package dart_name;
108

9+
import "dart_options.proto";
10+
1111
message DartName {
1212
optional string field = 1 [
1313
(dart_options.dart_name) = "renamedField"

protoc_plugin/test/protos/default_value_escape.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
syntax = "proto2";
66

7+
package default_value_escape;
8+
79
message F {
810
optional string a = 1 [default = "a\nb"];
911
optional string b = 2 [default = "a'b"];

protoc_plugin/test/protos/enum_name.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4+
15
syntax = "proto2";
26

37
package enum.name;

0 commit comments

Comments
 (0)