You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2015/11/14 14:28:44 UTC

[1/2] thrift git commit: THRIFT-3417: "namespace xsd" is not really working Client: XSD Patch: Benjamin Gould

Repository: thrift
Updated Branches:
  refs/heads/master a6b120301 -> eeb51962f


THRIFT-3417: "namespace xsd" is not really working
Client: XSD
Patch: Benjamin Gould

This closes #691


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/cc193c1b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/cc193c1b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/cc193c1b

Branch: refs/heads/master
Commit: cc193c1becb78b75fbbb178a6e2e0e5aaa0f5b24
Parents: a6b1203
Author: BCG <bg...@users.noreply.github.com>
Authored: Thu Nov 12 21:02:51 2015 -0500
Committer: Jens Geyer <je...@apache.org>
Committed: Sat Nov 14 14:28:09 2015 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_xsd_generator.cc |  5 +++++
 compiler/cpp/src/parse/t_program.h           | 12 ++++++++++++
 compiler/cpp/src/thrifty.yy                  |  6 +++++-
 test/ThriftTest.thrift                       |  1 +
 4 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/generate/t_xsd_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index fd3685d..1301656 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -260,6 +260,11 @@ void t_xsd_generator::generate_service(t_service* tservice) {
   f_xsd_.open(f_xsd_name.c_str());
 
   string ns = program_->get_namespace("xsd");
+  const std::map<std::string, std::string> annot = program_->get_namespace_annotations("xsd");
+  const std::map<std::string, std::string>::const_iterator uri = annot.find("uri");
+  if (uri != annot.end()) {
+    ns = uri->second;
+  }
   if (ns.size() > 0) {
     ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" "
          + "elementFormDefault=\"qualified\"";

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/parse/t_program.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 556ee6c..c973b13 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -324,6 +324,15 @@ public:
   const std::map<std::string, std::string>& get_all_namespaces(){
      return namespaces_;
   }
+
+  void set_namespace_annotations(std::string language, std::map<std::string, std::string> annotations) {
+    namespace_annotations_[language] = annotations;
+  }
+
+  const std::map<std::string, std::string>& get_namespace_annotations(std::string language) {
+    return namespace_annotations_[language];
+  }
+
   // Language specific namespace / packaging
 
   void add_cpp_include(std::string path) { cpp_includes_.push_back(path); }
@@ -371,6 +380,9 @@ private:
   // Dynamic namespaces
   std::map<std::string, std::string> namespaces_;
 
+  // Annotations for dynamic namespaces
+  std::map<std::string, std::map<std::string, std::string>> namespace_annotations_;
+
   // C++ extra includes
   std::vector<std::string> cpp_includes_;
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/compiler/cpp/src/thrifty.yy
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index e0dde8c..59f6b4f 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -297,13 +297,17 @@ Header:
     {
       pdebug("Header -> Include");
     }
-| tok_namespace tok_identifier tok_identifier
+| tok_namespace tok_identifier tok_identifier TypeAnnotations
     {
       pdebug("Header -> tok_namespace tok_identifier tok_identifier");
       declare_valid_program_doctext();
       if (g_parse_mode == PROGRAM) {
         g_program->set_namespace($2, $3);
       }
+      if ($4 != NULL) {
+        g_program->set_namespace_annotations($2, $4->annotations_);
+        delete $4;
+      }
     }
 | tok_namespace '*' tok_identifier
     {

http://git-wip-us.apache.org/repos/asf/thrift/blob/cc193c1b/test/ThriftTest.thrift
----------------------------------------------------------------------
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index f545227..414f9a5 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -36,6 +36,7 @@ namespace php ThriftTest
 namespace delphi Thrift.Test
 namespace cocoa ThriftTest
 namespace lua ThriftTest
+namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
 
 // Presence of namespaces and sub-namespaces for which there is
 // no generator should compile with warnings only


[2/2] thrift git commit: THRIFT-3426 Align autogen comment in XSD Client: XSD Patch: Jens Geyer

Posted by je...@apache.org.
THRIFT-3426 Align autogen comment in XSD
Client: XSD
Patch: Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/eeb51962
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/eeb51962
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/eeb51962

Branch: refs/heads/master
Commit: eeb51962fa47c4d48ab374ffa95c088b29108396
Parents: cc193c1
Author: Jens Geyer <je...@apache.org>
Authored: Sat Nov 14 14:03:33 2015 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Sat Nov 14 14:28:10 2015 +0100

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_generator.h      | 17 +++++++++++++++++
 compiler/cpp/src/generate/t_oop_generator.h  | 17 -----------------
 compiler/cpp/src/generate/t_xsd_generator.cc | 14 ++++++++++++--
 3 files changed, 29 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/eeb51962/compiler/cpp/src/generate/t_generator.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h
index 99d878a..da32757 100644
--- a/compiler/cpp/src/generate/t_generator.h
+++ b/compiler/cpp/src/generate/t_generator.h
@@ -27,6 +27,7 @@
 #include "parse/t_program.h"
 #include "globals.h"
 #include "t_generator_registry.h"
+#include "version.h"
 
 /**
  * Base class for a thrift code generator. This class defines the basic
@@ -145,6 +146,22 @@ protected:
   }
 
   /**
+   * Generates a comment about this code being autogenerated, using C++ style
+   * comments, which are also fair game in Java / PHP, yay!
+   *
+   * @return C-style comment mentioning that this file is autogenerated.
+   */
+  virtual std::string autogen_comment() {
+    return std::string("/**\n") + " * " + autogen_summary() + "\n" + " *\n"
+           + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+           + " *  @generated\n" + " */\n";
+  }
+
+  virtual std::string autogen_summary() {
+    return std::string("Autogenerated by Thrift Compiler (") + THRIFT_VERSION + ")";
+  }
+
+  /**
    * Indentation level modifiers
    */
 

http://git-wip-us.apache.org/repos/asf/thrift/blob/eeb51962/compiler/cpp/src/generate/t_oop_generator.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_oop_generator.h b/compiler/cpp/src/generate/t_oop_generator.h
index 925d108..07c9d85 100644
--- a/compiler/cpp/src/generate/t_oop_generator.h
+++ b/compiler/cpp/src/generate/t_oop_generator.h
@@ -25,7 +25,6 @@
 
 #include "globals.h"
 #include "t_generator.h"
-#include "version.h"
 
 #include <algorithm>
 
@@ -57,22 +56,6 @@ public:
     return original;
   }
 
-  /**
-   * Generates a comment about this code being autogenerated, using C++ style
-   * comments, which are also fair game in Java / PHP, yay!
-   *
-   * @return C-style comment mentioning that this file is autogenerated.
-   */
-  virtual std::string autogen_comment() {
-    return std::string("/**\n") + " * " + autogen_summary() + "\n" + " *\n"
-           + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
-           + " *  @generated\n" + " */\n";
-  }
-
-  virtual std::string autogen_summary() {
-    return std::string("Autogenerated by Thrift Compiler (") + THRIFT_VERSION + ")";
-  }
-
   virtual std::string get_enum_class_name(t_type* type) {
     std::string package = "";
     t_program* program = type->get_program();

http://git-wip-us.apache.org/repos/asf/thrift/blob/eeb51962/compiler/cpp/src/generate/t_xsd_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index 1301656..cf7937a 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sstream>
 #include "t_generator.h"
+#include "version.h"
 #include "platform.h"
 
 using std::map;
@@ -87,6 +88,12 @@ private:
   std::string type_name(t_type* ttype);
   std::string base_type_name(t_base_type::t_base tbase);
 
+  virtual std::string xml_autogen_comment() {
+    return std::string("<!--\n") + " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+           + " *\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+           + " -->\n";
+  }
+
   /**
    * Output xsd/php file
    */
@@ -107,7 +114,8 @@ void t_xsd_generator::init_generator() {
   string f_php_name = get_out_dir() + program_->get_name() + "_xsd.php";
   f_php_.open(f_php_name.c_str());
 
-  f_php_ << "<?php" << endl;
+  f_php_ << "<?php" << endl
+         << autogen_comment() << endl;
 }
 
 void t_xsd_generator::close_generator() {
@@ -254,6 +262,7 @@ void t_xsd_generator::generate_element(ostream& out,
   }
 }
 
+
 void t_xsd_generator::generate_service(t_service* tservice) {
   // Make output file
   string f_xsd_name = get_out_dir() + tservice->get_name() + ".xsd";
@@ -273,7 +282,8 @@ void t_xsd_generator::generate_service(t_service* tservice) {
   // Print the XSD header
   f_xsd_ << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl
          << "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" << ns << ">" << endl
-         << endl << "<!-- Yo yo yo, this XSD woz be generated by Thrift. -->" << endl << endl;
+         << xml_autogen_comment()
+         << endl;
 
   // Print out the type definitions
   indent(f_xsd_) << s_xsd_types_.str();