2 Star 5 Fork 6

Nepxion/Skeleton

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

Nepxion Skeleton

Total visits Total lines License Maven Central Javadocs Build Status Codacy Badge Stars Stars

           

Nepxion Skeleton是一款基于FreeMarker,支持对任何文本格式的代码和文件的生成器,可以轻松快速实现对框架代码的一键创建,支持多套脚手架系统在同一个脚手架服务下工作,并内置提供Docker化的基于Spring Cloud的脚手架一键生成

简介

  • 严格遵照Maven结构进行脚手架编排
  • 支持任何文件文件的逆向创建,包括Java类文件,配置文件,脚本文件,XML文件,YAML文件等
  • 使用者只需要关注模板原型文件的编辑(遵循FreeMarker语法),并设置动态变量
  • 使用者根据模板原型文件创建Generator类,进行动态创建和替换
  • 采用插件式部署方式,可以多个脚手架系统部署在同一个平台上,也可以一个平台部署一个脚手架系统,自由灵活,动态切换
  • 基于Spring Cloud的调用
  • 支持Docker化一键部署
  • 支持Swagger
  • 支持在线生成代码并下载

在线创建

  • 获取脚手架代码
    • 在浏览器里输入http://skeleton.springcloud.cn访问,填入相关参数,点“生成工程”,保存代码压缩包。解压后,可获取到脚手架代码
  • 代码运行
    • 在IDE里运行:导入IDE,即可运行,脚手架代码,代码执行顺序一般为EurekaApplication,ServerApplication,ClientApplication,如图1
    • 在Docker里运行:执行三个脚本,即可一键部署到Docker容器里,脚本执行顺序必须为install-eureka-docker,install-server-docker,install-client-docker,如图2
    • 提供Rpc和Rest两种测试(启动ClientApplication服务即可启动定时测试),提供正常调用和熔断调用场景(停止ServerApplication服务即可)
  • 组件集成
    • 集成Spring Cloud基础组件,包括Eureka,Ribbon,Feign,Hystrix等
    • 集成Swagger组件

图1

图2

图3

图4

图5

本地部署

服务端部署

客户端部署

二次开发

介绍

  • skeleton-engine是脚手架的生成引擎,不依赖Spring环境,你只需要在Java环境下可以对任何格式的文本文件进行模板化创建
  • skeleton-framework是基于Spring环境的脚手架框架,并抽象在Spring环境下的配置和行为
  • skeleton-service是脚手架的平台,是多个脚手架生成插件的汇集之处
  • skeleton-starter是脚手架的Starter
  • skeleton-plugin-springcloud是基于Spring Cloud的脚手架生成插件,您可以扩展出skeleton-plugin-dubbo,skeleton-plugin-motan等

图6

兼容

最新版本兼容

  • Spring 4.x.x和Spring Boot 1.x.x
  • Spring 5.x.x和Spring Boot 2.x.x

依赖

引擎包
<dependency>
    <groupId>com.nepxion</groupId>
    <artifactId>skeleton-engine</artifactId>
    <version>${skeleton.version}</version>
</dependency>

框架包
<dependency>
    <groupId>com.nepxion</groupId>
    <artifactId>skeleton-framework</artifactId>
    <version>${skeleton.version}</version>
</dependency>

启动包
<dependency>
    <groupId>com.nepxion</groupId>
    <artifactId>skeleton-starter</artifactId>
    <version>${skeleton.version}</version>
</dependency>

用法

@SpringBootApplication
@EnableSkeleton
@Import(SpringCloudPluginConfiguration.class)
public class SkeletonApplication {
}

配置

  • skeleton-data.properties,见skeleton-plugin-springcloud/src/main/resources/springcloud/config/skeleton-data.properties
    • 用来描述模板文件的全局配置值,里面的值替换模板文件里的动态变量(用${}表示),脚手架生成需要依赖这个文件
    • 配置文件中,“工程配置”下的productName和basePackage是必需的,其他字段可自己随便定义,建议驼峰形式命名
  • skeleton-description.xml,见skeleton-plugin-springcloud/src/main/resources/springcloud/config/skeleton-description.xml
    • 用来描述模界面驱动的数据结构,渲染和布局组件,它里面定义的组件里的value值则取值于skeleton-data.properties
    • 分为Group和Entity结构,一个Group包含多个Entity
  • skeleton-context.properties,见skeleton-plugin-springcloud/src/main/resources/springcloud/config/skeleton-context.properties
    • 用来配置脚手架全局上下文参数
  • 三个配置文件它的上级目录必须为config

规则

  • 一个Generator类对应一个template模板文件
  • 提供SkeletonFileGenerator和SkeletonJavaGenerator两种方式,前者可以生成任何类型的文本文件,后者因为Java文件相对比较特殊,所以做了一些封装
  • 模板文件(*.template)有如下两种放置方式
    • 模板文件resources/template目录下(模板文件所在的前置目录名必须设置为"template",在application.properties可以修改),目录结构参照第一张图片
    • Generator类和对应的模板文件必须放在同一个目录下(模板文件所在的前置目录名必须设置为null),目录结构参照第二张图片

