aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk4
-rw-r--r--java/README.txt13
-rw-r--r--java/pom.xml6
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_generator.cc59
4 files changed, 51 insertions, 31 deletions
diff --git a/Android.mk b/Android.mk
index c977d3c..ec28bec 100644
--- a/Android.mk
+++ b/Android.mk
@@ -374,6 +374,8 @@ LOCAL_SRC_FILES := \
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
-LOCAL_PROTO_JAVA_OUTPUT_PARAMS := java_package=$(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,java_outer_classname=$(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
+LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
+ java_package = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano, \
+ java_outer_classname = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/java/README.txt b/java/README.txt
index ced78d2..0646c23 100644
--- a/java/README.txt
+++ b/java/README.txt
@@ -580,9 +580,9 @@ To use nano protobufs within the Android repo:
LOCAL_STATIC_JAVA_LIBRARIES variable, so you don't need to.
- Set 'LOCAL_PROTO_JAVA_OUTPUT_PARAMS := ...' in your local .mk file
for any command-line options you need. Use commas to join multiple
- options. Write all options on the same line; avoid backslash-newline
- or '+=', because they will introduce spaces in the middle of your
- options and the generator is not prepared to handle them.
+ options. In the nano flavor only, whitespace surrounding the option
+ names and values are ignored, so you can use backslash-newline or
+ '+=' to structure your make files nicely.
- The options will be applied to *all* proto files in LOCAL_SRC_FILES
when you build a Java library or package. In case different options
are needed for different proto files, build separate Java libraries
@@ -603,10 +603,9 @@ To use nano protobufs outside of Android repo:
- Invoke with --javanano_out, e.g.:
./protoc '--javanano_out=\
-java_package=src/proto/simple-data.proto|my_package,\
-java_outer_classname=src/proto/simple-data.proto|OuterName:\
-.' src/proto/simple-data.proto
-
+ java_package=src/proto/simple-data.proto|my_package,\
+ java_outer_classname=src/proto/simple-data.proto|OuterName\
+ :.' src/proto/simple-data.proto
Contributing to nano:
diff --git a/java/pom.xml b/java/pom.xml
index 2f40b98..d7ea4d1 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -133,7 +133,11 @@
</exec>
<!-- java nano -->
<exec executable="../src/protoc">
- <arg value="--javanano_out=java_package=google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,java_outer_classname=google/protobuf/unittest_import_nano.proto|UnittestImportNano,generate_equals=true:target/generated-test-sources" />
+ <arg value="--javanano_out=
+ java_package = google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,
+ java_outer_classname = google/protobuf/unittest_import_nano.proto|UnittestImportNano,
+ generate_equals = true
+ :target/generated-test-sources" />
<arg value="--proto_path=../src" />
<arg value="--proto_path=src/test/java" />
<arg value="../src/google/protobuf/unittest_nano.proto" />
diff --git a/src/google/protobuf/compiler/javanano/javanano_generator.cc b/src/google/protobuf/compiler/javanano/javanano_generator.cc
index 5c8bcb6..d514dd8 100644
--- a/src/google/protobuf/compiler/javanano/javanano_generator.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_generator.cc
@@ -46,6 +46,19 @@ namespace protobuf {
namespace compiler {
namespace javanano {
+namespace {
+
+string TrimString(const string& s) {
+ string::size_type start = s.find_first_not_of(" \n\r\t");
+ if (start == string::npos) {
+ return "";
+ }
+ string::size_type end = s.find_last_not_of(" \n\r\t") + 1;
+ return s.substr(start, end - start);
+}
+
+} // namespace
+
void UpdateParamsRecursively(Params& params,
const FileDescriptor* file) {
// Add any parameters for this file
@@ -93,42 +106,44 @@ bool JavaNanoGenerator::Generate(const FileDescriptor* file,
// Replace any existing options with ones from command line
for (int i = 0; i < options.size(); i++) {
- if (options[i].first == "output_list_file") {
- output_list_file = options[i].second;
- } else if (options[i].first == "java_package") {
+ string option_name = TrimString(options[i].first);
+ string option_value = TrimString(options[i].second);
+ if (option_name == "output_list_file") {
+ output_list_file = option_value;
+ } else if (option_name == "java_package") {
vector<string> parts;
- SplitStringUsing(options[i].second, "|", &parts);
+ SplitStringUsing(option_value, "|", &parts);
if (parts.size() != 2) {
*error = "Bad java_package, expecting filename|PackageName found '"
- + options[i].second + "'";
+ + option_value + "'";
return false;
}
params.set_java_package(parts[0], parts[1]);
- } else if (options[i].first == "java_outer_classname") {
+ } else if (option_name == "java_outer_classname") {
vector<string> parts;
- SplitStringUsing(options[i].second, "|", &parts);
+ SplitStringUsing(option_value, "|", &parts);
if (parts.size() != 2) {
*error = "Bad java_outer_classname, "
"expecting filename|ClassName found '"
- + options[i].second + "'";
+ + option_value + "'";
return false;
}
params.set_java_outer_classname(parts[0], parts[1]);
- } else if (options[i].first == "store_unknown_fields") {
- params.set_store_unknown_fields(options[i].second == "true");
- } else if (options[i].first == "java_multiple_files") {
- params.set_override_java_multiple_files(options[i].second == "true");
- } else if (options[i].first == "java_nano_generate_has") {
- params.set_generate_has(options[i].second == "true");
- } else if (options[i].first == "enum_style") {
- params.set_java_enum_style(options[i].second == "java");
- } else if (options[i].first == "optional_field_style") {
- params.set_optional_field_accessors(options[i].second == "accessors");
- params.set_use_reference_types_for_primitives(options[i].second == "reftypes");
- } else if (options[i].first == "generate_equals") {
- params.set_generate_equals(options[i].second == "true");
+ } else if (option_name == "store_unknown_fields") {
+ params.set_store_unknown_fields(option_value == "true");
+ } else if (option_name == "java_multiple_files") {
+ params.set_override_java_multiple_files(option_value == "true");
+ } else if (option_name == "java_nano_generate_has") {
+ params.set_generate_has(option_value == "true");
+ } else if (option_name == "enum_style") {
+ params.set_java_enum_style(option_value == "java");
+ } else if (option_name == "optional_field_style") {
+ params.set_optional_field_accessors(option_value == "accessors");
+ params.set_use_reference_types_for_primitives(option_value == "reftypes");
+ } else if (option_name == "generate_equals") {
+ params.set_generate_equals(option_value == "true");
} else {
- *error = "Ignore unknown javanano generator option: " + options[i].first;
+ *error = "Ignore unknown javanano generator option: " + option_name;
}
}