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 14479e7d444b15f27d4558d3494f5f62d1ff655f Author: MabinGo <bin...@huawei.com> AuthorDate: Thu May 30 20:29:46 2019 +0800 Adjust mustache model and bugfixed Signed-off-by: MabinGo <bin...@huawei.com> --- .../toolkit/codegen/ServiceCombCodegen.java | 10 +- .../ServiceComb/consumer/Application.mustache | 24 +--- .../ServiceComb/consumer/apiConsumer.mustache | 79 +++++------ .../consumer/formParamsConsumer.mustache | 3 +- .../resources/ServiceComb/consumer/pom.mustache | 105 ++++++++------- .../main/resources/ServiceComb/enumClass.mustache | 71 +++++----- .../resources/ServiceComb/enumOuterClass.mustache | 12 +- .../libraries/JAX-RS/Application.mustache | 1 - .../ServiceComb/libraries/JAX-RS/api.mustache | 37 +++-- .../ServiceComb/libraries/JAX-RS/api_test.mustache | 39 ------ .../libraries/JAX-RS/formParams.mustache | 3 +- .../ServiceComb/libraries/JAX-RS/pom.mustache | 150 ++++++++++----------- .../libraries/POJO/Application.mustache | 1 - .../ServiceComb/libraries/POJO/api.mustache | 21 ++- .../libraries/POJO/apiInterface.mustache | 16 +-- .../ServiceComb/libraries/POJO/formParams.mustache | 3 +- .../ServiceComb/libraries/POJO/pom.mustache | 69 +++++----- .../libraries/SpringBoot/Application.mustache | 1 - .../ServiceComb/libraries/SpringBoot/api.mustache | 13 +- .../libraries/SpringBoot/api_test.mustache | 38 ------ .../libraries/SpringBoot/formParams.mustache | 3 +- .../libraries/SpringBoot/operationMethod.mustache | 13 +- .../ServiceComb/libraries/SpringBoot/pom.mustache | 69 +++++----- .../libraries/SpringMVC/Application.mustache | 1 - .../ServiceComb/libraries/SpringMVC/api.mustache | 31 ++--- .../libraries/SpringMVC/api_test.mustache | 103 -------------- .../libraries/SpringMVC/formParams.mustache | 3 +- .../ServiceComb/libraries/SpringMVC/pom.mustache | 68 +++++----- .../resources/ServiceComb/model/model.mustache | 9 -- .../main/resources/ServiceComb/model/pom.mustache | 20 +-- .../src/main/resources/ServiceComb/pojo.mustache | 111 ++++----------- .../resources/ServiceComb/project/pom.mustache | 90 +++++-------- .../toolkit/common/ImmediateClassLoader.java | 6 +- .../toolkit/common/TextCompareTest.java | 31 +++-- .../docgen/ContractsSwaggerUIGenerator.java | 5 +- .../src/test/java/docgen/DocGeneratorTest.java | 122 ++++++++--------- toolkit-cli/pom.xml | 26 +++- .../servicecomb/toolkit/cli/CodeGenerate.java | 15 ++- .../servicecomb/toolkit/cli/DocGenerate.java | 31 ++++- .../servicecomb/toolkit/cli/ToolkitMain.java | 2 +- toolkit-cli/src/main/resources/log4j2.xml | 35 +++++ .../apache/servicecomb/toolkit/cli/CliTest.java | 2 +- .../java/plugin/GenerateContractsDocMojoTest.java | 21 ++- .../java/plugin/GenerateContractsMojoTest.java | 26 ++-- .../projects/project-generateContracts/pom.xml | 52 +++---- .../projects/project-generateContractsDoc/pom.xml | 54 ++++---- 46 files changed, 701 insertions(+), 944 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 686afaa..957feef 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 @@ -106,7 +106,8 @@ public class ServiceCombCodegen extends AbstractJavaCodegen implements CodegenCo supportedLibraries.put(DEFAULT_LIBRARY, "ServiceComb Server application using the springboot programming model."); supportedLibraries.put(POJO_LIBRARY, "ServiceComb Server application using the pojo programming model."); supportedLibraries.put(JAX_RS_LIBRARY, "ServiceComb Server application using the jax-rs programming model."); - supportedLibraries.put(SPRING_BOOT_LIBRARY, "ServiceComb Server application using the SpringBoot programming model."); + supportedLibraries + .put(SPRING_BOOT_LIBRARY, "ServiceComb Server application using the SpringBoot programming model."); setLibrary(DEFAULT_LIBRARY); @@ -216,10 +217,12 @@ public class ServiceCombCodegen extends AbstractJavaCodegen implements CodegenCo resourcesFolder(providerProject), "log4j2.xml") ); + supportingFiles.add(new SupportingFile(providerTemplateFolder + "/microservice.mustache", resourcesFolder(providerProject), "microservice.yaml") ); + apiTemplateFiles.put(apiConsumerTemplate, "Consumer.java"); } @@ -235,6 +238,11 @@ public class ServiceCombCodegen extends AbstractJavaCodegen implements CodegenCo "Application.java") ); + supportingFiles.add(new SupportingFile("log4j2.mustache", + resourcesFolder(consumerProject), + "log4j2.xml") + ); + supportingFiles.add(new SupportingFile(consumerTemplateFolder + "/microservice.mustache", resourcesFolder(consumerProject), "microservice.yaml") diff --git a/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache b/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache index 2ee4969..855c97c 100755 --- a/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache +++ b/code-generator/src/main/resources/ServiceComb/consumer/Application.mustache @@ -1,28 +1,10 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - package {{mainClassPackage}}; import org.apache.servicecomb.foundation.common.utils.BeanUtils; public class Application { - public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "notExistJustForceLocal"); - BeanUtils.init(); - } + public static void main(String[] args) throws Exception { + BeanUtils.init(); + } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache index 109d0f9..d23f0b3 100755 --- a/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache +++ b/code-generator/src/main/resources/ServiceComb/consumer/apiConsumer.mustache @@ -1,10 +1,13 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - +import static org.springframework.http.MediaType.*; +import java.util.List; +import java.util.Map; +import java.util.HashMap; {{#imports}}import {{import}}; {{/imports}} - +import {{modelPackage}}.*; +import org.apache.servicecomb.provider.rest.common.RestSchema; import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder; import org.springframework.util.MultiValueMap; import org.springframework.http.*; @@ -17,49 +20,47 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; -import org.apache.servicecomb.provider.rest.common.RestSchema; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import static org.springframework.http.MediaType.*; {{#operations}} public class {{classname}}Consumer { - {{#operation}} +{{#operation}} - public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>consumer/queryParamsConsumer}}{{>consumer/pathParamsConsumer}}{{>consumer/headerParamsConsumer}}{{>consumer/bodyParamsConsumer}}{{>consumer/formParamsConsumer}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}) { + public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>consumer/queryParamsConsumer}}{{>consumer/pathParamsConsumer}}{{>consumer/headerParamsConsumer}}{{>consumer/bodyParamsConsumer}}{{>consumer/formParamsConsumer}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - Map<String, Object> params = new HashMap<>(); - HttpEntity httpEntity = null; - HttpHeaders headers = new HttpHeaders(); - {{#allParams}} - {{#isPathParam}} params.put("{{paramName}}",{{paramName}}); {{/isPathParam}} - {{#isQueryParam}} params.put("{{paramName}}",{{paramName}}); {{/isQueryParam}} - {{#isHeaderParam}} - headers.add("{{paramName}}",{{paramName}}); - {{/isHeaderParam}} - {{#isFormParam}} - {{#notFile}} - httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers); - {{/notFile}} - {{#isFile}} - httpEntity = new HttpEntity<MultipartFile>({{paramName}}, headers); - {{/isFile}} - {{/isFormParam}} - {{#isBodyParam}} - httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers); - {{/isBodyParam}} + Map<String, Object> params = new HashMap<>(); + HttpEntity httpEntity = null; + HttpHeaders headers = new HttpHeaders(); + {{#allParams}} + {{#isPathParam}} + params.put("{{paramName}}",{{paramName}}); + {{/isPathParam}} + {{#isQueryParam}} + params.put("{{paramName}}",{{paramName}}); + {{/isQueryParam}} + {{#isHeaderParam}} + headers.add("{{paramName}}",{{paramName}}); + {{/isHeaderParam}} + {{#isFormParam}} + {{#notFile}} + httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers); + {{/notFile}} + {{#isFile}} + httpEntity = new HttpEntity<MultipartFile>({{paramName}}, headers); + {{/isFile}} + {{/isFormParam}} + {{#isBodyParam}} + httpEntity = new HttpEntity<{{{dataType}}}>({{paramName}}, headers); + {{/isBodyParam}} + {{/allParams}} - {{/allParams}} - RestTemplate restTemplate = RestTemplateBuilder.create(); + RestTemplate restTemplate = RestTemplateBuilder.create(); - ResponseEntity<{{>returnTypes}}> result = restTemplate.exchange("cse://{{microserviceName}}/{{path}}",HttpMethod.{{httpMethod}},httpEntity,{{#getGenericClassType}}{{>returnTypes}}{{/getGenericClassType}}.class,params); + ResponseEntity<{{>returnTypes}}> result = restTemplate.exchange("cse://{{microserviceName}}/{{path}}",HttpMethod.{{httpMethod}},httpEntity,{{#getGenericClassType}}{{>returnTypes}}{{/getGenericClassType}}.class,params); - // do something - return result; - } + // do something - {{/operation}} - } + return result; + } +{{/operation}} +} {{/operations}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache b/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache index 6f911b1..5e9bb31 100755 --- a/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache +++ b/code-generator/src/main/resources/ServiceComb/consumer/formParamsConsumer.mustache @@ -1,2 +1 @@ -{{#isFormParam}}{{#notFile}} - {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache b/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache index 32991a8..7d1333a 100755 --- a/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/consumer/pom.mustache @@ -1,4 +1,6 @@ -<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"> +<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"> + <modelVersion>4.0.0</modelVersion> <groupId>{{groupId}}</groupId> <artifactId>consumer</artifactId> @@ -7,8 +9,8 @@ <version>{{artifactVersion}}</version> <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> </properties> <dependencyManagement> @@ -24,54 +26,61 @@ </dependencyManagement> <dependencies> + <dependency> + <groupId>{{groupId}}</groupId> + <artifactId>model</artifactId> + <version>${project.version}</version> + </dependency> - <dependency> - <groupId>{{groupId}}</groupId> - <artifactId>model</artifactId> - <version>${project.version}</version> - </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-bizkeeper</artifactId> + </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-bizkeeper</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-loadbalance</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>transport-highway</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>transport-rest-vertx</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-flowcontrol-qps</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>provider-pojo</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>provider-springmvc</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-loadbalance</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>transport-highway</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>transport-rest-vertx</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-flowcontrol-qps</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>provider-pojo</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>provider-springmvc</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> </dependencies> <build> diff --git a/code-generator/src/main/resources/ServiceComb/enumClass.mustache b/code-generator/src/main/resources/ServiceComb/enumClass.mustache index dfdada5..7c013d8 100755 --- a/code-generator/src/main/resources/ServiceComb/enumClass.mustache +++ b/code-generator/src/main/resources/ServiceComb/enumClass.mustache @@ -1,43 +1,40 @@ - /** - * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} - */ - public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { +public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} { +{{#gson}} + {{#allowableValues}} + {{#enumVars}} + @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}} + {{/enumVars}} + {{/allowableValues}} +{{/gson}} +{{^gson}} + {{#allowableValues}} + {{#enumVars}} + {{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}} + {{/enumVars}} + {{/allowableValues}} +{{/gson}} - {{#gson}} - {{#allowableValues}} - {{#enumVars}} - @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) - {{{name}}}({{{value}}}){{^-last}}, - {{/-last}}{{#-last}};{{/-last}} - {{/enumVars}} - {{/allowableValues}} - {{/gson}} - {{^gson}} - {{#allowableValues}} - {{#enumVars}} - {{{name}}}({{{value}}}){{^-last}}, - {{/-last}}{{#-last}};{{/-last}} - {{/enumVars}} - {{/allowableValues}} - {{/gson}} + private {{{datatype}}} value; - private {{{datatype}}} value; + {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{datatype}}} value) { + this.value = value; + } - {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{datatype}}} value) { - this.value = value; - } - - @Override - public String toString() { - return String.valueOf(value); - } + @Override + public String toString() { + return String.valueOf(value); + } - public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) { - for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { - if (String.valueOf(b.value).equals(text)) { - return b; - } + public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) { + for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; } - return null; } - } \ No newline at end of file + + return null; + } +} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache b/code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache index 6666a6a..7fed969 100755 --- a/code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache +++ b/code-generator/src/main/resources/ServiceComb/enumOuterClass.mustache @@ -1,18 +1,15 @@ -/** - * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} - */ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { - {{#gson}} +{{#gson}} {{#allowableValues}}{{#enumVars}} @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) {{{name}}}({{{value}}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} - {{/gson}} - {{^gson}} +{{/gson}} +{{^gson}} {{#allowableValues}}{{#enumVars}} {{{name}}}({{{value}}}){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} - {{/gson}} +{{/gson}} private {{{dataType}}} value; @@ -31,6 +28,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum return b; } } + return null; } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/Application.mustache b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/Application.mustache index fda8d43..7fb2d98 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/Application.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/Application.mustache @@ -5,7 +5,6 @@ import org.apache.servicecomb.foundation.common.utils.BeanUtils; public class Application { public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "notExistJustForceLocal"); BeanUtils.init(); } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api.mustache b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api.mustache index 750d5ba..b4caf82 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api.mustache @@ -1,39 +1,38 @@ package {{package}}; -{{#models}}import {{modelPackage}}.*;{{/models}} -import io.swagger.annotations.ApiParam; - -{{#imports}}import {{import}}; -{{/imports}} - import java.util.Map; import java.util.List; - import java.io.InputStream; - import javax.servlet.ServletConfig; import javax.servlet.http.Part; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; import javax.ws.rs.*; +{{#imports}}import {{import}}; +{{/imports}} +{{#models}}import {{modelPackage}}.*;{{/models}} import org.apache.servicecomb.provider.rest.common.RestSchema; +import io.swagger.annotations.ApiParam; -@RestSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}") -@Path("/") {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} {{#operations}} -public class {{classname}} { - +@RestSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}") +@Path("/") +public class {{classname}} { {{#operation}} - @Path("{{{path}}}") - @{{httpMethod}} - {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} - {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} - public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) { - return null; - } + + {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} + {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} + @Path("{{{path}}}") + @{{httpMethod}} + public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) { + + // do something + + return null; + } {{/operation}} } {{/operations}} diff --git a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api_test.mustache b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api_test.mustache deleted file mode 100755 index 8f93bb4..0000000 --- a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/api_test.mustache +++ /dev/null @@ -1,39 +0,0 @@ -package {{package}}; - -{{#imports}}import {{import}}; -{{/imports}} -import java.util.*; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class {{classname}}Test { -@Autowired -private {{classname}} api; -{{#operations}} - {{#operation}} - @Test - public void {{operationId}}Test() throws Exception { - {{#allParams}} - {{^isFile}} - {{{dataType}}} {{paramName}} = {{{example}}}; - {{/isFile}} - {{#isFile}} - org.springframework.web.multipart.MultipartFile {{paramName}} = null; - {{/isFile}} - {{/allParams}} - ResponseEntity<{{>returnTypes}}> responseEntity = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); - } - {{/operation}} -{{/operations}} -} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/formParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/formParams.mustache index 5a4ebf2..9f5b8ec 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/formParams.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/formParams.mustache @@ -1,2 +1 @@ -{{#isFormParam}}{{#notFile}} {{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/notFile}}{{#isFile}} - Part {{paramName}}{{/isFile}}{{/isFormParam}} +{{#isFormParam}}{{#notFile}} {{#vendorExtensions.x-multipart}} @FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/notFile}}{{#isFile}} Part {{paramName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/pom.mustache b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/pom.mustache index 35ec7b1..63d56f3 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/JAX-RS/pom.mustache @@ -1,18 +1,20 @@ -<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"> +<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>provider</artifactId> <packaging>jar</packaging> <name>{{artifactId}}</name> <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> </properties> <dependencyManagement> @@ -28,98 +30,96 @@ </dependencyManagement> <dependencies> + <dependency> + <groupId>{{groupId}}</groupId> + <artifactId>model</artifactId> + <version>${project.version}</version> + </dependency> - <dependency> - <groupId>{{groupId}}</groupId> - <artifactId>model</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-bizkeeper</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-loadbalance</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>handler-flowcontrol-qps</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>transport-highway</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>transport-rest-vertx</artifactId> - </dependency> - <dependency> - <groupId>org.apache.servicecomb</groupId> - <artifactId>provider-jaxrs</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-bizkeeper</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-loadbalance</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>handler-flowcontrol-qps</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>transport-highway</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>transport-rest-vertx</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>provider-jaxrs</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> </dependencies> - <!--for package and deploy--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.6</version> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <classpathPrefix>lib/</classpathPrefix> - <!--change to your main class--> - <mainClass>${package}.Application</mainClass> - </manifest> - <manifestEntries> - <Class-Path>. </Class-Path> - </manifestEntries> - </archive> + <source>1.8</source> + <target>1.8</target> </configuration> </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> + <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>${package}.Application</mainClass> + <outputDirectory>target/bin</outputDirectory> + </configuration> <executions> <execution> - <id>copy-dependencies</id> - <phase>package</phase> <goals> - <goal>copy-dependencies</goal> + <goal>repackage</goal> </goals> - <configuration> - <outputDirectory>target/lib</outputDirectory> - </configuration> </execution> </executions> </plugin> - <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> - </plugins> </build> diff --git a/code-generator/src/main/resources/ServiceComb/libraries/POJO/Application.mustache b/code-generator/src/main/resources/ServiceComb/libraries/POJO/Application.mustache index fda8d43..7fb2d98 100644 --- a/code-generator/src/main/resources/ServiceComb/libraries/POJO/Application.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/POJO/Application.mustache @@ -5,7 +5,6 @@ import org.apache.servicecomb.foundation.common.utils.BeanUtils; public class Application { public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "notExistJustForceLocal"); BeanUtils.init(); } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/POJO/api.mustache b/code-generator/src/main/resources/ServiceComb/libraries/POJO/api.mustache old mode 100644 new mode 100755 index abb8da0..ea99a96 --- a/code-generator/src/main/resources/ServiceComb/libraries/POJO/api.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/POJO/api.mustache @@ -1,10 +1,12 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - +import static org.springframework.http.MediaType.*; +import java.util.List; +import java.util.Map; +import java.io.File; {{#imports}}import {{import}}; {{/imports}} - +import {{modelPackage}}.*; import org.apache.servicecomb.provider.pojo.RpcSchema; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -16,10 +18,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -import java.util.List; -import java.util.Map; -import java.io.File; -import static org.springframework.http.MediaType.*; @RpcSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}") {{#operations}} @@ -27,12 +25,11 @@ public class {{classname}} implements {{#removeImplSuffix}}{{classname}}{{/remov {{#operation}} @Override - public {{>returnTypes}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}) { - // do some magic! - return null; - } + public {{>returnTypes}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + // do something + return null; + } {{/operation}} } {{/operations}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/POJO/apiInterface.mustache b/code-generator/src/main/resources/ServiceComb/libraries/POJO/apiInterface.mustache old mode 100644 new mode 100755 index d7c5b3e..84cc2c8 --- a/code-generator/src/main/resources/ServiceComb/libraries/POJO/apiInterface.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/POJO/apiInterface.mustache @@ -1,23 +1,17 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - -{{#imports}}import {{import}}; -{{/imports}} - import java.util.List; import java.util.Map; import java.util.HashMap; import java.io.File; - +{{#imports}}import {{import}}; +{{/imports}} +import {{modelPackage}}.*; {{#operations}} public interface {{#removeImplSuffix}}{{classname}}{{/removeImplSuffix}} { {{#operation}} - - public {{>returnTypes}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}); - + public {{>returnTypes}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); {{/operation}} - } +} {{/operations}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/POJO/formParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/POJO/formParams.mustache index 96f17c8..22cb5a8 100644 --- a/code-generator/src/main/resources/ServiceComb/libraries/POJO/formParams.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/POJO/formParams.mustache @@ -1,2 +1 @@ -{{#isFormParam}}{{#notFile}} -{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} File {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} File {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/POJO/pom.mustache b/code-generator/src/main/resources/ServiceComb/libraries/POJO/pom.mustache old mode 100644 new mode 100755 index c2ceb61..4eb5156 --- a/code-generator/src/main/resources/ServiceComb/libraries/POJO/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/POJO/pom.mustache @@ -1,10 +1,12 @@ -<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"> +<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>provider</artifactId> <packaging>jar</packaging> @@ -28,99 +30,96 @@ </dependencyManagement> <dependencies> - <dependency> <groupId>{{groupId}}</groupId> <artifactId>model</artifactId> <version>${project.version}</version> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-bizkeeper</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-loadbalance</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>transport-highway</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>transport-rest-vertx</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-flowcontrol-qps</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>provider-pojo</artifactId> </dependency> - <!--log4j2--> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> - </dependencies> - <!--for package and deploy--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.6</version> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <classpathPrefix>lib/</classpathPrefix> - <!--change to your main class--> - <mainClass>${package}.Application</mainClass> - </manifest> - <manifestEntries> - <Class-Path>. </Class-Path> - </manifestEntries> - </archive> + <source>1.8</source> + <target>1.8</target> </configuration> </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> + <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>${package}.Application</mainClass> + <outputDirectory>target/bin</outputDirectory> + </configuration> <executions> <execution> - <id>copy-dependencies</id> - <phase>package</phase> <goals> - <goal>copy-dependencies</goal> + <goal>repackage</goal> </goals> - <configuration> - <outputDirectory>target/lib</outputDirectory> - </configuration> </execution> </executions> </plugin> - <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> - </plugins> </build> diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/Application.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/Application.mustache index 2184ccb..0cf7ff0 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/Application.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/Application.mustache @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class Application { public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "notExistJustForceLocal"); SpringApplication.run(Application.class, args); } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api.mustache index 33f5a4b..486641c 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api.mustache @@ -1,10 +1,12 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - +import static org.springframework.http.MediaType.*; +import java.util.List; +import java.util.Map; {{#imports}}import {{import}}; {{/imports}} - +import {{modelPackage}}.*; +import org.apache.servicecomb.provider.rest.common.RestSchema; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -15,10 +17,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -import org.apache.servicecomb.provider.rest.common.RestSchema; -import java.util.List; -import java.util.Map; -import static org.springframework.http.MediaType.*; @RestSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}") @RequestMapping(value = "/", produces = {APPLICATION_JSON_VALUE}) @@ -26,6 +24,5 @@ import static org.springframework.http.MediaType.*; public class {{classname}} { {{>operationMethod}} - } {{/operations}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api_test.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api_test.mustache deleted file mode 100755 index d0444c2..0000000 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/api_test.mustache +++ /dev/null @@ -1,38 +0,0 @@ -package {{package}}; -{{#imports}}import {{import}}; -{{/imports}} -import java.util.*; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class {{classname}}Test { -@Autowired -private {{classname}} api; -{{#operations}} - {{#operation}} - @Test - public void {{operationId}}Test() throws Exception { - {{#allParams}} - {{^isFile}} - {{{dataType}}} {{paramName}} = {{{example}}}; - {{/isFile}} - {{#isFile}} - org.springframework.web.multipart.MultipartFile {{paramName}} = null; - {{/isFile}} - {{/allParams}} - ResponseEntity<{{>returnTypes}}> responseEntity = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); - } - {{/operation}} -{{/operations}} -} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/formParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/formParams.mustache index 336c14d..794cbfe 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/formParams.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/formParams.mustache @@ -1,2 +1 @@ -{{#isFormParam}}{{#notFile}} -@RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@RequestPart("file") MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{#notFile}}@RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@RequestPart("file") MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ 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 18b598c..948212d 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/operationMethod.mustache @@ -1,13 +1,8 @@ {{#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 - @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 some magic! - return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); + return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); } - {{/operation}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/pom.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/pom.mustache index 3c487c7..23571ee 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringBoot/pom.mustache @@ -1,18 +1,20 @@ -<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"> +<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>provider</artifactId> <packaging>jar</packaging> <name>provider</name> <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> </properties> <dependencyManagement> @@ -28,12 +30,12 @@ </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> @@ -48,77 +50,72 @@ <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> - <!--for package and deploy--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.6</version> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <classpathPrefix>lib/</classpathPrefix> - <!--change to your main class--> - <mainClass>${package}.Application</mainClass> - </manifest> - <manifestEntries> - <Class-Path>. </Class-Path> - </manifestEntries> - </archive> + <source>1.8</source> + <target>1.8</target> </configuration> </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> + <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>${package}.Application</mainClass> + <outputDirectory>target/bin</outputDirectory> + </configuration> <executions> <execution> - <id>copy-dependencies</id> - <phase>package</phase> <goals> - <goal>copy-dependencies</goal> + <goal>repackage</goal> </goals> - <configuration> - <outputDirectory>target/lib</outputDirectory> - </configuration> </execution> </executions> </plugin> - <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> - </plugins> </build> diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache index fda8d43..7fb2d98 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/Application.mustache @@ -5,7 +5,6 @@ import org.apache.servicecomb.foundation.common.utils.BeanUtils; public class Application { public static void main(String[] args) throws Exception { - System.setProperty("local.registry.file", "notExistJustForceLocal"); BeanUtils.init(); } } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache index 5ef2b31..49ef6aa 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api.mustache @@ -1,10 +1,12 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - +import static org.springframework.http.MediaType.*; +import java.util.List; +import java.util.Map; {{#imports}}import {{import}}; {{/imports}} - +import {{modelPackage}}.*; +import org.apache.servicecomb.provider.rest.common.RestSchema; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -15,28 +17,19 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -import org.apache.servicecomb.provider.rest.common.RestSchema; -import java.util.List; -import java.util.Map; -import static org.springframework.http.MediaType.*; @RestSchema(schemaId = "{{#camelcase}}{{classname}}{{/camelcase}}") @RequestMapping(value = "/", produces = {APPLICATION_JSON_VALUE}) - {{#operations}} public class {{classname}} { - {{#operation}} +{{#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 - return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); - } + @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 - {{/operation}} + return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); + } +{{/operation}} } {{/operations}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache deleted file mode 100755 index 3a7bed4..0000000 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/api_test.mustache +++ /dev/null @@ -1,103 +0,0 @@ -package {{package}}; - -{{#imports}}import {{import}}; -{{/imports}} -import java.util.*; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.junit.Assert.assertEquals; - -public class {{classname}}ContractTest { - @Autowired - private {{classname}} api; - - private static final String NAME_LARRY_JSON = "{\"name\": \"larry\"}"; - - @Rule - public TestFailureProviderRule mockTestProvider = new TestFailureProviderRule("{{#camelcase}}{{classname}}{{/camelcase}}Provider", this); - - @Pact(provider="{{#camelcase}}{{classname}}{{/camelcase}}Provider", consumer="{{#camelcase}}{{classname}}{{/camelcase}}Consumer") - public RequestResponsePact createFragment(PactDslWithProvider builder) { - -{{#operations}} - {{#operation}} - {{#hasHeaderParams}} - Map<String, String> {{operationId}}RequestHeaders = new HashMap<String, String>(); - {{/hasHeaderParams}} - {{/operation}} -{{/operations}} -{{#operations}} - {{#operation}} - {{#responseHeaders}} - Map<String, String> {{operationId}}ResponseHeaders = new HashMap<String, String>(); - {{/responseHeaders}} - {{/operation}} -{{/operations}} - - return builder -{{#operations}} - {{#operation}} - .uponReceiving("{{summary}}") - .path("{{path}}") - .method("{{httpMethod}}") - {{#hasHeaderParams}} - .headers({{operationId}}RequestHeaders) - {{/hasHeaderParams}} - .willRespondWith() - .status(200) - {{#responseHeaders}} - .headers({{operationId}}ResponseHeaders) - {{/responseHeaders}} - .body("{\"responsetest\": true, \"name\": \"harry\"}") - {{/operation}} -{{/operations}} - .toPact(); - } - - - @Test - @PactVerification({"{{#camelcase}}{{classname}}{{/camelcase}}Provider"}) - public void allPass() throws IOException { - mockTestProvider.validateResultWith((result, t) -> { - assertThat(t, is(nullValue())); - assertThat(result, is(PactVerificationResult.Ok.INSTANCE)); - }); - doTest("/", NAME_LARRY_JSON); - } - - private void doTest(String path, String json) throws IOException { - Consumer consumer = new Consumer(mockTestProvider.getUrl()); - consumer.options("/second"); - try { - consumer.getAsMap(path, ""); - } catch (IOException e) { - } - try { - new Consumer(mockTestProvider2.getUrl()).putAsMap("/", json); - } catch (IOException e) { - } - } - -/* - @Test - public void {{operationId}}Test() throws Exception { - {{#allParams}} - {{^isFile}} - {{{dataType}}} {{paramName}} = {{{example}}}; - {{/isFile}} - {{#isFile}} - org.springframework.web.multipart.MultipartFile {{paramName}} = null; - {{/isFile}} - {{/allParams}} - ResponseEntity<{{>returnTypes}}> responseEntity = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); - } -*/ -} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache index 336c14d..794cbfe 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/formParams.mustache @@ -1,2 +1 @@ -{{#isFormParam}}{{#notFile}} -@RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@RequestPart("file") MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{#notFile}}@RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@RequestPart("file") MultipartFile {{baseName}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache index c0a4aad..ea04f8c 100755 --- a/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/libraries/SpringMVC/pom.mustache @@ -1,22 +1,23 @@ -<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"> +<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>provider</artifactId> <packaging>jar</packaging> <name>{{artifactId}}</name> <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> </properties> <dependencies> - <dependency> <groupId>{{groupId}}</groupId> <artifactId>model</artifactId> @@ -27,76 +28,71 @@ <groupId>org.apache.servicecomb</groupId> <artifactId>transport-rest-vertx</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>transport-highway</artifactId> </dependency> + <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>provider-springmvc</artifactId> </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> - </dependencies> - <!--for package and deploy--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.6</version> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <classpathPrefix>lib/</classpathPrefix> - <!--change to your main class--> - <mainClass>${package}.Application</mainClass> - </manifest> - <manifestEntries> - <Class-Path>. </Class-Path> - </manifestEntries> - </archive> + <source>1.8</source> + <target>1.8</target> </configuration> </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> + <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>${package}.Application</mainClass> + <outputDirectory>target/bin</outputDirectory> + </configuration> <executions> <execution> - <id>copy-dependencies</id> - <phase>package</phase> <goals> - <goal>copy-dependencies</goal> + <goal>repackage</goal> </goals> - <configuration> - <outputDirectory>target/lib</outputDirectory> - </configuration> </execution> </executions> </plugin> - <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> - </plugins> </build> diff --git a/code-generator/src/main/resources/ServiceComb/model/model.mustache b/code-generator/src/main/resources/ServiceComb/model/model.mustache index 1923ac6..4ea9d7a 100755 --- a/code-generator/src/main/resources/ServiceComb/model/model.mustache +++ b/code-generator/src/main/resources/ServiceComb/model/model.mustache @@ -1,16 +1,7 @@ package {{package}}; -import java.util.Objects; {{#imports}}import {{import}}; {{/imports}} -{{#serializableModel}} -import java.io.Serializable; -{{/serializableModel}} -{{#useBeanValidation}} -import org.springframework.validation.annotation.Validated; -import javax.validation.Valid; -import javax.validation.constraints.*; -{{/useBeanValidation}} {{#withXml}} import javax.xml.bind.annotation.*; {{/withXml}} diff --git a/code-generator/src/main/resources/ServiceComb/model/pom.mustache b/code-generator/src/main/resources/ServiceComb/model/pom.mustache index d52c176..15086b9 100755 --- a/code-generator/src/main/resources/ServiceComb/model/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/model/pom.mustache @@ -1,27 +1,29 @@ -<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"> +<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>model</artifactId> <packaging>jar</packaging> <name>{{artifactId}}</name> <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> </properties> <dependencies> - {{^isPOJO}} - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - </dependency> - {{/isPOJO}} + {{^isPOJO}} + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + </dependency> + {{/isPOJO}} </dependencies> <build> diff --git a/code-generator/src/main/resources/ServiceComb/pojo.mustache b/code-generator/src/main/resources/ServiceComb/pojo.mustache index ee0aca9..1bf2369 100755 --- a/code-generator/src/main/resources/ServiceComb/pojo.mustache +++ b/code-generator/src/main/resources/ServiceComb/pojo.mustache @@ -1,26 +1,23 @@ -/** - * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} - */ {{#useBeanValidation}}@Validated{{/useBeanValidation}} {{#discriminator}}{{/discriminator}} public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { -{{#serializableModel}} + {{#serializableModel}} private static final long serialVersionUID = 1L; + {{/serializableModel}} -{{/serializableModel}} {{#vars}} - {{#isEnum}} - {{^isContainer}} -{{>enumClass}} - {{/isContainer}} - {{/isEnum}} - {{#items.isEnum}} - {{#items}} - {{^isContainer}} -{{>enumClass}} - {{/isContainer}} - {{/items}} - {{/items.isEnum}} + {{#isEnum}} + {{^isContainer}} + {{>enumClass}} + {{/isContainer}} + {{/isEnum}} + {{#items.isEnum}} + {{#items}} + {{^isContainer}} + {{>enumClass}} + {{/isContainer}} + {{/items}} + {{/items.isEnum}} {{#gson}} @SerializedName("{{baseName}}") {{/gson}} @@ -31,104 +28,50 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{^isContainer}} private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}}; {{/isContainer}} - {{/vars}} + {{#vars}} public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}; return this; } - {{#isListContainer}} + {{#isListContainer}} public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { - {{^required}} + {{^required}} if (this.{{name}} == null) { this.{{name}} = {{{defaultValue}}}; } - {{/required}} + {{/required}} this.{{name}}.add({{name}}Item); return this; } {{/isListContainer}} - {{#isMapContainer}} + {{#isMapContainer}} public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { - {{^required}} + {{^required}} if (this.{{name}} == null) { this.{{name}} = {{{defaultValue}}}; } - {{/required}} + {{/required}} this.{{name}}.put(key, {{name}}Item); return this; } {{/isMapContainer}} - /** - {{#description}} - * {{{description}}} - {{/description}} - {{^description}} - * Get {{name}} - {{/description}} - {{#minimum}} - * minimum: {{minimum}} - {{/minimum}} - {{#maximum}} - * maximum: {{maximum}} - {{/maximum}} - * @return {{name}} - **/ - {{#vendorExtensions.extraAnnotation}} + {{#vendorExtensions.extraAnnotation}} {{{vendorExtensions.extraAnnotation}}} {{/vendorExtensions.extraAnnotation}} -{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{#isBoolean}}is{{/isBoolean}}{{getter}}() { + {{#useBeanValidation}} + {{>beanValidation}} + {{/useBeanValidation}} + public {{{datatypeWithEnum}}} {{#isBoolean}}is{{/isBoolean}}{{getter}}() { return {{name}}; } public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}; } - - {{/vars}} - - @Override - public boolean equals(java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - }{{#hasVars}} - {{classname}} {{classVarName}} = ({{classname}}) o; - return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} && - {{/hasMore}}{{/vars}}{{#parent}} && - super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}} - return true;{{/hasVars}} - } - - @Override - public int hashCode() { - return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class {{classname}} {\n"); - {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} - {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); - {{/vars}}sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(java.lang.Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } +{{/vars}} } \ No newline at end of file diff --git a/code-generator/src/main/resources/ServiceComb/project/pom.mustache b/code-generator/src/main/resources/ServiceComb/project/pom.mustache index bca8ce9..b1acd44 100755 --- a/code-generator/src/main/resources/ServiceComb/project/pom.mustache +++ b/code-generator/src/main/resources/ServiceComb/project/pom.mustache @@ -1,63 +1,43 @@ -<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"> - <modelVersion>4.0.0</modelVersion> - <groupId>{{groupId}}</groupId> - <artifactId>{{artifactId}}</artifactId> - <packaging>pom</packaging> - <name>{{artifactId}}</name> - <version>{{artifactVersion}}</version> +<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"> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java-chassis.version>1.2.0</java-chassis.version> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <java.version>1.8</java.version> - </properties> + <modelVersion>4.0.0</modelVersion> + <groupId>{{groupId}}</groupId> + <artifactId>{{artifactId}}</artifactId> + <packaging>pom</packaging> + <name>{{artifactId}}</name> + <version>{{artifactVersion}}</version> - <modules> - <module>provider</module> - <module>consumer</module> - <module>model</module> - </modules> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <java-chassis.version>1.2.0</java-chassis.version> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.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> + <modules> + <module>provider</module> + <module>consumer</module> + <module>model</module> + </modules> + <dependencyManagement> <dependencies> - <dependency> - <groupId>org.hibernate.validator</groupId> - <artifactId>hibernate-validator</artifactId> - </dependency> + <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>org.hibernate.validator</groupId> + <artifactId>hibernate-validator</artifactId> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <version>0.13</version> - <configuration> - <excludes> - <exclude>.travis.yml</exclude> - <exclude>**/*.md</exclude> - <exclude>**/target/*</exclude> - <!-- Skip the ssl configuration files --> - <exculde>**/resources/ssl/**</exculde> - <!-- Skip the protobuf files --> - <exclude>**/*.proto</exclude> - <!-- Skip the idl files --> - <exclude>**/*.idl</exclude> - </excludes> - </configuration> - </plugin> - </plugins> - </build> </project> \ No newline at end of file diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/ImmediateClassLoader.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/ImmediateClassLoader.java index 08ccced..5e939e5 100755 --- a/common/src/main/java/org/apache/servicecomb/toolkit/common/ImmediateClassLoader.java +++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/ImmediateClassLoader.java @@ -17,13 +17,13 @@ package org.apache.servicecomb.toolkit.common; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ImmediateClassLoader extends URLClassLoader { private final static Logger LOGGER = LoggerFactory.getLogger(ImmediateClassLoader.class); diff --git a/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java b/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java old mode 100644 new mode 100755 index 14df512..c8236ab --- a/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java +++ b/common/src/test/java/org/apache/servicecomb/toolkit/common/TextCompareTest.java @@ -1,8 +1,10 @@ package org.apache.servicecomb.toolkit.common; -import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -13,20 +15,20 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.*; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; public class TextCompareTest { Path sourcePath = Paths.get("./src/test/resources/compare/HelloEndPoint.yaml"); + Path destPath = Paths.get("./src/test/resources/compare/HelloEndPoint2.yaml"); @Test public void contractCompareText() throws IOException { ContractComparator contractComparator = new ContractComparator(new String(Files.readAllBytes(sourcePath)), - new String(Files.readAllBytes(destPath))); + new String(Files.readAllBytes(destPath))); assertEquals(MyersAlgorithm.class, contractComparator.getAlgorithm().getClass()); List<Comparison> comparisonList = contractComparator.compare(); @@ -37,7 +39,7 @@ public class TextCompareTest { @Test public void contractCompareResultPrint() throws IOException { ContractComparator contractComparator = new ContractComparator(new String(Files.readAllBytes(sourcePath)), - new String(Files.readAllBytes(destPath))); + new String(Files.readAllBytes(destPath))); assertEquals(MyersAlgorithm.class, contractComparator.getAlgorithm().getClass()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); @@ -79,7 +81,7 @@ public class TextCompareTest { }); ContractComparator contractComparator = new ContractComparator("source line", - "destination line", oneLineAlgorithm); + "destination line", oneLineAlgorithm); ByteArrayOutputStream bout = new ByteArrayOutputStream(); contractComparator.splitPrint(bout); @@ -88,10 +90,9 @@ public class TextCompareTest { bout = new ByteArrayOutputStream(); contractComparator = new ContractComparator("source line", - "source line", oneLineAlgorithm); + "source line", oneLineAlgorithm); contractComparator.splitPrint(bout); - assertEquals(ComparisionType.EQUAL , contractComparator.compare().get(0).type); - + assertEquals(ComparisionType.EQUAL, contractComparator.compare().get(0).type); } private boolean hasNewLine(String s) { @@ -104,13 +105,11 @@ public class TextCompareTest { try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { ContractComparator contractComparator = new ContractComparator(null, - new String(Files.readAllBytes(destPath))); + new String(Files.readAllBytes(destPath))); assertEquals(MyersAlgorithm.class, contractComparator.getAlgorithm().getClass()); contractComparator.splitPrint(bout); - } catch (RuntimeException e) { assertEquals("source must not be null", e.getMessage()); } - } } diff --git a/doc-generator/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java b/doc-generator/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java index 5a27171..f39cd22 100755 --- a/doc-generator/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java +++ b/doc-generator/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java @@ -28,11 +28,12 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.swagger.models.Swagger; -import io.swagger.util.Json; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.swagger.models.Swagger; +import io.swagger.util.Json; + public class ContractsSwaggerUIGenerator implements DocGenerator { private final static Logger LOGGER = LoggerFactory.getLogger(ContractsSwaggerUIGenerator.class); diff --git a/doc-generator/src/test/java/docgen/DocGeneratorTest.java b/doc-generator/src/test/java/docgen/DocGeneratorTest.java old mode 100644 new mode 100755 index 0ca5bc9..2fe24b9 --- a/doc-generator/src/test/java/docgen/DocGeneratorTest.java +++ b/doc-generator/src/test/java/docgen/DocGeneratorTest.java @@ -1,12 +1,5 @@ package docgen; -import io.swagger.models.Swagger; -import io.swagger.parser.Swagger20Parser; -import org.apache.commons.io.FileUtils; -import org.apache.servicecomb.toolkit.docgen.DocGeneratorManager; -import org.junit.Assert; -import org.junit.Test; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -14,83 +7,90 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -public class DocGeneratorTest { - +import org.apache.commons.io.FileUtils; +import org.apache.servicecomb.toolkit.docgen.DocGeneratorManager; +import org.junit.Assert; +import org.junit.Test; - @Test - public void contractToAsciidoc() throws IOException { +import io.swagger.models.Swagger; +import io.swagger.parser.Swagger20Parser; - Swagger20Parser swagger20Parser = new Swagger20Parser(); - InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); +public class DocGeneratorTest { - StringBuilder sb = new StringBuilder(); - byte[] bytes = new byte[1024]; - int len = -1; - while ((len = in.read(bytes)) != -1){ - sb.append(new String(bytes,0,len)); - } - Swagger swagger = swagger20Parser.parse(sb.toString()); - Path tempDir = Files.createTempDirectory(null); - Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() - + File.separator + "asciidoc.html"); + @Test + public void contractToAsciidoc() throws IOException { - DocGeneratorManager.generate(swagger,outputPath.toFile().getCanonicalPath() , "asciidoc-html"); + Swagger20Parser swagger20Parser = new Swagger20Parser(); + InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); - Assert.assertTrue(Files.exists(outputPath)); - FileUtils.deleteDirectory(tempDir.toFile()); + StringBuilder sb = new StringBuilder(); + byte[] bytes = new byte[1024]; + int len = -1; + while ((len = in.read(bytes)) != -1) { + sb.append(new String(bytes, 0, len)); } - @Test - public void contractTransferToSwaggerUI() throws IOException { + Swagger swagger = swagger20Parser.parse(sb.toString()); + Path tempDir = Files.createTempDirectory(null); + Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() + + File.separator + "asciidoc.html"); - Swagger20Parser swagger20Parser = new Swagger20Parser(); + DocGeneratorManager.generate(swagger, outputPath.toFile().getCanonicalPath(), "asciidoc-html"); - InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); + Assert.assertTrue(Files.exists(outputPath)); + FileUtils.deleteDirectory(tempDir.toFile()); + } - StringBuilder sb = new StringBuilder(); - byte[] bytes = new byte[1024]; - int len = -1; - while ((len = in.read(bytes)) != -1) { - sb.append(new String(bytes, 0, len)); - } + @Test + public void contractTransferToSwaggerUI() throws IOException { - Swagger swagger = swagger20Parser.parse(sb.toString()); + Swagger20Parser swagger20Parser = new Swagger20Parser(); - Path tempDir = Files.createTempDirectory(null); - Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() - + File.separator + "swagger-ui.html"); - DocGeneratorManager.generate(swagger,outputPath.toFile().getCanonicalPath() , "swagger-ui"); + InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); - Assert.assertTrue(Files.exists(outputPath)); - FileUtils.deleteDirectory(tempDir.toFile()); + StringBuilder sb = new StringBuilder(); + byte[] bytes = new byte[1024]; + int len = -1; + while ((len = in.read(bytes)) != -1) { + sb.append(new String(bytes, 0, len)); } - @Test - public void contractTransferToOther() throws IOException { + Swagger swagger = swagger20Parser.parse(sb.toString()); - Swagger20Parser swagger20Parser = new Swagger20Parser(); + Path tempDir = Files.createTempDirectory(null); + Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() + + File.separator + "swagger-ui.html"); + DocGeneratorManager.generate(swagger, outputPath.toFile().getCanonicalPath(), "swagger-ui"); - InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); + Assert.assertTrue(Files.exists(outputPath)); + FileUtils.deleteDirectory(tempDir.toFile()); + } - StringBuilder sb = new StringBuilder(); - byte[] bytes = new byte[1024]; - int len = -1; - while ((len = in.read(bytes)) != -1) { - sb.append(new String(bytes, 0, len)); - } + @Test + public void contractTransferToOther() throws IOException { - Swagger swagger = swagger20Parser.parse(sb.toString()); + Swagger20Parser swagger20Parser = new Swagger20Parser(); - Path tempDir = Files.createTempDirectory(null); - Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() - + File.separator + "swagger-ui.html"); + InputStream in = DocGeneratorTest.class.getClassLoader().getResourceAsStream("HelloEndPoint.yaml"); - DocGeneratorManager.generate(swagger, outputPath.toFile().getCanonicalPath(), "other"); + StringBuilder sb = new StringBuilder(); + byte[] bytes = new byte[1024]; + int len = -1; + while ((len = in.read(bytes)) != -1) { + sb.append(new String(bytes, 0, len)); + } - Assert.assertFalse(Files.exists(outputPath)); + Swagger swagger = swagger20Parser.parse(sb.toString()); - FileUtils.deleteDirectory(tempDir.toFile()); - } + Path tempDir = Files.createTempDirectory(null); + Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath() + + File.separator + "swagger-ui.html"); + + DocGeneratorManager.generate(swagger, outputPath.toFile().getCanonicalPath(), "other"); + + Assert.assertFalse(Files.exists(outputPath)); + FileUtils.deleteDirectory(tempDir.toFile()); + } } diff --git a/toolkit-cli/pom.xml b/toolkit-cli/pom.xml index 73de4b3..295ad61 100755 --- a/toolkit-cli/pom.xml +++ b/toolkit-cli/pom.xml @@ -30,6 +30,7 @@ <properties> <main.class>org.apache.servicecomb.toolkit.cli.ToolkitMain</main.class> + <log4j2.version>2.11.0</log4j2.version> </properties> <dependencies> @@ -57,6 +58,24 @@ <artifactId>doc-generator</artifactId> <version>${project.version}</version> </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>${log4j2.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>${log4j2.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>${log4j2.version}</version> + </dependency> </dependencies> <build> @@ -98,12 +117,5 @@ </executions> </plugin> </plugins> - - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - </resource> - </resources> </build> </project> diff --git a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java index 49f99d1..df01175 100755 --- a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java +++ b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/CodeGenerate.java @@ -29,12 +29,12 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import org.apache.servicecomb.toolkit.codegen.DefaultCodeGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.airlift.airline.Command; import io.airlift.airline.Option; import io.swagger.codegen.config.CodegenConfigurator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Command(name = "codegenerate", description = "Generate multiple models of microservice project by OpenAPI specification file") @@ -96,18 +96,25 @@ public class CodeGenerate implements Runnable { configurator.setInputSpec(file.toFile().getCanonicalPath()) .addAdditionalProperty("apiName", file.toFile().getName().split("\\.")[0]); - new DefaultCodeGenerator().opts(configurator).generate(); + try { + new DefaultCodeGenerator().opts(configurator).generate(); + } catch (RuntimeException e) { + throw new RuntimeException("Failed to generate code base on file " + file.toFile().getName()); + } return super.visitFile(file, attrs); } }); - } catch (IOException e) { + } catch (RuntimeException | IOException e) { LOGGER.error(e.getMessage()); + return; } } else { configurator.setInputSpec(specFile); new DefaultCodeGenerator().opts(configurator).generate(); } + + LOGGER.info("Success to generate code, the directory is: {}", output); } } } diff --git a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java index 988389a..ca007d6 100755 --- a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java +++ b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java @@ -27,13 +27,14 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import org.apache.servicecomb.toolkit.docgen.DocGeneratorManager; +import org.apache.commons.lang3.StringUtils; import org.apache.servicecomb.swagger.SwaggerUtils; +import org.apache.servicecomb.toolkit.docgen.DocGeneratorManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.airlift.airline.Command; import io.airlift.airline.Option; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Command(name = "docgenerate", description = "Generate document by OpenAPI specification file") public class DocGenerate implements Runnable { @@ -59,30 +60,48 @@ public class DocGenerate implements Runnable { try { Path specPath = Paths.get(specFile); + String[] retValues = new String[1]; + String[] fileName = new String[1]; + if (Files.isDirectory(specPath)) { Files.walkFileTree(specPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - DocGeneratorManager.generate(SwaggerUtils.parseSwagger(file.toUri().toURL()), + retValues[0] = DocGeneratorManager.generate(SwaggerUtils.parseSwagger(file.toUri().toURL()), output + File.separator + file.toFile().getName().substring(0, file.toFile().getName().indexOf(".")), format); + if (StringUtils.isEmpty(retValues[0])) { + fileName[0] = file.toFile().getName(); + return FileVisitResult.TERMINATE; + } + return super.visitFile(file, attrs); } }); } else if (Files.isRegularFile(specPath)) { + fileName[0] = specPath.toFile().getName(); - DocGeneratorManager.generate(SwaggerUtils.parseSwagger(specPath.toUri().toURL()), + retValues[0] = DocGeneratorManager.generate(SwaggerUtils.parseSwagger(specPath.toUri().toURL()), output + File.separator + new File(specFile).getName() .substring(0, new File(specFile).getName().indexOf(".")), format); } else { - DocGeneratorManager.generate(SwaggerUtils.parseSwagger(URI.create(specFile).toURL()), + fileName[0] = specFile; + + retValues[0] = DocGeneratorManager.generate(SwaggerUtils.parseSwagger(URI.create(specFile).toURL()), output + File.separator + new File(specFile).getName() .substring(0, new File(specFile).getName().indexOf(".")), format); } + + if (StringUtils.isEmpty(retValues[0])) { + LOGGER.error("Failed to generate document base on file {}", fileName[0]); + return; + } + + LOGGER.info("Success to generate document, the directory is: {}", output); } catch (IOException e) { LOGGER.error(e.getMessage()); } diff --git a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java index 7d0f10b..b5da899 100755 --- a/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java +++ b/toolkit-cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java @@ -35,7 +35,7 @@ public class ToolkitMain { Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("java -jar toolkit-cli-" + projectVersion + ".jar"); builder.withDescription("Microservice development toolkit(version " + projectVersion - + "). More info on https://github.com/MabinGo/toolkit"); + + "). "); builder.withDefaultCommand(Help.class); builder.withCommands(CodeGenerate.class, DocGenerate.class, Help.class); Runnable cmd = builder.build().parse(args); diff --git a/toolkit-cli/src/main/resources/log4j2.xml b/toolkit-cli/src/main/resources/log4j2.xml new file mode 100755 index 0000000..03ca678 --- /dev/null +++ b/toolkit-cli/src/main/resources/log4j2.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<!--this is sample configuration, please modify as your wish--> + +<configuration> + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%m%n"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="Console"/> + </Root> + <Logger name="io.swagger" additivity="false" level="error"> + <AppenderRef ref="Console"/> + </Logger> + </Loggers> +</configuration> \ No newline at end of file diff --git a/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java b/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java index 647be5c..5924444 100755 --- a/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java +++ b/toolkit-cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java @@ -31,7 +31,7 @@ public class CliTest { @Test public void generateServiceCombCodeFromSingleContract() throws IOException { - String[] programModels = new String[] {"SpringMVC","POJO","JAX-RS","SpringBoot"}; + String[] programModels = new String[] {"SpringMVC", "POJO", "JAX-RS", "SpringBoot"}; Path tempDir = Files.createTempDirectory(null); Arrays.stream(programModels).forEach(model -> { try { diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java old mode 100644 new mode 100755 index 1fa05c4..1734236 --- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java +++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java @@ -1,5 +1,14 @@ package plugin; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import org.apache.maven.plugin.testing.MojoRule; import org.apache.maven.plugin.testing.resources.TestResources; import org.apache.maven.project.MavenProject; @@ -7,15 +16,6 @@ import org.apache.servicecomb.toolkit.plugin.GenerateContractsDocMojo; import org.junit.Rule; import org.junit.Test; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; -import static org.mockito.Mockito.mock; - public class GenerateContractsDocMojoTest { @@ -46,8 +46,5 @@ public class GenerateContractsDocMojoTest { assertEquals(".yaml", this.rule.getVariableValueFromObject(generateContractsDocMojo, "format")); rule.executeMojo(project, PLUGIN_GOAL); generateContractsDocMojo.execute(); - } - - } diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java old mode 100644 new mode 100755 index df9d780..7472485 --- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java +++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java @@ -1,5 +1,15 @@ package plugin; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.testing.MojoRule; import org.apache.maven.plugin.testing.resources.TestResources; @@ -8,18 +18,6 @@ import org.apache.servicecomb.toolkit.plugin.GenerateContractsMojo; import org.junit.Rule; import org.junit.Test; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; -import static org.mockito.Mockito.mock; - public class GenerateContractsMojoTest { private static final String PLUGIN_GOAL = "generateContracts"; @@ -57,12 +55,12 @@ public class GenerateContractsMojoTest { rule.setVariableValueToObject(generateContractsMojo, "project", project); assertNotNull(this.rule.getVariableValueFromObject(generateContractsMojo, "project")); - assertEquals("target/test_output_contracts", this.rule.getVariableValueFromObject(generateContractsMojo, "outputDir")); + assertEquals("target/test_output_contracts", + this.rule.getVariableValueFromObject(generateContractsMojo, "outputDir")); assertEquals(".yaml", this.rule.getVariableValueFromObject(generateContractsMojo, "format")); generateContractsMojo.execute(); assertTrue(new File("target/test_output_contracts").exists()); } - } diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml b/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml old mode 100644 new mode 100755 index 9a71eb5..0be2ad0 --- a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml +++ b/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml @@ -14,33 +14,33 @@ --> <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"> + 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"> - <modelVersion>4.0.0</modelVersion> - <prerequisites> - <maven>3.0.3</maven> - </prerequisites> + <modelVersion>4.0.0</modelVersion> + <prerequisites> + <maven>3.0.3</maven> + </prerequisites> - <groupId>org.apache.servicecomb</groupId> - <artifactId>this-is-for-test-only</artifactId> - <version>0.1.0-SNAPSHOT</version> - <name>This is for Test ONLY</name> - <packaging>jar</packaging> + <groupId>org.apache.servicecomb</groupId> + <artifactId>this-is-for-test-only</artifactId> + <version>0.1.0-SNAPSHOT</version> + <name>This is for Test ONLY</name> + <packaging>jar</packaging> - <build> - <plugins> - <plugin> - <groupId>org.apache.servicecomb</groupId> - <artifactId>toolkit-maven-plugin</artifactId> - <version>${project.version}</version> - <extensions>true</extensions> - <configuration> - <outputDir>target/test_output_contracts</outputDir> - <format>.yaml</format> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.servicecomb</groupId> + <artifactId>toolkit-maven-plugin</artifactId> + <version>${project.version}</version> + <extensions>true</extensions> + <configuration> + <outputDir>target/test_output_contracts</outputDir> + <format>.yaml</format> + </configuration> + </plugin> + </plugins> + </build> </project> \ No newline at end of file diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml old mode 100644 new mode 100755 index 2b05bdf..34187b2 --- a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml +++ b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml @@ -14,33 +14,33 @@ --> <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"> + 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"> - <modelVersion>4.0.0</modelVersion> - <prerequisites> - <maven>3.0.3</maven> - </prerequisites> - <groupId>org.apache.servicecomb</groupId> - <artifactId>this-is-for-test-only</artifactId> - <version>1.0-SNAPSHOT</version> - <name>This is for Test ONLY</name> - <packaging>jar</packaging> + <modelVersion>4.0.0</modelVersion> + <prerequisites> + <maven>3.0.3</maven> + </prerequisites> + <groupId>org.apache.servicecomb</groupId> + <artifactId>this-is-for-test-only</artifactId> + <version>1.0-SNAPSHOT</version> + <name>This is for Test ONLY</name> + <packaging>jar</packaging> - <build> - <plugins> - <plugin> - <groupId>org.apache.servicecomb</groupId> - <artifactId>toolkit-maven-plugin</artifactId> - <version>${project.version}</version> - <extensions>true</extensions> - <configuration> - <outputDir>./target/plugin-test-output</outputDir> - <docOutputDir>./target/plugin-test-output</docOutputDir> - <format>.yaml</format> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.servicecomb</groupId> + <artifactId>toolkit-maven-plugin</artifactId> + <version>${project.version}</version> + <extensions>true</extensions> + <configuration> + <outputDir>./target/plugin-test-output</outputDir> + <docOutputDir>./target/plugin-test-output</docOutputDir> + <format>.yaml</format> + </configuration> + </plugin> + </plugins> + </build> </project> \ No newline at end of file