插件

  • 如果多个脚手架系统部署在同一个平台上,需要采用独立工程的方式,同时避免同名类和同名配置文件冲突,规定如下,见图7

    • 工程名应该是xxx-plugin-[插件名]
    • 包名应该是xx.xx.xx...plugin.[插件名]
    • 配置文件目录应该是resources/[插件名],下面放config和template
    • 脚手架总入口(实现SkeletonService),上面加注解@SkeletonPlugin(name="[插件名]")
    • 上述四个插件名必须统一,在本项目中,我们知道插件名叫“springcloud”。按照这种规则,我们可以扩展出多个脚手架插件,例如skeleton-plugin-dubbo,skeleton-plugin-motan等
    • 插件名,将被SkeletonController接口中用到,见“Spring Cloud接口”章节
  • 如果一个脚手架系统部署在一个平台上,那么则没有那么多讲究,规定如下,见图8

    • 脚手架总入口(实现SkeletonService),上面加注解@SkeletonPlugin

图7

图8

示例

本地使用方式

运行skeleton-plugin-springcloud/src/test/java/com.nepxion.skeleton.plugin.springcloud.SkeletonTest.java,可在本地创建脚手架文件,具体使用方式,参考该类里的中文注释

Spring Cloud使用方式

Spring Cloud配置文件,见skeleton-service/src/main/resources/application.properties

Spring Cloud接口,见skeleton-framework/src/main/java/com.nepxion.skeleton.framework.controller.SkeletonController.java

  • 获取脚手架插件列表接口
@RequestMapping(value = "/getPlugins", method = RequestMethod.GET)
public List<String> getPlugins();
  • 获取默认界面驱动的元数据接口
@RequestMapping(value = "/getMetaData", method = RequestMethod.GET)
public List<SkeletonGroup> getMetaData();

返回JSON格式的文件,如下:

[
  {
    "key": "project", // 组所对应的唯一Key
    "label": "工程配置", // 组的标签
    "description": "工程配置", // 组的描述
    "type": "MIX_GROUP", // 组的类型,包括MIX_GROUP(默认,组里可以放任何种类的组件,混合组),CHECKBOX_GROUP(组里只能放CHECKBOX),RADIO_GROUP(组里只能放RADIO),COMBOBOX_GROUP(组里只能放COMBOBOX)
    "layout": "VERTICAL", // 组的布局,包括VERTICAL(默认,组里组件以垂直方向布局),HORIZONTAL(默认,组里组件以水平方向布局)
    "titledBorder": "true", // 是否需要显示组标题(默认显示)
    "entityList": [
      {
        "key": "productName", // 组件所对应的唯一Key
        "label": "产品名", // 组件的标签
        "description": "", // 组件的描述
        "note": "【必改项】首字母必须小写,中间只允许出现“-”", // 组件的使用提示
        "value": "sales", // 组件内容
        "type": "TEXTFIELD", // 组件类型,包括TEXTFIELD(默认),CHECKBOX,RADIO,COMBOBOX,EDITABLE_COMBOBOX
        "options": null, // 对应项如果是下来菜单(COMBOBOX,EDITABLE_COMBOBOX)方式的时候,里面的值列表,可以为null
        "highlightable": true, // 标识为高亮项,一般组件渲染成高亮方式,例如Label红色字体,提示使用者着重关注
        "defaultable": false, // 标识为默认项,一般组件渲染成默认项方式,提示使用者可以不修改对应值
        "emptiable": false, // 标识为留空项,一般组件渲染成留空项方式,提示使用者对应值可以为空
        "editable": true // 标识为不可编辑项,一般组件渲染成不可编辑项方式,如果false则把组件灰掉,提示使用者对应值不可编辑
      }
    ]
  }
]
  • 根据脚手架名称,获取对应的界面驱动的元数据接口。另一个不带skeletonName参数的接口,是默认获取方式,当脚手架非插件方式存在的时候,调用它。4. 5.的2个接口都存在这样的默认方式
@RequestMapping(value = "/getMetaData/{skeletonName}", method = RequestMethod.GET)
public List<SkeletonGroup> getMetaData(@PathVariable(value = "skeletonName") String skeletonName);
  • 根据脚手架名称,下载脚手架Zip文件的接口,返回Zip文件的byte数组类型,配置文件内容,可拷贝src/main/resources/config/skeleton-data.properties的内容
@RequestMapping(value = "/downloadBytes/{skeletonName}", method = RequestMethod.POST)
public byte[] downloadBytes(@PathVariable(value = "skeletonName") String skeletonName, @RequestBody String config);
  • 根据脚手架名称,下载脚手架Zip文件的接口,返回Zip文件的ResponseEntity类型,配置文件内容,可拷贝src/main/resources/config/skeleton-data.properties的内容
@RequestMapping(value = "/downloadResponse/{skeletonName}", method = RequestMethod.POST)
public ResponseEntity<Resource> downloadResponse(@PathVariable(value = "skeletonName") String skeletonName, @RequestBody String config);

请联系我

微信、钉钉、公众号和文档

Star走势图

Stargazers over time

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed 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.

About

🔨 Nepxion Skeleton is a generic codes and files generator based on freemaker for any text formats, and provides skeleton of Spring Cloud with docker deployment 基于Docker & Spring Cloud的代码和文件的脚手架生成平台 expand collapse
Java and 3 more languages
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/nepxion/Skeleton.git
git@gitee.com:nepxion/Skeleton.git
nepxion
Skeleton
Skeleton
master

Search

Dd8185d8 1850385 E526c682 1850385