You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/06/21 07:09:57 UTC

[servicecomb-toolkit] 41/49: Support generating SpringBoot consumer code

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 30e4f0014c3a9b5360188224d88ef7ca73a478c3
Author: kakulisen <18...@163.com>
AuthorDate: Mon Jun 3 17:35:02 2019 +0800

    Support generating SpringBoot consumer code
    
    Signed-off-by: kakulisen <18...@163.com>
---
 .../toolkit/codegen/ServiceCombCodegen.java        |  10 +-
 .../consumer/springboot/Application.mustache       |  14 +++
 .../ServiceComb/consumer/springboot/pom.mustache   | 132 +++++++++++++++++++++
 .../libraries/SpringBoot/operationMethod.mustache  |   1 +
 4 files changed, 155 insertions(+), 2 deletions(-)

diff --git a/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java
index ee1c004..cbfbb46 100755
--- a/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java
+++ b/code-generator/src/main/java/org/apache/servicecomb/toolkit/codegen/ServiceCombCodegen.java
@@ -248,12 +248,18 @@ public class ServiceCombCodegen extends AbstractJavaCodegen implements CodegenCo
 
   private void processConsumerOpts() {
 
-    supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/pom.mustache",
+    String newConsumerTemplateFolder = consumerTemplateFolder;
+
+    if (SPRING_BOOT_LIBRARY.equals(getLibrary())) {
+      newConsumerTemplateFolder += "/springboot";
+    }
+
+    supportingFiles.add(new SupportingFile(newConsumerTemplateFolder + "/pom.mustache",
         consumerProject,
         "pom.xml")
     );
 
-    supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/Application.mustache",
+    supportingFiles.add(new SupportingFile(newConsumerTemplateFolder + "/Application.mustache",
         mainClassFolder(consumerProject),
         "Application.java")
     );
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/springboot/Application.mustache b/code-generator/src/main/resources/ServiceComb/consumer/springboot/Application.mustache
new file mode 100755
index 0000000..0cf7ff0
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/springboot/Application.mustache
@@ -0,0 +1,14 @@
+package {{mainClassPackage}};
+
+import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableServiceComb
+public class Application {
+
+  public static void main(String[] args) throws Exception {
+    SpringApplication.run(Application.class, args);
+  }
+}
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/consumer/springboot/pom.mustache b/code-generator/src/main/resources/ServiceComb/consumer/springboot/pom.mustache
new file mode 100755
index 0000000..dbeb038
--- /dev/null
+++ b/code-generator/src/main/resources/ServiceComb/consumer/springboot/pom.mustache
@@ -0,0 +1,132 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <artifactId>{{artifactId}}</artifactId>
+    <groupId>{{groupId}}</groupId>
+    <version>{{artifactVersion}}</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>consumer</artifactId>
+  <packaging>jar</packaging>
+  <name>consumer</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <java-chassis.version>1.2.0</java-chassis.version>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
+        <artifactId>java-chassis-dependencies</artifactId>
+        <version>${java-chassis.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>{{groupId}}</groupId>
+      <artifactId>model</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>spring-boot-starter-provider</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>spring-boot-starter-provider</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>handler-flowcontrol-qps</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>handler-bizkeeper</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>handler-tracing-zipkin</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>inspector</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.hibernate.validator</groupId>
+      <artifactId>hibernate-validator</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.validation</groupId>
+      <artifactId>validation-api</artifactId>
+      <version>2.0.1.Final</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.1</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>3.0.0</version>
+        <configuration>
+          <encoding>UTF-8</encoding>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+        <version>1.5.12.RELEASE</version>
+        <configuration>
+          <fork>true</fork>
+          <mainClass>{{mainClassPackage}}.Application</mainClass>
+          <outputDirectory>target/bin</outputDirectory>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>repackage</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
\ No newline at end of file
diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache
index 948212d..f6c2ef9 100755
--- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache
+++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache
@@ -1,4 +1,5 @@
 {{#operation}}
+
   @RequestMapping(value = "{{path}}", {{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}} {{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}} method = RequestMethod.{{httpMethod}})
   public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
     // do something